improvements to the nmi_backtrace code
Subsystems (27)
v7 cover improvements to the nmi_backtrace code
This is a rebase of the v6 series onto v4.8-rc1, plus some changes from Petr Mladek's review this morning.
From the version 1 cover letter:
This patch series modifies the trigger_xxx_backtrace() NMI-based remote backtracing code to make it more flexible, and makes a few small improvements along the way.
The motivation comes from the task isolation code, where there are scenarios where we want to be able to diagnose a case where some cpu is about to interrupt a task-isolated cpu. It can be helpful to see both where the interrupting cpu is, and also an approximation of where the cpu that is being interrupted is. The nmi_backtrace framework allows us to discover the stack of the interrupted cpu.
I've tested that the change works as desired on tile, and build-tested x86, arm64, and arm. For x86 and arm64 I confirmed that the generic cpuidle stuff as well as the architecture-specific routines are in the new cpuidle section. For arm I just build-tested it and made sure the generic cpuidle routines were in the new cpuidle section, but I didn't attempt to tease apart the tangle of platform-specific idle routines that arm has and tag them with __cpuidle. That might be more usefully done by someone with arm platform experience in a follow-up patch.
I have also pushed it up to kernel.org to pull if that's easier:
git://git.kernel.org/pub/scm/linux/kernel/git/cmetcalf/linux-tile.git nmi-backtrace
v7: Rebased to kernel v4.8-r1
Retained the "include_self" bool to avoid cpumask allocation [Petr] Switched to using "cpumask_of" to avoid cpumask allocation [Petr]
v6: Rebased to kernel v4.7-rc7
v5: Add CPUIDLE_TEXT to the new arch/arm/kernel/vmlinux-xip.lds.S
https://lkml.kernel.org/g/[email protected]
v4: Added some more __cpuidle functions (PeterZ, Rafael Wysocki)
Rebased to kernel v4.6-rc1
https://lkml.kernel.org/g/[email protected]
v3: Various improvements to the set of __cpuidle functions;
Add back in a missing section accidentally removed in modpost.c (PeterZ)
https://lkml.kernel.org/r/[email protected]
v2: Switch to using __cpuidle tagging, switch S-O-B to Mellanox
https://lkml.kernel.org/r/[email protected]
Chris Metcalf (4):
nmi_backtrace: add more trigger_*_cpu_backtrace() methods
nmi_backtrace: do a local dump_stack() instead of a self-NMI arch/tile: adopt the new nmi_backtrace framework
nmi_backtrace: generate one-line reports for idle cpus
arch/alpha/kernel/vmlinux.lds.S | 1 + arch/arc/kernel/vmlinux.lds.S | 1 + arch/arm/include/asm/irq.h | 5 ++- arch/arm/kernel/smp.c | 13 +------ arch/arm/kernel/vmlinux-xip.lds.S | 1 + arch/arm/kernel/vmlinux.lds.S | 1 + arch/arm64/kernel/vmlinux.lds.S | 1 + arch/arm64/mm/proc.S | 2 + arch/avr32/kernel/vmlinux.lds.S | 1 + arch/blackfin/kernel/vmlinux.lds.S | 1 + arch/c6x/kernel/vmlinux.lds.S | 1 + arch/cris/kernel/vmlinux.lds.S | 1 + arch/frv/kernel/vmlinux.lds.S | 1 + arch/h8300/kernel/vmlinux.lds.S | 1 + arch/hexagon/kernel/vmlinux.lds.S | 1 + arch/ia64/kernel/vmlinux.lds.S | 1 + arch/m32r/kernel/vmlinux.lds.S | 1 + arch/m68k/kernel/vmlinux-nommu.lds | 1 + arch/m68k/kernel/vmlinux-std.lds | 1 + arch/m68k/kernel/vmlinux-sun3.lds | 1 + arch/metag/kernel/vmlinux.lds.S | 1 + arch/microblaze/kernel/vmlinux.lds.S | 1 + arch/mips/kernel/vmlinux.lds.S | 1 + arch/mn10300/kernel/vmlinux.lds.S | 1 + arch/nios2/kernel/vmlinux.lds.S | 1 + arch/openrisc/kernel/vmlinux.lds.S | 1 + arch/parisc/kernel/vmlinux.lds.S | 1 + arch/powerpc/kernel/vmlinux.lds.S | 1 + arch/s390/kernel/vmlinux.lds.S | 1 + arch/score/kernel/vmlinux.lds.S | 1 + arch/sh/kernel/vmlinux.lds.S | 1 + arch/sparc/kernel/vmlinux.lds.S | 1 + arch/tile/include/asm/irq.h | 5 ++- arch/tile/kernel/entry.S | 2 +- arch/tile/kernel/pmc.c | 3 -- arch/tile/kernel/process.c | 73 +++++++++--------------------------- arch/tile/kernel/traps.c | 7 +++- arch/tile/kernel/vmlinux.lds.S | 1 + arch/um/kernel/dyn.lds.S | 1 + arch/um/kernel/uml.lds.S | 1 + arch/unicore32/kernel/vmlinux.lds.S | 1 + arch/x86/include/asm/irq.h | 5 ++- arch/x86/kernel/acpi/cstate.c | 2 +- arch/x86/kernel/apic/hw_nmi.c | 7 ++-- arch/x86/kernel/process.c | 4 +- arch/x86/kernel/vmlinux.lds.S | 1 + arch/xtensa/kernel/vmlinux.lds.S | 3 ++ drivers/acpi/processor_idle.c | 5 ++- drivers/cpuidle/driver.c | 5 ++- drivers/idle/intel_idle.c | 4 +- include/asm-generic/vmlinux.lds.h | 6 +++ include/linux/cpu.h | 5 +++ include/linux/nmi.h | 49 +++++++++++++++++------- kernel/sched/idle.c | 13 ++++++- lib/nmi_backtrace.c | 38 +++++++++++++------ scripts/mod/modpost.c | 2 +- scripts/recordmcount.c | 1 + scripts/recordmcount.pl | 1 + 58 files changed, 176 insertions(+), 118 deletions(-)
Signature · 1 line
2.7.2
PATCH v7 1/4 nmi_backtrace: add more trigger_*_cpu_backtrace() methods
Currently you can only request a backtrace of either all cpus, or all cpus but yourself. It can also be helpful to request a remote backtrace of a single cpu, and since we want that, the logical extension is to support a cpumask as the underlying primitive.
This change modifies the existing lib/nmi_backtrace.c code to take a cpumask as its basic primitive, and modifies the linux/nmi.h code to use either the old "all/all_but_self" arch methods, or the new "cpumask" method, depending on which is available.
The existing clients of nmi_backtrace (arm and x86) are converted to using the new cpumask approach in this change.
--- arch/arm/include/asm/irq.h | 5 +++-- arch/arm/kernel/smp.c | 4 ++-- arch/x86/include/asm/irq.h | 5 +++-- arch/x86/kernel/apic/hw_nmi.c | 7 ++++--- include/linux/nmi.h | 49 +++++++++++++++++++++++++++++++------------ lib/nmi_backtrace.c | 13 ++++++------ 6 files changed, 55 insertions(+), 28 deletions(-)
arch/arm/include/asm/irq.h +3 -2
@@ -36,8 +36,9 @@ extern void set_handle_irq(void (*handle_irq)(struct pt_regs *));#endif #ifdef CONFIG_SMP -extern void arch_trigger_all_cpu_backtrace (bool ); -#define arch_trigger_all_cpu_backtrace (x) arch_trigger_all_cpu_backtrace(x) +extern void arch_trigger_cpumask_backtrace (bool include_self, +const cpumask_t *mask); +#define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace#endif static inline int nr_legacy_irqs (void )
arch/arm/kernel/smp.c +2 -2
@@ -760,7 +760,7 @@ static void raise_nmi(cpumask_t *mask)smp_cross_call (mask,IPI_CPU_BACKTRACE ); } -void arch_trigger_all_cpu_backtrace (bool include_self) +void arch_trigger_cpumask_backtrace (bool include_self,const cpumask_t *mask) { -nmi_trigger_all_cpu_backtrace (include_self, raise_nmi); +nmi_trigger_cpumask_backtrace (include_self, mask, raise_nmi); }
arch/x86/include/asm/irq.h +3 -2
@@ -50,8 +50,9 @@ extern int vector_used_by_percpu_irq(unsigned int vector);extern void init_ISA_irqs (void );#ifdef CONFIG_X86_LOCAL_APIC -void arch_trigger_all_cpu_backtrace (bool ); -#define arch_trigger_all_cpu_backtrace arch_trigger_all_cpu_backtrace +void arch_trigger_cpumask_backtrace (bool include_self, +const struct cpumask *mask); +#define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace#endif #endif /* _ASM_X86_IRQ_H */
arch/x86/kernel/apic/hw_nmi.c +4 -3
@@ -26,15 +26,16 @@ u64 hw_nmi_get_sample_period(int watchdog_thresh) }#endif -#ifdef arch_trigger_all_cpu_backtrace +#ifdef arch_trigger_cpumask_backtracestatic void nmi_raise_cpu_backtrace (cpumask_t *mask) { apic->send_IPI_mask (mask,NMI_VECTOR ); } -void arch_trigger_all_cpu_backtrace (bool include_self) +void arch_trigger_cpumask_backtrace (bool include_self,const cpumask_t *mask) { -nmi_trigger_all_cpu_backtrace (include_self, nmi_raise_cpu_backtrace); +nmi_trigger_cpumask_backtrace (include_self, mask, + nmi_raise_cpu_backtrace); } static int
include/linux/nmi.h +36 -13
74 lines not on this page · raw message
lib/nmi_backtrace.c +7 -6
@@ -17,7 +17,7 @@#include <linux/kprobes.h> #include <linux/nmi.h> -#ifdef arch_trigger_all_cpu_backtrace +#ifdef arch_trigger_cpumask_backtrace/* For reliability, we're prepared to waste bits here. */ static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
@@ -25,12 +25,13 @@ static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;static unsigned long backtrace_flag;/* -* When raise() is called it will be is passed a pointer to the +* When raise() is called it will be passed a pointer to the * backtrace_mask. Architectures that call nmi_cpu_backtrace() * directly from their raise() functions may rely on the mask * they are passed being updated as a side effect of this call. */ -void nmi_trigger_all_cpu_backtrace (bool include_self, +void nmi_trigger_cpumask_backtrace (bool include_self, +const cpumask_t *mask,void (*raise)(cpumask_t *mask)) {int i, this_cpu =get_cpu ();
@@ -44,13 +45,13 @@ void nmi_trigger_all_cpu_backtrace(bool include_self,return ; } -cpumask_copy (to_cpumask (backtrace_mask), cpu_online_mask); +cpumask_copy (to_cpumask (backtrace_mask), mask);if (!include_self)cpumask_clear_cpu (this_cpu,to_cpumask (backtrace_mask));if (!cpumask_empty (to_cpumask (backtrace_mask))) { -pr_info ("Sending NMI to %s CPUs:\n" , - (include_self ?"all" :"other" )); +pr_info ("Sending NMI from CPU %d to CPUs %*pbl:\n" , + this_cpu, nr_cpumask_bits,to_cpumask (backtrace_mask));raise (to_cpumask (backtrace_mask)); }
Signature · 1 line
2.7.2
Re: [PATCH v7 1/4] nmi_backtrace: add more trigger_*_cpu_backtrace() methods
Quoted 9 lines · Chris Metcalf
Currently you can only request a backtrace of either all cpus, or all cpus but yourself. It can also be helpful to request a remote backtrace of a single cpu, and since we want that, the logical extension is to support a cpumask as the underlying primitive.
This change modifies the existing
lib/nmi_backtrace.ccode to take a cpumask as its basic primitive, and modifies thelinux/nmi.hcode to use either the old "all/all_but_self" arch methods, or the new "cpumask" method, depending on which is available.
I seems to work fine. But I have some comments from the nitpicking department, please see below.
Quoted 4 lines
arch/x86/kernel/apic/hw_nmi.c +0
-0
arch/x86/kernel/apic/hw_nmi.c u64 hw_nmi_get_sample_period(int watchdog_thresh) · line 38
Quoted 10 lines
arch/x86/kernel/apic/hw_nmi.c +3
-2{ apic->send_IPI_mask (mask,NMI_VECTOR ); } -void arch_trigger_all_cpu_backtrace (bool include_self) +void arch_trigger_cpumask_backtrace (bool include_self,const cpumask_t *mask) { -nmi_trigger_all_cpu_backtrace (include_self, nmi_raise_cpu_backtrace); +nmi_trigger_cpumask_backtrace (include_self, mask, + nmi_raise_cpu_backtrace);
It would make sense to rename too the functions in in arch/x86/kernel/apic/hw_nmi.c that contains the "all_cpu" in the name. In fact, the current names are rather confusing. I suggest to do:
register_trigger_all_cpu_backtrace()
-> register_nmi_cpu_backtrace_handler()
arch_trigger_all_cpu_backtrace_handler()
-> nmi_cpu_backtrace_handler()
Quoted 21 lines
}
static int
include/linux/nmi.h +2
-3@@ -31,38 +31,61 @@ static inline void hardlockup_detector_disable(void) {}#endif /* -* Create trigger_all_cpu_backtrace() out of the arch-provided -* base function. Return whether such support was available, +* Create trigger_all_cpu_backtrace() etc out of the arch-provided +* base function(s). Return whether such support was available, * to allow calling code to fall back to some other mechanism: */ -#ifdef arch_trigger_all_cpu_backtracestatic inline bool trigger_all_cpu_backtrace (void ) {
include/linux/nmi.h static inline void hardlockup_detector_disable(void) {} · line 48
Quoted 10 lines
include/linux/nmi.h +7
-1+#if defined(arch_trigger_all_cpu_backtrace)arch_trigger_all_cpu_backtrace (true); -return true; +#elif defined(arch_trigger_cpumask_backtrace) +arch_trigger_cpumask_backtrace (true, cpu_online_mask); +return true; +#else +return false; +#endif
Please, are there any plans to implement the cpumask variant also on mips and sparc? So that all architectures are alligned again and ifdefs reduced.
Quoted 17 lines
lib/nmi_backtrace.c +1
-1@@ -17,7 +17,7 @@#include <linux/kprobes.h> #include <linux/nmi.h> -#ifdef arch_trigger_all_cpu_backtrace +#ifdef arch_trigger_cpumask_backtrace/* For reliability, we're prepared to waste bits here. */ static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;@@ -25,12 +25,13 @@ static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;static unsigned long backtrace_flag;/*
lib/nmi_backtrace.c static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly; · line 35
Quoted 10 lines
lib/nmi_backtrace.c +3
-2-* When raise() is called it will be is passed a pointer to the +* When raise() is called it will be passed a pointer to the * backtrace_mask. Architectures that call nmi_cpu_backtrace() * directly from their raise() functions may rely on the mask * they are passed being updated as a side effect of this call. */ -void nmi_trigger_all_cpu_backtrace (bool include_self, +void nmi_trigger_cpumask_backtrace (bool include_self, +const cpumask_t *mask,void (*raise)(cpumask_t *mask))
The name "include_self" is confusing. The code does the opposite. It excludes self when the value is false. I would rename it to "exclude_self".
Also I would put the "mask" as the first parameter. The cpumask is the main information. It is modified by the boolean. Finally the NMI is raised by the "raise" function.
Best Regards,
Petr
PATCH v7 2/4 nmi_backtrace: do a local dump_stack() instead of a self-NMI
In reply to Chris MetcalfCurrently on arm there is code that checks whether it should call dump_stack() explicitly, to avoid trying to raise an NMI when the current context is not preemptible by the backtrace IPI. Similarly, the forthcoming arch/tile support uses an IPI mechanism that does not support generating an NMI to self.
Accordingly, move the code that guards this case into the generic mechanism, and invoke it unconditionally whenever we want a backtrace of the current cpu. It seems plausible that in all cases, dump_stack() will generate better information than generating a stack from the NMI handler. The register state will be missing, but that state is likely not particularly helpful in any case.
Or, if we think it is helpful, we should be capturing and emitting the current register state in all cases when regs == NULL is passed to nmi_cpu_backtrace().
--- arch/arm/kernel/smp.c | 9 --------- lib/nmi_backtrace.c | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-)
arch/arm/kernel/smp.c +0 -9
@@ -748,15 +748,6 @@ core_initcall(register_cpufreq_notifier);static void raise_nmi (cpumask_t *mask) { -/* -* Generate the backtrace directly if we are running in a calling -* context that is not preemptible by the backtrace IPI. Note -* that nmi_cpu_backtrace() automatically removes the current cpu -* from mask. -*/ -if (cpumask_test_cpu (smp_processor_id (), mask) &&irqs_disabled ()) -nmi_cpu_backtrace (NULL ); -smp_cross_call (mask,IPI_CPU_BACKTRACE ); }
lib/nmi_backtrace.c +9 -0
@@ -49,6 +49,15 @@ void nmi_trigger_cpumask_backtrace(bool include_self,if (!include_self)cpumask_clear_cpu (this_cpu,to_cpumask (backtrace_mask)); +/* +* Don't try to send an NMI to this cpu; it may work on some +* architectures, but on others it may not, and we'll get +* information at least as useful just by doing a dump_stack() here. +* Note that nmi_cpu_backtrace(NULL) will clear the cpu bit. +*/ +if (cpumask_test_cpu (this_cpu,to_cpumask (backtrace_mask))) +nmi_cpu_backtrace (NULL ); +if (!cpumask_empty (to_cpumask (backtrace_mask))) {pr_info ("Sending NMI from CPU %d to CPUs %*pbl:\n" , this_cpu, nr_cpumask_bits,to_cpumask (backtrace_mask));
Signature · 1 line
2.7.2
Re: [PATCH v7 2/4] nmi_backtrace: do a local dump_stack() instead of a self-NMI
Quoted 13 lines · Chris Metcalf
Currently on arm there is code that checks whether it should call
dump_stack()explicitly, to avoid trying to raise an NMI when the current context is not preemptible by the backtrace IPI. Similarly, the forthcomingarch/tilesupport uses an IPI mechanism that does not support generating an NMI to self.Accordingly, move the code that guards this case into the generic mechanism, and invoke it unconditionally whenever we want a backtrace of the current cpu. It seems plausible that in all cases,
dump_stack()will generate better information than generating a stack from the NMI handler. The register state will be missing, but that state is likely not particularly helpful in any case.
Quoted 6 lines
Or, if we think it is helpful, we should be capturing and emitting the current register state in all cases when regs == NULL is passed to
nmi_cpu_backtrace().Signed-off-by Chris Metcalf <[email protected]>Acked-by Aaron Tomlin <[email protected]>
Sounds and looks fine to me.
Best Regards,
Petr Mladek
PATCH v7 3/4 arch/tile: adopt the new nmi_backtrace framework
In reply to Chris MetcalfPreviously tile was rolling its own method of capturing backtrace data in the NMI handlers, but it was relying on running printk() from the NMI handler, which is not always safe. So adopt the nmi_backtrace model (with the new cpumask extension) instead.
So we can call the nmi_backtrace code directly from the nmi handler, move the nmi_enter()/exit() into the top-level tile NMI handler.
The semantics of the routine change slightly since it is now synchronous with the remote cores completing the backtraces. Previously it was asynchronous, but with protection to avoid starting a new remote backtrace if the old one was still in progress.
--- arch/tile/include/asm/irq.h | 5 ++-- arch/tile/kernel/pmc.c | 3 -- arch/tile/kernel/process.c | 73 +++++++++++---------------------------------- arch/tile/kernel/traps.c | 7 +++-- 4 files changed, 25 insertions(+), 63 deletions(-)
arch/tile/include/asm/irq.h +3 -2
@@ -79,8 +79,9 @@ void tile_irq_activate(unsigned int irq, int tile_irq_type);void setup_irq_regs (void );#ifdef __tilegx__ -void arch_trigger_all_cpu_backtrace (bool self); -#define arch_trigger_all_cpu_backtrace arch_trigger_all_cpu_backtrace +void arch_trigger_cpumask_backtrace (bool include_self, +const struct cpumask *mask); +#define arch_trigger_cpumask_backtrace arch_trigger_cpumask_backtrace#endif #endif /* _ASM_TILE_IRQ_H */
arch/tile/kernel/pmc.c +0 -3
@@ -16,7 +16,6 @@#include <linux/spinlock.h> #include <linux/module.h> #include <linux/atomic.h> -#include <linux/interrupt.h> #include <asm/processor.h> #include <asm/pmc.h>
@@ -29,9 +28,7 @@ int handle_perf_interrupt(struct pt_regs *regs, int fault)if (!perf_irq)panic ("Unexpected PERF_COUNT interrupt %d\n" , fault); -nmi_enter (); retval =perf_irq (regs, fault); -nmi_exit ();return retval; }
arch/tile/kernel/process.c +17 -56
118 lines not on this page · raw message
arch/tile/kernel/traps.c +5 -2
@@ -20,6 +20,8 @@#include <linux/reboot.h> #include <linux/uaccess.h> #include <linux/ptrace.h> +#include <linux/hardirq.h> +#include <linux/nmi.h> #include <asm/stack.h> #include <asm/traps.h> #include <asm/setup.h>
@@ -392,14 +394,15 @@ void __kprobes do_trap(struct pt_regs *regs, int fault_num,void do_nmi (struct pt_regs *regs,int fault_num,unsigned long reason) { +nmi_enter ();switch (reason) {case TILE_NMI_DUMP_STACK : -do_nmi_dump_stack (regs); +nmi_cpu_backtrace (regs);break ;default :panic ("Unexpected do_nmi type %ld" , reason); -return ; } +nmi_exit (); }/* Deprecated function currently only used here. */
Signature · 1 line
2.7.2
PATCH v7 4/4 nmi_backtrace: generate one-line reports for idle cpus
In reply to Chris MetcalfWhen doing an nmi backtrace of many cores, most of which 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: idling at pc 0xNNN".
We do this by grouping all the cpuidle code together into a new .cpuidle.text section, and then checking the address of the interrupted PC to see if it lies within that section.
This commit suitably tags x86, arm64, and tile idle routines, and only adds in the minimal framework for other architectures.
--- arch/alpha/kernel/vmlinux.lds.S | 1 + arch/arc/kernel/vmlinux.lds.S | 1 + arch/arm/kernel/vmlinux-xip.lds.S | 1 + arch/arm/kernel/vmlinux.lds.S | 1 + arch/arm64/kernel/vmlinux.lds.S | 1 + arch/arm64/mm/proc.S | 2 ++ arch/avr32/kernel/vmlinux.lds.S | 1 + arch/blackfin/kernel/vmlinux.lds.S | 1 + arch/c6x/kernel/vmlinux.lds.S | 1 + arch/cris/kernel/vmlinux.lds.S | 1 + arch/frv/kernel/vmlinux.lds.S | 1 + arch/h8300/kernel/vmlinux.lds.S | 1 + arch/hexagon/kernel/vmlinux.lds.S | 1 + arch/ia64/kernel/vmlinux.lds.S | 1 + arch/m32r/kernel/vmlinux.lds.S | 1 + arch/m68k/kernel/vmlinux-nommu.lds | 1 + arch/m68k/kernel/vmlinux-std.lds | 1 + arch/m68k/kernel/vmlinux-sun3.lds | 1 + arch/metag/kernel/vmlinux.lds.S | 1 + arch/microblaze/kernel/vmlinux.lds.S | 1 + arch/mips/kernel/vmlinux.lds.S | 1 + arch/mn10300/kernel/vmlinux.lds.S | 1 + arch/nios2/kernel/vmlinux.lds.S | 1 + arch/openrisc/kernel/vmlinux.lds.S | 1 + arch/parisc/kernel/vmlinux.lds.S | 1 + arch/powerpc/kernel/vmlinux.lds.S | 1 + arch/s390/kernel/vmlinux.lds.S | 1 + arch/score/kernel/vmlinux.lds.S | 1 + arch/sh/kernel/vmlinux.lds.S | 1 + arch/sparc/kernel/vmlinux.lds.S | 1 + arch/tile/kernel/entry.S | 2 +- arch/tile/kernel/vmlinux.lds.S | 1 + arch/um/kernel/dyn.lds.S | 1 + arch/um/kernel/uml.lds.S | 1 + arch/unicore32/kernel/vmlinux.lds.S | 1 + arch/x86/kernel/acpi/cstate.c | 2 +- arch/x86/kernel/process.c | 4 ++-- arch/x86/kernel/vmlinux.lds.S | 1 + arch/xtensa/kernel/vmlinux.lds.S | 3 +++ drivers/acpi/processor_idle.c | 5 +++-- drivers/cpuidle/driver.c | 5 +++-- drivers/idle/intel_idle.c | 4 ++-- include/asm-generic/vmlinux.lds.h | 6 ++++++ include/linux/cpu.h | 5 +++++ kernel/sched/idle.c | 13 +++++++++++-- lib/nmi_backtrace.c | 16 +++++++++++----- scripts/mod/modpost.c | 2 +- scripts/recordmcount.c | 1 + scripts/recordmcount.pl | 1 + 49 files changed, 87 insertions(+), 18 deletions(-)
arch/alpha/kernel/vmlinux.lds.S +1 -0
@@ -22,6 +22,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.gnu.warning)
arch/arc/kernel/vmlinux.lds.S +1 -0
@@ -97,6 +97,7 @@ SECTIONS _text = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.fixup)
arch/arm/kernel/vmlinux-xip.lds.S +1 -0
@@ -98,6 +98,7 @@ SECTIONS IRQENTRY_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.gnu.warning)
arch/arm/kernel/vmlinux.lds.S +1 -0
@@ -111,6 +111,7 @@ SECTIONS SOFTIRQENTRY_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT HYPERVISOR_TEXT KPROBES_TEXT
arch/arm64/kernel/vmlinux.lds.S +1 -0
@@ -122,6 +122,7 @@ SECTIONS ENTRY_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT HYPERVISOR_TEXT
arch/arm64/mm/proc.S +2 -0
@@ -48,11 +48,13 @@ * * Idle the processor (wait for interrupt). */ + .pushsection ".cpuidle.text","ax" ENTRY(cpu_do_idle) dsb sy // WFI may enter a low-power mode wfi ret ENDPROC(cpu_do_idle) + .popsection #ifdef CONFIG_CPU_PM /**
arch/avr32/kernel/vmlinux.lds.S +1 -0
@@ -52,6 +52,7 @@ SECTIONS KPROBES_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.gnu.warning)
arch/blackfin/kernel/vmlinux.lds.S +1 -0
@@ -33,6 +33,7 @@ SECTIONS #ifndef CONFIG_SCHEDULE_L1 SCHED_TEXT #endif + CPUIDLE_TEXT LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT
arch/c6x/kernel/vmlinux.lds.S +1 -0
@@ -70,6 +70,7 @@ SECTIONS _stext = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT
arch/cris/kernel/vmlinux.lds.S +1 -0
@@ -43,6 +43,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.text.__*)
arch/frv/kernel/vmlinux.lds.S +1 -0
@@ -63,6 +63,7 @@ SECTIONS *(.text..tlbmiss) TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT #ifdef CONFIG_DEBUG_INFO INIT_TEXT
arch/h8300/kernel/vmlinux.lds.S +1 -0
@@ -29,6 +29,7 @@ SECTIONS _stext = . ; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT #if defined(CONFIG_ROMKERNEL) *(.int_redirect)
arch/hexagon/kernel/vmlinux.lds.S +1 -0
@@ -50,6 +50,7 @@ SECTIONS _text = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.fixup)
arch/ia64/kernel/vmlinux.lds.S +1 -0
@@ -46,6 +46,7 @@ SECTIONS { __end_ivt_text = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.gnu.linkonce.t*)
arch/m32r/kernel/vmlinux.lds.S +1 -0
@@ -31,6 +31,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.gnu.warning)
arch/m68k/kernel/vmlinux-nommu.lds +1 -0
@@ -45,6 +45,7 @@ SECTIONS { HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) . = ALIGN(16);
arch/m68k/kernel/vmlinux-std.lds +1 -0
@@ -16,6 +16,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.gnu.warning)
arch/m68k/kernel/vmlinux-sun3.lds +1 -0
@@ -16,6 +16,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.gnu.warning)
arch/metag/kernel/vmlinux.lds.S +1 -0
@@ -21,6 +21,7 @@ SECTIONS .text : { TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXT
arch/microblaze/kernel/vmlinux.lds.S +1 -0
@@ -33,6 +33,7 @@ SECTIONS { EXIT_TEXT EXIT_CALL SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXT
arch/mips/kernel/vmlinux.lds.S +1 -0
@@ -55,6 +55,7 @@ SECTIONS .text : { TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXT
arch/mn10300/kernel/vmlinux.lds.S +1 -0
@@ -30,6 +30,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.fixup)
arch/nios2/kernel/vmlinux.lds.S +1 -0
@@ -37,6 +37,7 @@ SECTIONS .text : { TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT
arch/openrisc/kernel/vmlinux.lds.S +1 -0
@@ -47,6 +47,7 @@ SECTIONS _stext = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXT
arch/parisc/kernel/vmlinux.lds.S +1 -0
@@ -69,6 +69,7 @@ SECTIONS .text ALIGN(PAGE_SIZE) : { TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXT
arch/powerpc/kernel/vmlinux.lds.S +1 -0
@@ -52,6 +52,7 @@ SECTIONS /* careful! __ftr_alt_* sections need to be close to .text */ *(.text .fixup __ftr_alt_* .ref.text) SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXT
arch/s390/kernel/vmlinux.lds.S +1 -0
@@ -35,6 +35,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXT
arch/score/kernel/vmlinux.lds.S +1 -0
@@ -40,6 +40,7 @@ SECTIONS _text = .; /* Text and read-only data */ TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.text.*)
arch/sh/kernel/vmlinux.lds.S +1 -0
@@ -36,6 +36,7 @@ SECTIONS TEXT_TEXT EXTRA_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXT
arch/sparc/kernel/vmlinux.lds.S +1 -0
@@ -49,6 +49,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXT
arch/tile/kernel/entry.S +1 -1
@@ -50,7 +50,7 @@ STD_ENTRY(smp_nap) * When interrupted at _cpu_idle_nap, we bump the PC forward 8, and * as a result return to the function that called _cpu_idle(). */ -STD_ENTRY(_cpu_idle) +STD_ENTRY_SECTION(_cpu_idle, .cpuidle.text) movei r1, 1 IRQ_ENABLE_LOAD(r2, r3) mtspr INTERRUPT_CRITICAL_SECTION, r1
arch/tile/kernel/vmlinux.lds.S +1 -0
@@ -42,6 +42,7 @@ SECTIONS .text : AT (ADDR(.text) - LOAD_OFFSET) { HEAD_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXT
arch/um/kernel/dyn.lds.S +1 -0
@@ -68,6 +68,7 @@ SECTIONS _stext = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.stub .text.* .gnu.linkonce.t.*)
arch/um/kernel/uml.lds.S +1 -0
@@ -28,6 +28,7 @@ SECTIONS _stext = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) /* .gnu.warning sections are handled specially by elf32.em. */
arch/unicore32/kernel/vmlinux.lds.S +1 -0
@@ -37,6 +37,7 @@ SECTIONS .text : { /* Real text segment */ TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup)
arch/x86/kernel/acpi/cstate.c +1 -1
@@ -152,7 +152,7 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu, }EXPORT_SYMBOL_GPL (acpi_processor_ffh_cstate_probe); -void acpi_processor_ffh_cstate_enter (struct acpi_processor_cx *cx) +void __cpuidle acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cx) {unsigned int cpu =smp_processor_id ();struct cstate_entry *percpu_entry;
arch/x86/kernel/process.c +2 -2
@@ -301,7 +301,7 @@ void arch_cpu_idle(void)/* * We use this if we don't have any better idle routine.. */ -void default_idle (void ) +void __cpuidle default_idle(void) {trace_cpu_idle_rcuidle (1 ,smp_processor_id ());safe_halt ();
@@ -416,7 +416,7 @@ static int prefer_mwait_c1_over_halt(const struct cpuinfo_x86 *c)* with interrupts enabled and no flags, which is backwards compatible with the * original MWAIT implementation. */ -static void mwait_idle (void ) +static __cpuidle void mwait_idle(void) {if (!current_set_polling_and_test ()) {trace_cpu_idle_rcuidle (1 ,smp_processor_id ());
arch/x86/kernel/vmlinux.lds.S +1 -0
@@ -97,6 +97,7 @@ SECTIONS _stext = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT ENTRY_TEXT
arch/xtensa/kernel/vmlinux.lds.S +3 -0
@@ -93,6 +93,9 @@ SECTIONS VMLINUX_SYMBOL(__sched_text_start) = .; *(.sched.literal .sched.text) VMLINUX_SYMBOL(__sched_text_end) = .; + VMLINUX_SYMBOL(__cpuidle_text_start) = .; + *(.cpuidle.literal .cpuidle.text) + VMLINUX_SYMBOL(__cpuidle_text_end) = .; VMLINUX_SYMBOL(__lock_text_start) = .; *(.spinlock.literal .spinlock.text) VMLINUX_SYMBOL(__lock_text_end) = .;
drivers/acpi/processor_idle.c +3 -2
@@ -31,6 +31,7 @@#include <linux/sched.h> /* need_resched() */ #include <linux/tick.h> #include <linux/cpuidle.h> +#include <linux/cpu.h> #include <acpi/processor.h> /*
@@ -115,7 +116,7 @@ static const struct dmi_system_id processor_power_dmi_table[] = {* Callers should disable interrupts before the call and enable * interrupts after return. */ -static void acpi_safe_halt (void ) +static void __cpuidle acpi_safe_halt(void) {if (!tif_need_resched ()) {safe_halt ();
@@ -645,7 +646,7 @@ static int acpi_idle_bm_check(void)* * Caller disables interrupt before call and enables interrupt after return. */ -static void acpi_idle_do_entry (struct acpi_processor_cx *cx) +static void __cpuidle acpi_idle_do_entry(struct acpi_processor_cx *cx) {if (cx->entry_method ==ACPI_CSTATE_FFH ) {/* Call into architectural FFH based C-state */
drivers/cpuidle/driver.c +3 -2
@@ -14,6 +14,7 @@#include <linux/cpuidle.h> #include <linux/cpumask.h> #include <linux/tick.h> +#include <linux/cpu.h> #include "cpuidle.h"
@@ -178,8 +179,8 @@ static void __cpuidle_driver_init(struct cpuidle_driver *drv) }#ifdef CONFIG_ARCH_HAS_CPU_RELAX -static int poll_idle (struct cpuidle_device *dev, -struct cpuidle_driver *drv,int index) +static int __cpuidle poll_idle(struct cpuidle_device *dev, +struct cpuidle_driver *drv,int index) {local_irq_enable ();if (!current_set_polling_and_test ()) {
drivers/idle/intel_idle.c +2 -2
@@ -863,8 +863,8 @@ static struct cpuidle_state dnv_cstates[] = {* * Must be called under local_irq_disable(). */ -static int intel_idle (struct cpuidle_device *dev, -struct cpuidle_driver *drv,int index) +static __cpuidle int intel_idle(struct cpuidle_device *dev, +struct cpuidle_driver *drv,int index) {unsigned long ecx =1 ;/* break on interrupt flag */ struct cpuidle_state *state = &drv->states[index];
include/asm-generic/vmlinux.lds.h +6 -0
@@ -454,6 +454,12 @@ *(.spinlock.text) \ VMLINUX_SYMBOL(__lock_text_end) = .; +#define CPUIDLE_TEXT \ + ALIGN_FUNCTION(); \ + VMLINUX_SYMBOL(__cpuidle_text_start) = .; \ + *(.cpuidle.text) \ + VMLINUX_SYMBOL(__cpuidle_text_end) = .; +#define KPROBES_TEXT \ ALIGN_FUNCTION(); \ VMLINUX_SYMBOL(__kprobes_text_start) = .; \
include/linux/cpu.h +5 -0
@@ -239,6 +239,11 @@ void cpu_startup_entry(enum cpuhp_state state);void cpu_idle_poll_ctrl (bool enable); +/* Attach to any functions which should be considered cpuidle. */ +#define __cpuidle __attribute__((__section__(".cpuidle.text"))) + +bool cpu_in_idle (unsigned long pc); +void arch_cpu_idle (void );void arch_cpu_idle_prepare (void );void arch_cpu_idle_enter (void );
kernel/sched/idle.c +11 -2
@@ -16,6 +16,9 @@#include "sched.h" +/* Linker adds these: start and end of __cpuidle functions */ +extern char __cpuidle_text_start[], __cpuidle_text_end[]; +/** * sched_idle_set_state - Record idle state for the current CPU. * @idle_state: State to record.
@@ -53,7 +56,7 @@ static int __init cpu_idle_nopoll_setup(char *__unused)__setup ("hlt" , cpu_idle_nopoll_setup);#endif -static inline int cpu_idle_poll (void ) +static noinline int __cpuidle cpu_idle_poll(void) {rcu_idle_enter ();trace_cpu_idle_rcuidle (0 ,smp_processor_id ());
@@ -84,7 +87,7 @@ void __weak arch_cpu_idle(void)* * To use when the cpuidle framework cannot be used. */ -void default_idle_call (void ) +void __cpuidle default_idle_call(void) {if (current_clr_polling_and_test ()) {local_irq_enable ();
@@ -271,6 +274,12 @@ static void cpu_idle_loop(void) } } +bool cpu_in_idle (unsigned long pc) +{ +return pc >= (unsigned long )__cpuidle_text_start && + pc < (unsigned long )__cpuidle_text_end; +} +void cpu_startup_entry (enum cpuhp_state state) {/*
lib/nmi_backtrace.c +11 -5
@@ -16,6 +16,7 @@#include <linux/delay.h> #include <linux/kprobes.h> #include <linux/nmi.h> +#include <linux/cpu.h> #ifdef arch_trigger_cpumask_backtrace/* For reliability, we're prepared to waste bits here. */
@@ -87,11 +88,16 @@ bool nmi_cpu_backtrace(struct pt_regs *regs)int cpu =smp_processor_id ();if (cpumask_test_cpu (cpu,to_cpumask (backtrace_mask))) { -pr_warn ("NMI backtrace for cpu %d\n" , cpu); -if (regs) -show_regs (regs); -else -dump_stack (); +if (regs &&cpu_in_idle (instruction_pointer (regs))) { +pr_warn ("NMI backtrace for cpu %d skipped: idling at pc %#lx\n" , + cpu,instruction_pointer (regs)); + }else { +pr_warn ("NMI backtrace for cpu %d\n" , cpu); +if (regs) +show_regs (regs); +else +dump_stack (); + }cpumask_clear_cpu (cpu,to_cpumask (backtrace_mask));return true; }
scripts/mod/modpost.c +1 -1
@@ -888,7 +888,7 @@ static void check_section(const char *modname, struct elf_info *elf,#define DATA_SECTIONS ".data", ".data.rel"#define TEXT_SECTIONS ".text", ".text.unlikely", ".sched.text", \ - ".kprobes.text" + ".kprobes.text", ".cpuidle.text"#define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \ ".fixup", ".entry.text", ".exception.text", ".text.*", \ ".coldtext"
scripts/recordmcount.c +1 -0
@@ -364,6 +364,7 @@ is_mcounted_section_name(char const *const txtname)strcmp (".spinlock.text" , txtname) ==0 ||strcmp (".irqentry.text" , txtname) ==0 ||strcmp (".kprobes.text" , txtname) ==0 || +strcmp (".cpuidle.text" , txtname) ==0 ||strcmp (".text.unlikely" , txtname) ==0 ; }
scripts/recordmcount.pl +1 -0
@@ -135,6 +135,7 @@ my %text_sections = ( ".spinlock.text" => 1, ".irqentry.text" => 1, ".kprobes.text" => 1, + ".cpuidle.text" => 1, ".text.unlikely" => 1, );
Signature · 1 line
2.7.2
Mark Rutland
reviewerRe: [PATCH v7 4/4] nmi_backtrace: generate one-line reports for idle cpus
Hi,
[adding Lorenzo]
Quoted 40 lines · Chris Metcalf
When doing an nmi backtrace of many cores, most of which 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: idling at pc 0xNNN".
We do this by grouping all the cpuidle code together into a new .cpuidle.text section, and then checking the address of the interrupted PC to see if it lies within that section.
This commit suitably tags x86, arm64, and tile idle routines, and only adds in the minimal framework for other architectures.
arch/arm64/kernel/vmlinux.lds.S +1
-0@@ -122,6 +122,7 @@ SECTIONS ENTRY_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT HYPERVISOR_TEXTarch/arm64/mm/proc.S +2
-0@@ -48,11 +48,13 @@ * * Idle the processor (wait for interrupt). */ + .pushsection ".cpuidle.text","ax" ENTRY(cpu_do_idle) dsb sy // WFI may enter a low-power mode wfi ret ENDPROC(cpu_do_idle) + .popsection
Quoted 1 line
From a quick scan it looks like we only call this with interrupts
disabled, and we have no NMI. So shouldn't we be annotating arch_cpu_idle(), which calls this and subsequently enables interrupts?
I'm also not sure what you need to do for PSCI, which is the preferred (FW-backed) idle mechanism for arm64. The infrastrucure for that is spread over a few files:
arch/arm64/kernel/sleep.S
arch/arm64/kernel/smccc-call.S
arch/arm64/kernel/suspend.c
drivers/cpuidle/cpuidle-arm.c
drivers/firmware/psci.c
I'm not sure where we'd be an an interruptible state, and therefore I'm not immediately sure what we should annotate.
Thanks,
Mark.
Re: [PATCH v7 4/4] nmi_backtrace: generate one-line reports for idle cpus
Quoted 53 lines · Mark Rutland
Hi,
[adding Lorenzo]
Quoted 29 lines · Chris Metcalf
When doing an nmi backtrace of many cores, most of which 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: idling at pc 0xNNN".
We do this by grouping all the cpuidle code together into a new .cpuidle.text section, and then checking the address of the interrupted PC to see if it lies within that section.
This commit suitably tags x86, arm64, and tile idle routines, and only adds in the minimal framework for other architectures.
arch/arm64/kernel/vmlinux.lds.S +1
-0@@ -122,6 +122,7 @@ SECTIONS ENTRY_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT HYPERVISOR_TEXTarch/arm64/mm/proc.S +0
-0arch/arm64/mm/proc.S line 57
Quoted 10 lines
arch/arm64/mm/proc.S +2
-0@@ -48,11 +48,13 @@ * * Idle the processor (wait for interrupt). */ + .pushsection ".cpuidle.text","ax" ENTRY(cpu_do_idle) dsb sy // WFI may enter a low-power mode wfi ret ENDPROC(cpu_do_idle) + .popsectionFrom a quick scan it looks like we only call this with interrupts disabled, and we have no NMI. So shouldn't we be annotating
arch_cpu_idle(), which calls this and subsequently enables interrupts?I'm also not sure what you need to do for PSCI, which is the preferred (FW-backed) idle mechanism for arm64. The infrastrucure for that is spread over a few files:
Quoted 8 lines
arch/arm64/kernel/sleep.S
arch/arm64/kernel/smccc-call.S
arch/arm64/kernel/suspend.c
drivers/cpuidle/cpuidle-arm.c
drivers/firmware/psci.cI'm not sure where we'd be an an interruptible state, and therefore I'm not immediately sure what we should annotate.
I am probably missing something here, but let me add that I am not sure I understand how this patch can be used on ARM/ARM64 systems so ARM platform idle back-end code annotation is basically useless given that it is code that can't be preempted anyway (and even if it could PC range check can even fail given that we may execute some code with MMU off so out of physical addresses).
What's the purpose of this cpu idle tracking ? Can't it be implemented in a simpler way (ie RCU API) ?
Lorenzo
Re: [PATCH v7 4/4] nmi_backtrace: generate one-line reports for idle cpus
Quoted 39 lines · Lorenzo Pieralisi
Quoted 38 lines · Mark Rutland
Hi,
[adding Lorenzo]
Quoted 33 lines · Chris Metcalf
When doing an nmi backtrace of many cores, most of which 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: idling at pc 0xNNN".
We do this by grouping all the cpuidle code together into a new .cpuidle.text section, and then checking the address of the interrupted PC to see if it lies within that section.
This commit suitably tags x86, arm64, and tile idle routines, and only adds in the minimal framework for other architectures.
arch/arm64/kernel/vmlinux.lds.S +1
-0@@ -122,6 +122,7 @@ SECTIONS ENTRY_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT HYPERVISOR_TEXTarch/arm64/mm/proc.S +1
-0@@ -48,11 +48,13 @@ * * Idle the processor (wait for interrupt). */ + .pushsection ".cpuidle.text","ax" ENTRY(cpu_do_idle)
Quoted 8 lines
Quoted 8 lines
arch/arm64/mm/proc.S line 57
Quoted 5 lines
arch/arm64/mm/proc.S +1
-0dsb sy // WFI may enter a low-power mode wfi ret ENDPROC(cpu_do_idle) + .popsectionFrom a quick scan it looks like we only call this with interrupts
disabled, and we have no NMI. So shouldn't we be annotatingarch_cpu_idle(), which calls this and subsequently enables interrupts?
You're right - I made a quick mental mapping between the arch/tile _cpu_idle assembly and the arch/arm64 cpu_do_idle. But on tile the way it works is we can racelessly enable interrupts and then issue the "nap" instruction; it is similar to WFI except that you actually take the interrupt right from the nap instruction itself, and then have to manually bump forward the PC in the handler if you want the nap to act more like a WFI. I see on closer examination that you're right, we won't interrupt in the cpu_do_idle assembly anyway.
You're also right that there is no support for remote stack dump on arm64 right now. I added the arm64 "support" just because I am hacking on arm64 most of the day at this point anyway, and felt like the cpu_idle tracking knowledge might as well be there if/when support for some kind of NMI-style remote interrupt was added to the Linux implementation.
The Tile architecture also has no "NMI" per se, but we use individual bitmasks to enable and disable interrupts, so the Linux irq_disable() just amounts to "write a particular bitmask into the enable register". The bitmask itself is just a per-cpu variable that changes as interrupt sources are configured, and there are a few (a couple of performance interrupts, and a synthetic one used for cross-core ipi) that we never mark as maskable.
Quoted 10 lines
Quoted 10 lines
I'm also not sure what you need to do for PSCI, which is the preferred (FW-backed) idle mechanism for arm64. The infrastrucure for that is spread over a few files:
arch/arm64/kernel/sleep.S
arch/arm64/kernel/smccc-call.S
arch/arm64/kernel/suspend.c
drivers/cpuidle/cpuidle-arm.c
drivers/firmware/psci.c
Quoted 8 lines
Quoted 2 lines
I'm not sure where we'd be an an interruptible state, and therefore I'm not immediately sure what we should annotate.
I am probably missing something here, but let me add that I am not sure I understand how this patch can be used on ARM/ARM64 systems so ARM platform idle back-end code annotation is basically useless given that it is code that can't be preempted anyway (and even if it could PC range check can even fail given that we may execute some code with MMU off so out of physical addresses).
I think this is all fair enough, and I will back out the arm64 "support" for my next patch series.
Quoted 2 lines
What's the purpose of this cpu idle tracking ? Can't it be implemented in a simpler way (ie RCU API) ?
The cpu idle tracking here is done solely to make the "backtrace all cpus" output less crazy-verbose. We annotate functions because claiming "there's nothing interesting to see here; go away" is not something you want to do unless you're really quite sure that there's nothing interesting going on there. In particular, if the RCU stuff is screwed up, you want to see backtraces out of the RCU code if you happen to be somehow stuck there, even if some RCU state claims you are idle.
See e.g. the discussion with Peter Ziljstra starting around here:
https://lkml.org/lkml/2016/3/7/681
Thanks!
Signature · 2 lines
Chris Metcalf, Mellanox Technologies http://www.mellanox.com
Re: [PATCH v7 4/4] nmi_backtrace: generate one-line reports for idle cpus
In reply to Chris MetcalfQuoted 715 lines · Chris Metcalf
When doing an nmi backtrace of many cores, most of which 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: idling at pc 0xNNN".
We do this by grouping all the cpuidle code together into a new .cpuidle.text section, and then checking the address of the interrupted PC to see if it lies within that section.
This commit suitably tags x86, arm64, and tile idle routines, and only adds in the minimal framework for other architectures.
Signed-off-by Chris Metcalf <[email protected]>--- arch/alpha/kernel/vmlinux.lds.S | 1 + arch/arc/kernel/vmlinux.lds.S | 1 + arch/arm/kernel/vmlinux-xip.lds.S | 1 + arch/arm/kernel/vmlinux.lds.S | 1 + arch/arm64/kernel/vmlinux.lds.S | 1 + arch/arm64/mm/proc.S | 2 ++ arch/avr32/kernel/vmlinux.lds.S | 1 + arch/blackfin/kernel/vmlinux.lds.S | 1 + arch/c6x/kernel/vmlinux.lds.S | 1 + arch/cris/kernel/vmlinux.lds.S | 1 + arch/frv/kernel/vmlinux.lds.S | 1 + arch/h8300/kernel/vmlinux.lds.S | 1 + arch/hexagon/kernel/vmlinux.lds.S | 1 + arch/ia64/kernel/vmlinux.lds.S | 1 + arch/m32r/kernel/vmlinux.lds.S | 1 + arch/m68k/kernel/vmlinux-nommu.lds | 1 + arch/m68k/kernel/vmlinux-std.lds | 1 + arch/m68k/kernel/vmlinux-sun3.lds | 1 + arch/metag/kernel/vmlinux.lds.S | 1 + arch/microblaze/kernel/vmlinux.lds.S | 1 + arch/mips/kernel/vmlinux.lds.S | 1 + arch/mn10300/kernel/vmlinux.lds.S | 1 + arch/nios2/kernel/vmlinux.lds.S | 1 + arch/openrisc/kernel/vmlinux.lds.S | 1 + arch/parisc/kernel/vmlinux.lds.S | 1 + arch/powerpc/kernel/vmlinux.lds.S | 1 + arch/s390/kernel/vmlinux.lds.S | 1 + arch/score/kernel/vmlinux.lds.S | 1 + arch/sh/kernel/vmlinux.lds.S | 1 + arch/sparc/kernel/vmlinux.lds.S | 1 + arch/tile/kernel/entry.S | 2 +- arch/tile/kernel/vmlinux.lds.S | 1 + arch/um/kernel/dyn.lds.S | 1 + arch/um/kernel/uml.lds.S | 1 + arch/unicore32/kernel/vmlinux.lds.S | 1 + arch/x86/kernel/acpi/cstate.c | 2 +- arch/x86/kernel/process.c | 4 ++-- arch/x86/kernel/vmlinux.lds.S | 1 + arch/xtensa/kernel/vmlinux.lds.S | 3 +++ drivers/acpi/processor_idle.c | 5 +++-- drivers/cpuidle/driver.c | 5 +++-- drivers/idle/intel_idle.c | 4 ++-- include/asm-generic/vmlinux.lds.h | 6 ++++++ include/linux/cpu.h | 5 +++++ kernel/sched/idle.c | 13 +++++++++++-- lib/nmi_backtrace.c | 16 +++++++++++----- scripts/mod/modpost.c | 2 +- scripts/recordmcount.c | 1 + scripts/recordmcount.pl | 1 + 49 files changed, 87 insertions(+), 18 deletions(-)arch/alpha/kernel/vmlinux.lds.S +1
-0@@ -22,6 +22,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.gnu.warning)arch/arc/kernel/vmlinux.lds.S +1
-0@@ -97,6 +97,7 @@ SECTIONS _text = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.fixup)arch/arm/kernel/vmlinux-xip.lds.S +1
-0@@ -98,6 +98,7 @@ SECTIONS IRQENTRY_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.gnu.warning)arch/arm/kernel/vmlinux.lds.S +1
-0@@ -111,6 +111,7 @@ SECTIONS SOFTIRQENTRY_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT HYPERVISOR_TEXT KPROBES_TEXTarch/arm64/kernel/vmlinux.lds.S +1
-0@@ -122,6 +122,7 @@ SECTIONS ENTRY_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT HYPERVISOR_TEXTarch/arm64/mm/proc.S +2
-0@@ -48,11 +48,13 @@ * * Idle the processor (wait for interrupt). */ + .pushsection ".cpuidle.text","ax" ENTRY(cpu_do_idle) dsb sy // WFI may enter a low-power mode wfi ret ENDPROC(cpu_do_idle) + .popsection #ifdef CONFIG_CPU_PM /**arch/avr32/kernel/vmlinux.lds.S +1
-0@@ -52,6 +52,7 @@ SECTIONS KPROBES_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.gnu.warning)arch/blackfin/kernel/vmlinux.lds.S +1
-0@@ -33,6 +33,7 @@ SECTIONS #ifndef CONFIG_SCHEDULE_L1 SCHED_TEXT #endif + CPUIDLE_TEXT LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXTarch/c6x/kernel/vmlinux.lds.S +1
-0@@ -70,6 +70,7 @@ SECTIONS _stext = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXTarch/cris/kernel/vmlinux.lds.S +1
-0@@ -43,6 +43,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.text.__*)arch/frv/kernel/vmlinux.lds.S +1
-0@@ -63,6 +63,7 @@ SECTIONS *(.text..tlbmiss) TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT #ifdef CONFIG_DEBUG_INFO INIT_TEXTarch/h8300/kernel/vmlinux.lds.S +1
-0@@ -29,6 +29,7 @@ SECTIONS _stext = . ; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT #if defined(CONFIG_ROMKERNEL) *(.int_redirect)arch/hexagon/kernel/vmlinux.lds.S +1
-0@@ -50,6 +50,7 @@ SECTIONS _text = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.fixup)arch/ia64/kernel/vmlinux.lds.S +1
-0@@ -46,6 +46,7 @@ SECTIONS { __end_ivt_text = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.gnu.linkonce.t*)arch/m32r/kernel/vmlinux.lds.S +1
-0@@ -31,6 +31,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.gnu.warning)arch/m68k/kernel/vmlinux-nommu.lds +1
-0@@ -45,6 +45,7 @@ SECTIONS { HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) . = ALIGN(16);arch/m68k/kernel/vmlinux-std.lds +1
-0@@ -16,6 +16,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.gnu.warning)arch/m68k/kernel/vmlinux-sun3.lds +1
-0@@ -16,6 +16,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.gnu.warning)arch/metag/kernel/vmlinux.lds.S +1
-0@@ -21,6 +21,7 @@ SECTIONS .text : { TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXTarch/microblaze/kernel/vmlinux.lds.S +1
-0@@ -33,6 +33,7 @@ SECTIONS { EXIT_TEXT EXIT_CALL SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXTarch/mips/kernel/vmlinux.lds.S +1
-0@@ -55,6 +55,7 @@ SECTIONS .text : { TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXTarch/mn10300/kernel/vmlinux.lds.S +1
-0@@ -30,6 +30,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.fixup)arch/nios2/kernel/vmlinux.lds.S +1
-0@@ -37,6 +37,7 @@ SECTIONS .text : { TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXTarch/openrisc/kernel/vmlinux.lds.S +1
-0@@ -47,6 +47,7 @@ SECTIONS _stext = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXTarch/parisc/kernel/vmlinux.lds.S +1
-0@@ -69,6 +69,7 @@ SECTIONS .text ALIGN(PAGE_SIZE) : { TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXTarch/powerpc/kernel/vmlinux.lds.S +1
-0@@ -52,6 +52,7 @@ SECTIONS /* careful! __ftr_alt_* sections need to be close to .text */ *(.text .fixup __ftr_alt_* .ref.text) SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXTarch/s390/kernel/vmlinux.lds.S +1
-0@@ -35,6 +35,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXTarch/score/kernel/vmlinux.lds.S +1
-0@@ -40,6 +40,7 @@ SECTIONS _text = .; /* Text and read-only data */ TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT *(.text.*)arch/sh/kernel/vmlinux.lds.S +1
-0@@ -36,6 +36,7 @@ SECTIONS TEXT_TEXT EXTRA_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXTarch/sparc/kernel/vmlinux.lds.S +1
-0@@ -49,6 +49,7 @@ SECTIONS HEAD_TEXT TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXTarch/tile/kernel/entry.S +1
-1@@ -50,7 +50,7 @@ STD_ENTRY(smp_nap) * When interrupted at _cpu_idle_nap, we bump the PC forward 8, and * as a result return to the function that called _cpu_idle(). */ -STD_ENTRY(_cpu_idle) +STD_ENTRY_SECTION(_cpu_idle, .cpuidle.text) movei r1, 1 IRQ_ENABLE_LOAD(r2, r3) mtspr INTERRUPT_CRITICAL_SECTION, r1arch/tile/kernel/vmlinux.lds.S +1
-0@@ -42,6 +42,7 @@ SECTIONS .text : AT (ADDR(.text) - LOAD_OFFSET) { HEAD_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT IRQENTRY_TEXTarch/um/kernel/dyn.lds.S +1
-0@@ -68,6 +68,7 @@ SECTIONS _stext = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) *(.stub .text.* .gnu.linkonce.t.*)arch/um/kernel/uml.lds.S +1
-0@@ -28,6 +28,7 @@ SECTIONS _stext = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup) /* .gnu.warning sections are handled specially by elf32.em. */arch/unicore32/kernel/vmlinux.lds.S +1
-0@@ -37,6 +37,7 @@ SECTIONS .text : { /* Real text segment */ TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT *(.fixup)arch/x86/kernel/acpi/cstate.c +1
-1@@ -152,7 +152,7 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu, }EXPORT_SYMBOL_GPL (acpi_processor_ffh_cstate_probe); -void acpi_processor_ffh_cstate_enter (struct acpi_processor_cx *cx) +void __cpuidle acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cx) {unsigned int cpu =smp_processor_id ();struct cstate_entry *percpu_entry;arch/x86/kernel/process.c +2
-2@@ -301,7 +301,7 @@ void arch_cpu_idle(void)/* * We use this if we don't have any better idle routine.. */ -void default_idle (void ) +void __cpuidle default_idle(void) {trace_cpu_idle_rcuidle (1 ,smp_processor_id ());safe_halt ();@@ -416,7 +416,7 @@ static int prefer_mwait_c1_over_halt(const struct cpuinfo_x86 *c)* with interrupts enabled and no flags, which is backwards compatible with the * original MWAIT implementation. */ -static void mwait_idle (void ) +static __cpuidle void mwait_idle(void) {if (!current_set_polling_and_test ()) {trace_cpu_idle_rcuidle (1 ,smp_processor_id ());arch/x86/kernel/vmlinux.lds.S +1
-0@@ -97,6 +97,7 @@ SECTIONS _stext = .; TEXT_TEXT SCHED_TEXT + CPUIDLE_TEXT LOCK_TEXT KPROBES_TEXT ENTRY_TEXTarch/xtensa/kernel/vmlinux.lds.S +3
-0@@ -93,6 +93,9 @@ SECTIONS VMLINUX_SYMBOL(__sched_text_start) = .; *(.sched.literal .sched.text) VMLINUX_SYMBOL(__sched_text_end) = .; + VMLINUX_SYMBOL(__cpuidle_text_start) = .; + *(.cpuidle.literal .cpuidle.text) + VMLINUX_SYMBOL(__cpuidle_text_end) = .; VMLINUX_SYMBOL(__lock_text_start) = .; *(.spinlock.literal .spinlock.text) VMLINUX_SYMBOL(__lock_text_end) = .;drivers/acpi/processor_idle.c +3
-2@@ -31,6 +31,7 @@#include <linux/sched.h> /* need_resched() */ #include <linux/tick.h> #include <linux/cpuidle.h> +#include <linux/cpu.h> #include <acpi/processor.h> /* @@ -115,7 +116,7 @@ static const struct dmi_system_id processor_power_dmi_table[] = {* Callers should disable interrupts before the call and enable * interrupts after return. */ -static void acpi_safe_halt (void ) +static void __cpuidle acpi_safe_halt(void) {if (!tif_need_resched ()) {safe_halt ();@@ -645,7 +646,7 @@ static int acpi_idle_bm_check(void)* * Caller disables interrupt before call and enables interrupt after return. */ -static void acpi_idle_do_entry (struct acpi_processor_cx *cx) +static void __cpuidle acpi_idle_do_entry(struct acpi_processor_cx *cx) {if (cx->entry_method ==ACPI_CSTATE_FFH ) {/* Call into architectural FFH based C-state */ drivers/cpuidle/driver.c +3
-2@@ -14,6 +14,7 @@#include <linux/cpuidle.h> #include <linux/cpumask.h> #include <linux/tick.h> +#include <linux/cpu.h> #include "cpuidle.h" @@ -178,8 +179,8 @@ static void __cpuidle_driver_init(struct cpuidle_driver *drv) }#ifdef CONFIG_ARCH_HAS_CPU_RELAX -static int poll_idle (struct cpuidle_device *dev, -struct cpuidle_driver *drv,int index) +static int __cpuidle poll_idle(struct cpuidle_device *dev, +struct cpuidle_driver *drv,int index) {local_irq_enable ();if (!current_set_polling_and_test ()) {drivers/idle/intel_idle.c +2
-2@@ -863,8 +863,8 @@ static struct cpuidle_state dnv_cstates[] = {* * Must be called under local_irq_disable(). */ -static int intel_idle (struct cpuidle_device *dev, -struct cpuidle_driver *drv,int index) +static __cpuidle int intel_idle(struct cpuidle_device *dev, +struct cpuidle_driver *drv,int index) {unsigned long ecx =1 ;/* break on interrupt flag */ struct cpuidle_state *state = &drv->states[index];include/asm-generic/vmlinux.lds.h +6
-0@@ -454,6 +454,12 @@ *(.spinlock.text) \ VMLINUX_SYMBOL(__lock_text_end) = .; +#define CPUIDLE_TEXT \ + ALIGN_FUNCTION(); \ + VMLINUX_SYMBOL(__cpuidle_text_start) = .; \ + *(.cpuidle.text) \ + VMLINUX_SYMBOL(__cpuidle_text_end) = .; +#define KPROBES_TEXT \ ALIGN_FUNCTION(); \ VMLINUX_SYMBOL(__kprobes_text_start) = .; \include/linux/cpu.h +5
-0@@ -239,6 +239,11 @@ void cpu_startup_entry(enum cpuhp_state state);void cpu_idle_poll_ctrl (bool enable); +/* Attach to any functions which should be considered cpuidle. */ +#define __cpuidle __attribute__((__section__(".cpuidle.text"))) + +bool cpu_in_idle (unsigned long pc); +void arch_cpu_idle (void );void arch_cpu_idle_prepare (void );void arch_cpu_idle_enter (void );kernel/sched/idle.c +11
-2@@ -16,6 +16,9 @@#include "sched.h" +/* Linker adds these: start and end of __cpuidle functions */ +extern char __cpuidle_text_start[], __cpuidle_text_end[]; +/** * sched_idle_set_state - Record idle state for the current CPU. * @idle_state: State to record. @@ -53,7 +56,7 @@ static int __init cpu_idle_nopoll_setup(char *__unused)__setup ("hlt" , cpu_idle_nopoll_setup);#endif -static inline int cpu_idle_poll (void ) +static noinline int __cpuidle cpu_idle_poll(void) {rcu_idle_enter ();trace_cpu_idle_rcuidle (0 ,smp_processor_id ());@@ -84,7 +87,7 @@ void __weak arch_cpu_idle(void)* * To use when the cpuidle framework cannot be used. */ -void default_idle_call (void ) +void __cpuidle default_idle_call(void) {if (current_clr_polling_and_test ()) {local_irq_enable ();@@ -271,6 +274,12 @@ static void cpu_idle_loop(void) } } +bool cpu_in_idle (unsigned long pc) +{ +return pc >= (unsigned long )__cpuidle_text_start && + pc < (unsigned long )__cpuidle_text_end; +} +void cpu_startup_entry (enum cpuhp_state state) {/* lib/nmi_backtrace.c +1
-0@@ -16,6 +16,7 @@#include <linux/delay.h> #include <linux/kprobes.h> #include <linux/nmi.h> +#include <linux/cpu.h> #ifdef arch_trigger_cpumask_backtrace/* For reliability, we're prepared to waste bits here. */ @@ -87,11 +88,16 @@ bool nmi_cpu_backtrace(struct pt_regs *regs)int cpu =smp_processor_id ();
lib/nmi_backtrace.c bool nmi_cpu_backtrace(struct pt_regs *regs) · line 93
Quoted 10 lines
lib/nmi_backtrace.c +3
-5if (cpumask_test_cpu (cpu,to_cpumask (backtrace_mask))) { -pr_warn ("NMI backtrace for cpu %d\n" , cpu); -if (regs) -show_regs (regs); -else -dump_stack (); +if (regs &&cpu_in_idle (instruction_pointer (regs))) { +pr_warn ("NMI backtrace for cpu %d skipped: idling at pc %#lx\n" , + cpu,instruction_pointer (regs));
Hmm, I do not see this message even though the CPU is in the idle state:
[ 7918.884535] CPU: 3 PID: 0 Comm: swapper/3 Not tainted 4.8.0-rc1-4-default+ #3088 [ 7918.884538] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 [ 7918.884539] task: ffff88013a594380 task.stack: ffff88013a598000 [ 7918.884541] RIP: 0010:[<ffffffff81050bc6>] [<ffffffff81050bc6>] native_safe_halt+0x6/0x10 [ 7918.884543] RSP: 0018:ffff88013a59bea8 EFLAGS: 00000206 [ 7918.884544] RAX: ffff88013a594380 RBX: 0000000000000003 RCX: 0000000000000000 [ 7918.884546] RDX: ffff88013a594380 RSI: 0000000000000001 RDI: ffff88013a594380 [ 7918.884548] RBP: ffff88013a59bea8 R08: 0000000000000000 R09: 0000000000000000 [ 7918.884550] R10: 0000000000000001 R11: 0000000000000001 R12: 0000000000000003 [ 7918.884551] R13: 0000000000000000 R14: ffff88013a598000 R15: ffff88013a598000 [ 7918.884553] FS: 0000000000000000(0000) GS:ffff88013fd80000(0000) knlGS:0000000000000000 [ 7918.884554] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 7918.884556] CR2: 00007f8afc65e000 CR3: 00000001383b8000 CR4: 00000000000006e0 [ 7918.884557] Stack: [ 7918.884559] ffff88013a59bec8 ffffffff819573d3 0000000000000003 0000000000000000 [ 7918.884561] ffff88013a59bed8 ffffffff8102628f ffff88013a59bee8 ffffffff819579ea [ 7918.884562] ffff88013a59bf30 ffffffff810bfe1a ffff88013a598000 ffff88013a598000 [ 7918.884563] Call Trace: [ 7918.884565] [<ffffffff819573d3>] default_idle+0x23/0x170 [ 7918.884566] [<ffffffff8102628f>] arch_cpu_idle+0xf/0x20 [ 7918.884568] [<ffffffff819579ea>] default_idle_call+0x2a/0x50 [ 7918.884570] [<ffffffff810bfe1a>] cpu_startup_entry+0x16a/0x260 [ 7918.884571] [<ffffffff8103faf6>] start_secondary+0xf6/0x100 [ 7918.884573] Code: 00 00 00 00 00 55 48 89 e5 fa 5d c3 66 0f 1f 84 00 00 00 00 00 55 48 89 e5 fb 5d c3 66 0f 1f 84 00 00 00 00 00 55 48 89 e5 fb f4 <5d> c3 0f 1f 84 00 00 00 00 00 55 48 89 e5 f4 5d c3 66 0f 1f 84
Note that I test it in a virtual machine using qemu.
The strange thing is that I do not see .cpuidle.text section in the vmlinux binary. But it is possible that I have misunderstood the concept.
Best Regards,
Petr
Re: [PATCH v7 4/4] nmi_backtrace: generate one-line reports for idle cpus
Quoted 33 lines · Petr Mladek
Quoted 4 lines · Chris Metcalf
When doing an nmi backtrace of many cores, most of which 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: idling at pc 0xNNN".
Hmm, I do not see this message even though the CPU is in the idle state:
[ 7918.884535] CPU: 3 PID: 0 Comm: swapper/3 Not tainted 4.8.0-rc1-4-default+ #3088 [ 7918.884538] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 [ 7918.884539] task: ffff88013a594380 task.stack: ffff88013a598000 [ 7918.884541] RIP: 0010:[<ffffffff81050bc6>] [<ffffffff81050bc6>] native_safe_halt+0x6/0x10 [ 7918.884543] RSP: 0018:ffff88013a59bea8 EFLAGS: 00000206 [ 7918.884544] RAX: ffff88013a594380 RBX: 0000000000000003 RCX: 0000000000000000 [ 7918.884546] RDX: ffff88013a594380 RSI: 0000000000000001 RDI: ffff88013a594380 [ 7918.884548] RBP: ffff88013a59bea8 R08: 0000000000000000 R09: 0000000000000000 [ 7918.884550] R10: 0000000000000001 R11: 0000000000000001 R12: 0000000000000003 [ 7918.884551] R13: 0000000000000000 R14: ffff88013a598000 R15: ffff88013a598000 [ 7918.884553] FS: 0000000000000000(0000) GS:ffff88013fd80000(0000) knlGS:0000000000000000 [ 7918.884554] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 7918.884556] CR2: 00007f8afc65e000 CR3: 00000001383b8000 CR4: 00000000000006e0 [ 7918.884557] Stack: [ 7918.884559] ffff88013a59bec8 ffffffff819573d3 0000000000000003 0000000000000000 [ 7918.884561] ffff88013a59bed8 ffffffff8102628f ffff88013a59bee8 ffffffff819579ea [ 7918.884562] ffff88013a59bf30 ffffffff810bfe1a ffff88013a598000 ffff88013a598000 [ 7918.884563] Call Trace: [ 7918.884565] [<ffffffff819573d3>] default_idle+0x23/0x170 [ 7918.884566] [<ffffffff8102628f>] arch_cpu_idle+0xf/0x20 [ 7918.884568] [<ffffffff819579ea>] default_idle_call+0x2a/0x50 [ 7918.884570] [<ffffffff810bfe1a>] cpu_startup_entry+0x16a/0x260 [ 7918.884571] [<ffffffff8103faf6>] start_secondary+0xf6/0x100 [ 7918.884573] Code: 00 00 00 00 00 55 48 89 e5 fa 5d c3 66 0f 1f 84 00 00 00 00 00 55 48 89 e5 fb 5d c3 66 0f 1f 84 00 00 00 00 00 55 48 89 e5 fb f4 <5d> c3 0f 1f 84 00 00 00 00 00 55 48 89 e5 f4 5d c3 66 0f 1f 84
Quoted 5 lines
Note that I test it in a virtual machine using qemu.
The strange thing is that I do not see .cpuidle.text section in the vmlinux binary. But it is possible that I have misunderstood the concept.
The .cpuidle.text sections are merged into the final kernel's overall text segment. What you should see is something like this in the "nm -n" output from the built vmlinux:
[...]ffffffff81922aa8 T __cpuidle_text_start ffffffff81922ab0 T default_idle ffffffff81922b90 t mwait_idle ffffffff81922d20 T acpi_processor_ffh_cstate_enter ffffffff81922df0 T default_idle_call ffffffff81922e30 t cpu_idle_poll ffffffff81922f50 t intel_idle ffffffff81923085 t acpi_idle_do_entry ffffffff819230d0 t poll_idle ffffffff81923143 T __cpuidle_text_end [...]
In other words, all the cpuidle functions grouped together and bracketed by the __cpuidle_text_{start,end} symbols.
Perhaps you were running with a kernel that didn't have the actual patch 4/4 applied, but just the earlier patches? Or perhaps your host Linux has been patched, but not the guest Linux running in qemu? Or perhaps you are ending up doing an NMI backtrace on the host kernel, not the guest?
Thanks for your other reviews as well. I have incorporated all of your suggestions into a v8 patch series and pushed it up to kernel.org.
I will just wait to repost it until we sort out this issue that you've reported here.
Signature · 2 lines
Chris Metcalf, Mellanox Technologies http://www.mellanox.com
Re: [PATCH v7 4/4] nmi_backtrace: generate one-line reports for idle cpus
Quoted 57 lines · Chris Metcalf
Quoted 33 lines · Petr Mladek
Quoted 4 lines · Chris Metcalf
When doing an nmi backtrace of many cores, most of which 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: idling at pc 0xNNN".
Hmm, I do not see this message even though the CPU is in the idle state:
[ 7918.884535] CPU: 3 PID: 0 Comm: swapper/3 Not tainted 4.8.0-rc1-4-default+ #3088 [ 7918.884538] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 [ 7918.884539] task: ffff88013a594380 task.stack: ffff88013a598000 [ 7918.884541] RIP: 0010:[<ffffffff81050bc6>] [<ffffffff81050bc6>] native_safe_halt+0x6/0x10 [ 7918.884543] RSP: 0018:ffff88013a59bea8 EFLAGS: 00000206 [ 7918.884544] RAX: ffff88013a594380 RBX: 0000000000000003 RCX: 0000000000000000 [ 7918.884546] RDX: ffff88013a594380 RSI: 0000000000000001 RDI: ffff88013a594380 [ 7918.884548] RBP: ffff88013a59bea8 R08: 0000000000000000 R09: 0000000000000000 [ 7918.884550] R10: 0000000000000001 R11: 0000000000000001 R12: 0000000000000003 [ 7918.884551] R13: 0000000000000000 R14: ffff88013a598000 R15: ffff88013a598000 [ 7918.884553] FS: 0000000000000000(0000) GS:ffff88013fd80000(0000) knlGS:0000000000000000 [ 7918.884554] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 7918.884556] CR2: 00007f8afc65e000 CR3: 00000001383b8000 CR4: 00000000000006e0 [ 7918.884557] Stack: [ 7918.884559] ffff88013a59bec8 ffffffff819573d3 0000000000000003 0000000000000000 [ 7918.884561] ffff88013a59bed8 ffffffff8102628f ffff88013a59bee8 ffffffff819579ea [ 7918.884562] ffff88013a59bf30 ffffffff810bfe1a ffff88013a598000 ffff88013a598000 [ 7918.884563] Call Trace: [ 7918.884565] [<ffffffff819573d3>] default_idle+0x23/0x170 [ 7918.884566] [<ffffffff8102628f>] arch_cpu_idle+0xf/0x20 [ 7918.884568] [<ffffffff819579ea>] default_idle_call+0x2a/0x50 [ 7918.884570] [<ffffffff810bfe1a>] cpu_startup_entry+0x16a/0x260 [ 7918.884571] [<ffffffff8103faf6>] start_secondary+0xf6/0x100 [ 7918.884573] Code: 00 00 00 00 00 55 48 89 e5 fa 5d c3 66 0f 1f 84 00 00 00 00 00 55 48 89 e5 fb 5d c3 66 0f 1f 84 00 00 00 00 00 55 48 89 e5 fb f4 <5d> c3 0f 1f 84 00 00 00 00 00 55 48 89 e5 f4 5d c3 66 0f 1f 84Quoted 5 lines
Note that I test it in a virtual machine using qemu.
The strange thing is that I do not see .cpuidle.text section in the vmlinux binary. But it is possible that I have misunderstood the concept.
The .cpuidle.text sections are merged into the final kernel's overall text segment. What you should see is something like this in the "nm -n" output from the built vmlinux:
[...]
ffffffff81922aa8T__cpuidle_text_startffffffff81922ab0Tdefault_idleffffffff81922b90tmwait_idleffffffff81922d20Tacpi_processor_ffh_cstate_enterffffffff81922df0Tdefault_idle_callffffffff81922e30tcpu_idle_pollffffffff81922f50tintel_idleffffffff81923085tacpi_idle_do_entryffffffff819230d0tpoll_idleffffffff81923143T__cpuidle_text_end[...]
Quoted 7 lines
In other words, all the cpuidle functions grouped together and bracketed by the __cpuidle_text_{start,end} symbols.
Perhaps you were running with a kernel that didn't have the actual patch 4/4 applied, but just the earlier patches? Or perhaps your host Linux has been patched, but not the guest Linux running in qemu? Or perhaps you are ending up doing an NMI backtrace on the host kernel, not the guest?
Hmm, the problem is that native_safe_halt() is called from default_idle() here. The function is marked as inline but the compiler did not inline it.
It helped me to put native_safe_halt() into the __cpuidle_text section:
arch/x86/include/asm/irqflags.h +1 -1
@@ -44,7 +44,7 @@ static inline void native_irq_enable(void) asmvolatile ("sti" : : :"memory" ); } -static inline void native_safe_halt (void ) +static inline __attribute__((__section__ (".cpuidle.text" )))void native_safe_halt (void ) { asmvolatile ("sti; hlt" : : :"memory" ); }
I did not use __cpuidle macro because I was not able to include linux/cpu.h into that header.
I wonder if it would be possible to detect the idle thread an other way. For example, I wonder if it would be enough to check for the PID 0.
Best Regards,
Petr
Peter Zijlstra
maintainerRe: [PATCH v7 4/4] nmi_backtrace: generate one-line reports for idle cpus
arch/x86/include/asm/irqflags.h static inline void native_irq_enable(void) · line 50
Quoted 13 lines · Petr Mladek
arch/x86/include/asm/irqflags.h +1
-1@@ -44,7 +44,7 @@ static inline void native_irq_enable(void) asmvolatile ("sti" : : :"memory" ); } -static inline void native_safe_halt (void ) +static inline __attribute__((__section__ (".cpuidle.text" )))void native_safe_halt (void ) { asmvolatile ("sti; hlt" : : :"memory" ); }
An alternative is to use __always_inline I suppose.
Re: [PATCH v7 4/4] nmi_backtrace: generate one-line reports for idle cpus
In reply to Petr MladekQuoted 10 lines · Petr Mladek
Quoted 4 lines · Chris Metcalf
Quoted 4 lines
Quoted 4 lines
When doing an nmi backtrace of many cores, most of which 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: idling at pc 0xNNN".
Hmm, the problem is that
native_safe_halt()is called fromdefault_idle()here. The function is marked as inline but the compiler did not inline it.It helped me to put
native_safe_halt()into the__cpuidle_textsection:
Following Peter Z's suggestion, I have added an __always_inline marker to native_safe_halt. For consistency, I also did arch_safe_halt(), since that invokes native_safe_halt, and then also native_halt() and halt(), so that we're not being weirdly inconsistent with markings for halt inlines.
There are also the native_irq_enable(), etc., accessors in that same header that are still only marked "inline" not "always_inline", but I wanted to stop before I was touching too much unrelated code.
Quoted 3 lines
I wonder if it would be possible to detect the idle thread an other way. For example, I wonder if it would be enough to check for the PID 0.
No, the problem is that pid 0 can also go off and run "interesting" code for things like power management, etc., so we really just want to focus on being quite sure that the running code isn't interesting before we suppress the backtrace information.
See the thread around here:
https://lkml.kernel.org/r/[email protected]
Signature · 2 lines
Chris Metcalf, Mellanox Technologies http://www.mellanox.com
Re: [PATCH v7 4/4] nmi_backtrace: generate one-line reports for idle cpus
Quoted 12 lines · Chris Metcalf
Quoted 10 lines · Petr Mladek
Quoted 4 lines · Chris Metcalf
Quoted 4 lines
Quoted 4 lines
When doing an nmi backtrace of many cores, most of which 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: idling at pc 0xNNN".
Hmm, the problem is that
native_safe_halt()is called fromdefault_idle()here. The function is marked as inline but the compiler did not inline it.It helped me to put
native_safe_halt()into the__cpuidle_textsection:
Quoted 8 lines
Following Peter Z's suggestion, I have added an
__always_inlinemarker tonative_safe_halt. For consistency, I also didarch_safe_halt(), since that invokesnative_safe_halt, and then alsonative_halt()andhalt(), so that we're not being weirdly inconsistent with markings for halt inlines.There are also the
native_irq_enable(), etc., accessors in that same header that are still only marked "inline" not "always_inline", but I wanted to stop before I was touching too much unrelated code.
Sounds fine.
Quoted 4 lines
Quoted 3 lines
I wonder if it would be possible to detect the idle thread an other way. For example, I wonder if it would be enough to check for the PID 0.
Quoted 8 lines
No, the problem is that pid 0 can also go off and run "interesting" code for things like power management, etc., so we really just want to focus on being quite sure that the running code isn't interesting before we suppress the backtrace information.
See the thread around here:
https://lkml.kernel.org/r/20160307204317.GR6344 at twins.programming.kicks-ass.net
Makes sense. Thanks for the poitner.
Best Regards,
Petr