md.jamal
md.jamal

Reputation: 4517

How are jiffies incremented in a tickless kernel?

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?

Upvotes: 4

Views: 2000

Answers (1)

Marco Bonelli
Marco Bonelli

Reputation: 69286

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().

Upvotes: 9

Related Questions