View
2
Download
0
Category
Preview:
Citation preview
Nachos Project Assignment 2System Call & CPU scheduling
TA: Chien-Wen, Huang.
Advisor: Farn, Wang.
2015/11/18
Outline
• Part 1. System Call• Sleep
• Part 2. CPU Scheduling• FCFS
• SJF
• Priority
• Report
• Grading Policy & Late Policy
• Reference
If you still have trouble to install Nachos
• make Error 127?• https://code.google.com/p/damody/downloads/detail?name=mips-
decstation.linux-xgcc.gz
• In fact, I have sent a mail about this problem at Oct.29.
• Make Error: cast from ‘void (*)()’ to ‘int’ lose precision.• Use 32-bits machine!
• Other Problem?
Part 1. System CallSleep
Part 1. System call – Sleep()
• 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()
• You can try implement some other kinds of system call.• Might be considered as bonus!
System call:start.s
• Assembly language assist to make system calls to the Nachos kernel
• http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html• Take System call PrintInt as an example
.globl PrintInt
.ent PrintInt
PrintInt:
addiu $2,$0,SC_ PrintInt
// put system call number in register 2
syscall
/* all parameter of this system call will be stored in register4, 5, 6, and 7 by MIPS machine automatically. */
.end PrintInt
Part 1. System call – Sleep()
• /code/threads/alarm.h
• /code/threads/alarm.cc
• 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.
Part 1. System call – Sleep()
• Q: How to write my own test code like test1 and test2?
• A: Write them in the same way as other test code.
• Take a test code named “test” as an example:• Create test.c in code/test/
• Modify the Makefile in code/test/
• In the same way as test1 and test2
• Type “make” in code/test/
Part 2. CPU SchedulingFCFS, SJF, Priority.
Part 2. CPU Scheduling
• Choose at least ONE of the following to implement:• First-Come-First-Service(FCFS)
• Shortest-Job-First(SJF)
• Priority
• Otherwise
• The extra implementation will be considered as BONUS.
• Design your own test code:• You can find Class::SelfTest() in many classes.
• Implement some test code, and call it in SelfTest().
Example. Non-preemptive shortest job first scheduler• Nachos default scheduler: Round Robin
• Shortest job first
• n+1 = tn + (1- )n
• n time of the nth predicate CPU burst
• tn time of the nth actual CPU burst
Example. Non-preemptive shortest job first scheduler• thread/alarm.cc, thread/alarm.h
• Implement WaitUntil(int x) to handle sleep(int t)
• Add a class to management the threads which are sleeping
Begin Running
Invoke Sleep(x)
Per timer interrupt:1.Record actual CPU burst2.Wake up time up threads
1.Set next predicted CPU burst2.Insert this thread to Sleeping thread lists3.Invoke thread->Sleep
Part 2. CPU Scheduling
• Only FCFS, SJF, priority available?• You can choose any scheduling algorithm from lecture.
• Specify your algorithm in the report.
• Design at least 2 test case to proof your result• Specify the test case setting and plot that screenshot in your report.
• Design the nachos interface to switch different scheduling algorithm if you implement more than one.
Some files that might useful.
• To change the program interface:• threads/main.cc
• To make your own SelfTest() function:• threads/thread.h
• threads/thread.cc
• To call your test code in ThreadedKernel:• threads/kernel.cc
Some files that might useful.
• Recall Part 1.• threads/alarm.h
• threads/alarm.cc
• Where are the schedulers?• threads/scheduler.h
• threads/scheduler.cc
• Useful data structure• E.g. lib/list.h for SortedList.
15
Report & PolicyReport contents, grading policy, late policy and the summary.
Report
• Report• Motivation and the problem analysis.
• What’s your plan to deal with the problem(high-level).
• How you really implement to solve the problem in Nachos.
• You can including some (not all) important code segments and comments.
• Experiment result and some discussion.
• Extra effort (e.g. bonus part) or observation.
• Remember there are two parts in project2.
• Please saved as [Student ID]_NachOS_report.pdf• E.g. r04942044_NachOS_report.pdf
17
Bonus
• Implement more than one scheduling algorithm.• Tell me how to switch different scheduling algorithm in your program in the
report or the README.
• You can implement any kind of scheduling algorithm
• Extra observation or modification on nachos.
• Please write down on your report if you did it.
Hand in source code & report
• Source Code
• tar zcvf [Student ID]_Nachos2.tar.gz ./nachos-4.0
• E.g. r04942044_Nachos2.tar.gz
• Mail your source code and report to r04942044@ntu.edu.tw• One pdf file as report and one tar.gz file as source code.
• Deadline: Dec.16.2015, 23:59:59.
19
Grading PolicyWith presentation• Nachos source code: (40%)
• Part 1: (20%)
• Part 2: (20%)
• Report: (30%)
• Correct format: (10%)
• Presentation: (20%)
• Bonus
Grading PolicyWithout presentation• Nachos source code: (50%)
• Part 1: (25%)
• Part 2: (25%)
• Report: (40%)
• Correct format: (10%)
• Bonus
Late Policy
• 10% penalty per day.
• Late penalty only holds for a week• After 7 days, you will get 70% penalty, but no more penalty after that.
• That is, after n(n>=7) days, you will still get 70% penalty.
• Don’t give up!
• No plagiarism.
Summary
• Part 1. System Call
• Part 2. Implement at least one scheduling algorithm in previous slide.
• Write the report.
• Send to TA in the correct format before the deadline.• Dec.16.2015, 23:59:59
• Prepare the presentation if you should.
Reference
• Nachos System Call Implementation Sample.• http://puremonkey2010.blogspot.tw/2013/05/nachos-40-nachos-system-
call.html
• Nachos Beginner’s Guide:• https://www.ida.liu.se/~TDDI12/material/begguide/
Recommended