From: Breno Leitao <leitao@debian.org>
To: paulmck@kernel.org, Andrew Morton <akpm@linux-foundation.org>,
d@ilvokhin.com
Cc: linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
linux-kernel@vger.kernel.org, kernel-team@meta.com,
Thomas Gleixner <tglx@kernel.org>,
Breno Leitao <leitao@debian.org>
Subject: [PATCH v2 1/3] locking/csd-lock: Pack csd_lock_wait_toolong() state into a struct
Date: Mon, 10 Aug 2026 04:29:24 -0700 [thread overview]
Message-ID: <20260810-csd-stall-duration-v2-1-795083bf04a4@debian.org> (raw)
In-Reply-To: <20260810-csd-stall-duration-v2-0-795083bf04a4@debian.org>
csd_lock_wait_toolong() has some fields and they are being expanded now,
separate them into a structure, that can be easily digestible.
This simplify the function aslo, given the fields were passed by
reference, and the ts0/ts1 names say nothing about what the two
timestamps hold.
Pack them into struct csd_wait_state and name the timestamps for what
they store, ts_start and ts_report. The local ts2 becomes ts_now.
Reporting a further timestamp, such as next patch, then costs a struct
member rather than another argument.
No functional change.
Suggested-by: Dmitry Ilvokhin <d@ilvokhin.com>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
kernel/smp.c | 56 +++++++++++++++++++++++++++++++-------------------------
1 file changed, 31 insertions(+), 25 deletions(-)
diff --git a/kernel/smp.c b/kernel/smp.c
index 52dffc86555cd..e00b8f620c5d9 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -223,50 +223,58 @@ bool csd_lock_is_stuck(void)
return !!atomic_read(&n_csd_lock_stuck);
}
+/* State that csd_lock_wait_toolong() carries across the __csd_lock_wait() loop. */
+struct csd_wait_state {
+ u64 ts_start; /* When the wait began. */
+ u64 ts_report; /* When the last complaint was printed. */
+ int bug_id;
+ unsigned long nmessages;
+};
+
/*
* Complain if too much time spent waiting. Note that only
* the CSD_TYPE_SYNC/ASYNC types provide the destination CPU,
* so waiting on other types gets much less information.
*/
-static bool csd_lock_wait_toolong(call_single_data_t *csd, u64 ts0, u64 *ts1, int *bug_id, unsigned long *nmessages)
+static bool csd_lock_wait_toolong(call_single_data_t *csd, struct csd_wait_state *state)
{
int cpu = -1;
int cpux;
bool firsttime;
- u64 ts2, ts_delta;
+ u64 ts_now, ts_delta;
call_single_data_t *cpu_cur_csd;
unsigned int flags = READ_ONCE(csd->node.u_flags);
unsigned long long csd_lock_timeout_ns = csd_lock_timeout * NSEC_PER_MSEC;
if (!(flags & CSD_FLAG_LOCK)) {
- if (!unlikely(*bug_id))
+ if (!unlikely(state->bug_id))
return true;
cpu = csd_lock_wait_getcpu(csd);
pr_alert("csd: CSD lock (#%d) got unstuck on CPU#%02d, CPU#%02d released the lock.\n",
- *bug_id, raw_smp_processor_id(), cpu);
+ state->bug_id, raw_smp_processor_id(), cpu);
atomic_dec(&n_csd_lock_stuck);
return true;
}
- ts2 = ktime_get_mono_fast_ns();
+ ts_now = ktime_get_mono_fast_ns();
/* How long since we last checked for a stuck CSD lock.*/
- ts_delta = ts2 - *ts1;
- if (likely(ts_delta <= csd_lock_timeout_ns * (*nmessages + 1) *
- (!*nmessages ? 1 : (ilog2(num_online_cpus()) / 2 + 1)) ||
+ ts_delta = ts_now - state->ts_report;
+ if (likely(ts_delta <= csd_lock_timeout_ns * (state->nmessages + 1) *
+ (!state->nmessages ? 1 : (ilog2(num_online_cpus()) / 2 + 1)) ||
csd_lock_timeout_ns == 0))
return false;
- if (ts0 > ts2) {
+ if (state->ts_start > ts_now) {
/* Our own sched_clock went backward; don't blame another CPU. */
- ts_delta = ts0 - ts2;
+ ts_delta = state->ts_start - ts_now;
pr_alert("sched_clock on CPU %d went backward by %llu ns\n", raw_smp_processor_id(), ts_delta);
- *ts1 = ts2;
+ state->ts_report = ts_now;
return false;
}
- firsttime = !*bug_id;
+ firsttime = !state->bug_id;
if (firsttime)
- *bug_id = atomic_inc_return(&csd_bug_count);
+ state->bug_id = atomic_inc_return(&csd_bug_count);
cpu = csd_lock_wait_getcpu(csd);
if (WARN_ONCE(cpu < 0 || cpu >= nr_cpu_ids, "%s: cpu = %d\n", __func__, cpu))
cpux = 0;
@@ -274,11 +282,11 @@ static bool csd_lock_wait_toolong(call_single_data_t *csd, u64 ts0, u64 *ts1, in
cpux = cpu;
cpu_cur_csd = smp_load_acquire(&per_cpu(cur_csd, cpux)); /* Before func and info. */
/* How long since this CSD lock was stuck. */
- ts_delta = ts2 - ts0;
+ ts_delta = ts_now - state->ts_start;
pr_alert("csd: %s non-responsive CSD lock (#%d) on CPU#%d, waiting %lld ns for CPU#%02d %pS(%ps).\n",
- firsttime ? "Detected" : "Continued", *bug_id, raw_smp_processor_id(), (s64)ts_delta,
+ firsttime ? "Detected" : "Continued", state->bug_id, raw_smp_processor_id(), (s64)ts_delta,
cpu, csd->func, csd->info);
- (*nmessages)++;
+ state->nmessages++;
if (firsttime)
atomic_inc(&n_csd_lock_stuck);
/*
@@ -289,23 +297,23 @@ static bool csd_lock_wait_toolong(call_single_data_t *csd, u64 ts0, u64 *ts1, in
BUG_ON(panic_on_ipistall > 0 && (s64)ts_delta > ((s64)panic_on_ipistall * NSEC_PER_MSEC));
if (cpu_cur_csd && csd != cpu_cur_csd) {
pr_alert("\tcsd: CSD lock (#%d) handling prior %pS(%ps) request.\n",
- *bug_id, READ_ONCE(per_cpu(cur_csd_func, cpux)),
+ state->bug_id, READ_ONCE(per_cpu(cur_csd_func, cpux)),
READ_ONCE(per_cpu(cur_csd_info, cpux)));
} else {
pr_alert("\tcsd: CSD lock (#%d) %s.\n",
- *bug_id, !cpu_cur_csd ? "unresponsive" : "handling this request");
+ state->bug_id, !cpu_cur_csd ? "unresponsive" : "handling this request");
}
if (cpu >= 0) {
if (atomic_cmpxchg_acquire(&per_cpu(trigger_backtrace, cpu), 1, 0))
dump_cpu_task(cpu);
if (!cpu_cur_csd) {
- pr_alert("csd: Re-sending CSD lock (#%d) IPI from CPU#%02d to CPU#%02d\n", *bug_id, raw_smp_processor_id(), cpu);
+ pr_alert("csd: Re-sending CSD lock (#%d) IPI from CPU#%02d to CPU#%02d\n", state->bug_id, raw_smp_processor_id(), cpu);
arch_send_call_function_single_ipi(cpu);
}
}
if (firsttime)
dump_stack();
- *ts1 = ts2;
+ state->ts_report = ts_now;
return false;
}
@@ -319,13 +327,11 @@ static bool csd_lock_wait_toolong(call_single_data_t *csd, u64 ts0, u64 *ts1, in
*/
static void __csd_lock_wait(call_single_data_t *csd)
{
- unsigned long nmessages = 0;
- int bug_id = 0;
- u64 ts0, ts1;
+ struct csd_wait_state state = {};
- ts1 = ts0 = ktime_get_mono_fast_ns();
+ state.ts_report = state.ts_start = ktime_get_mono_fast_ns();
for (;;) {
- if (csd_lock_wait_toolong(csd, ts0, &ts1, &bug_id, &nmessages))
+ if (csd_lock_wait_toolong(csd, &state))
break;
cpu_relax();
}
--
2.53.0-Meta
next prev parent reply other threads:[~2026-08-10 11:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 11:29 [PATCH v2 0/3] locking/csd-lock: Report how long a CSD stall lasted Breno Leitao
2026-08-10 11:29 ` Breno Leitao [this message]
2026-08-10 14:32 ` [PATCH v2 1/3] locking/csd-lock: Pack csd_lock_wait_toolong() state into a struct Dmitry Ilvokhin
2026-08-10 11:29 ` [PATCH v2 2/3] locking/csd-lock: Report how long a stuck CSD lock took to recover Breno Leitao
2026-08-10 11:29 ` [PATCH v2 3/3] lib/test_csd_lock: Add a module to stall a CPU on a CSD lock Breno Leitao
2026-08-12 0:14 ` [PATCH v2 0/3] locking/csd-lock: Report how long a CSD stall lasted Paul E. McKenney
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=20260810-csd-stall-duration-v2-1-795083bf04a4@debian.org \
--to=leitao@debian.org \
--cc=akpm@linux-foundation.org \
--cc=bigeasy@linutronix.de \
--cc=d@ilvokhin.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@kernel.org \
/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
all inboxes | Powered by JetHome®