[PATCH 2/4] nmi_backtrace: generate one-line reports for idle cpus
From: Chris Metcalf
Date: Mon Feb 29 2016 - 16:40:52 EST
When doing an nmi backtrace of many cores, and most of them are idle,
the output is a little overwhelming and very uninformative. Suppress
messages for cpus that are idling when they are interrupted and
just emit one line, "NMI backtrace for N skipped: idle".
Signed-off-by: Chris Metcalf <cmetcalf@xxxxxxxxxx>
---
lib/nmi_backtrace.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/lib/nmi_backtrace.c b/lib/nmi_backtrace.c
index db63ac75eba0..f878efc9e851 100644
--- a/lib/nmi_backtrace.c
+++ b/lib/nmi_backtrace.c
@@ -142,6 +142,15 @@ static int nmi_vprintk(const char *fmt, va_list args)
return seq_buf_used(&s->seq) - len;
}
+static bool idling(void)
+{
+ if (!is_idle_task(current))
+ return false;
+
+ /* Account for nmi_enter() having been called once. */
+ return hardirq_count() == HARDIRQ_OFFSET && !in_softirq();
+}
+
bool nmi_cpu_backtrace(struct pt_regs *regs)
{
int cpu = smp_processor_id();
@@ -151,11 +160,16 @@ bool nmi_cpu_backtrace(struct pt_regs *regs)
/* Replace printk to write into the NMI seq */
this_cpu_write(printk_func, nmi_vprintk);
- pr_warn("NMI backtrace for cpu %d\n", cpu);
- if (regs)
- show_regs(regs);
- else
- dump_stack();
+ if (idling()) {
+ pr_warn("NMI backtrace for cpu %d skipped: idle\n",
+ cpu);
+ } else {
+ pr_warn("NMI backtrace for cpu %d\n", cpu);
+ if (regs)
+ show_regs(regs);
+ else
+ dump_stack();
+ }
this_cpu_write(printk_func, printk_func_save);
cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));
--
2.1.2