Each process has three different priorities stored in
.Vt struct proc :
member is the user priority of the process calculated from a process
estimated CPU time and nice level.
member is the saved priority used by
When a process obtains a mutex, its priority is saved in
While it holds the mutex, the processs priority may be bumped by another
process that blocks on the mutex.
When the process releases the mutex, then its priority is restored to the
priority saved in
member is the actual priority of the process and is used to determine what
it runs on, for example.
function compares the cached priority of the currently running process with
If the currently running process has a higher priority, then it will return
a value less than zero.
If the current process has a lower priority, then it will return a value
greater than zero.
If the current process has the same priority as
will return zero.
The cached priority of the currently running process is updated when a process
or returns to userland in
and is stored in the private variable
function compares the priorities of the current thread and
has a higher priority than the current thread, then a context switch is
looks at the process that owns the mutex
is blocked on.
That processs priority is bumped to the priority of
If the process is currently running, then the function returns.
If the process is on a
then the process is moved to the appropriate
for its new priority.
If the process is blocked on a mutex, its position in the list of
processes blocked on the mutex in question is updated to reflect its new
Then, the function repeats the procedure using the process that owns the
mutex just encountered.
Note that a processs priorities are only bumped to the priority of the
not to the priority of the previously encountered process.
function recomputes the user priority of the ksegrp
to force a reschedule of each thread in the group if needed.
function is used as a
function to force a reschedule every
function simply returns the number of clock ticks in between reschedules
Thus, all it does is return the current value of
function is a
that is called to start the callout driven scheduler functions.
It just calls the
functions for the first time.
After the initial call, the two functions will propagate themselves by
registering their callout event again at the completion of the respective
function is called by
to adjust the priority of the currently running threads ksegrp.
It updates the groups estimated CPU time and then adjusts the priority via
function updates all process priorities.
First, it updates statistics that track how long processes have been in various
Secondly, it updates the estimated CPU time for the current process such
that about 90% of the CPU usage is forgotten in 5 * load average seconds.
For example, if the load average is 2.00,
then at least 90% of the estimated CPU time for the process should be based
on the amount of CPU time the process has had in the last 10 seconds.
It then recomputes the priority of the process and moves it to the
Thirdly, it updates the %CPU estimate used by utilities such as
so that 95% of the CPU usage is forgotten in 60 seconds.
Once all process priorities have been updated,
to update various other statistics including the load average.
Finally, it schedules itself to run again in
function is used to change a processs state to be runnable.
The process is placed on a
if needed, and the swapper process is woken up and told to swap the process in
if the process is swapped out.
If the process has been asleep for at least one run of
is used to adjust the priority of the process.
function is used to adjust the priority of a process that has been asleep.
It retroactively decays the estimated CPU time of the process for each
event that the process was asleep.
Finally, it calls
to adjust the priority of the process.