7.11 Exercises
-
1.
Implement semaphores in xv6 without using
sleep
andwakeup
(but it is OK to use spin locks). Choose a few of xv6’s uses of sleep and wakeup and replace them with semaphores. Judge the result. -
2.
Fix the race mentioned above between
kill
andsleep
, so that akill
that occurs after the victim’s sleep loop checksp->killed
but before it callssleep
results in the victim abandoning the current system call. -
3.
Design a plan so that every sleep loop checks
p->killed
so that, for example, a process that is in the virtio driver can return quickly from the while loop if it is killed by another process. -
4.
Modify xv6 to use only one context switch when switching from one process’s kernel thread to another, rather than switching through the scheduler thread. The yielding thread will need to select the next thread itself and call swtch. The challenges will be to prevent multiple CPUs from executing the same thread accidentally; to get the locking right; and to avoid deadlocks.
-
5.
Modify xv6’s
scheduler
to use the RISC-VWFI
(wait for interrupt) instruction when no processes are runnable. Try to ensure that, any time there are runnable processes waiting to run, no CPUs are pausing in WFI.