Nachos Project Assignment 2 CPU scheduling
Download
Report
Transcript Nachos Project Assignment 2 CPU scheduling
Nachos Project Assignment 2
CPU scheduling
TA : 吳哲榮
2010/11/18
Nachos Assignment 2
Abstract
You have already learned how OS schedules
processes, so this assignment is to implement
one by yourself.
Implement a system call – Sleep()
Non-preemptive shortest job first scheduler
System Call - Sleep
Please implement Sleep(int x) system call
block the thread which called this system
call, and return to READY state after x timer
interrupts.
System Call - Sleep - Hints
Please study
userprog/exception.cc
userprog/syscall.h
test/start.s
to realize how system calls are implemented.
System Call - test/start.s
Assembly language assist to make system
calls to the Nachos kernel.
Define System call stubs
system call code -- r2
arg1 -- r4
arg2 -- r5
arg3 -- r6
arg4 -- r7
The result of the system call, if any, must be put back into
r2.
System Call - test/start.s
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. */
j $31
.end PrintInt
Declare a new system call –
userprog/syscall.h
Define a new system call ID.
Declare the interface for Nachos system calls,
which will be called by the user program.
ExceptionHandler userprog/exception.cc
Fetch system call number in Register 2
Add new case to the exception handler
case SyscallException:
switch(type) {
…
}
System Call - Sleep (Hint)
1.
2.
Modify exception.cc, syscall.h, start.s
Modify thread/alarm.cc, thread/alarm.h to
implement WaitUntil(int x) to handle
Sleep(int x) system call
Add a new class to manage these threads
blocked by calling Sleep(x).
Nachos Scheduling Policy
The Nachos scheduling policy is simple:
threads reside on a single, unprioritized ready
list, and threads are selected in a round-robin
fashion. That is, threads are always
appended to the end of the ready list, and the
scheduler always selects the thread at the
front of the list.
SJF Scheduling
Default Nachos scheduling algorithm is RoundRobin,we are going to implement another nonpreemptive SJF scheduling
Use n+1 = tn + (1- )n to predict next CPU burst
n : nth predicted CPU burst length
tn : nth actual CPU burst length
: set to 0.5
(one timer interrupt means CPU burst plus 1)
SJF Hint
Begin Running
Per timer interrupt:
1.Record actual CPU burst
2.Wake up next threads
Invoke Sleep(x)
1.Set next predicted CPU burst
2.Insert this thread to Sleeping thread lists
3.Invoke thread->Sleep
SJF Hint
You need to modify schedule.cc, alarm.cc
and the other related files,and you may add
a new class to manager those threads that
blocked by calling Sleep(x).
Begin Running
Per timer interrupt:
1.Record actual CPU burst
2.Wake up next threads
Invoke Sleep(x)
1.Set next predicted CPU burst
2.Insert this thread to Sleeping thread lists
3.Invoke thread->Sleep
Assignment Requirements
1.Implement system call “Sleep”
2.Implement Shortest-Job-First scheduling
3.Design several test case to proof your
result
Assignment Requirements
Assignment Report (12/23 on the class)
Please compress the following in a .zip.
modified source code(s) with path
presentation power-point
final report
E-mail your .zip
(project1_b99901000_b99901001.zip) to TA.
Deadline: 2010/12/23 23:59
Grading Policy
Correct Result
Report
50%
50%