timers: Recalculate next timer interrupt only when necessary
authorFrederic Weisbecker <frederic@kernel.org>
Thu, 23 Jul 2020 15:16:41 +0000 (17:16 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 24 Jul 2020 10:49:40 +0000 (12:49 +0200)
commit31cd0e119d50cf27ebe214d1a8f7ca36692f13a5
tree4e393a04f8ec71e0f417953cdcbecc859a3a0c83
parent1b7efaa6154960396f414551841f1886d99b6872
timers: Recalculate next timer interrupt only when necessary

The nohz tick code recalculates the timer wheel's next expiry on each idle
loop iteration.

On the other hand, the base next expiry is now always cached and updated
upon timer enqueue and execution. Only timer dequeue may leave
base->next_expiry out of date (but then its stale value won't ever go past
the actual next expiry to be recalculated).

Since recalculating the next_expiry isn't a free operation, especially when
the last wheel level is reached to find out that no timer has been enqueued
at all, reuse the next expiry cache when it is known to be reliable, which
it is most of the time.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200723151641.12236-1-frederic@kernel.org
kernel/time/timer.c