Nachos Assignment2 Priority Scheduling Nachos scheduling policy n

  • Slides: 14
Download presentation
Nachos Assignment#2 Priority Scheduling

Nachos Assignment#2 Priority Scheduling

Nachos scheduling policy n n : FIFO Jobs run to completion in order of

Nachos scheduling policy n n : FIFO Jobs run to completion in order of arrival. In interactive systems, run until I/O; after I/O completes, put back at end of queue. Response time poor. Scheduling is handled by routines in the Scheduler object:

Scheduler n n The scheduler is invoked whenever the current thread wishes to give

Scheduler n n The scheduler is invoked whenever the current thread wishes to give up the CPU For example, the current thread may have initiated an I/O operation and must wait for it to complete before executing further

Implement priority scheduling n n n Add the method void Thread: Set. Priority (int

Implement priority scheduling n n n Add the method void Thread: Set. Priority (int p) to set the priority of a thread. When the scheduler makes a decision as to next thread to run from the ready. List, it selects the thread with the highest priority. The higher the value of p, the higher the priority.

Thread introduction n Status: n n READY: RUNNING: BLOCKED: JUST_CREATED:

Thread introduction n Status: n n READY: RUNNING: BLOCKED: JUST_CREATED:

Thread introduction n Some operations: n Fork(Void. Function. Ptr func, int arg) n Initialize

Thread introduction n Some operations: n Fork(Void. Function. Ptr func, int arg) n Initialize the stack and put the thread on the ready queue n void Yield() n Suspend the calling thread and select a new one for execution

Class “thread” n n Add member data “priority” Add member function n n get.

Class “thread” n n Add member data “priority” Add member function n n get. Priority set. Priority

Class “list” n Original: n n n void Prepend(T item); void Append(T item); Add

Class “list” n Original: n n n void Prepend(T item); void Append(T item); Add following method (e. g. ): n n Void Sorted. Prepend(); Void Sorted. Append();

void Ready. To. Run(Thread *thread): n n Make thready to run and place it

void Ready. To. Run(Thread *thread): n n Make thready to run and place it on the ready list It simply changes its state to READY and places it on the ready list Ready. To. Run is invoked, for example, by Thread: : Fork() after a new thread has been created. Modify: ready. List->Append(thread);

Thread *Find. Next. To. Run(): n n n Select a ready thread and return

Thread *Find. Next. To. Run(): n n n Select a ready thread and return it. Find. Next. To. Run simply returns the thread at the front of the ready list. Modify: return ready. List->Remove. Front() //If priority of selected thread is lower, put it back and return NULL

void Run(Thread *next. Thread): n n n Do the dirty work of suspending the

void Run(Thread *next. Thread): n n n Do the dirty work of suspending the current thread and switching to the new one. Note that it is the currently running thread that calls Run(). A thread calls this routine when it no longer wishes to execute. Change the state of newly selected thread to RUNNING

Project grading policy n Primary requirement n n n Priority scheduling implementation : 85%

Project grading policy n Primary requirement n n n Priority scheduling implementation : 85% Documentation : 15% Bonus n How to verify your work? : +20%

Project Deadline n n 6/25 24: 00 E-mail your project to r 91050@im. ntu.

Project Deadline n n 6/25 24: 00 E-mail your project to r 91050@im. ntu. edu. tw n Use student id as file name. (one of the two group member) Ex: R 91725050

Your files SHOULD include: n n n Modified files Test files (Bonus) 5 page-report

Your files SHOULD include: n n n Modified files Test files (Bonus) 5 page-report n n n Do not put source code in your report. Explain why you chose to modify these files. Problems encountered and your solution Anything else. Package your files in. tar or. zip format.