Download presentation
1
Nachos Project Assignment 2 CPU scheduling
2010/11/18
2
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
3
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.
4
System Call - Sleep - Hints
Please study userprog/exception.cc userprog/syscall.h test/start.s to realize how system calls are implemented.
5
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.
6
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
7
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.
8
ExceptionHandler - userprog/exception.cc
Fetch system call number in Register 2 Add new case to the exception handler case SyscallException: switch(type) { … }
9
System Call - Sleep (Hint)
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).
10
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.
11
SJF Scheduling Default Nachos scheduling algorithm is Round-Robin,we are going to implement another non-preemptive 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)
12
SJF Hint Begin Running Per timer interrupt: 1.Record actual CPU burst
Invoke Sleep(x) Per timer interrupt: 1.Record actual CPU burst 2.Wake up next threads 1.Set next predicted CPU burst 2.Insert this thread to Sleeping thread lists 3.Invoke thread->Sleep
13
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 Invoke Sleep(x) Per timer interrupt: 1.Record actual CPU burst 2.Wake up next threads 1.Set next predicted CPU burst 2.Insert this thread to Sleeping thread lists 3.Invoke thread->Sleep
14
Assignment Requirements
1.Implement system call “Sleep” 2.Implement Shortest-Job-First scheduling 3.Design several test case to proof your result
15
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 your .zip (project1_b _b zip) to TA. Deadline: 2010/12/23 23:59
16
Grading Policy Correct Result 50% Report 50%
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.