From: Christoph Lameter (Ampere) Date: Wed, 2 Jul 2025 19:29:57 +0000 (-0700) Subject: Skew tick for systems with a large number of processors X-Git-Url: https://gentwo.org/gitweb/?a=commitdiff_plain;h=93fd2fb71676d7a8220f3b44bb12693fac862af5;p=linux%2F.git Skew tick for systems with a large number of processors Synchronized ticks mean that all processors will simultaneously process ticks and enter the scheduler. So the contention increases as the number of cpu increases. The contention causes latency jitter that scales with the number of processors. Staggering the timer interrupt also helps mitigate voltage droop related issues that may be observed in SOCs with large core counts. See https://semiengineering.com/mitigating-voltage-droop/ for a more detailed explanation. Switch to skewed tick for systems with more than 64 processors. Signed-off-by: Christoph Lameter (Ampere) --- diff --git a/kernel/Kconfig.hz b/kernel/Kconfig.hz index ce1435cb08b1..245d938d446b 100644 --- a/kernel/Kconfig.hz +++ b/kernel/Kconfig.hz @@ -57,3 +57,13 @@ config HZ config SCHED_HRTICK def_bool HIGH_RES_TIMERS + +config TICK_SKEW_LIMIT + int + default 64 + help + If the kernel is booted on systems with a large number of cpus then the + concurrent execution of timer ticks causes long holdoffs due to + serialization. Synchrononous executions of interrupts can also cause + voltage droop in SOCs. So switch to skewed mode. This mechanism + can be overridden by specifying "tick_skew=x" on the kernel command line. diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index c527b421c865..aab7a1cc25c7 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1554,7 +1554,7 @@ void tick_irq_enter(void) tick_nohz_irq_enter(); } -static int sched_skew_tick; +static int sched_skew_tick = -1; static int __init skew_tick(char *str) { @@ -1572,6 +1572,16 @@ void tick_setup_sched_timer(bool hrtimer) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); + /* Figure out if we should skew the tick */ + if (sched_skew_tick < 0) { + if (num_possible_cpus() >= CONFIG_TICK_SKEW_LIMIT) { + sched_skew_tick = 1; + pr_info("Tick skewed mode enabled. Possible cpus %u > %u\n", + num_possible_cpus(), CONFIG_TICK_SKEW_LIMIT); + } else + sched_skew_tick = 0; + } + /* Emulate tick processing via per-CPU hrtimers: */ hrtimer_setup(&ts->sched_timer, tick_nohz_handler, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); @@ -1587,7 +1597,9 @@ void tick_setup_sched_timer(bool hrtimer) do_div(offset, num_possible_cpus()); offset *= smp_processor_id(); hrtimer_add_expires_ns(&ts->sched_timer, offset); - } + } else + pr_info("Tick operating in synchronized mode.\n"); + hrtimer_forward_now(&ts->sched_timer, TICK_NSEC); if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) && hrtimer)