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_slicecounter ofcurrentup-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_tickfield 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_RESCHEDflag 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access