4
votes

Kernel maintains a global variable called jiffies which holds the number of ticks/timer interrupts from system boot.

Every time a timer interrupt occurs, the value of an internal kernel counter is incremented.

In tickless kernel/dynamic ticks, where the interrupts does not happen periodically, how is the value of jiffies incremented?

1
This question How SMP scheduling works may also be of interest. 'Tickless' is not without interrupts. 'Tickless' will not wake if there is no work to do. When there is work to do, instead of adding '1' tick to jiffies, the timer interrupt will add ticks since last interrupt. Since there is no work, there is no one to look at jiffies. For other interrupt sources, the timer chip hardware can read 'jiffies' before executing that code to correct the value.artless noise

1 Answers

6
votes

The value of jiffies is always updated calling the do_timer() function from the timer interrupt handler, no matter the configuration. What really changes between a "normal" and a "tickless" kernel is only when such interrupts can happen.

First, let me clarify that there is no such thing as a real "tickless" kernel. The kernel will always need ticks to happen on at least one CPU. Unless all CPUs are idle, at least one CPU must keep the scheduling-clock interrupt going in order to support accurate timekeeping. I highly recommend reading Documentation/timers/NO_HZ.txt for more very useful and insightful information on the topic.

In particular, the jiffies value is only updated by the same CPU (i.e. the global variable tick_do_timer_cpu). The two following scenarios are possible:

  • In case of periodic ticks, the tick_handle_periodic() handler is used. This handler simply calls tick_periodic(), which then calls do_timer(1) incrementing jiffies by 1 tick.

  • In case of non-periodic ticks, the tick_nohz_handler() is used. This handler calls tick_sched_do_timer(), which calls tick_do_update_jiffies64(), which updates jiffies dynamically calculating the number of ticks that happened since the last update (which can be more than 1), with the help of the ktime_t passed by tick_nohz_handler() and obtained through ktime_get().