140 likes | 169 Views
This assignment focuses on implementing priority scheduling in the Nachos operating system to enhance system responsiveness and efficiency. Learn about FIFO scheduling, thread priorities, and scheduling policies in interactive systems.
E N D
Nachos Assignment#2 Priority Scheduling
Nachos scheduling policy :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 • 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 • Add the method void Thread:SetPriority (int p) to set the priority of a thread. • When the scheduler makes a decision as to next thread to run from the readyList,it selects the thread with the highest priority. • The higher the value of p, the higher the priority.
Thread introduction • Status: • READY: • RUNNING: • BLOCKED: • JUST_CREATED:
Thread introduction • Some operations: • Fork(VoidFunctionPtr func, int arg) • Initialize the stack and put the thread on the ready queue • void Yield() • Suspend the calling thread and select a new one for execution
Class “thread” • Add member data “priority” • Add member function • getPriority • setPriority
Class “list” • Original: • void Prepend(T item); • void Append(T item); • Add following method (e.g.): • Void SortedPrepend(); • Void SortedAppend();
void ReadyToRun(Thread *thread): • Make thread ready to run and place it on the ready list • It simply changes its state to READY and places it on the ready list • ReadyToRun is invoked, for example, by Thread::Fork() after a new thread has been created. • Modify: readyList->Append(thread);
Thread *FindNextToRun(): • Select a ready thread and return it. • FindNextToRun simply returns the thread at the front of the ready list. • Modify: return readyList->RemoveFront() //If priority of selected thread is lower,put it back and return NULL
void Run(Thread *nextThread): • 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 • Primary requirement • Priority scheduling implementation :85% • Documentation :15% • Bonus • How to verify your work?: +20%
Project Deadline • 6/25 24:00 • E-mail your project to r91050@im.ntu.edu.tw • Use student id as file name.(one of the two group member) Ex:R91725050
Your files SHOULD include: • Modified files • Test files (Bonus) • 5 page-report • 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.