<style>
.reveal .slides {
text-align: left;
}
</style>
## Project 2 - System Call & CPU Scheduling
---
### Part 1 - System call
---
### System Call (Cont.)
Implement a system call - Sleep()
* `userprog/syscall.h`
* Define a system call number of Sleep
* `test/start.s`
* Prepare registers for Sleep
* `userprog/exception.cc`
* Add a new case for Sleep in ExceptionHandler
* Note the use of `kernel->alarm->WaitUntil()`
---
### System Call (Cont.)
* Alarm - software alarm clock, that generates an interrupt every X time ticks
* `threads/alarm.h`
* The **WaitUntil()** will be called when a thread going to sleep.
* Call the **CallBack()** to check which thread should wake up.
* See the comments in the file, they are helpful.
* Don’t forget the useful data structure like list in the **lib** folder.
---
### System Call (Cont.)
* Write your own **test code** like test1 and test2
* Create `test.c` in `test/`
* Modify the Makefile in `test/`
* Compile in the same way as test1 and test2
---
### Part 2 - CPU Scheduling
RR, FCFS, SJF, Priority
---
### CPU Scheduling
Choose **at least one** of the following to implement (The extra implementation will be considered as BONUS) :
* First-Come-First-Service (FCFS)
* Shortest-Job-First (SJF)
* Priority
Design your own test code :
* Modify `Thread::SelfTest()` or create your method for testing.
---
### CPU Scheduling (Cont.)
Design **at least 2** test cases to proof your result
* Specify your algorithm in the report.
* Specify the test case setting and output in your report.
* Design the NachOS interface to switch different scheduling algorithm
* `threads/main.cc`
---
### Reference
* [The University of Chicago - Com Sci 230 System Calls and Other Exceptions](https://people.cs.uchicago.edu/~odonnell/OData/Courses/CS230/NACHOS/code-syscall.html)
* [Purdue University - CS 354 Thread Scheduling and Sleeping](https://web.ics.purdue.edu/~cs354/labs/lab3/)
---
### Report & Policy
Report contents, grading policy, late policy
---
### Report
1. **Motivation**
* Motivation and the problem analysis
* What’s your plan to deal with the problem
2. **Implementation**
* How do you implement to solve the problem in Nachos
* You can including some (not all) important code segments and comments
3. **Result**
* Experiment result and some discussion
* Extra effort or observation
---
### Grading Policy
* Nachos source code: (40%)
* Report: (40%)
* Correct format: (20%)
* <span style="color: red;">No plagiarism</span>
---
### Late Policy
* 10% penalty per day
* After 7 days, you will get 70% penalty, but no more penalty after that.
---
### Submission
---
Create a folder for the source code and report
```
{Student ID}_Nachos2/
|_ nachos-4.0/
|_ report.pdf
// Name the folder w/o curly braces, e.g. r07943154_Nachos2
```
Compress
```shell=
tar -zcvf {Student ID}_Nachos2.tar.gz ./{Student ID}_Nachos2
```
> **Your source code and report should be handed out by Ceiba**
---
###### tags: `Fall 2020 OS`
{"metaMigratedAt":"2023-06-15T15:01:39.443Z","metaMigratedFrom":"YAML","title":"Nachos Project 2 - System Call & CPU Scheduling","breaks":true,"slideOptions":"{\"theme\":\"sky\",\"transition\":\"fade\",\"spotlight\":{\"enabled\":false}}","contributors":"[{\"id\":\"db1bbfb1-bf49-4f62-8368-01fe50a4bb3c\",\"add\":3392,\"del\":0}]"}