CS444 Lab 3
Modifying the Xv6 Scheduler
While your operating system started out rather spartan, those days
are over. It is time now to add some true functionality. Gone are
the days of the text processing software your homework is idly
sitting in using all your computer power - no! Finally, now, the
kitten-picture browsing session can have the priority it deserves.
We made some changes to the scheduler recently which should improve
Odin's performance when many people are trying their code in the
QEMU VM; it allows the OS to intelligently detect when there's
nothing to do, and idle to save processor cycles on our host :) .
Because these changes are in the scheduler, you'll want to pull
these changes before you start working.
Try the following code in your repository root:
git pull upstream master
This may ask you to make a merge commit, so don't be alarmed if a
text editor pops up :)
If that doesn't work correctly, try this:
git remote add upstream https://gitlab.cosi.clarkson.edu/cs444-sp17/xv6-cs444.git
git pull upstream master
...if either of these complain about "please, commit or stash your
changes", try running git stash before doing the pull, and
git stash pop afterward; finally, if any of these complain about
"merge conflicts", you're about to have fun; you might want to ask
for some help :)
In any case, also feel free to contact me if you feel you need help
(it's better than accidentally destroying your work)!
For this lab, you should read (if you haven't already) chapter
5 of the XV6 book.
The current scheduler in is, as the book elucidates, a
round robin scheduler with no other special properties.
The scheduler you should implement will be a slight variation on
their round-robin design, but with priorities, and the guarantee
that a higher-priority runnable process should be selected before
any runnable process of lower priority.
There are various ways of achieving this, and I encourage your
creativity, but if you're lost, here's a naïve
implementation in pseudocode: iterate over all priorities, from
highest to lowest, and do the round-robin loop on each one; if a
process was found to run, reset the priority to the highest value
and continue, otherwise, proceed to the next lower priority. If you
make it through this entire loop without finding a runnable
process, halt (until the next interrupt).
The astute reader will note the previous example is
O(PRIORITIES * NPROC), which is pretty bad; exercises on
fixing this complexity are not necessary, but recommended for bonus
Due by 5:00PM on Thursday, March 9, 2017
Implement the setpriority syscall and userspace program.
Modify the scheduler to run the modified priority algorithm
described in the slides.
You'll want to work in the following locations:
- proc.h to add a priority field to struct proc;
- proc.c to:
- change allocproc to set the default priority (50);
- change fork to copy the priority from proc (which refers to the current process);
- add a setprio or similar function to actually change the priority;
- actually change scheduler to implement priority-based scheduling :)
- syscall.h, userspace/user.h and userspace/usys.S to register your new setprio syscall;
- sysproc.c to actually add the syscall trampoline (e.g., sys_setprio)—feel free to add policy decisions here, like not being able to set a higher priority than its parent, etc.;
- userspace/Makefile and a file in userspace/ to actually add a program which can use your syscall :) .
As before, submit your work to your xv6 GitLab repository to hand it in.