Inder
Inder

Reputation: 51

Which CPU increments the jiffies in SMP?

As I read, the jiffies is incremented on every timer tick by the timer ISR. But in SMP, all CPUs will have their own timer interrupt and hence their own timer ISRs. So my question is:

Is jiffies global across all CPUs? If so, how and which CPU increments it in its timer ISR?

As per my understanding the jiffies can not be per CPU otherwise the same process when scheduled on different CPU will see different jiffy value.

Upvotes: 5

Views: 3258

Answers (2)

ugoren
ugoren

Reputation: 16449

There are two timer interrupts:
The local timer interrupt (LOC in /proc/interrupts) fires once per jiffy on each CPU.
The global timer interrupts (interrupt 0) fires once per jiffy, on any CPU. It increments jiffies.

Note that the "Tickless Kernel" configuration option (introduced in Linux 2.6.21, CONFIG_NO_HZ), removes these interrupts. With a tickless kernel, there's no periodic interrupt any more. Instead, when a process starts its quantum, Linux sets an "alarm clock" in the hardware to trigger an interrupt when the quantum is over.

Upvotes: 6

wrymarkX
wrymarkX

Reputation: 99

See this post link.

Basically, tick_do_timer_cpu variable holds CPU ID which is supposed to run code which manages jiffies. The jiffies management function execution can jump from one core to the another, but update cannot be done on different cores in the same time obviously.

See also kernel/time/tick-common.c

Upvotes: 0

Related Questions