blob: 4d6fb047952e8abec336175d3bc5abe12dc76e76 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/x86_64/nmi.c
3 *
4 * NMI watchdog support on APIC systems
5 *
6 * Started by Ingo Molnar <mingo@redhat.com>
7 *
8 * Fixes:
9 * Mikael Pettersson : AMD K7 support for local APIC NMI watchdog.
10 * Mikael Pettersson : Power Management for local APIC NMI watchdog.
11 * Pavel Machek and
12 * Mikael Pettersson : PM converted to driver model. Disable/enable API.
13 */
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/module.h>
19#include <linux/sysdev.h>
20#include <linux/nmi.h>
21#include <linux/sysctl.h>
Andi Kleeneddb6fb2006-02-03 21:50:41 +010022#include <linux/kprobes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/nmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/proto.h>
27#include <asm/kdebug.h>
Andi Kleen553f2652006-04-07 19:49:57 +020028#include <asm/mce.h>
Venkatesh Pallipadi248dcb22006-09-26 10:52:27 +020029#include <asm/intel_arch_perfmon.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Don Zickus828f0af2006-09-26 10:52:26 +020031/* perfctr_nmi_owner tracks the ownership of the perfctr registers:
32 * evtsel_nmi_owner tracks the ownership of the event selection
33 * - different performance counters/ event selection may be reserved for
34 * different subsystems this reservation system just tries to coordinate
35 * things a little
36 */
37static DEFINE_PER_CPU(unsigned, perfctr_nmi_owner);
38static DEFINE_PER_CPU(unsigned, evntsel_nmi_owner[2]);
39
40/* this number is calculated from Intel's MSR_P4_CRU_ESCR5 register and it's
41 * offset from MSR_P4_BSU_ESCR0. It will be the max for all platforms (for now)
42 */
43#define NMI_MAX_COUNTER_BITS 66
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/* nmi_active:
Don Zickusf2802e72006-09-26 10:52:26 +020046 * >0: the lapic NMI watchdog is active, but can be disabled
47 * <0: the lapic NMI watchdog has not been set up, and cannot
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 * be enabled
Don Zickusf2802e72006-09-26 10:52:26 +020049 * 0: the lapic NMI watchdog is disabled, but can be enabled
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 */
Don Zickusf2802e72006-09-26 10:52:26 +020051atomic_t nmi_active = ATOMIC_INIT(0); /* oprofile uses this */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052int panic_on_timeout;
53
54unsigned int nmi_watchdog = NMI_DEFAULT;
55static unsigned int nmi_hz = HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Don Zickusf2802e72006-09-26 10:52:26 +020057struct nmi_watchdog_ctlblk {
58 int enabled;
59 u64 check_bit;
60 unsigned int cccr_msr;
61 unsigned int perfctr_msr; /* the MSR to reset in NMI handler */
62 unsigned int evntsel_msr; /* the MSR to select the events to handle */
63};
64static DEFINE_PER_CPU(struct nmi_watchdog_ctlblk, nmi_watchdog_ctlblk);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Don Zickusf2802e72006-09-26 10:52:26 +020066/* local prototypes */
Don Zickusf2802e72006-09-26 10:52:26 +020067static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu);
Andi Kleen75152112005-05-16 21:53:34 -070068
Don Zickus828f0af2006-09-26 10:52:26 +020069/* converts an msr to an appropriate reservation bit */
70static inline unsigned int nmi_perfctr_msr_to_bit(unsigned int msr)
71{
72 /* returns the bit offset of the performance counter register */
73 switch (boot_cpu_data.x86_vendor) {
74 case X86_VENDOR_AMD:
75 return (msr - MSR_K7_PERFCTR0);
76 case X86_VENDOR_INTEL:
Venkatesh Pallipadi248dcb22006-09-26 10:52:27 +020077 if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON))
78 return (msr - MSR_ARCH_PERFMON_PERFCTR0);
79 else
80 return (msr - MSR_P4_BPU_PERFCTR0);
Don Zickus828f0af2006-09-26 10:52:26 +020081 }
82 return 0;
83}
84
85/* converts an msr to an appropriate reservation bit */
86static inline unsigned int nmi_evntsel_msr_to_bit(unsigned int msr)
87{
88 /* returns the bit offset of the event selection register */
89 switch (boot_cpu_data.x86_vendor) {
90 case X86_VENDOR_AMD:
91 return (msr - MSR_K7_EVNTSEL0);
92 case X86_VENDOR_INTEL:
Venkatesh Pallipadi248dcb22006-09-26 10:52:27 +020093 if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON))
94 return (msr - MSR_ARCH_PERFMON_EVENTSEL0);
95 else
96 return (msr - MSR_P4_BSU_ESCR0);
Don Zickus828f0af2006-09-26 10:52:26 +020097 }
98 return 0;
99}
100
101/* checks for a bit availability (hack for oprofile) */
102int avail_to_resrv_perfctr_nmi_bit(unsigned int counter)
103{
104 BUG_ON(counter > NMI_MAX_COUNTER_BITS);
105
106 return (!test_bit(counter, &__get_cpu_var(perfctr_nmi_owner)));
107}
108
109/* checks the an msr for availability */
110int avail_to_resrv_perfctr_nmi(unsigned int msr)
111{
112 unsigned int counter;
113
114 counter = nmi_perfctr_msr_to_bit(msr);
115 BUG_ON(counter > NMI_MAX_COUNTER_BITS);
116
117 return (!test_bit(counter, &__get_cpu_var(perfctr_nmi_owner)));
118}
119
120int reserve_perfctr_nmi(unsigned int msr)
121{
122 unsigned int counter;
123
124 counter = nmi_perfctr_msr_to_bit(msr);
125 BUG_ON(counter > NMI_MAX_COUNTER_BITS);
126
127 if (!test_and_set_bit(counter, &__get_cpu_var(perfctr_nmi_owner)))
128 return 1;
129 return 0;
130}
131
132void release_perfctr_nmi(unsigned int msr)
133{
134 unsigned int counter;
135
136 counter = nmi_perfctr_msr_to_bit(msr);
137 BUG_ON(counter > NMI_MAX_COUNTER_BITS);
138
139 clear_bit(counter, &__get_cpu_var(perfctr_nmi_owner));
140}
141
142int reserve_evntsel_nmi(unsigned int msr)
143{
144 unsigned int counter;
145
146 counter = nmi_evntsel_msr_to_bit(msr);
147 BUG_ON(counter > NMI_MAX_COUNTER_BITS);
148
149 if (!test_and_set_bit(counter, &__get_cpu_var(evntsel_nmi_owner)))
150 return 1;
151 return 0;
152}
153
154void release_evntsel_nmi(unsigned int msr)
155{
156 unsigned int counter;
157
158 counter = nmi_evntsel_msr_to_bit(msr);
159 BUG_ON(counter > NMI_MAX_COUNTER_BITS);
160
161 clear_bit(counter, &__get_cpu_var(evntsel_nmi_owner));
162}
163
Ashok Raje6982c62005-06-25 14:54:58 -0700164static __cpuinit inline int nmi_known_cpu(void)
Andi Kleen75152112005-05-16 21:53:34 -0700165{
166 switch (boot_cpu_data.x86_vendor) {
167 case X86_VENDOR_AMD:
168 return boot_cpu_data.x86 == 15;
169 case X86_VENDOR_INTEL:
Venkatesh Pallipadi248dcb22006-09-26 10:52:27 +0200170 if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON))
171 return 1;
172 else
173 return (boot_cpu_data.x86 == 15);
Andi Kleen75152112005-05-16 21:53:34 -0700174 }
175 return 0;
176}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178/* Run after command line and cpu_init init, but before all other checks */
Don Zickuse33e89a2006-09-26 10:52:27 +0200179void nmi_watchdog_default(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 if (nmi_watchdog != NMI_DEFAULT)
182 return;
Andi Kleen75152112005-05-16 21:53:34 -0700183 if (nmi_known_cpu())
184 nmi_watchdog = NMI_LOCAL_APIC;
185 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 nmi_watchdog = NMI_IO_APIC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187}
188
Andi Kleen75152112005-05-16 21:53:34 -0700189#ifdef CONFIG_SMP
190/* The performance counters used by NMI_LOCAL_APIC don't trigger when
191 * the CPU is idle. To make sure the NMI watchdog really ticks on all
192 * CPUs during the test make them busy.
193 */
194static __init void nmi_cpu_busy(void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Andi Kleen75152112005-05-16 21:53:34 -0700196 volatile int *endflag = data;
Ingo Molnar366c7f52006-07-03 00:25:25 -0700197 local_irq_enable_in_hardirq();
Andi Kleen75152112005-05-16 21:53:34 -0700198 /* Intentionally don't use cpu_relax here. This is
199 to make sure that the performance counter really ticks,
200 even if there is a simulator or similar that catches the
201 pause instruction. On a real HT machine this is fine because
202 all other CPUs are busy with "useless" delay loops and don't
203 care if they get somewhat less cycles. */
204 while (*endflag == 0)
205 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
Andi Kleen75152112005-05-16 21:53:34 -0700207#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Andi Kleen75152112005-05-16 21:53:34 -0700209int __init check_nmi_watchdog (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Andi Kleen75152112005-05-16 21:53:34 -0700211 volatile int endflag = 0;
Andi Kleenac6b9312005-05-16 21:53:19 -0700212 int *counts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 int cpu;
214
Don Zickusf2802e72006-09-26 10:52:26 +0200215 if ((nmi_watchdog == NMI_NONE) || (nmi_watchdog == NMI_DEFAULT))
216 return 0;
217
218 if (!atomic_read(&nmi_active))
219 return 0;
220
Andi Kleen75152112005-05-16 21:53:34 -0700221 counts = kmalloc(NR_CPUS * sizeof(int), GFP_KERNEL);
222 if (!counts)
223 return -1;
Jack F Vogel67701ae2005-05-01 08:58:48 -0700224
Andi Kleen75152112005-05-16 21:53:34 -0700225 printk(KERN_INFO "testing NMI watchdog ... ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Andi Kleen7554c3f2006-01-11 22:45:45 +0100227#ifdef CONFIG_SMP
Andi Kleen75152112005-05-16 21:53:34 -0700228 if (nmi_watchdog == NMI_LOCAL_APIC)
229 smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0);
Andi Kleen7554c3f2006-01-11 22:45:45 +0100230#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 for (cpu = 0; cpu < NR_CPUS; cpu++)
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100233 counts[cpu] = cpu_pda(cpu)->__nmi_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 local_irq_enable();
235 mdelay((10*1000)/nmi_hz); // wait 10 ticks
236
Andrew Morton394e3902006-03-23 03:01:05 -0800237 for_each_online_cpu(cpu) {
Don Zickusf2802e72006-09-26 10:52:26 +0200238 if (!per_cpu(nmi_watchdog_ctlblk, cpu).enabled)
239 continue;
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100240 if (cpu_pda(cpu)->__nmi_count - counts[cpu] <= 5) {
Andi Kleen75152112005-05-16 21:53:34 -0700241 printk("CPU#%d: NMI appears to be stuck (%d->%d)!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 cpu,
Andi Kleen75152112005-05-16 21:53:34 -0700243 counts[cpu],
Ravikiran G Thirumalaidf79efd2006-01-11 22:45:39 +0100244 cpu_pda(cpu)->__nmi_count);
Don Zickusf2802e72006-09-26 10:52:26 +0200245 per_cpu(nmi_watchdog_ctlblk, cpu).enabled = 0;
246 atomic_dec(&nmi_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 }
248 }
Don Zickusf2802e72006-09-26 10:52:26 +0200249 if (!atomic_read(&nmi_active)) {
250 kfree(counts);
251 atomic_set(&nmi_active, -1);
252 return -1;
253 }
Andi Kleen75152112005-05-16 21:53:34 -0700254 endflag = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 printk("OK.\n");
256
257 /* now that we know it works we can reduce NMI frequency to
258 something more reasonable; makes a difference in some configs */
Venkatesh Pallipadi248dcb22006-09-26 10:52:27 +0200259 if (nmi_watchdog == NMI_LOCAL_APIC) {
260 struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 nmi_hz = 1;
Venkatesh Pallipadi248dcb22006-09-26 10:52:27 +0200263 /*
264 * On Intel CPUs with ARCH_PERFMON only 32 bits in the counter
265 * are writable, with higher bits sign extending from bit 31.
266 * So, we can only program the counter with 31 bit values and
267 * 32nd bit should be 1, for 33.. to be 1.
268 * Find the appropriate nmi_hz
269 */
270 if (wd->perfctr_msr == MSR_ARCH_PERFMON_PERFCTR0 &&
271 ((u64)cpu_khz * 1000) > 0x7fffffffULL) {
272 nmi_hz = ((u64)cpu_khz * 1000) / 0x7fffffffUL + 1;
273 }
274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Andi Kleenac6b9312005-05-16 21:53:19 -0700276 kfree(counts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 return 0;
278}
279
280int __init setup_nmi_watchdog(char *str)
281{
282 int nmi;
283
284 if (!strncmp(str,"panic",5)) {
285 panic_on_timeout = 1;
286 str = strchr(str, ',');
287 if (!str)
288 return 1;
289 ++str;
290 }
291
292 get_option(&str, &nmi);
293
Don Zickusf2802e72006-09-26 10:52:26 +0200294 if ((nmi >= NMI_INVALID) || (nmi < NMI_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 return 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200296
297 if ((nmi == NMI_LOCAL_APIC) && (nmi_known_cpu() == 0))
298 return 0; /* no lapic support */
Andi Kleen75152112005-05-16 21:53:34 -0700299 nmi_watchdog = nmi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return 1;
301}
302
303__setup("nmi_watchdog=", setup_nmi_watchdog);
304
305static void disable_lapic_nmi_watchdog(void)
306{
Don Zickusf2802e72006-09-26 10:52:26 +0200307 BUG_ON(nmi_watchdog != NMI_LOCAL_APIC);
308
309 if (atomic_read(&nmi_active) <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return;
Don Zickusf2802e72006-09-26 10:52:26 +0200311
312 on_each_cpu(stop_apic_nmi_watchdog, NULL, 0, 1);
313
314 BUG_ON(atomic_read(&nmi_active) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
317static void enable_lapic_nmi_watchdog(void)
318{
Don Zickusf2802e72006-09-26 10:52:26 +0200319 BUG_ON(nmi_watchdog != NMI_LOCAL_APIC);
320
321 /* are we already enabled */
322 if (atomic_read(&nmi_active) != 0)
323 return;
324
325 /* are we lapic aware */
326 if (nmi_known_cpu() <= 0)
327 return;
328
329 on_each_cpu(setup_apic_nmi_watchdog, NULL, 0, 1);
330 touch_nmi_watchdog();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331}
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333void disable_timer_nmi_watchdog(void)
334{
Don Zickusf2802e72006-09-26 10:52:26 +0200335 BUG_ON(nmi_watchdog != NMI_IO_APIC);
336
337 if (atomic_read(&nmi_active) <= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 return;
339
340 disable_irq(0);
Don Zickusf2802e72006-09-26 10:52:26 +0200341 on_each_cpu(stop_apic_nmi_watchdog, NULL, 0, 1);
342
343 BUG_ON(atomic_read(&nmi_active) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344}
345
346void enable_timer_nmi_watchdog(void)
347{
Don Zickusf2802e72006-09-26 10:52:26 +0200348 BUG_ON(nmi_watchdog != NMI_IO_APIC);
349
350 if (atomic_read(&nmi_active) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 touch_nmi_watchdog();
Don Zickusf2802e72006-09-26 10:52:26 +0200352 on_each_cpu(setup_apic_nmi_watchdog, NULL, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 enable_irq(0);
354 }
355}
356
357#ifdef CONFIG_PM
358
359static int nmi_pm_active; /* nmi_active before suspend */
360
Pavel Machek829ca9a2005-09-03 15:56:56 -0700361static int lapic_nmi_suspend(struct sys_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Shaohua Li4038f902006-09-26 10:52:27 +0200363 /* only CPU0 goes here, other CPUs should be offline */
Don Zickusf2802e72006-09-26 10:52:26 +0200364 nmi_pm_active = atomic_read(&nmi_active);
Shaohua Li4038f902006-09-26 10:52:27 +0200365 stop_apic_nmi_watchdog(NULL);
366 BUG_ON(atomic_read(&nmi_active) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 return 0;
368}
369
370static int lapic_nmi_resume(struct sys_device *dev)
371{
Shaohua Li4038f902006-09-26 10:52:27 +0200372 /* only CPU0 goes here, other CPUs should be offline */
373 if (nmi_pm_active > 0) {
374 setup_apic_nmi_watchdog(NULL);
375 touch_nmi_watchdog();
376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 return 0;
378}
379
380static struct sysdev_class nmi_sysclass = {
381 set_kset_name("lapic_nmi"),
382 .resume = lapic_nmi_resume,
383 .suspend = lapic_nmi_suspend,
384};
385
386static struct sys_device device_lapic_nmi = {
387 .id = 0,
388 .cls = &nmi_sysclass,
389};
390
391static int __init init_lapic_nmi_sysfs(void)
392{
393 int error;
394
Don Zickusf2802e72006-09-26 10:52:26 +0200395 /* should really be a BUG_ON but b/c this is an
396 * init call, it just doesn't work. -dcz
397 */
398 if (nmi_watchdog != NMI_LOCAL_APIC)
399 return 0;
400
401 if ( atomic_read(&nmi_active) < 0 )
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 return 0;
403
404 error = sysdev_class_register(&nmi_sysclass);
405 if (!error)
406 error = sysdev_register(&device_lapic_nmi);
407 return error;
408}
409/* must come after the local APIC's device_initcall() */
410late_initcall(init_lapic_nmi_sysfs);
411
412#endif /* CONFIG_PM */
413
Don Zickusf2802e72006-09-26 10:52:26 +0200414/*
415 * Activate the NMI watchdog via the local APIC.
416 * Original code written by Keith Owens.
417 */
418
419/* Note that these events don't tick when the CPU idles. This means
420 the frequency varies with CPU load. */
421
422#define K7_EVNTSEL_ENABLE (1 << 22)
423#define K7_EVNTSEL_INT (1 << 20)
424#define K7_EVNTSEL_OS (1 << 17)
425#define K7_EVNTSEL_USR (1 << 16)
426#define K7_EVENT_CYCLES_PROCESSOR_IS_RUNNING 0x76
427#define K7_NMI_EVENT K7_EVENT_CYCLES_PROCESSOR_IS_RUNNING
428
Don Zickus828f0af2006-09-26 10:52:26 +0200429static int setup_k7_watchdog(void)
Andi Kleen75152112005-05-16 21:53:34 -0700430{
Don Zickusf2802e72006-09-26 10:52:26 +0200431 unsigned int perfctr_msr, evntsel_msr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 unsigned int evntsel;
Don Zickusf2802e72006-09-26 10:52:26 +0200433 struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Don Zickusf2802e72006-09-26 10:52:26 +0200435 perfctr_msr = MSR_K7_PERFCTR0;
436 evntsel_msr = MSR_K7_EVNTSEL0;
437 if (!reserve_perfctr_nmi(perfctr_msr))
Don Zickus828f0af2006-09-26 10:52:26 +0200438 goto fail;
439
Don Zickusf2802e72006-09-26 10:52:26 +0200440 if (!reserve_evntsel_nmi(evntsel_msr))
Don Zickus828f0af2006-09-26 10:52:26 +0200441 goto fail1;
442
443 /* Simulator may not support it */
Don Zickusf2802e72006-09-26 10:52:26 +0200444 if (checking_wrmsrl(evntsel_msr, 0UL))
Don Zickus828f0af2006-09-26 10:52:26 +0200445 goto fail2;
Don Zickusf2802e72006-09-26 10:52:26 +0200446 wrmsrl(perfctr_msr, 0UL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 evntsel = K7_EVNTSEL_INT
449 | K7_EVNTSEL_OS
450 | K7_EVNTSEL_USR
451 | K7_NMI_EVENT;
452
Don Zickusf2802e72006-09-26 10:52:26 +0200453 /* setup the timer */
454 wrmsr(evntsel_msr, evntsel, 0);
455 wrmsrl(perfctr_msr, -((u64)cpu_khz * 1000 / nmi_hz));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 apic_write(APIC_LVTPC, APIC_DM_NMI);
457 evntsel |= K7_EVNTSEL_ENABLE;
Don Zickusf2802e72006-09-26 10:52:26 +0200458 wrmsr(evntsel_msr, evntsel, 0);
459
460 wd->perfctr_msr = perfctr_msr;
461 wd->evntsel_msr = evntsel_msr;
462 wd->cccr_msr = 0; //unused
463 wd->check_bit = 1ULL<<63;
Don Zickus828f0af2006-09-26 10:52:26 +0200464 return 1;
465fail2:
Don Zickusf2802e72006-09-26 10:52:26 +0200466 release_evntsel_nmi(evntsel_msr);
Don Zickus828f0af2006-09-26 10:52:26 +0200467fail1:
Don Zickusf2802e72006-09-26 10:52:26 +0200468 release_perfctr_nmi(perfctr_msr);
Don Zickus828f0af2006-09-26 10:52:26 +0200469fail:
470 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471}
472
Don Zickusf2802e72006-09-26 10:52:26 +0200473static void stop_k7_watchdog(void)
474{
475 struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
476
477 wrmsr(wd->evntsel_msr, 0, 0);
478
479 release_evntsel_nmi(wd->evntsel_msr);
480 release_perfctr_nmi(wd->perfctr_msr);
481}
482
483/* Note that these events don't tick when the CPU idles. This means
484 the frequency varies with CPU load. */
485
486#define MSR_P4_MISC_ENABLE_PERF_AVAIL (1<<7)
487#define P4_ESCR_EVENT_SELECT(N) ((N)<<25)
488#define P4_ESCR_OS (1<<3)
489#define P4_ESCR_USR (1<<2)
490#define P4_CCCR_OVF_PMI0 (1<<26)
491#define P4_CCCR_OVF_PMI1 (1<<27)
492#define P4_CCCR_THRESHOLD(N) ((N)<<20)
493#define P4_CCCR_COMPLEMENT (1<<19)
494#define P4_CCCR_COMPARE (1<<18)
495#define P4_CCCR_REQUIRED (3<<16)
496#define P4_CCCR_ESCR_SELECT(N) ((N)<<13)
497#define P4_CCCR_ENABLE (1<<12)
498#define P4_CCCR_OVF (1<<31)
499/* Set up IQ_COUNTER0 to behave like a clock, by having IQ_CCCR0 filter
500 CRU_ESCR0 (with any non-null event selector) through a complemented
501 max threshold. [IA32-Vol3, Section 14.9.9] */
Andi Kleen75152112005-05-16 21:53:34 -0700502
503static int setup_p4_watchdog(void)
504{
Don Zickusf2802e72006-09-26 10:52:26 +0200505 unsigned int perfctr_msr, evntsel_msr, cccr_msr;
506 unsigned int evntsel, cccr_val;
Andi Kleen75152112005-05-16 21:53:34 -0700507 unsigned int misc_enable, dummy;
Don Zickusf2802e72006-09-26 10:52:26 +0200508 unsigned int ht_num;
509 struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
Andi Kleen75152112005-05-16 21:53:34 -0700510
Don Zickusf2802e72006-09-26 10:52:26 +0200511 rdmsr(MSR_IA32_MISC_ENABLE, misc_enable, dummy);
Andi Kleen75152112005-05-16 21:53:34 -0700512 if (!(misc_enable & MSR_P4_MISC_ENABLE_PERF_AVAIL))
513 return 0;
514
Andi Kleen75152112005-05-16 21:53:34 -0700515#ifdef CONFIG_SMP
Don Zickusf2802e72006-09-26 10:52:26 +0200516 /* detect which hyperthread we are on */
517 if (smp_num_siblings == 2) {
518 unsigned int ebx, apicid;
Andi Kleen75152112005-05-16 21:53:34 -0700519
Don Zickusf2802e72006-09-26 10:52:26 +0200520 ebx = cpuid_ebx(1);
521 apicid = (ebx >> 24) & 0xff;
522 ht_num = apicid & 1;
523 } else
524#endif
525 ht_num = 0;
526
527 /* performance counters are shared resources
528 * assign each hyperthread its own set
529 * (re-use the ESCR0 register, seems safe
530 * and keeps the cccr_val the same)
531 */
532 if (!ht_num) {
533 /* logical cpu 0 */
534 perfctr_msr = MSR_P4_IQ_PERFCTR0;
535 evntsel_msr = MSR_P4_CRU_ESCR0;
536 cccr_msr = MSR_P4_IQ_CCCR0;
537 cccr_val = P4_CCCR_OVF_PMI0 | P4_CCCR_ESCR_SELECT(4);
538 } else {
539 /* logical cpu 1 */
540 perfctr_msr = MSR_P4_IQ_PERFCTR1;
541 evntsel_msr = MSR_P4_CRU_ESCR0;
542 cccr_msr = MSR_P4_IQ_CCCR1;
543 cccr_val = P4_CCCR_OVF_PMI1 | P4_CCCR_ESCR_SELECT(4);
544 }
545
546 if (!reserve_perfctr_nmi(perfctr_msr))
Don Zickus828f0af2006-09-26 10:52:26 +0200547 goto fail;
548
Don Zickusf2802e72006-09-26 10:52:26 +0200549 if (!reserve_evntsel_nmi(evntsel_msr))
Don Zickus828f0af2006-09-26 10:52:26 +0200550 goto fail1;
Andi Kleen75152112005-05-16 21:53:34 -0700551
Don Zickusf2802e72006-09-26 10:52:26 +0200552 evntsel = P4_ESCR_EVENT_SELECT(0x3F)
553 | P4_ESCR_OS
554 | P4_ESCR_USR;
555
556 cccr_val |= P4_CCCR_THRESHOLD(15)
557 | P4_CCCR_COMPLEMENT
558 | P4_CCCR_COMPARE
559 | P4_CCCR_REQUIRED;
560
561 wrmsr(evntsel_msr, evntsel, 0);
562 wrmsr(cccr_msr, cccr_val, 0);
563 wrmsrl(perfctr_msr, -((u64)cpu_khz * 1000 / nmi_hz));
Andi Kleen75152112005-05-16 21:53:34 -0700564 apic_write(APIC_LVTPC, APIC_DM_NMI);
Don Zickusf2802e72006-09-26 10:52:26 +0200565 cccr_val |= P4_CCCR_ENABLE;
566 wrmsr(cccr_msr, cccr_val, 0);
567
568 wd->perfctr_msr = perfctr_msr;
569 wd->evntsel_msr = evntsel_msr;
570 wd->cccr_msr = cccr_msr;
571 wd->check_bit = 1ULL<<39;
Andi Kleen75152112005-05-16 21:53:34 -0700572 return 1;
Don Zickus828f0af2006-09-26 10:52:26 +0200573fail1:
Don Zickusf2802e72006-09-26 10:52:26 +0200574 release_perfctr_nmi(perfctr_msr);
Don Zickus828f0af2006-09-26 10:52:26 +0200575fail:
576 return 0;
Andi Kleen75152112005-05-16 21:53:34 -0700577}
578
Don Zickusf2802e72006-09-26 10:52:26 +0200579static void stop_p4_watchdog(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
Don Zickusf2802e72006-09-26 10:52:26 +0200581 struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
Andi Kleen75152112005-05-16 21:53:34 -0700582
Don Zickusf2802e72006-09-26 10:52:26 +0200583 wrmsr(wd->cccr_msr, 0, 0);
584 wrmsr(wd->evntsel_msr, 0, 0);
585
586 release_evntsel_nmi(wd->evntsel_msr);
587 release_perfctr_nmi(wd->perfctr_msr);
588}
589
Venkatesh Pallipadi248dcb22006-09-26 10:52:27 +0200590#define ARCH_PERFMON_NMI_EVENT_SEL ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL
591#define ARCH_PERFMON_NMI_EVENT_UMASK ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK
592
593static int setup_intel_arch_watchdog(void)
594{
595 unsigned int ebx;
596 union cpuid10_eax eax;
597 unsigned int unused;
598 unsigned int perfctr_msr, evntsel_msr;
599 unsigned int evntsel;
600 struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
601
602 /*
603 * Check whether the Architectural PerfMon supports
604 * Unhalted Core Cycles Event or not.
605 * NOTE: Corresponding bit = 0 in ebx indicates event present.
606 */
607 cpuid(10, &(eax.full), &ebx, &unused, &unused);
608 if ((eax.split.mask_length < (ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX+1)) ||
609 (ebx & ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT))
610 goto fail;
611
612 perfctr_msr = MSR_ARCH_PERFMON_PERFCTR0;
613 evntsel_msr = MSR_ARCH_PERFMON_EVENTSEL0;
614
615 if (!reserve_perfctr_nmi(perfctr_msr))
616 goto fail;
617
618 if (!reserve_evntsel_nmi(evntsel_msr))
619 goto fail1;
620
621 wrmsrl(perfctr_msr, 0UL);
622
623 evntsel = ARCH_PERFMON_EVENTSEL_INT
624 | ARCH_PERFMON_EVENTSEL_OS
625 | ARCH_PERFMON_EVENTSEL_USR
626 | ARCH_PERFMON_NMI_EVENT_SEL
627 | ARCH_PERFMON_NMI_EVENT_UMASK;
628
629 /* setup the timer */
630 wrmsr(evntsel_msr, evntsel, 0);
631 wrmsrl(perfctr_msr, -((u64)cpu_khz * 1000 / nmi_hz));
632
633 apic_write(APIC_LVTPC, APIC_DM_NMI);
634 evntsel |= ARCH_PERFMON_EVENTSEL0_ENABLE;
635 wrmsr(evntsel_msr, evntsel, 0);
636
637 wd->perfctr_msr = perfctr_msr;
638 wd->evntsel_msr = evntsel_msr;
639 wd->cccr_msr = 0; //unused
640 wd->check_bit = 1ULL << (eax.split.bit_width - 1);
641 return 1;
642fail1:
643 release_perfctr_nmi(perfctr_msr);
644fail:
645 return 0;
646}
647
648static void stop_intel_arch_watchdog(void)
649{
650 unsigned int ebx;
651 union cpuid10_eax eax;
652 unsigned int unused;
653 struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
654
655 /*
656 * Check whether the Architectural PerfMon supports
657 * Unhalted Core Cycles Event or not.
658 * NOTE: Corresponding bit = 0 in ebx indicates event present.
659 */
660 cpuid(10, &(eax.full), &ebx, &unused, &unused);
661 if ((eax.split.mask_length < (ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX+1)) ||
662 (ebx & ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT))
663 return;
664
665 wrmsr(wd->evntsel_msr, 0, 0);
666
667 release_evntsel_nmi(wd->evntsel_msr);
668 release_perfctr_nmi(wd->perfctr_msr);
669}
670
Don Zickusf2802e72006-09-26 10:52:26 +0200671void setup_apic_nmi_watchdog(void *unused)
672{
Shaohua Li4038f902006-09-26 10:52:27 +0200673 struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
674
Don Zickusf2802e72006-09-26 10:52:26 +0200675 /* only support LOCAL and IO APICs for now */
676 if ((nmi_watchdog != NMI_LOCAL_APIC) &&
677 (nmi_watchdog != NMI_IO_APIC))
678 return;
679
Shaohua Li4038f902006-09-26 10:52:27 +0200680 if (wd->enabled == 1)
681 return;
682
683 /* cheap hack to support suspend/resume */
684 /* if cpu0 is not active neither should the other cpus */
685 if ((smp_processor_id() != 0) && (atomic_read(&nmi_active) <= 0))
686 return;
687
Don Zickusf2802e72006-09-26 10:52:26 +0200688 if (nmi_watchdog == NMI_LOCAL_APIC) {
689 switch (boot_cpu_data.x86_vendor) {
690 case X86_VENDOR_AMD:
691 if (strstr(boot_cpu_data.x86_model_id, "Screwdriver"))
692 return;
693 if (!setup_k7_watchdog())
694 return;
695 break;
696 case X86_VENDOR_INTEL:
Venkatesh Pallipadi248dcb22006-09-26 10:52:27 +0200697 if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) {
698 if (!setup_intel_arch_watchdog())
699 return;
700 break;
701 }
Don Zickusf2802e72006-09-26 10:52:26 +0200702 if (!setup_p4_watchdog())
703 return;
704 break;
705 default:
706 return;
707 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 }
Shaohua Li4038f902006-09-26 10:52:27 +0200709 wd->enabled = 1;
Don Zickusf2802e72006-09-26 10:52:26 +0200710 atomic_inc(&nmi_active);
711}
712
Shaohua Li4038f902006-09-26 10:52:27 +0200713void stop_apic_nmi_watchdog(void *unused)
Don Zickusf2802e72006-09-26 10:52:26 +0200714{
Shaohua Li4038f902006-09-26 10:52:27 +0200715 struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
716
Don Zickusf2802e72006-09-26 10:52:26 +0200717 /* only support LOCAL and IO APICs for now */
718 if ((nmi_watchdog != NMI_LOCAL_APIC) &&
719 (nmi_watchdog != NMI_IO_APIC))
720 return;
721
Shaohua Li4038f902006-09-26 10:52:27 +0200722 if (wd->enabled == 0)
723 return;
724
Don Zickusf2802e72006-09-26 10:52:26 +0200725 if (nmi_watchdog == NMI_LOCAL_APIC) {
726 switch (boot_cpu_data.x86_vendor) {
727 case X86_VENDOR_AMD:
728 if (strstr(boot_cpu_data.x86_model_id, "Screwdriver"))
729 return;
730 stop_k7_watchdog();
731 break;
732 case X86_VENDOR_INTEL:
Venkatesh Pallipadi248dcb22006-09-26 10:52:27 +0200733 if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) {
734 stop_intel_arch_watchdog();
735 break;
736 }
Don Zickusf2802e72006-09-26 10:52:26 +0200737 stop_p4_watchdog();
738 break;
739 default:
740 return;
741 }
742 }
Shaohua Li4038f902006-09-26 10:52:27 +0200743 wd->enabled = 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200744 atomic_dec(&nmi_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745}
746
747/*
748 * the best way to detect whether a CPU has a 'hard lockup' problem
749 * is to check it's local APIC timer IRQ counts. If they are not
750 * changing then that CPU has some problem.
751 *
752 * as these watchdog NMI IRQs are generated on every CPU, we only
753 * have to check the current processor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 */
755
Andi Kleen75152112005-05-16 21:53:34 -0700756static DEFINE_PER_CPU(unsigned, last_irq_sum);
757static DEFINE_PER_CPU(local_t, alert_counter);
758static DEFINE_PER_CPU(int, nmi_touch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760void touch_nmi_watchdog (void)
761{
Jan Beulich99019e92006-02-16 23:41:55 +0100762 if (nmi_watchdog > 0) {
763 unsigned cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Jan Beulich99019e92006-02-16 23:41:55 +0100765 /*
766 * Tell other CPUs to reset their alert counters. We cannot
767 * do it ourselves because the alert count increase is not
768 * atomic.
769 */
770 for_each_present_cpu (cpu)
771 per_cpu(nmi_touch, cpu) = 1;
772 }
Ingo Molnar8446f1d2005-09-06 15:16:27 -0700773
774 touch_softlockup_watchdog();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
776
Don Zickus3adbbcce2006-09-26 10:52:26 +0200777int __kprobes nmi_watchdog_tick(struct pt_regs * regs, unsigned reason)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778{
Andi Kleen75152112005-05-16 21:53:34 -0700779 int sum;
780 int touched = 0;
Don Zickusf2802e72006-09-26 10:52:26 +0200781 struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
782 u64 dummy;
Don Zickus3adbbcce2006-09-26 10:52:26 +0200783 int rc=0;
Don Zickusf2802e72006-09-26 10:52:26 +0200784
785 /* check for other users first */
786 if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT)
787 == NOTIFY_STOP) {
Don Zickus3adbbcce2006-09-26 10:52:26 +0200788 rc = 1;
Don Zickusf2802e72006-09-26 10:52:26 +0200789 touched = 1;
790 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 sum = read_pda(apic_timer_irqs);
Andi Kleen75152112005-05-16 21:53:34 -0700793 if (__get_cpu_var(nmi_touch)) {
794 __get_cpu_var(nmi_touch) = 0;
795 touched = 1;
796 }
Don Zickusf2802e72006-09-26 10:52:26 +0200797
Andi Kleen553f2652006-04-07 19:49:57 +0200798#ifdef CONFIG_X86_MCE
799 /* Could check oops_in_progress here too, but it's safer
800 not too */
801 if (atomic_read(&mce_entry) > 0)
802 touched = 1;
803#endif
Don Zickusf2802e72006-09-26 10:52:26 +0200804 /* if the apic timer isn't firing, this cpu isn't doing much */
Andi Kleen75152112005-05-16 21:53:34 -0700805 if (!touched && __get_cpu_var(last_irq_sum) == sum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 /*
807 * Ayiee, looks like this CPU is stuck ...
808 * wait a few IRQs (5 seconds) before doing the oops ...
809 */
Andi Kleen75152112005-05-16 21:53:34 -0700810 local_inc(&__get_cpu_var(alert_counter));
Don Zickusf2802e72006-09-26 10:52:26 +0200811 if (local_read(&__get_cpu_var(alert_counter)) == 5*nmi_hz)
Andi Kleenfac58552006-09-26 10:52:27 +0200812 die_nmi("NMI Watchdog detected LOCKUP on CPU %d\n", regs,
813 panic_on_timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 } else {
Andi Kleen75152112005-05-16 21:53:34 -0700815 __get_cpu_var(last_irq_sum) = sum;
816 local_set(&__get_cpu_var(alert_counter), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 }
Don Zickusf2802e72006-09-26 10:52:26 +0200818
819 /* see if the nmi watchdog went off */
820 if (wd->enabled) {
821 if (nmi_watchdog == NMI_LOCAL_APIC) {
822 rdmsrl(wd->perfctr_msr, dummy);
823 if (dummy & wd->check_bit){
824 /* this wasn't a watchdog timer interrupt */
825 goto done;
826 }
827
828 /* only Intel uses the cccr msr */
829 if (wd->cccr_msr != 0) {
830 /*
831 * P4 quirks:
832 * - An overflown perfctr will assert its interrupt
833 * until the OVF flag in its CCCR is cleared.
834 * - LVTPC is masked on interrupt and must be
835 * unmasked by the LVTPC handler.
836 */
837 rdmsrl(wd->cccr_msr, dummy);
838 dummy &= ~P4_CCCR_OVF;
839 wrmsrl(wd->cccr_msr, dummy);
840 apic_write(APIC_LVTPC, APIC_DM_NMI);
Venkatesh Pallipadi248dcb22006-09-26 10:52:27 +0200841 } else if (wd->perfctr_msr == MSR_ARCH_PERFMON_PERFCTR0) {
842 /*
843 * ArchPerfom/Core Duo needs to re-unmask
844 * the apic vector
845 */
846 apic_write(APIC_LVTPC, APIC_DM_NMI);
847 }
Don Zickusf2802e72006-09-26 10:52:26 +0200848 /* start the cycle over again */
849 wrmsrl(wd->perfctr_msr, -((u64)cpu_khz * 1000 / nmi_hz));
Don Zickus3adbbcce2006-09-26 10:52:26 +0200850 rc = 1;
851 } else if (nmi_watchdog == NMI_IO_APIC) {
852 /* don't know how to accurately check for this.
853 * just assume it was a watchdog timer interrupt
854 * This matches the old behaviour.
855 */
856 rc = 1;
857 } else
858 printk(KERN_WARNING "Unknown enabled NMI hardware?!\n");
Andi Kleen75152112005-05-16 21:53:34 -0700859 }
Don Zickusf2802e72006-09-26 10:52:26 +0200860done:
Don Zickus3adbbcce2006-09-26 10:52:26 +0200861 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862}
863
Andi Kleeneddb6fb2006-02-03 21:50:41 +0100864asmlinkage __kprobes void do_nmi(struct pt_regs * regs, long error_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 nmi_enter();
867 add_pda(__nmi_count,1);
Don Zickus3adbbcce2006-09-26 10:52:26 +0200868 default_do_nmi(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 nmi_exit();
870}
871
Don Zickus3adbbcce2006-09-26 10:52:26 +0200872int do_nmi_callback(struct pt_regs * regs, int cpu)
873{
Don Zickus2fbe7b22006-09-26 10:52:27 +0200874#ifdef CONFIG_SYSCTL
875 if (unknown_nmi_panic)
876 return unknown_nmi_panic_callback(regs, cpu);
877#endif
878 return 0;
Don Zickus3adbbcce2006-09-26 10:52:26 +0200879}
880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881#ifdef CONFIG_SYSCTL
882
883static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu)
884{
885 unsigned char reason = get_nmi_reason();
886 char buf[64];
887
Don Zickus2fbe7b22006-09-26 10:52:27 +0200888 sprintf(buf, "NMI received for unknown reason %02x\n", reason);
Andi Kleenfac58552006-09-26 10:52:27 +0200889 die_nmi(buf, regs, 1); /* Always panic here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 return 0;
891}
892
Don Zickus407984f2006-09-26 10:52:27 +0200893/*
894 * proc handler for /proc/sys/kernel/nmi
895 */
896int proc_nmi_enabled(struct ctl_table *table, int write, struct file *file,
897 void __user *buffer, size_t *length, loff_t *ppos)
898{
899 int old_state;
900
901 nmi_watchdog_enabled = (atomic_read(&nmi_active) > 0) ? 1 : 0;
902 old_state = nmi_watchdog_enabled;
903 proc_dointvec(table, write, file, buffer, length, ppos);
904 if (!!old_state == !!nmi_watchdog_enabled)
905 return 0;
906
907 if (atomic_read(&nmi_active) < 0) {
908 printk( KERN_WARNING "NMI watchdog is permanently disabled\n");
Don Zickuse33e89a2006-09-26 10:52:27 +0200909 return -EIO;
Don Zickus407984f2006-09-26 10:52:27 +0200910 }
911
912 /* if nmi_watchdog is not set yet, then set it */
913 nmi_watchdog_default();
914
Don Zickuse33e89a2006-09-26 10:52:27 +0200915 if (nmi_watchdog == NMI_LOCAL_APIC) {
Don Zickus407984f2006-09-26 10:52:27 +0200916 if (nmi_watchdog_enabled)
917 enable_lapic_nmi_watchdog();
918 else
919 disable_lapic_nmi_watchdog();
Don Zickus407984f2006-09-26 10:52:27 +0200920 } else {
Don Zickuse33e89a2006-09-26 10:52:27 +0200921 printk( KERN_WARNING
Don Zickus407984f2006-09-26 10:52:27 +0200922 "NMI watchdog doesn't know what hardware to touch\n");
923 return -EIO;
924 }
925 return 0;
926}
927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928#endif
929
930EXPORT_SYMBOL(nmi_active);
931EXPORT_SYMBOL(nmi_watchdog);
Don Zickus828f0af2006-09-26 10:52:26 +0200932EXPORT_SYMBOL(avail_to_resrv_perfctr_nmi);
933EXPORT_SYMBOL(avail_to_resrv_perfctr_nmi_bit);
934EXPORT_SYMBOL(reserve_perfctr_nmi);
935EXPORT_SYMBOL(release_perfctr_nmi);
936EXPORT_SYMBOL(reserve_evntsel_nmi);
937EXPORT_SYMBOL(release_evntsel_nmi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938EXPORT_SYMBOL(disable_timer_nmi_watchdog);
939EXPORT_SYMBOL(enable_timer_nmi_watchdog);
940EXPORT_SYMBOL(touch_nmi_watchdog);