aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorDon Zickus <dzickus@redhat.com>2010-05-07 17:11:47 -0400
committerFrederic Weisbecker <fweisbec@gmail.com>2010-05-12 17:55:46 -0400
commitf69bcf60c3f17aa367e16eef7bc6ab001ea6d58a (patch)
tree494f08132eaaefc7e196059a4145ee4f5abbed7b /kernel
parent2508ce1845a3b256798532b2c6b7997c2dc6533b (diff)
lockup_detector: Remove nmi_watchdog.c file
This file migrated to kernel/watchdog.c and then combined with kernel/softlockup.c. As a result kernel/nmi_watchdog.c is no longer needed. Just remove it. Signed-off-by: Don Zickus <dzickus@redhat.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Cyrill Gorcunov <gorcunov@gmail.com> Cc: Eric Paris <eparis@redhat.com> Cc: Randy Dunlap <randy.dunlap@oracle.com> LKML-Reference: <1273266711-18706-5-git-send-email-dzickus@redhat.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/nmi_watchdog.c259
1 files changed, 0 insertions, 259 deletions
diff --git a/kernel/nmi_watchdog.c b/kernel/nmi_watchdog.c
deleted file mode 100644
index a79d211c30df..000000000000
--- a/kernel/nmi_watchdog.c
+++ /dev/null
@@ -1,259 +0,0 @@
1/*
2 * Detect Hard Lockups using the NMI
3 *
4 * started by Don Zickus, Copyright (C) 2010 Red Hat, Inc.
5 *
6 * this code detects hard lockups: incidents in where on a CPU
7 * the kernel does not respond to anything except NMI.
8 *
9 * Note: Most of this code is borrowed heavily from softlockup.c,
10 * so thanks to Ingo for the initial implementation.
11 * Some chunks also taken from arch/x86/kernel/apic/nmi.c, thanks
12 * to those contributors as well.
13 */
14
15#include <linux/mm.h>
16#include <linux/cpu.h>
17#include <linux/nmi.h>
18#include <linux/init.h>
19#include <linux/delay.h>
20#include <linux/freezer.h>
21#include <linux/lockdep.h>
22#include <linux/notifier.h>
23#include <linux/module.h>
24#include <linux/sysctl.h>
25
26#include <asm/irq_regs.h>
27#include <linux/perf_event.h>
28
29static DEFINE_PER_CPU(struct perf_event *, nmi_watchdog_ev);
30static DEFINE_PER_CPU(int, nmi_watchdog_touch);
31static DEFINE_PER_CPU(long, alert_counter);
32
33static int panic_on_timeout;
34
35void touch_nmi_watchdog(void)
36{
37 __raw_get_cpu_var(nmi_watchdog_touch) = 1;
38 touch_softlockup_watchdog();
39}
40EXPORT_SYMBOL(touch_nmi_watchdog);
41
42void touch_all_nmi_watchdog(void)
43{
44 int cpu;
45
46 for_each_online_cpu(cpu)
47 per_cpu(nmi_watchdog_touch, cpu) = 1;
48 touch_softlockup_watchdog();
49}
50
51static int __init setup_nmi_watchdog(char *str)
52{
53 if (!strncmp(str, "panic", 5)) {
54 panic_on_timeout = 1;
55 str = strchr(str, ',');
56 if (!str)
57 return 1;
58 ++str;
59 }
60 return 1;
61}
62__setup("nmi_watchdog=", setup_nmi_watchdog);
63
64struct perf_event_attr wd_hw_attr = {
65 .type = PERF_TYPE_HARDWARE,
66 .config = PERF_COUNT_HW_CPU_CYCLES,
67 .size = sizeof(struct perf_event_attr),
68 .pinned = 1,
69 .disabled = 1,
70};
71
72struct perf_event_attr wd_sw_attr = {
73 .type = PERF_TYPE_SOFTWARE,
74 .config = PERF_COUNT_SW_CPU_CLOCK,
75 .size = sizeof(struct perf_event_attr),
76 .pinned = 1,
77 .disabled = 1,
78};
79
80void wd_overflow(struct perf_event *event, int nmi,
81 struct perf_sample_data *data,
82 struct pt_regs *regs)
83{
84 int cpu = smp_processor_id();
85 int touched = 0;
86
87 if (__get_cpu_var(nmi_watchdog_touch)) {
88 per_cpu(nmi_watchdog_touch, cpu) = 0;
89 touched = 1;
90 }
91
92 /* check to see if the cpu is doing anything */
93 if (!touched && hw_nmi_is_cpu_stuck(regs)) {
94 /*
95 * Ayiee, looks like this CPU is stuck ...
96 * wait a few IRQs (5 seconds) before doing the oops ...
97 */
98 per_cpu(alert_counter, cpu) += 1;
99 if (per_cpu(alert_counter, cpu) == 5) {
100 if (panic_on_timeout)
101 panic("NMI Watchdog detected LOCKUP on cpu %d", cpu);
102 else
103 WARN(1, "NMI Watchdog detected LOCKUP on cpu %d", cpu);
104 }
105 } else {
106 per_cpu(alert_counter, cpu) = 0;
107 }
108
109 return;
110}
111
112static int enable_nmi_watchdog(int cpu)
113{
114 struct perf_event *event;
115 struct perf_event_attr *wd_attr;
116
117 event = per_cpu(nmi_watchdog_ev, cpu);
118 if (event && event->state > PERF_EVENT_STATE_OFF)
119 return 0;
120
121 if (event == NULL) {
122 /* Try to register using hardware perf events first */
123 wd_attr = &wd_hw_attr;
124 wd_attr->sample_period = hw_nmi_get_sample_period();
125 event = perf_event_create_kernel_counter(wd_attr, cpu, -1, wd_overflow);
126 if (IS_ERR(event)) {
127 /* hardware doesn't exist or not supported, fallback to software events */
128 printk(KERN_INFO "nmi_watchdog: hardware not available, trying software events\n");
129 wd_attr = &wd_sw_attr;
130 wd_attr->sample_period = NSEC_PER_SEC;
131 event = perf_event_create_kernel_counter(wd_attr, cpu, -1, wd_overflow);
132 if (IS_ERR(event)) {
133 printk(KERN_ERR "nmi watchdog failed to create perf event on %i: %p\n", cpu, event);
134 return -1;
135 }
136 }
137 per_cpu(nmi_watchdog_ev, cpu) = event;
138 }
139 perf_event_enable(per_cpu(nmi_watchdog_ev, cpu));
140 return 0;
141}
142
143static void disable_nmi_watchdog(int cpu)
144{
145 struct perf_event *event;
146
147 event = per_cpu(nmi_watchdog_ev, cpu);
148 if (event) {
149 perf_event_disable(per_cpu(nmi_watchdog_ev, cpu));
150 per_cpu(nmi_watchdog_ev, cpu) = NULL;
151 perf_event_release_kernel(event);
152 }
153}
154
155#ifdef CONFIG_SYSCTL
156/*
157 * proc handler for /proc/sys/kernel/nmi_watchdog
158 */
159int nmi_watchdog_enabled;
160
161int proc_nmi_enabled(struct ctl_table *table, int write,
162 void __user *buffer, size_t *length, loff_t *ppos)
163{
164 int cpu;
165
166 if (!write) {
167 struct perf_event *event;
168 for_each_online_cpu(cpu) {
169 event = per_cpu(nmi_watchdog_ev, cpu);
170 if (event && event->state > PERF_EVENT_STATE_OFF) {
171 nmi_watchdog_enabled = 1;
172 break;
173 }
174 }
175 proc_dointvec(table, write, buffer, length, ppos);
176 return 0;
177 }
178
179 touch_all_nmi_watchdog();
180 proc_dointvec(table, write, buffer, length, ppos);
181 if (nmi_watchdog_enabled) {
182 for_each_online_cpu(cpu)
183 if (enable_nmi_watchdog(cpu)) {
184 printk(KERN_ERR "NMI watchdog failed configuration, "
185 " can not be enabled\n");
186 }
187 } else {
188 for_each_online_cpu(cpu)
189 disable_nmi_watchdog(cpu);
190 }
191 return 0;
192}
193
194#endif /* CONFIG_SYSCTL */
195
196/*
197 * Create/destroy watchdog threads as CPUs come and go:
198 */
199static int __cpuinit
200cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
201{
202 int hotcpu = (unsigned long)hcpu;
203
204 switch (action) {
205 case CPU_UP_PREPARE:
206 case CPU_UP_PREPARE_FROZEN:
207 per_cpu(nmi_watchdog_touch, hotcpu) = 0;
208 break;
209 case CPU_ONLINE:
210 case CPU_ONLINE_FROZEN:
211 if (enable_nmi_watchdog(hotcpu))
212 return NOTIFY_BAD;
213 break;
214#ifdef CONFIG_HOTPLUG_CPU
215 case CPU_UP_CANCELED:
216 case CPU_UP_CANCELED_FROZEN:
217 disable_nmi_watchdog(hotcpu);
218 case CPU_DEAD:
219 case CPU_DEAD_FROZEN:
220 break;
221#endif /* CONFIG_HOTPLUG_CPU */
222 }
223 return NOTIFY_OK;
224}
225
226static struct notifier_block __cpuinitdata cpu_nfb = {
227 .notifier_call = cpu_callback
228};
229
230static int __initdata nonmi_watchdog;
231
232static int __init nonmi_watchdog_setup(char *str)
233{
234 nonmi_watchdog = 1;
235 return 1;
236}
237__setup("nonmi_watchdog", nonmi_watchdog_setup);
238
239static int __init spawn_nmi_watchdog_task(void)
240{
241 void *cpu = (void *)(long)smp_processor_id();
242 int err;
243
244 if (nonmi_watchdog)
245 return 0;
246
247 printk(KERN_INFO "NMI watchdog enabled, takes one hw-pmu counter.\n");
248
249 err = cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu);
250 if (err == NOTIFY_BAD) {
251 BUG();
252 return 1;
253 }
254 cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
255 register_cpu_notifier(&cpu_nfb);
256
257 return 0;
258}
259early_initcall(spawn_nmi_watchdog_task);