8.10 setpri (2156)

2161:

Process priorities are calculated according to the formula

\begin{tabbing}  priority = min(\=  127,\\ \>  (time used + PUSER + p\_ nice))\\ \end{tabbing}

where

(1)

time used = accumulated central processor time (usually since the process was last swapped in), measured in clock ticks divided by 16 i.e. thirds of a second. (More on this later when we discuss the clock interrupt.);

(2)

PUSER == 100;

(3)

“p_nice” is a parameter used to bias the process priority. It is normally positive and hence reduces the process’s effective precedence.

Note the somewhat confusing convention in UNIX that the lower the priority, the higher the precedence. Thus a priority of –10 beats a priority of 100 every time.

2165:

Set the rescheduling flag if the process, whose priority has just been recalculated, has less precedence than the current process.

The sense of the test on line 2165 is surprising, especially when it is compared with line 2141. We leave it to the reader to satisfy himself that this is not an error. (Hint: look at the parameters for the calls on “setpri”.)