Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/i386/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 | * Mikael Pettersson : Pentium 4 support for local APIC NMI watchdog. |
| 12 | * Pavel Machek and |
| 13 | * Mikael Pettersson : PM converted to driver model. Disable/enable API. |
| 14 | */ |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/nmi.h> |
| 20 | #include <linux/sysdev.h> |
| 21 | #include <linux/sysctl.h> |
Don Zickus | 3e4ff11 | 2006-06-26 13:57:01 +0200 | [diff] [blame] | 22 | #include <linux/percpu.h> |
Andi Kleen | 1de8497 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 23 | #include <linux/dmi.h> |
Fernando Luis Vázquez Cao | 0603975 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 24 | #include <linux/kprobes.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include <asm/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/nmi.h> |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 28 | #include <asm/kdebug.h> |
Venkatesh Pallipadi | 248dcb2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 29 | #include <asm/intel_arch_perfmon.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #include "mach_traps.h" |
| 32 | |
Andi Kleen | 29cbc78 | 2006-09-30 01:47:55 +0200 | [diff] [blame] | 33 | int unknown_nmi_panic; |
| 34 | int nmi_watchdog_enabled; |
| 35 | |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 36 | /* perfctr_nmi_owner tracks the ownership of the perfctr registers: |
| 37 | * evtsel_nmi_owner tracks the ownership of the event selection |
| 38 | * - different performance counters/ event selection may be reserved for |
| 39 | * different subsystems this reservation system just tries to coordinate |
| 40 | * things a little |
| 41 | */ |
| 42 | static DEFINE_PER_CPU(unsigned long, perfctr_nmi_owner); |
| 43 | static DEFINE_PER_CPU(unsigned long, evntsel_nmi_owner[3]); |
| 44 | |
| 45 | /* this number is calculated from Intel's MSR_P4_CRU_ESCR5 register and it's |
| 46 | * offset from MSR_P4_BSU_ESCR0. It will be the max for all platforms (for now) |
| 47 | */ |
| 48 | #define NMI_MAX_COUNTER_BITS 66 |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /* nmi_active: |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 51 | * >0: the lapic NMI watchdog is active, but can be disabled |
| 52 | * <0: the lapic NMI watchdog has not been set up, and cannot |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | * be enabled |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 54 | * 0: the lapic NMI watchdog is disabled, but can be enabled |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | */ |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 56 | atomic_t nmi_active = ATOMIC_INIT(0); /* oprofile uses this */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 58 | unsigned int nmi_watchdog = NMI_DEFAULT; |
| 59 | static unsigned int nmi_hz = HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 61 | struct nmi_watchdog_ctlblk { |
| 62 | int enabled; |
| 63 | u64 check_bit; |
| 64 | unsigned int cccr_msr; |
| 65 | unsigned int perfctr_msr; /* the MSR to reset in NMI handler */ |
| 66 | unsigned int evntsel_msr; /* the MSR to select the events to handle */ |
| 67 | }; |
| 68 | static DEFINE_PER_CPU(struct nmi_watchdog_ctlblk, nmi_watchdog_ctlblk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 70 | /* local prototypes */ |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 71 | static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu); |
| 72 | |
| 73 | extern void show_registers(struct pt_regs *regs); |
| 74 | extern int unknown_nmi_panic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 76 | /* converts an msr to an appropriate reservation bit */ |
| 77 | static inline unsigned int nmi_perfctr_msr_to_bit(unsigned int msr) |
| 78 | { |
| 79 | /* returns the bit offset of the performance counter register */ |
| 80 | switch (boot_cpu_data.x86_vendor) { |
| 81 | case X86_VENDOR_AMD: |
| 82 | return (msr - MSR_K7_PERFCTR0); |
| 83 | case X86_VENDOR_INTEL: |
Venkatesh Pallipadi | 248dcb2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 84 | if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) |
| 85 | return (msr - MSR_ARCH_PERFMON_PERFCTR0); |
| 86 | |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 87 | switch (boot_cpu_data.x86) { |
| 88 | case 6: |
| 89 | return (msr - MSR_P6_PERFCTR0); |
| 90 | case 15: |
| 91 | return (msr - MSR_P4_BPU_PERFCTR0); |
| 92 | } |
| 93 | } |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | /* converts an msr to an appropriate reservation bit */ |
| 98 | static inline unsigned int nmi_evntsel_msr_to_bit(unsigned int msr) |
| 99 | { |
| 100 | /* returns the bit offset of the event selection register */ |
| 101 | switch (boot_cpu_data.x86_vendor) { |
| 102 | case X86_VENDOR_AMD: |
| 103 | return (msr - MSR_K7_EVNTSEL0); |
| 104 | case X86_VENDOR_INTEL: |
Venkatesh Pallipadi | 248dcb2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 105 | if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) |
| 106 | return (msr - MSR_ARCH_PERFMON_EVENTSEL0); |
| 107 | |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 108 | switch (boot_cpu_data.x86) { |
| 109 | case 6: |
| 110 | return (msr - MSR_P6_EVNTSEL0); |
| 111 | case 15: |
| 112 | return (msr - MSR_P4_BSU_ESCR0); |
| 113 | } |
| 114 | } |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | /* checks for a bit availability (hack for oprofile) */ |
| 119 | int avail_to_resrv_perfctr_nmi_bit(unsigned int counter) |
| 120 | { |
| 121 | BUG_ON(counter > NMI_MAX_COUNTER_BITS); |
| 122 | |
| 123 | return (!test_bit(counter, &__get_cpu_var(perfctr_nmi_owner))); |
| 124 | } |
| 125 | |
| 126 | /* checks the an msr for availability */ |
| 127 | int avail_to_resrv_perfctr_nmi(unsigned int msr) |
| 128 | { |
| 129 | unsigned int counter; |
| 130 | |
| 131 | counter = nmi_perfctr_msr_to_bit(msr); |
| 132 | BUG_ON(counter > NMI_MAX_COUNTER_BITS); |
| 133 | |
| 134 | return (!test_bit(counter, &__get_cpu_var(perfctr_nmi_owner))); |
| 135 | } |
| 136 | |
| 137 | int reserve_perfctr_nmi(unsigned int msr) |
| 138 | { |
| 139 | unsigned int counter; |
| 140 | |
| 141 | counter = nmi_perfctr_msr_to_bit(msr); |
| 142 | BUG_ON(counter > NMI_MAX_COUNTER_BITS); |
| 143 | |
| 144 | if (!test_and_set_bit(counter, &__get_cpu_var(perfctr_nmi_owner))) |
| 145 | return 1; |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | void release_perfctr_nmi(unsigned int msr) |
| 150 | { |
| 151 | unsigned int counter; |
| 152 | |
| 153 | counter = nmi_perfctr_msr_to_bit(msr); |
| 154 | BUG_ON(counter > NMI_MAX_COUNTER_BITS); |
| 155 | |
| 156 | clear_bit(counter, &__get_cpu_var(perfctr_nmi_owner)); |
| 157 | } |
| 158 | |
| 159 | int reserve_evntsel_nmi(unsigned int msr) |
| 160 | { |
| 161 | unsigned int counter; |
| 162 | |
| 163 | counter = nmi_evntsel_msr_to_bit(msr); |
| 164 | BUG_ON(counter > NMI_MAX_COUNTER_BITS); |
| 165 | |
| 166 | if (!test_and_set_bit(counter, &__get_cpu_var(evntsel_nmi_owner)[0])) |
| 167 | return 1; |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | void release_evntsel_nmi(unsigned int msr) |
| 172 | { |
| 173 | unsigned int counter; |
| 174 | |
| 175 | counter = nmi_evntsel_msr_to_bit(msr); |
| 176 | BUG_ON(counter > NMI_MAX_COUNTER_BITS); |
| 177 | |
| 178 | clear_bit(counter, &__get_cpu_var(evntsel_nmi_owner)[0]); |
| 179 | } |
| 180 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 181 | static __cpuinit inline int nmi_known_cpu(void) |
| 182 | { |
| 183 | switch (boot_cpu_data.x86_vendor) { |
| 184 | case X86_VENDOR_AMD: |
| 185 | return ((boot_cpu_data.x86 == 15) || (boot_cpu_data.x86 == 6)); |
| 186 | case X86_VENDOR_INTEL: |
Venkatesh Pallipadi | 248dcb2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 187 | if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) |
| 188 | return 1; |
| 189 | else |
| 190 | return ((boot_cpu_data.x86 == 15) || (boot_cpu_data.x86 == 6)); |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 191 | } |
| 192 | return 0; |
| 193 | } |
| 194 | |
Eric W. Biederman | 29b7008 | 2005-10-30 14:59:40 -0800 | [diff] [blame] | 195 | #ifdef CONFIG_SMP |
| 196 | /* The performance counters used by NMI_LOCAL_APIC don't trigger when |
| 197 | * the CPU is idle. To make sure the NMI watchdog really ticks on all |
| 198 | * CPUs during the test make them busy. |
| 199 | */ |
| 200 | static __init void nmi_cpu_busy(void *data) |
| 201 | { |
| 202 | volatile int *endflag = data; |
Ingo Molnar | 366c7f5 | 2006-07-03 00:25:25 -0700 | [diff] [blame] | 203 | local_irq_enable_in_hardirq(); |
Eric W. Biederman | 29b7008 | 2005-10-30 14:59:40 -0800 | [diff] [blame] | 204 | /* Intentionally don't use cpu_relax here. This is |
| 205 | to make sure that the performance counter really ticks, |
| 206 | even if there is a simulator or similar that catches the |
| 207 | pause instruction. On a real HT machine this is fine because |
| 208 | all other CPUs are busy with "useless" delay loops and don't |
| 209 | care if they get somewhat less cycles. */ |
| 210 | while (*endflag == 0) |
| 211 | barrier(); |
| 212 | } |
| 213 | #endif |
| 214 | |
Jack F Vogel | 67701ae9 | 2005-05-01 08:58:48 -0700 | [diff] [blame] | 215 | static int __init check_nmi_watchdog(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
Eric W. Biederman | 29b7008 | 2005-10-30 14:59:40 -0800 | [diff] [blame] | 217 | volatile int endflag = 0; |
| 218 | unsigned int *prev_nmi_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | int cpu; |
| 220 | |
Andi Kleen | 1de8497 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 221 | /* Enable NMI watchdog for newer systems. |
Andi Kleen | a1bae67 | 2006-10-21 18:37:02 +0200 | [diff] [blame] | 222 | Probably safe on most older systems too, but let's be careful. |
| 223 | IBM ThinkPads use INT10 inside SMM and that allows early NMI inside SMM |
| 224 | which hangs the system. Disable watchdog for all thinkpads */ |
| 225 | if (nmi_watchdog == NMI_DEFAULT && dmi_get_year(DMI_BIOS_DATE) >= 2004 && |
| 226 | !dmi_name_in_vendors("ThinkPad")) |
Andi Kleen | 1de8497 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 227 | nmi_watchdog = NMI_LOCAL_APIC; |
| 228 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 229 | if ((nmi_watchdog == NMI_NONE) || (nmi_watchdog == NMI_DEFAULT)) |
| 230 | return 0; |
| 231 | |
| 232 | if (!atomic_read(&nmi_active)) |
Jack F Vogel | 67701ae9 | 2005-05-01 08:58:48 -0700 | [diff] [blame] | 233 | return 0; |
| 234 | |
Eric W. Biederman | 29b7008 | 2005-10-30 14:59:40 -0800 | [diff] [blame] | 235 | prev_nmi_count = kmalloc(NR_CPUS * sizeof(int), GFP_KERNEL); |
| 236 | if (!prev_nmi_count) |
| 237 | return -1; |
| 238 | |
Jack F Vogel | 67701ae9 | 2005-05-01 08:58:48 -0700 | [diff] [blame] | 239 | printk(KERN_INFO "Testing NMI watchdog ... "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Eric W. Biederman | 29b7008 | 2005-10-30 14:59:40 -0800 | [diff] [blame] | 241 | if (nmi_watchdog == NMI_LOCAL_APIC) |
| 242 | smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0); |
| 243 | |
KAMEZAWA Hiroyuki | c8912599 | 2006-03-28 01:56:39 -0800 | [diff] [blame] | 244 | for_each_possible_cpu(cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | prev_nmi_count[cpu] = per_cpu(irq_stat, cpu).__nmi_count; |
| 246 | local_irq_enable(); |
| 247 | mdelay((10*1000)/nmi_hz); // wait 10 ticks |
| 248 | |
KAMEZAWA Hiroyuki | c8912599 | 2006-03-28 01:56:39 -0800 | [diff] [blame] | 249 | for_each_possible_cpu(cpu) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | #ifdef CONFIG_SMP |
| 251 | /* Check cpu_callin_map here because that is set |
| 252 | after the timer is started. */ |
| 253 | if (!cpu_isset(cpu, cpu_callin_map)) |
| 254 | continue; |
| 255 | #endif |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 256 | if (!per_cpu(nmi_watchdog_ctlblk, cpu).enabled) |
| 257 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (nmi_count(cpu) - prev_nmi_count[cpu] <= 5) { |
Eric W. Biederman | 29b7008 | 2005-10-30 14:59:40 -0800 | [diff] [blame] | 259 | printk("CPU#%d: NMI appears to be stuck (%d->%d)!\n", |
| 260 | cpu, |
| 261 | prev_nmi_count[cpu], |
| 262 | nmi_count(cpu)); |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 263 | per_cpu(nmi_watchdog_ctlblk, cpu).enabled = 0; |
| 264 | atomic_dec(&nmi_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 267 | if (!atomic_read(&nmi_active)) { |
| 268 | kfree(prev_nmi_count); |
| 269 | atomic_set(&nmi_active, -1); |
| 270 | return -1; |
| 271 | } |
Eric W. Biederman | 29b7008 | 2005-10-30 14:59:40 -0800 | [diff] [blame] | 272 | endflag = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | printk("OK.\n"); |
| 274 | |
| 275 | /* now that we know it works we can reduce NMI frequency to |
| 276 | something more reasonable; makes a difference in some configs */ |
Venkatesh Pallipadi | 248dcb2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 277 | if (nmi_watchdog == NMI_LOCAL_APIC) { |
| 278 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
| 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | nmi_hz = 1; |
Venkatesh Pallipadi | 248dcb2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 281 | /* |
| 282 | * On Intel CPUs with ARCH_PERFMON only 32 bits in the counter |
| 283 | * are writable, with higher bits sign extending from bit 31. |
| 284 | * So, we can only program the counter with 31 bit values and |
| 285 | * 32nd bit should be 1, for 33.. to be 1. |
| 286 | * Find the appropriate nmi_hz |
| 287 | */ |
| 288 | if (wd->perfctr_msr == MSR_ARCH_PERFMON_PERFCTR0 && |
| 289 | ((u64)cpu_khz * 1000) > 0x7fffffffULL) { |
| 290 | u64 count = (u64)cpu_khz * 1000; |
| 291 | do_div(count, 0x7fffffffUL); |
| 292 | nmi_hz = count + 1; |
| 293 | } |
| 294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
Eric W. Biederman | 29b7008 | 2005-10-30 14:59:40 -0800 | [diff] [blame] | 296 | kfree(prev_nmi_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | return 0; |
| 298 | } |
Jack F Vogel | 67701ae9 | 2005-05-01 08:58:48 -0700 | [diff] [blame] | 299 | /* This needs to happen later in boot so counters are working */ |
| 300 | late_initcall(check_nmi_watchdog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | static int __init setup_nmi_watchdog(char *str) |
| 303 | { |
| 304 | int nmi; |
| 305 | |
| 306 | get_option(&str, &nmi); |
| 307 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 308 | if ((nmi >= NMI_INVALID) || (nmi < NMI_NONE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | /* |
| 311 | * If any other x86 CPU has a local APIC, then |
| 312 | * please test the NMI stuff there and send me the |
| 313 | * missing bits. Right now Intel P6/P4 and AMD K7 only. |
| 314 | */ |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 315 | if ((nmi == NMI_LOCAL_APIC) && (nmi_known_cpu() == 0)) |
| 316 | return 0; /* no lapic support */ |
| 317 | nmi_watchdog = nmi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | return 1; |
| 319 | } |
| 320 | |
| 321 | __setup("nmi_watchdog=", setup_nmi_watchdog); |
| 322 | |
| 323 | static void disable_lapic_nmi_watchdog(void) |
| 324 | { |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 325 | BUG_ON(nmi_watchdog != NMI_LOCAL_APIC); |
| 326 | |
| 327 | if (atomic_read(&nmi_active) <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 330 | on_each_cpu(stop_apic_nmi_watchdog, NULL, 0, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 332 | BUG_ON(atomic_read(&nmi_active) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | static void enable_lapic_nmi_watchdog(void) |
| 336 | { |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 337 | BUG_ON(nmi_watchdog != NMI_LOCAL_APIC); |
| 338 | |
| 339 | /* are we already enabled */ |
| 340 | if (atomic_read(&nmi_active) != 0) |
| 341 | return; |
| 342 | |
| 343 | /* are we lapic aware */ |
| 344 | if (nmi_known_cpu() <= 0) |
| 345 | return; |
| 346 | |
| 347 | on_each_cpu(setup_apic_nmi_watchdog, NULL, 0, 1); |
| 348 | touch_nmi_watchdog(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | void disable_timer_nmi_watchdog(void) |
| 352 | { |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 353 | BUG_ON(nmi_watchdog != NMI_IO_APIC); |
| 354 | |
| 355 | if (atomic_read(&nmi_active) <= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | return; |
| 357 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 358 | disable_irq(0); |
| 359 | on_each_cpu(stop_apic_nmi_watchdog, NULL, 0, 1); |
| 360 | |
| 361 | BUG_ON(atomic_read(&nmi_active) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | void enable_timer_nmi_watchdog(void) |
| 365 | { |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 366 | BUG_ON(nmi_watchdog != NMI_IO_APIC); |
| 367 | |
| 368 | if (atomic_read(&nmi_active) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | touch_nmi_watchdog(); |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 370 | on_each_cpu(setup_apic_nmi_watchdog, NULL, 0, 1); |
| 371 | enable_irq(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
| 375 | #ifdef CONFIG_PM |
| 376 | |
| 377 | static int nmi_pm_active; /* nmi_active before suspend */ |
| 378 | |
Pavel Machek | 438510f | 2005-04-16 15:25:24 -0700 | [diff] [blame] | 379 | static int lapic_nmi_suspend(struct sys_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
Shaohua Li | 4038f90 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 381 | /* only CPU0 goes here, other CPUs should be offline */ |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 382 | nmi_pm_active = atomic_read(&nmi_active); |
Shaohua Li | 4038f90 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 383 | stop_apic_nmi_watchdog(NULL); |
| 384 | BUG_ON(atomic_read(&nmi_active) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | static int lapic_nmi_resume(struct sys_device *dev) |
| 389 | { |
Shaohua Li | 4038f90 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 390 | /* only CPU0 goes here, other CPUs should be offline */ |
| 391 | if (nmi_pm_active > 0) { |
| 392 | setup_apic_nmi_watchdog(NULL); |
| 393 | touch_nmi_watchdog(); |
| 394 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | |
| 399 | static struct sysdev_class nmi_sysclass = { |
| 400 | set_kset_name("lapic_nmi"), |
| 401 | .resume = lapic_nmi_resume, |
| 402 | .suspend = lapic_nmi_suspend, |
| 403 | }; |
| 404 | |
| 405 | static struct sys_device device_lapic_nmi = { |
| 406 | .id = 0, |
| 407 | .cls = &nmi_sysclass, |
| 408 | }; |
| 409 | |
| 410 | static int __init init_lapic_nmi_sysfs(void) |
| 411 | { |
| 412 | int error; |
| 413 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 414 | /* should really be a BUG_ON but b/c this is an |
| 415 | * init call, it just doesn't work. -dcz |
| 416 | */ |
| 417 | if (nmi_watchdog != NMI_LOCAL_APIC) |
| 418 | return 0; |
| 419 | |
| 420 | if ( atomic_read(&nmi_active) < 0 ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | return 0; |
| 422 | |
| 423 | error = sysdev_class_register(&nmi_sysclass); |
| 424 | if (!error) |
| 425 | error = sysdev_register(&device_lapic_nmi); |
| 426 | return error; |
| 427 | } |
| 428 | /* must come after the local APIC's device_initcall() */ |
| 429 | late_initcall(init_lapic_nmi_sysfs); |
| 430 | |
| 431 | #endif /* CONFIG_PM */ |
| 432 | |
| 433 | /* |
| 434 | * Activate the NMI watchdog via the local APIC. |
| 435 | * Original code written by Keith Owens. |
| 436 | */ |
| 437 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 438 | static void write_watchdog_counter(unsigned int perfctr_msr, const char *descr) |
Jan Beulich | 7fbb4f6 | 2005-06-23 00:08:23 -0700 | [diff] [blame] | 439 | { |
| 440 | u64 count = (u64)cpu_khz * 1000; |
| 441 | |
| 442 | do_div(count, nmi_hz); |
| 443 | if(descr) |
| 444 | Dprintk("setting %s to -0x%08Lx\n", descr, count); |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 445 | wrmsrl(perfctr_msr, 0 - count); |
Jan Beulich | 7fbb4f6 | 2005-06-23 00:08:23 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 448 | /* Note that these events don't tick when the CPU idles. This means |
| 449 | the frequency varies with CPU load. */ |
| 450 | |
| 451 | #define K7_EVNTSEL_ENABLE (1 << 22) |
| 452 | #define K7_EVNTSEL_INT (1 << 20) |
| 453 | #define K7_EVNTSEL_OS (1 << 17) |
| 454 | #define K7_EVNTSEL_USR (1 << 16) |
| 455 | #define K7_EVENT_CYCLES_PROCESSOR_IS_RUNNING 0x76 |
| 456 | #define K7_NMI_EVENT K7_EVENT_CYCLES_PROCESSOR_IS_RUNNING |
| 457 | |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 458 | static int setup_k7_watchdog(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | { |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 460 | unsigned int perfctr_msr, evntsel_msr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | unsigned int evntsel; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 462 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 464 | perfctr_msr = MSR_K7_PERFCTR0; |
| 465 | evntsel_msr = MSR_K7_EVNTSEL0; |
| 466 | if (!reserve_perfctr_nmi(perfctr_msr)) |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 467 | goto fail; |
| 468 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 469 | if (!reserve_evntsel_nmi(evntsel_msr)) |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 470 | goto fail1; |
| 471 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 472 | wrmsrl(perfctr_msr, 0UL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | evntsel = K7_EVNTSEL_INT |
| 475 | | K7_EVNTSEL_OS |
| 476 | | K7_EVNTSEL_USR |
| 477 | | K7_NMI_EVENT; |
| 478 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 479 | /* setup the timer */ |
| 480 | wrmsr(evntsel_msr, evntsel, 0); |
| 481 | write_watchdog_counter(perfctr_msr, "K7_PERFCTR0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | apic_write(APIC_LVTPC, APIC_DM_NMI); |
| 483 | evntsel |= K7_EVNTSEL_ENABLE; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 484 | wrmsr(evntsel_msr, evntsel, 0); |
| 485 | |
| 486 | wd->perfctr_msr = perfctr_msr; |
| 487 | wd->evntsel_msr = evntsel_msr; |
| 488 | wd->cccr_msr = 0; //unused |
| 489 | wd->check_bit = 1ULL<<63; |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 490 | return 1; |
| 491 | fail1: |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 492 | release_perfctr_nmi(perfctr_msr); |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 493 | fail: |
| 494 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 497 | static void stop_k7_watchdog(void) |
| 498 | { |
| 499 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
| 500 | |
| 501 | wrmsr(wd->evntsel_msr, 0, 0); |
| 502 | |
| 503 | release_evntsel_nmi(wd->evntsel_msr); |
| 504 | release_perfctr_nmi(wd->perfctr_msr); |
| 505 | } |
| 506 | |
| 507 | #define P6_EVNTSEL0_ENABLE (1 << 22) |
| 508 | #define P6_EVNTSEL_INT (1 << 20) |
| 509 | #define P6_EVNTSEL_OS (1 << 17) |
| 510 | #define P6_EVNTSEL_USR (1 << 16) |
| 511 | #define P6_EVENT_CPU_CLOCKS_NOT_HALTED 0x79 |
| 512 | #define P6_NMI_EVENT P6_EVENT_CPU_CLOCKS_NOT_HALTED |
| 513 | |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 514 | static int setup_p6_watchdog(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | { |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 516 | unsigned int perfctr_msr, evntsel_msr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | unsigned int evntsel; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 518 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 520 | perfctr_msr = MSR_P6_PERFCTR0; |
| 521 | evntsel_msr = MSR_P6_EVNTSEL0; |
| 522 | if (!reserve_perfctr_nmi(perfctr_msr)) |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 523 | goto fail; |
| 524 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 525 | if (!reserve_evntsel_nmi(evntsel_msr)) |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 526 | goto fail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 528 | wrmsrl(perfctr_msr, 0UL); |
| 529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | evntsel = P6_EVNTSEL_INT |
| 531 | | P6_EVNTSEL_OS |
| 532 | | P6_EVNTSEL_USR |
| 533 | | P6_NMI_EVENT; |
| 534 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 535 | /* setup the timer */ |
| 536 | wrmsr(evntsel_msr, evntsel, 0); |
| 537 | write_watchdog_counter(perfctr_msr, "P6_PERFCTR0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | apic_write(APIC_LVTPC, APIC_DM_NMI); |
| 539 | evntsel |= P6_EVNTSEL0_ENABLE; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 540 | wrmsr(evntsel_msr, evntsel, 0); |
| 541 | |
| 542 | wd->perfctr_msr = perfctr_msr; |
| 543 | wd->evntsel_msr = evntsel_msr; |
| 544 | wd->cccr_msr = 0; //unused |
| 545 | wd->check_bit = 1ULL<<39; |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 546 | return 1; |
| 547 | fail1: |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 548 | release_perfctr_nmi(perfctr_msr); |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 549 | fail: |
| 550 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 553 | static void stop_p6_watchdog(void) |
| 554 | { |
| 555 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
| 556 | |
| 557 | wrmsr(wd->evntsel_msr, 0, 0); |
| 558 | |
| 559 | release_evntsel_nmi(wd->evntsel_msr); |
| 560 | release_perfctr_nmi(wd->perfctr_msr); |
| 561 | } |
| 562 | |
| 563 | /* Note that these events don't tick when the CPU idles. This means |
| 564 | the frequency varies with CPU load. */ |
| 565 | |
| 566 | #define MSR_P4_MISC_ENABLE_PERF_AVAIL (1<<7) |
| 567 | #define P4_ESCR_EVENT_SELECT(N) ((N)<<25) |
| 568 | #define P4_ESCR_OS (1<<3) |
| 569 | #define P4_ESCR_USR (1<<2) |
| 570 | #define P4_CCCR_OVF_PMI0 (1<<26) |
| 571 | #define P4_CCCR_OVF_PMI1 (1<<27) |
| 572 | #define P4_CCCR_THRESHOLD(N) ((N)<<20) |
| 573 | #define P4_CCCR_COMPLEMENT (1<<19) |
| 574 | #define P4_CCCR_COMPARE (1<<18) |
| 575 | #define P4_CCCR_REQUIRED (3<<16) |
| 576 | #define P4_CCCR_ESCR_SELECT(N) ((N)<<13) |
| 577 | #define P4_CCCR_ENABLE (1<<12) |
| 578 | #define P4_CCCR_OVF (1<<31) |
| 579 | /* Set up IQ_COUNTER0 to behave like a clock, by having IQ_CCCR0 filter |
| 580 | CRU_ESCR0 (with any non-null event selector) through a complemented |
| 581 | max threshold. [IA32-Vol3, Section 14.9.9] */ |
| 582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | static int setup_p4_watchdog(void) |
| 584 | { |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 585 | unsigned int perfctr_msr, evntsel_msr, cccr_msr; |
| 586 | unsigned int evntsel, cccr_val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | unsigned int misc_enable, dummy; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 588 | unsigned int ht_num; |
| 589 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 591 | rdmsr(MSR_IA32_MISC_ENABLE, misc_enable, dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | if (!(misc_enable & MSR_P4_MISC_ENABLE_PERF_AVAIL)) |
| 593 | return 0; |
| 594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | #ifdef CONFIG_SMP |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 596 | /* detect which hyperthread we are on */ |
| 597 | if (smp_num_siblings == 2) { |
| 598 | unsigned int ebx, apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 600 | ebx = cpuid_ebx(1); |
| 601 | apicid = (ebx >> 24) & 0xff; |
| 602 | ht_num = apicid & 1; |
| 603 | } else |
| 604 | #endif |
| 605 | ht_num = 0; |
| 606 | |
| 607 | /* performance counters are shared resources |
| 608 | * assign each hyperthread its own set |
| 609 | * (re-use the ESCR0 register, seems safe |
| 610 | * and keeps the cccr_val the same) |
| 611 | */ |
| 612 | if (!ht_num) { |
| 613 | /* logical cpu 0 */ |
| 614 | perfctr_msr = MSR_P4_IQ_PERFCTR0; |
| 615 | evntsel_msr = MSR_P4_CRU_ESCR0; |
| 616 | cccr_msr = MSR_P4_IQ_CCCR0; |
| 617 | cccr_val = P4_CCCR_OVF_PMI0 | P4_CCCR_ESCR_SELECT(4); |
| 618 | } else { |
| 619 | /* logical cpu 1 */ |
| 620 | perfctr_msr = MSR_P4_IQ_PERFCTR1; |
| 621 | evntsel_msr = MSR_P4_CRU_ESCR0; |
| 622 | cccr_msr = MSR_P4_IQ_CCCR1; |
| 623 | cccr_val = P4_CCCR_OVF_PMI1 | P4_CCCR_ESCR_SELECT(4); |
| 624 | } |
| 625 | |
| 626 | if (!reserve_perfctr_nmi(perfctr_msr)) |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 627 | goto fail; |
| 628 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 629 | if (!reserve_evntsel_nmi(evntsel_msr)) |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 630 | goto fail1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 632 | evntsel = P4_ESCR_EVENT_SELECT(0x3F) |
| 633 | | P4_ESCR_OS |
| 634 | | P4_ESCR_USR; |
| 635 | |
| 636 | cccr_val |= P4_CCCR_THRESHOLD(15) |
| 637 | | P4_CCCR_COMPLEMENT |
| 638 | | P4_CCCR_COMPARE |
| 639 | | P4_CCCR_REQUIRED; |
| 640 | |
| 641 | wrmsr(evntsel_msr, evntsel, 0); |
| 642 | wrmsr(cccr_msr, cccr_val, 0); |
| 643 | write_watchdog_counter(perfctr_msr, "P4_IQ_COUNTER0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | apic_write(APIC_LVTPC, APIC_DM_NMI); |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 645 | cccr_val |= P4_CCCR_ENABLE; |
| 646 | wrmsr(cccr_msr, cccr_val, 0); |
| 647 | wd->perfctr_msr = perfctr_msr; |
| 648 | wd->evntsel_msr = evntsel_msr; |
| 649 | wd->cccr_msr = cccr_msr; |
| 650 | wd->check_bit = 1ULL<<39; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | return 1; |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 652 | fail1: |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 653 | release_perfctr_nmi(perfctr_msr); |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 654 | fail: |
| 655 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 658 | static void stop_p4_watchdog(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | { |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 660 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 662 | wrmsr(wd->cccr_msr, 0, 0); |
| 663 | wrmsr(wd->evntsel_msr, 0, 0); |
| 664 | |
| 665 | release_evntsel_nmi(wd->evntsel_msr); |
| 666 | release_perfctr_nmi(wd->perfctr_msr); |
| 667 | } |
| 668 | |
Venkatesh Pallipadi | 248dcb2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 669 | #define ARCH_PERFMON_NMI_EVENT_SEL ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL |
| 670 | #define ARCH_PERFMON_NMI_EVENT_UMASK ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK |
| 671 | |
| 672 | static int setup_intel_arch_watchdog(void) |
| 673 | { |
| 674 | unsigned int ebx; |
| 675 | union cpuid10_eax eax; |
| 676 | unsigned int unused; |
| 677 | unsigned int perfctr_msr, evntsel_msr; |
| 678 | unsigned int evntsel; |
| 679 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
| 680 | |
| 681 | /* |
| 682 | * Check whether the Architectural PerfMon supports |
| 683 | * Unhalted Core Cycles Event or not. |
| 684 | * NOTE: Corresponding bit = 0 in ebx indicates event present. |
| 685 | */ |
| 686 | cpuid(10, &(eax.full), &ebx, &unused, &unused); |
| 687 | if ((eax.split.mask_length < (ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX+1)) || |
| 688 | (ebx & ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT)) |
| 689 | goto fail; |
| 690 | |
| 691 | perfctr_msr = MSR_ARCH_PERFMON_PERFCTR0; |
| 692 | evntsel_msr = MSR_ARCH_PERFMON_EVENTSEL0; |
| 693 | |
| 694 | if (!reserve_perfctr_nmi(perfctr_msr)) |
| 695 | goto fail; |
| 696 | |
| 697 | if (!reserve_evntsel_nmi(evntsel_msr)) |
| 698 | goto fail1; |
| 699 | |
| 700 | wrmsrl(perfctr_msr, 0UL); |
| 701 | |
| 702 | evntsel = ARCH_PERFMON_EVENTSEL_INT |
| 703 | | ARCH_PERFMON_EVENTSEL_OS |
| 704 | | ARCH_PERFMON_EVENTSEL_USR |
| 705 | | ARCH_PERFMON_NMI_EVENT_SEL |
| 706 | | ARCH_PERFMON_NMI_EVENT_UMASK; |
| 707 | |
| 708 | /* setup the timer */ |
| 709 | wrmsr(evntsel_msr, evntsel, 0); |
| 710 | write_watchdog_counter(perfctr_msr, "INTEL_ARCH_PERFCTR0"); |
| 711 | apic_write(APIC_LVTPC, APIC_DM_NMI); |
| 712 | evntsel |= ARCH_PERFMON_EVENTSEL0_ENABLE; |
| 713 | wrmsr(evntsel_msr, evntsel, 0); |
| 714 | |
| 715 | wd->perfctr_msr = perfctr_msr; |
| 716 | wd->evntsel_msr = evntsel_msr; |
| 717 | wd->cccr_msr = 0; //unused |
| 718 | wd->check_bit = 1ULL << (eax.split.bit_width - 1); |
| 719 | return 1; |
| 720 | fail1: |
| 721 | release_perfctr_nmi(perfctr_msr); |
| 722 | fail: |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | static void stop_intel_arch_watchdog(void) |
| 727 | { |
| 728 | unsigned int ebx; |
| 729 | union cpuid10_eax eax; |
| 730 | unsigned int unused; |
| 731 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
| 732 | |
| 733 | /* |
| 734 | * Check whether the Architectural PerfMon supports |
| 735 | * Unhalted Core Cycles Event or not. |
| 736 | * NOTE: Corresponding bit = 0 in ebx indicates event present. |
| 737 | */ |
| 738 | cpuid(10, &(eax.full), &ebx, &unused, &unused); |
| 739 | if ((eax.split.mask_length < (ARCH_PERFMON_UNHALTED_CORE_CYCLES_INDEX+1)) || |
| 740 | (ebx & ARCH_PERFMON_UNHALTED_CORE_CYCLES_PRESENT)) |
| 741 | return; |
| 742 | |
| 743 | wrmsr(wd->evntsel_msr, 0, 0); |
| 744 | release_evntsel_nmi(wd->evntsel_msr); |
| 745 | release_perfctr_nmi(wd->perfctr_msr); |
| 746 | } |
| 747 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 748 | void setup_apic_nmi_watchdog (void *unused) |
| 749 | { |
Shaohua Li | 4038f90 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 750 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
| 751 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 752 | /* only support LOCAL and IO APICs for now */ |
| 753 | if ((nmi_watchdog != NMI_LOCAL_APIC) && |
| 754 | (nmi_watchdog != NMI_IO_APIC)) |
| 755 | return; |
| 756 | |
Shaohua Li | 4038f90 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 757 | if (wd->enabled == 1) |
| 758 | return; |
| 759 | |
| 760 | /* cheap hack to support suspend/resume */ |
| 761 | /* if cpu0 is not active neither should the other cpus */ |
| 762 | if ((smp_processor_id() != 0) && (atomic_read(&nmi_active) <= 0)) |
| 763 | return; |
| 764 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 765 | if (nmi_watchdog == NMI_LOCAL_APIC) { |
| 766 | switch (boot_cpu_data.x86_vendor) { |
| 767 | case X86_VENDOR_AMD: |
| 768 | if (boot_cpu_data.x86 != 6 && boot_cpu_data.x86 != 15) |
| 769 | return; |
| 770 | if (!setup_k7_watchdog()) |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 771 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | break; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 773 | case X86_VENDOR_INTEL: |
Venkatesh Pallipadi | 248dcb2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 774 | if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) { |
| 775 | if (!setup_intel_arch_watchdog()) |
| 776 | return; |
| 777 | break; |
| 778 | } |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 779 | switch (boot_cpu_data.x86) { |
| 780 | case 6: |
| 781 | if (boot_cpu_data.x86_model > 0xd) |
| 782 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 784 | if (!setup_p6_watchdog()) |
| 785 | return; |
| 786 | break; |
| 787 | case 15: |
| 788 | if (boot_cpu_data.x86_model > 0x4) |
| 789 | return; |
| 790 | |
| 791 | if (!setup_p4_watchdog()) |
| 792 | return; |
| 793 | break; |
| 794 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | return; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 796 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | break; |
| 798 | default: |
| 799 | return; |
| 800 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | } |
Shaohua Li | 4038f90 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 802 | wd->enabled = 1; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 803 | atomic_inc(&nmi_active); |
| 804 | } |
| 805 | |
Shaohua Li | 4038f90 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 806 | void stop_apic_nmi_watchdog(void *unused) |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 807 | { |
Shaohua Li | 4038f90 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 808 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
| 809 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 810 | /* only support LOCAL and IO APICs for now */ |
| 811 | if ((nmi_watchdog != NMI_LOCAL_APIC) && |
| 812 | (nmi_watchdog != NMI_IO_APIC)) |
| 813 | return; |
| 814 | |
Shaohua Li | 4038f90 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 815 | if (wd->enabled == 0) |
| 816 | return; |
| 817 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 818 | if (nmi_watchdog == NMI_LOCAL_APIC) { |
| 819 | switch (boot_cpu_data.x86_vendor) { |
| 820 | case X86_VENDOR_AMD: |
| 821 | stop_k7_watchdog(); |
| 822 | break; |
| 823 | case X86_VENDOR_INTEL: |
Venkatesh Pallipadi | 248dcb2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 824 | if (cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) { |
| 825 | stop_intel_arch_watchdog(); |
| 826 | break; |
| 827 | } |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 828 | switch (boot_cpu_data.x86) { |
| 829 | case 6: |
| 830 | if (boot_cpu_data.x86_model > 0xd) |
| 831 | break; |
| 832 | stop_p6_watchdog(); |
| 833 | break; |
| 834 | case 15: |
| 835 | if (boot_cpu_data.x86_model > 0x4) |
| 836 | break; |
| 837 | stop_p4_watchdog(); |
| 838 | break; |
| 839 | } |
| 840 | break; |
| 841 | default: |
| 842 | return; |
| 843 | } |
| 844 | } |
Shaohua Li | 4038f90 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 845 | wd->enabled = 0; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 846 | atomic_dec(&nmi_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | /* |
| 850 | * the best way to detect whether a CPU has a 'hard lockup' problem |
| 851 | * is to check it's local APIC timer IRQ counts. If they are not |
| 852 | * changing then that CPU has some problem. |
| 853 | * |
| 854 | * as these watchdog NMI IRQs are generated on every CPU, we only |
| 855 | * have to check the current processor. |
| 856 | * |
| 857 | * since NMIs don't listen to _any_ locks, we have to be extremely |
| 858 | * careful not to rely on unsafe variables. The printk might lock |
| 859 | * up though, so we have to break up any console locks first ... |
| 860 | * [when there will be more tty-related locks, break them up |
| 861 | * here too!] |
| 862 | */ |
| 863 | |
| 864 | static unsigned int |
| 865 | last_irq_sums [NR_CPUS], |
| 866 | alert_counter [NR_CPUS]; |
| 867 | |
| 868 | void touch_nmi_watchdog (void) |
| 869 | { |
| 870 | int i; |
| 871 | |
| 872 | /* |
| 873 | * Just reset the alert counters, (other CPUs might be |
| 874 | * spinning on locks we hold): |
| 875 | */ |
KAMEZAWA Hiroyuki | c8912599 | 2006-03-28 01:56:39 -0800 | [diff] [blame] | 876 | for_each_possible_cpu(i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | alert_counter[i] = 0; |
Ingo Molnar | 8446f1d | 2005-09-06 15:16:27 -0700 | [diff] [blame] | 878 | |
| 879 | /* |
| 880 | * Tickle the softlockup detector too: |
| 881 | */ |
| 882 | touch_softlockup_watchdog(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | } |
Michal Schmidt | 1e86240 | 2006-07-30 03:03:29 -0700 | [diff] [blame] | 884 | EXPORT_SYMBOL(touch_nmi_watchdog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
| 886 | extern void die_nmi(struct pt_regs *, const char *msg); |
| 887 | |
Fernando Luis Vázquez Cao | 0603975 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 888 | __kprobes int nmi_watchdog_tick(struct pt_regs * regs, unsigned reason) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | { |
| 890 | |
| 891 | /* |
| 892 | * Since current_thread_info()-> is always on the stack, and we |
| 893 | * always switch the stack NMI-atomically, it's safe to use |
| 894 | * smp_processor_id(). |
| 895 | */ |
Jesper Juhl | b791cce | 2006-03-28 01:56:52 -0800 | [diff] [blame] | 896 | unsigned int sum; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 897 | int touched = 0; |
Jesper Juhl | b791cce | 2006-03-28 01:56:52 -0800 | [diff] [blame] | 898 | int cpu = smp_processor_id(); |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 899 | struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk); |
| 900 | u64 dummy; |
Don Zickus | 3adbbcc | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 901 | int rc=0; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 902 | |
| 903 | /* check for other users first */ |
| 904 | if (notify_die(DIE_NMI, "nmi", regs, reason, 2, SIGINT) |
| 905 | == NOTIFY_STOP) { |
Don Zickus | 3adbbcc | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 906 | rc = 1; |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 907 | touched = 1; |
| 908 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
| 910 | sum = per_cpu(irq_stat, cpu).apic_timer_irqs; |
| 911 | |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 912 | /* if the apic timer isn't firing, this cpu isn't doing much */ |
| 913 | if (!touched && last_irq_sums[cpu] == sum) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | /* |
| 915 | * Ayiee, looks like this CPU is stuck ... |
| 916 | * wait a few IRQs (5 seconds) before doing the oops ... |
| 917 | */ |
| 918 | alert_counter[cpu]++; |
| 919 | if (alert_counter[cpu] == 5*nmi_hz) |
George Anzinger | 748f2ed | 2005-09-03 15:56:48 -0700 | [diff] [blame] | 920 | /* |
| 921 | * die_nmi will return ONLY if NOTIFY_STOP happens.. |
| 922 | */ |
Ingo Molnar | 91368d7 | 2006-03-23 03:00:54 -0800 | [diff] [blame] | 923 | die_nmi(regs, "BUG: NMI Watchdog detected LOCKUP"); |
GOTO Masanori | b884e25 | 2006-03-07 21:55:29 -0800 | [diff] [blame] | 924 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | last_irq_sums[cpu] = sum; |
| 926 | alert_counter[cpu] = 0; |
| 927 | } |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 928 | /* see if the nmi watchdog went off */ |
| 929 | if (wd->enabled) { |
| 930 | if (nmi_watchdog == NMI_LOCAL_APIC) { |
| 931 | rdmsrl(wd->perfctr_msr, dummy); |
| 932 | if (dummy & wd->check_bit){ |
| 933 | /* this wasn't a watchdog timer interrupt */ |
| 934 | goto done; |
| 935 | } |
| 936 | |
| 937 | /* only Intel P4 uses the cccr msr */ |
| 938 | if (wd->cccr_msr != 0) { |
| 939 | /* |
| 940 | * P4 quirks: |
| 941 | * - An overflown perfctr will assert its interrupt |
| 942 | * until the OVF flag in its CCCR is cleared. |
| 943 | * - LVTPC is masked on interrupt and must be |
| 944 | * unmasked by the LVTPC handler. |
| 945 | */ |
| 946 | rdmsrl(wd->cccr_msr, dummy); |
| 947 | dummy &= ~P4_CCCR_OVF; |
| 948 | wrmsrl(wd->cccr_msr, dummy); |
| 949 | apic_write(APIC_LVTPC, APIC_DM_NMI); |
| 950 | } |
Venkatesh Pallipadi | 248dcb2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 951 | else if (wd->perfctr_msr == MSR_P6_PERFCTR0 || |
| 952 | wd->perfctr_msr == MSR_ARCH_PERFMON_PERFCTR0) { |
| 953 | /* P6 based Pentium M need to re-unmask |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 954 | * the apic vector but it doesn't hurt |
Venkatesh Pallipadi | 248dcb2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 955 | * other P6 variant. |
| 956 | * ArchPerfom/Core Duo also needs this */ |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 957 | apic_write(APIC_LVTPC, APIC_DM_NMI); |
| 958 | } |
| 959 | /* start the cycle over again */ |
| 960 | write_watchdog_counter(wd->perfctr_msr, NULL); |
Don Zickus | 3adbbcc | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 961 | rc = 1; |
| 962 | } else if (nmi_watchdog == NMI_IO_APIC) { |
| 963 | /* don't know how to accurately check for this. |
| 964 | * just assume it was a watchdog timer interrupt |
| 965 | * This matches the old behaviour. |
| 966 | */ |
| 967 | rc = 1; |
Fernando Luis Vázquez Cao | 0603975 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 968 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | } |
Don Zickus | b7471c6 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 970 | done: |
Don Zickus | 3adbbcc | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 971 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Don Zickus | 2fbe7b2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 974 | int do_nmi_callback(struct pt_regs * regs, int cpu) |
| 975 | { |
| 976 | #ifdef CONFIG_SYSCTL |
| 977 | if (unknown_nmi_panic) |
| 978 | return unknown_nmi_panic_callback(regs, cpu); |
| 979 | #endif |
| 980 | return 0; |
| 981 | } |
| 982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | #ifdef CONFIG_SYSCTL |
| 984 | |
| 985 | static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu) |
| 986 | { |
| 987 | unsigned char reason = get_nmi_reason(); |
| 988 | char buf[64]; |
| 989 | |
Don Zickus | 2fbe7b2 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 990 | sprintf(buf, "NMI received for unknown reason %02x\n", reason); |
| 991 | die_nmi(regs, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | return 0; |
| 993 | } |
| 994 | |
Don Zickus | 407984f | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 995 | /* |
Don Zickus | e33e89a | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 996 | * proc handler for /proc/sys/kernel/nmi |
Don Zickus | 407984f | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 997 | */ |
| 998 | int proc_nmi_enabled(struct ctl_table *table, int write, struct file *file, |
| 999 | void __user *buffer, size_t *length, loff_t *ppos) |
| 1000 | { |
| 1001 | int old_state; |
| 1002 | |
| 1003 | nmi_watchdog_enabled = (atomic_read(&nmi_active) > 0) ? 1 : 0; |
| 1004 | old_state = nmi_watchdog_enabled; |
| 1005 | proc_dointvec(table, write, file, buffer, length, ppos); |
| 1006 | if (!!old_state == !!nmi_watchdog_enabled) |
| 1007 | return 0; |
| 1008 | |
| 1009 | if (atomic_read(&nmi_active) < 0) { |
Don Zickus | e33e89a | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 1010 | printk( KERN_WARNING "NMI watchdog is permanently disabled\n"); |
| 1011 | return -EIO; |
Don Zickus | 407984f | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | if (nmi_watchdog == NMI_DEFAULT) { |
| 1015 | if (nmi_known_cpu() > 0) |
| 1016 | nmi_watchdog = NMI_LOCAL_APIC; |
| 1017 | else |
| 1018 | nmi_watchdog = NMI_IO_APIC; |
| 1019 | } |
| 1020 | |
Don Zickus | e33e89a | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 1021 | if (nmi_watchdog == NMI_LOCAL_APIC) { |
Don Zickus | 407984f | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 1022 | if (nmi_watchdog_enabled) |
| 1023 | enable_lapic_nmi_watchdog(); |
| 1024 | else |
| 1025 | disable_lapic_nmi_watchdog(); |
Don Zickus | 407984f | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 1026 | } else { |
| 1027 | printk( KERN_WARNING |
| 1028 | "NMI watchdog doesn't know what hardware to touch\n"); |
| 1029 | return -EIO; |
| 1030 | } |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | #endif |
| 1035 | |
| 1036 | EXPORT_SYMBOL(nmi_active); |
| 1037 | EXPORT_SYMBOL(nmi_watchdog); |
Don Zickus | 828f0af | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 1038 | EXPORT_SYMBOL(avail_to_resrv_perfctr_nmi); |
| 1039 | EXPORT_SYMBOL(avail_to_resrv_perfctr_nmi_bit); |
| 1040 | EXPORT_SYMBOL(reserve_perfctr_nmi); |
| 1041 | EXPORT_SYMBOL(release_perfctr_nmi); |
| 1042 | EXPORT_SYMBOL(reserve_evntsel_nmi); |
| 1043 | EXPORT_SYMBOL(release_evntsel_nmi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | EXPORT_SYMBOL(disable_timer_nmi_watchdog); |
| 1045 | EXPORT_SYMBOL(enable_timer_nmi_watchdog); |