Question: Process Scheduling: Please answer A,B,C and explain your answers. Thank you (a) What scheduling algorithm is implemented by this code? Is it fair (i.e., does
Process Scheduling: Please answer A,B,C and explain your answers. Thank you

(a) What scheduling algorithm is implemented by this code? Is it fair (i.e., does each process get an equal share of the CPU)?
(b) On li nes 20 and 21, we skip the rest of the loop if the process state is not RUNNABLE . What is an example of another state that a process could be in? What would go wrong if we tried to run a process in that state?
(c) The swtch function, called on line 29, is written in assembly. What is its purpose, and why does it need to be written in assembly rather than C?
1 // Per -CPU process scheduler 2 I Each CPU calls scheduler after setting itself up 3 /7 Scheduler never returns It loops doing: 11-choose a process to run 5 swtch to start running that process 6-eventually that process transfers control I via swtch back to the scheduler 8 void 9 scheduler void) struct proc pi 12 13 for ) 14 15 16 17 18 19 20 21 // Enable interrupts on this processor sti o // Loop over process table looking for process to run acquire (& ptable . lock ); for (pptable proc p state!RUNNABLE continue 23 24 25 2 6 27 28 29 30 31 32 // Switch to chosen process It is the process 's job // to release ptablelock and then reacquire it // before jumping back to us proc p; switchuvm (p) p-> state RUNNING ; swtch (& cpu scheduler ,proc - context switchkvm )i // Process is done running for now / It should have changed its p-> state before coming back proc0 34 35 36 37 38 39 release & ptable lock 1 // Per -CPU process scheduler 2 I Each CPU calls scheduler after setting itself up 3 /7 Scheduler never returns It loops doing: 11-choose a process to run 5 swtch to start running that process 6-eventually that process transfers control I via swtch back to the scheduler 8 void 9 scheduler void) struct proc pi 12 13 for ) 14 15 16 17 18 19 20 21 // Enable interrupts on this processor sti o // Loop over process table looking for process to run acquire (& ptable . lock ); for (pptable proc p state!RUNNABLE continue 23 24 25 2 6 27 28 29 30 31 32 // Switch to chosen process It is the process 's job // to release ptablelock and then reacquire it // before jumping back to us proc p; switchuvm (p) p-> state RUNNING ; swtch (& cpu scheduler ,proc - context switchkvm )i // Process is done running for now / It should have changed its p-> state before coming back proc0 34 35 36 37 38 39 release & ptable lock
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
