Skip to content

Commit 61be7fd

Browse files
author
Ingo Molnar
committed
Merge branch 'perf/nmi' into perf/core
Conflicts: kernel/Makefile Merge reason: Add the now complete topic, fix the conflict. Signed-off-by: Ingo Molnar <mingo@elte.hu>
2 parents 12a81c8 + eb703f9 commit 61be7fd

16 files changed

Lines changed: 770 additions & 348 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,8 @@ and is between 256 and 4096 characters. It is defined in the file
18121812

18131813
nousb [USB] Disable the USB subsystem
18141814

1815+
nowatchdog [KNL] Disable the lockup detector.
1816+
18151817
nowb [ARM]
18161818

18171819
nox2apic [X86-64,APIC] Do not enable x2APIC mode.

‎arch/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,11 @@ config HAVE_MIXED_BREAKPOINTS_REGS
151151
config HAVE_USER_RETURN_NOTIFIER
152152
bool
153153

154+
config HAVE_PERF_EVENTS_NMI
155+
bool
156+
help
157+
System hardware can generate an NMI using the perf event
158+
subsystem. Also has support for calculating CPU cycle events
159+
to determine how many clock cycles in a given period.
160+
154161
source "kernel/gcov/Kconfig"

‎arch/x86/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ config X86
5555
select HAVE_HW_BREAKPOINT
5656
select HAVE_MIXED_BREAKPOINTS_REGS
5757
select PERF_EVENTS
58+
select HAVE_PERF_EVENTS_NMI
5859
select ANON_INODES
5960
select HAVE_ARCH_KMEMCHECK
6061
select HAVE_USER_RETURN_NOTIFIER

‎arch/x86/include/asm/nmi.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ int do_nmi_callback(struct pt_regs *regs, int cpu);
1717

1818
extern void die_nmi(char *str, struct pt_regs *regs, int do_panic);
1919
extern int check_nmi_watchdog(void);
20+
#if !defined(CONFIG_LOCKUP_DETECTOR)
2021
extern int nmi_watchdog_enabled;
22+
#endif
2123
extern int avail_to_resrv_perfctr_nmi_bit(unsigned int);
2224
extern int reserve_perfctr_nmi(unsigned int);
2325
extern void release_perfctr_nmi(unsigned int);

‎arch/x86/kernel/apic/Makefile‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
# Makefile for local APIC drivers and for the IO-APIC code
33
#
44

5-
obj-$(CONFIG_X86_LOCAL_APIC) += apic.o apic_noop.o probe_$(BITS).o ipi.o nmi.o
5+
obj-$(CONFIG_X86_LOCAL_APIC) += apic.o apic_noop.o probe_$(BITS).o ipi.o
6+
ifneq ($(CONFIG_HARDLOCKUP_DETECTOR),y)
7+
obj-$(CONFIG_X86_LOCAL_APIC) += nmi.o
8+
endif
9+
obj-$(CONFIG_HARDLOCKUP_DETECTOR) += hw_nmi.o
10+
611
obj-$(CONFIG_X86_IO_APIC) += io_apic.o
712
obj-$(CONFIG_SMP) += ipi.o
813

‎arch/x86/kernel/apic/hw_nmi.c‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* HW NMI watchdog support
3+
*
4+
* started by Don Zickus, Copyright (C) 2010 Red Hat, Inc.
5+
*
6+
* Arch specific calls to support NMI watchdog
7+
*
8+
* Bits copied from original nmi.c file
9+
*
10+
*/
11+
#include <asm/apic.h>
12+
13+
#include <linux/cpumask.h>
14+
#include <linux/kdebug.h>
15+
#include <linux/notifier.h>
16+
#include <linux/kprobes.h>
17+
#include <linux/nmi.h>
18+
#include <linux/module.h>
19+
20+
/* For reliability, we're prepared to waste bits here. */
21+
static DECLARE_BITMAP(backtrace_mask, NR_CPUS) __read_mostly;
22+
23+
u64 hw_nmi_get_sample_period(void)
24+
{
25+
return (u64)(cpu_khz) * 1000 * 60;
26+
}
27+
28+
#ifdef ARCH_HAS_NMI_WATCHDOG
29+
void arch_trigger_all_cpu_backtrace(void)
30+
{
31+
int i;
32+
33+
cpumask_copy(to_cpumask(backtrace_mask), cpu_online_mask);
34+
35+
printk(KERN_INFO "sending NMI to all CPUs:\n");
36+
apic->send_IPI_all(NMI_VECTOR);
37+
38+
/* Wait for up to 10 seconds for all CPUs to do the backtrace */
39+
for (i = 0; i < 10 * 1000; i++) {
40+
if (cpumask_empty(to_cpumask(backtrace_mask)))
41+
break;
42+
mdelay(1);
43+
}
44+
}
45+
46+
static int __kprobes
47+
arch_trigger_all_cpu_backtrace_handler(struct notifier_block *self,
48+
unsigned long cmd, void *__args)
49+
{
50+
struct die_args *args = __args;
51+
struct pt_regs *regs;
52+
int cpu = smp_processor_id();
53+
54+
switch (cmd) {
55+
case DIE_NMI:
56+
case DIE_NMI_IPI:
57+
break;
58+
59+
default:
60+
return NOTIFY_DONE;
61+
}
62+
63+
regs = args->regs;
64+
65+
if (cpumask_test_cpu(cpu, to_cpumask(backtrace_mask))) {
66+
static arch_spinlock_t lock = __ARCH_SPIN_LOCK_UNLOCKED;
67+
68+
arch_spin_lock(&lock);
69+
printk(KERN_WARNING "NMI backtrace for cpu %d\n", cpu);
70+
show_regs(regs);
71+
dump_stack();
72+
arch_spin_unlock(&lock);
73+
cpumask_clear_cpu(cpu, to_cpumask(backtrace_mask));
74+
return NOTIFY_STOP;
75+
}
76+
77+
return NOTIFY_DONE;
78+
}
79+
80+
static __read_mostly struct notifier_block backtrace_notifier = {
81+
.notifier_call = arch_trigger_all_cpu_backtrace_handler,
82+
.next = NULL,
83+
.priority = 1
84+
};
85+
86+
static int __init register_trigger_all_cpu_backtrace(void)
87+
{
88+
register_die_notifier(&backtrace_notifier);
89+
return 0;
90+
}
91+
early_initcall(register_trigger_all_cpu_backtrace);
92+
#endif
93+
94+
/* STUB calls to mimic old nmi_watchdog behaviour */
95+
#if defined(CONFIG_X86_LOCAL_APIC)
96+
unsigned int nmi_watchdog = NMI_NONE;
97+
EXPORT_SYMBOL(nmi_watchdog);
98+
void acpi_nmi_enable(void) { return; }
99+
void acpi_nmi_disable(void) { return; }
100+
#endif
101+
atomic_t nmi_active = ATOMIC_INIT(0); /* oprofile uses this */
102+
EXPORT_SYMBOL(nmi_active);
103+
int unknown_nmi_panic;
104+
void cpu_nmi_set_wd_enabled(void) { return; }
105+
void stop_apic_nmi_watchdog(void *unused) { return; }
106+
void setup_apic_nmi_watchdog(void *unused) { return; }
107+
int __init check_nmi_watchdog(void) { return 0; }

