Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

hrtimer: Use NOHZ information for locality

The decision to keep a timer which is associated to the local CPU on that
CPU does not take NOHZ information into account. As a result there are a
lot of hrtimer base switch invocations which end up not switching the base
and stay on the local CPU. That's just work for nothing and can be further
improved.

If the local CPU is part of the NOISE housekeeping mask, then check:

1) Whether the local CPU has the tick running, which means it is
either not idle or already expecting a timer soon.

2) Whether the tick is stopped and need_resched() is set, which
means the CPU is about to exit idle.

This reduces the amount of hrtimer base switch attempts, which end up on
the local CPU anyway, significantly and prepares for further optimizations.

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

authored by

Thomas Gleixner and committed by
Peter Zijlstra
c9391914 3288cd48

+12 -1
+12 -1
kernel/time/hrtimer.c
··· 1231 1231 */ 1232 1232 if (!is_local) 1233 1233 return false; 1234 - return is_first || is_pinned; 1234 + if (is_first || is_pinned) 1235 + return true; 1236 + 1237 + /* Honour the NOHZ full restrictions */ 1238 + if (!housekeeping_cpu(smp_processor_id(), HK_TYPE_KERNEL_NOISE)) 1239 + return false; 1240 + 1241 + /* 1242 + * If the tick is not stopped or need_resched() is set, then 1243 + * there is no point in moving the timer somewhere else. 1244 + */ 1245 + return !tick_nohz_tick_stopped() || need_resched(); 1235 1246 } 1236 1247 return is_local; 1237 1248 }