Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 15: Time Management


This code is run at the very beginning oftick_sched_timer.


  1. When the handler is finished, it is usually required to reprogram the tick device such that the
    next tick will happen at the right time. If ticks are stopped, this is not necessary:
    kernel/time/tick-sched.c
    / Do not restart, when we are in the idle loop /
    if (ts->tick_stopped)
    return HRTIMER_NORESTART;


Only a single change to the existing code is required to initialize dynamic tick mode in a high-resolution
regime. Recall thattick_setup_sched_timeris used to initialize the tick emulation layer for high-
resolution systems. If dynamic ticks are enabled at compile time, a short piece of code is added to the
function:

kernel/time/tick-sched.c
void tick_setup_sched_timer(void)
{
...
#ifdef CONFIG_NO_HZ
if (tick_nohz_enabled)
ts->nohz_mode = NOHZ_MODE_HIGHRES;
#endif
}

This announces officially that dynamic ticks are in use with high-resolution timers.

15.5.4 Stopping and Starting Periodic Ticks


Dynamic ticks provide the framework to defer periodic ticks for a while. What the kernel still needs to
decide iswhenticks are supposed to be stopped and restarted.

A natural possibility to stop ticks is when the idle task is scheduled: This proves that a processor really
does not have anything better to do.tick_nohz_stop_sched_tickis provided by the dynamic tick
framework to stop ticks. Note that the same function is used independent of low and high resolution.
If dynamic ticks are disabled at compile time, the function is replaced by an empty dummy.

The idle task is implemented in an architecture-specific way, and not all architectures have been updated
to support disabling the periodic tick yet. At the time of writing, ARM, MIPS, PowerPC, SuperH, Sparc64,
IA-32, and AMD64^19 turn off ticks in the idle task.

Integratingtick_nohz_stop_sched_tickis rather straightforward. Consider, for instance, the imple-
mentation ofcpu_idle(which is run in the idle task) on ARM systems:

arch/arm/kernel/process.c
void cpu_idle(void)
{
...
/* endless idle loop with no priority at all */

(^19) And user-mode Linux if you want to count that as a separate architecture.

Free download pdf