‎arch/x86/kernel/apic/nmi.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,6 @@ nmi_watchdog_tick(struct pt_regs *regs, unsigned reason)
401401
int cpu = smp_processor_id();
402402
int rc = 0;
403403

404-
/* check for other users first */
405-
if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
406-
== NOTIFY_STOP) {
407-
rc = 1;
408-
touched = 1;
409-
}
410-
411404
sum = get_timer_irqs(cpu);
412405

413406
if (__get_cpu_var(nmi_touch)) {

‎arch/x86/kernel/traps.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,21 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
392392
if (notify_die(DIE_NMI_IPI, "nmi_ipi", regs, reason, 2, SIGINT)
393393
== NOTIFY_STOP)
394394
return;
395+
395396
#ifdef CONFIG_X86_LOCAL_APIC
397+
if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
398+
== NOTIFY_STOP)
399+
return;
400+
401+
#ifndef CONFIG_LOCKUP_DETECTOR
396402
/*
397403
* Ok, so this is none of the documented NMI sources,
398404
* so it must be the NMI watchdog.
399405
*/
400406
if (nmi_watchdog_tick(regs, reason))
401407
return;
402408
if (!do_nmi_callback(regs, cpu))
409+
#endif /* !CONFIG_LOCKUP_DETECTOR */
403410
unknown_nmi_error(reason, regs);
404411
#else
405412
unknown_nmi_error(reason, regs);

‎include/linux/nmi.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ extern void touch_nmi_watchdog(void);
2020
extern void acpi_nmi_disable(void);
2121
extern void acpi_nmi_enable(void);
2222
#else
23+
#ifndef CONFIG_HARDLOCKUP_DETECTOR
2324
static inline void touch_nmi_watchdog(void)
2425
{
2526
touch_softlockup_watchdog();
2627
}
28+
#else
29+
extern void touch_nmi_watchdog(void);
30+
#endif
2731
static inline void acpi_nmi_disable(void) { }
2832
static inline void acpi_nmi_enable(void) { }
2933
#endif
@@ -47,4 +51,13 @@ static inline bool trigger_all_cpu_backtrace(void)
4751
}
4852
#endif
4953

54+
#ifdef CONFIG_LOCKUP_DETECTOR
55+
int hw_nmi_is_cpu_stuck(struct pt_regs *);
56+
u64 hw_nmi_get_sample_period(void);
57+
extern int watchdog_enabled;
58+
struct ctl_table;
59+
extern int proc_dowatchdog_enabled(struct ctl_table *, int ,
60+
void __user *, size_t *, loff_t *);
61+
#endif
62+
5063
#endif

‎include/linux/sched.h‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,20 +316,16 @@ extern void scheduler_tick(void);
316316

317317
extern void sched_show_task(struct task_struct *p);
318318

319-
#ifdef CONFIG_DETECT_SOFTLOCKUP
320-
extern void softlockup_tick(void);
319+
#ifdef CONFIG_LOCKUP_DETECTOR
321320
extern void touch_softlockup_watchdog(void);
322321
extern void touch_softlockup_watchdog_sync(void);
323322
extern void touch_all_softlockup_watchdogs(void);
324-
extern int proc_dosoftlockup_thresh(struct ctl_table *table, int write,
325-
void __user *buffer,
326-
size_t *lenp, loff_t *ppos);
323+
extern int proc_dowatchdog_thresh(struct ctl_table *table, int write,
324+
void __user *buffer,
325+
size_t *lenp, loff_t *ppos);
327326
extern unsigned int softlockup_panic;
328327
extern int softlockup_thresh;
329328
#else
330-
static inline void softlockup_tick(void)
331-
{
332-
}
333329
static inline void touch_softlockup_watchdog(void)
334330
{
335331
}

0 commit comments

Comments
 (0)