Re: [PATCH] lib/nmi_backtrace: print out the CPUs which fail to respond to NMI
From: Andrew Morton
Date: Thu May 21 2026 - 23:53:39 EST
On Fri, 22 May 2026 09:46:26 +0800 Feng Tang <feng.tang@xxxxxxxxxxxxxxxxx> wrote:
> > It's a nitpick, but
> >
> > : /* Wait for up to 10 seconds for all CPUs to do the backtrace */
> > : for (i = 0; i < 10 * 1000; i++) {
> > : if (cpumask_empty(to_cpumask(backtrace_mask)))
> > : break;
> > : mdelay(1);
> > : touch_softlockup_watchdog();
> > : }
> > :
> > : if (!cpumask_empty(to_cpumask(backtrace_mask))) {
> > : pr_warn("After 10 seconds, these CPUS still haven't responded to the NMI: %*pbl\n",
> >
> > Here we're hard-coding "10" in two places and in a comment. It would
> > be nicer to do
> >
> > #define FOO_TIMEOUT 10
> >
> > then use that throughout.
> >
> > (bonus points for figuring out how to paste that "10" into the
> > pr_warn() control string rather than using %d!)
>
> How about this followon patch?
Looks great. But you missed the fun part!
--- a/lib/nmi_backtrace.c~lib-nmi_backtrace-print-out-the-cpus-which-fail-to-respond-to-nmi-fix-fix
+++ a/lib/nmi_backtrace.c
@@ -16,6 +16,7 @@
#include <linux/cpumask.h>
#include <linux/delay.h>
#include <linux/kprobes.h>
+#include <linux/stringify.h>
#include <linux/nmi.h>
#include <linux/cpu.h>
#include <linux/sched/debug.h>
@@ -79,8 +80,8 @@ void nmi_trigger_cpumask_backtrace(const
}
if (!cpumask_empty(to_cpumask(backtrace_mask))) {
- pr_warn("After %d seconds, these CPUS still haven't responded to the NMI: %*pbl\n",
- NMI_BT_TIMEOUT_SEC, cpumask_pr_args(to_cpumask(backtrace_mask)));
+ pr_warn("After " __stringify(NMI_BT_TIMEOUT_SEC) " seconds, these CPUS still haven't responded to the NMI: %*pbl\n",
+ cpumask_pr_args(to_cpumask(backtrace_mask)));
nmi_backtrace_stall_check(to_cpumask(backtrace_mask));
}
_
It saved five bytes!