Answered step by step
Verified Expert Solution
Question
1 Approved Answer
What to do for this Project ( Implementation of Fair Scheduler ) : Change ready queue from unsorted list to list sorted by vruntime and
What to do for this Project Implementation of Fair Scheduler :
Change ready queue from unsorted list to list sorted by vruntime and tid
Each tick calculate the ideal runtime and compare time running
If time running is longer yield and add to ready queue unless ready to terminate
Thread block
Remove from ready queue
Thread Unblock
Add to ready queue
Cause current thread to yield if CPU was idle or if get sleeping boost
What to do variables
Variables to think about :
Vruntime for each thread
Weight table for scheduler to use
Minvruntime for each ready queue
vruntime for each thread
CPU time consumed for each thread
Threads time slice ideal runtime for each thread
Number of threads running or ready for each ready queue
Weight of thread for each thread
Sum of weights for each ready queue
What to do Initialization
Some variables need to be initialized when each CPU first thread is initialized and ready queue is setup
Some variables need to be initialized when threads are created
Each Tick
Threadtick calls schedtick
Determine if thread needs to yield
Calculate and compare ideal runtime to the amount of time that thread has been running
Then threadyield calls schedyield
Update how long thread has been running
Add to readyqueue in order by runtime and tid
Update number of threads in ready queue
Update sum of weights
Then threadtick calls schedule
Calls next thread to run which calls schedpicknext
Remove from ready queue just like before but also
Update any variables about when it was last run or runtime was calculated etc if you are using them
Update number of threads in ready queue
Update sum of weights
Calls switch thread
Calls threadscheduletail
Thread BlockUnblock
Block
Remove from ready queue
Update variables
Unblock
Add to ready queue
Update variables
Trigger schedule if CPU was NULL or if thread got a sleeping boost
Theory :
CFS Niceness :
Niceness in thread struct
indication of priority
Higher niceness lower priority
Function: int threadgetnice void
Returns the current thread's nice value.
Function: void threadsetnice int newnice
Sets the current thread's nice value to newnice.
CFS Weights :
static const uintt priotoweight
Algorithm Summary :
Preempt the current thread at each timer tick if it exceeds its ideal runtime.
Select the next thread with the lowest virtual runtime vruntime using thread ID tid to break ties.
Update a thread's vruntime by adding d ww where d is the CPU time since the last update, w is the base weight and w is the threads weight.
Keep track of the minimum vruntime minvruntime across all threads, ensuring it remains nonnegative.
Calculate idealruntime as n ws where n being the count of active or ready threads, w is the current threads weight and s the total weight of all active or ready threads
For a thread unblocked for the first time, set its vruntime to minvruntime.
For threads unblocked subsequently, adjust their vruntime to the maximum of its current vruntime or minvruntime minus
Prompt the CPU to yield if an unblocked thread has a lower vruntime than the current thread or if the CPU is idle, ensuring efficient and fair scheduling.
Provide code as per Pseudocode and necessary changes in Pintos Multi Processor OS to implement a complete Fair Scheduler.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started