]> Gentwo Git Trees - linux/.git/commitdiff
Skew tick for systems with a large number of processors b4/tick_skew
authorChristoph Lameter (Ampere) <cl@gentwo.org>
Wed, 2 Jul 2025 19:29:57 +0000 (12:29 -0700)
committerChristoph Lameter <cl@gentwo.org>
Wed, 2 Jul 2025 19:36:56 +0000 (12:36 -0700)
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) <cl@gentwo.org>
kernel/Kconfig.hz
kernel/time/tick-sched.c

index ce1435cb08b1ecd7f800442e886c2d8270afeb18..245d938d446b926bfa79ec4ad48a4ceb166a719b 100644 (file)
@@ -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.
index c527b421c8652ca837038941feaaf546f2552fc3..aab7a1cc25c7867c2f5247a35b3ef0a6481e49ba 100644 (file)
@@ -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)