CS471/571 - Operating Systems


Exercise #8

Using a clean xv6 instance:

tar xf xv6-public.tgz

or at least make it work on a clean instance, make the following changes to the Xv6 system:

  1. Create a system call to set/adjust a processes scheduling priority:

    int setpriority(int pid, int priority);

    The function should set a priority value in the processes process table entry to the new priority which may have a range between -10 and 10. An additional integer called 'schedtick' should be added to the process table as well.

  2. Make a user-space program to set the priority of a process, called 'nice' that has two parameters:

    nice <pid> <priority>

  3. Update the process table listing (displayed when typing Ctrl-P on the Xv6 console.) to display the current process priority in square brackets:

$ nice 2 5
1 sleep  init [0] 80103fcd 80104bc9 80105c3d 801059dc
2 sleep  sh [5] 8010413a 801002d2 8010105c 80104e99 80104bc9 80105c3d 801059dc
  1. Alter the scheduler and possibly the yield/sched function(s) to do the following:

    • After a process has run, set an additional integer (schedtick) to equal the processes scheduling priority.

    • When a process has been select to run, if the schedtick value is < 0, increment it and continue looking for a process to run

    • As long as schedtick is above or equal to 0, decrement it and allow the process to continue running (i.e. don't yield or immediately swtch() back to the process.)