]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
hrtimer: Optimize for local timers
authorThomas Gleixner <tglx@kernel.org>
Tue, 24 Feb 2026 16:37:28 +0000 (17:37 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 27 Feb 2026 15:40:11 +0000 (16:40 +0100)
commit3288cd486376b322868c9fb41f10e35916e7e989
tree76f5ef2e9675fe6ddce5ee304ca8b7f9e85bdeb8
parent22f011be7aaa77ca8f502b9dd07b7334f9965d18
hrtimer: Optimize for local timers

The decision whether to keep timers on the local CPU or on the CPU they are
associated to is suboptimal and causes the expensive switch_hrtimer_base()
mechanism to be invoked more than necessary. This is especially true for
pinned timers.

Rewrite the decision logic so that the current base is kept if:

   1) The callback is running on the base

   2) The timer is associated to the local CPU and the first expiring timer as
      that allows to optimize for reprogramming avoidance

   3) The timer is associated to the local CPU and pinned

   4) The timer is associated to the local CPU and timer migration is
      disabled.

Only #2 was covered by the original code, but especially #3 makes a
difference for high frequency rearming timers like the scheduler hrtick
timer. If timer migration is disabled, then #4 avoids most of the base
switches.

Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260224163430.607935269@kernel.org
kernel/time/hrtimer.c