[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250702-tick_skew-v1-1-ff8d73035b02@gentwo.org>
Date: Wed, 02 Jul 2025 12:42:00 -0700
From: Christoph Lameter via B4 Relay <devnull+cl.gentwo.org@...nel.org>
To: Anna-Maria Behnsen <anna-maria@...utronix.de>,
Frederic Weisbecker <frederic@...nel.org>, Ingo Molnar <mingo@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>
Cc: linux-kernel@...r.kernel.org, linux-mm@...ck.org, sh@...two.org,
Darren Hart <dvhart@...radead.org>,
"Christoph Lameter (Ampere)" <cl@...two.org>
Subject: [PATCH] Skew tick for systems with a large number of processors
From: "Christoph Lameter (Ampere)" <cl@...two.org>
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@...two.org>
---
kernel/Kconfig.hz | 10 ++++++++++
kernel/time/tick-sched.c | 16 ++++++++++++++--
2 files changed, 24 insertions(+), 2 deletions(-)
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)
---
base-commit: 66701750d5565c574af42bef0b789ce0203e3071
change-id: 20250702-tick_skew-0e7858c10246
Best regards,
--
Christoph Lameter <cl@...two.org>
Powered by blists - more mailing lists