Stopping and Starting Periodic Ticks

Dynamic ticks provide the framework to defer periodic ticks for a while. What the kernel still needs to decide is when ticks 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_tick is 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 AMD6419 turn off ticks in the idle task.

Integrating tick_nohz_stop_sched_tick is rather straightforward. Consider, for instance, the implementation of cpu_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 */

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

tick_nohz_stop_sched_tickO; while (!need_resched()) idle();

tick_nohz_restart_sched_tick();

Other architectures differ in some details, but the general principle is the same. After calling tick_nohz_stop_sched_tick to turn off ticks, the system goes into an endless loop that ends when a process is available to be scheduled on the processor. Ticks are then necessary again, and are reactivated by tick_nohz_restart_sched_tick.

Recall that a sleeping process waits for some condition to be fulfilled such that it switches into a runnable state. A change of this condition is signaled by an interrupt — just suppose that the process has been waiting for some data to arrive, and the interrupt notifies the system that the data are now available. Since interrupts occur at random times from the kernel's point of view, it can well happen that one is raised during an idle period with ticks turned off. Two conditions can thus require restarting ticks:

1. An external interrupt make a process runnable, which requires the tick mechanism to work.20 In this case, ticks need to be resumed earlier than initially planned.

2. The next tick event is due, and the clock interrupt signals that the time for this has come. In this case, the tick mechanism is resumed as planned before.

Continue reading here: Stopping Ticks

Was this article helpful?

0 0