Functions Used by the Scheduler
The scheduler relies on several functions in order to do its work; the most important are:
scheduler_tick( )
Keeps the
time_slice
counter ofcurrent
up-to-datetry_to_wake_up( )
Awakens a sleeping process
recalc_task_prio( )
Updates the dynamic priority of a process
schedule( )
Selects a new process to be executed
load_balance()
Keeps the runqueues of a multiprocessor system balanced
The scheduler_tick( ) Function
We have already explained in the section "Updating Local CPU
Statistics" in Chapter
6 how scheduler_tick( )
is
invoked once every tick to perform some operations related to
scheduling. It executes the following main steps:
Stores in the
timestamp_last_tick
field of the local runqueue the current value of the TSC converted to nanoseconds; this timestamp is obtained from thesched_clock( )
function (see the previous section).Checks whether the current process is the swapper process of the local CPU. If so, it performs the following substeps:
If the local runqueue includes another runnable process besides swapper, it sets the
TIF_NEED_RESCHED
flag of the current process to force rescheduling. As we’ll see in the section "The schedule( ) Function" later in this chapter, if the kernel supports the hyper-threading technology (see the section "Runqueue Balancing in Multiprocessor Systems" later in this chapter), a logical CPU might be idle even if there are runnable processes in its runqueue, as long as those processes have significantly lower priorities than ...
Get Understanding the Linux Kernel, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.