From: Thomas Gleixner <tglx@linutronix.de>
To: Steve Wahl <steve.wahl@hpe.com>, Steve Wahl <steve.wahl@hpe.com>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>,
Ingo Molnar <mingo@kernel.org>,
linux-kernel@vger.kernel.org
Cc: Russ Anderson <rja@hpe.com>, Dimitri Sivanich <sivanich@hpe.com>,
Kyle Meyer <kyle.meyer@hpe.com>
Subject: Re: [PATCH] tick/sched: Use trylock for jiffies updates by non-timekeeper CPUs
Date: Thu, 16 Oct 2025 22:07:07 +0200 [thread overview]
Message-ID: <87a51q1uhg.ffs@tglx> (raw)
In-Reply-To: <20251013150959.298288-1-steve.wahl@hpe.com>
On Mon, Oct 13 2025 at 10:09, Steve Wahl wrote:
> -static void tick_do_update_jiffies64(ktime_t now)
> +static bool _tick_do_update_jiffies64(ktime_t now, bool trylock)
> {
> unsigned long ticks = 1;
> ktime_t delta, nextp;
> @@ -70,7 +70,7 @@ static void tick_do_update_jiffies64(ktime_t now)
> */
> if (IS_ENABLED(CONFIG_64BIT)) {
> if (ktime_before(now, smp_load_acquire(&tick_next_period)))
> - return;
> + return true;
> } else {
> unsigned int seq;
>
> @@ -84,18 +84,24 @@ static void tick_do_update_jiffies64(ktime_t now)
> } while (read_seqcount_retry(&jiffies_seq, seq));
>
> if (ktime_before(now, nextp))
> - return;
> + return true;
> }
>
> /* Quick check failed, i.e. update is required. */
> - raw_spin_lock(&jiffies_lock);
> + if (trylock) {
> + /* The cpu holding the lock will do the update. */
> + if (!raw_spin_trylock(&jiffies_lock))
> + return false;
> + } else {
> + raw_spin_lock(&jiffies_lock);
> + }
Why inflicting this horrible conditional locking scheme into the main
path? This can be solved without all this churn completely independent
from this function.
Something like the uncompiled below. You get the idea.
Thanks,
tglx
---
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -203,6 +203,21 @@ static inline void tick_sched_flag_clear
#define MAX_STALLED_JIFFIES 5
+static bool tick_try_update_jiffies64(struct tick_sched *ts, ktime_t now)
+{
+ static atomic_t in_progress;
+ int inp;
+
+ inp = atomic_read(&in_progress);
+ if (inp || !atomic_try_cmpxchg(&in_progress, &inp, 1))
+ return false;
+
+ if (ts->last_tick_jiffies == jiffies)
+ tick_do_update_jiffies64(now);
+ atomic_set(&in_progress, 0);
+ return true;
+}
+
static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now)
{
int tick_cpu, cpu = smp_processor_id();
@@ -239,10 +254,11 @@ static void tick_sched_do_timer(struct t
ts->stalled_jiffies = 0;
ts->last_tick_jiffies = READ_ONCE(jiffies);
} else {
- if (++ts->stalled_jiffies == MAX_STALLED_JIFFIES) {
- tick_do_update_jiffies64(now);
- ts->stalled_jiffies = 0;
- ts->last_tick_jiffies = READ_ONCE(jiffies);
+ if (++ts->stalled_jiffies >= MAX_STALLED_JIFFIES) {
+ if (tick_try_update_jiffies64(ts, now)) {
+ ts->stalled_jiffies = 0;
+ ts->last_tick_jiffies = READ_ONCE(jiffies);
+ }
}
}
next prev parent reply other threads:[~2025-10-16 20:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-13 15:09 [PATCH] tick/sched: Use trylock for jiffies updates by non-timekeeper CPUs Steve Wahl
2025-10-16 20:07 ` Thomas Gleixner [this message]
2025-10-16 20:57 ` Steve Wahl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a51q1uhg.ffs@tglx \
--to=tglx@linutronix.de \
--cc=anna-maria@linutronix.de \
--cc=frederic@kernel.org \
--cc=kyle.meyer@hpe.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=rja@hpe.com \
--cc=sivanich@hpe.com \
--cc=steve.wahl@hpe.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox