diff options
author | David S. Miller <davem@davemloft.net> | 2009-01-30 00:22:47 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-01-30 03:03:53 -0500 |
commit | e5553a6d04421eec326a629571d696e8e745a0e4 (patch) | |
tree | b6fe49a18135dbe27a464fb78828b2150c679689 /arch/sparc/kernel | |
parent | c3cf5e8cc56d272f828a66610bb78bbb727b2ce1 (diff) |
sparc64: Implement NMI watchdog on capable cpus.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc/kernel')
-rw-r--r-- | arch/sparc/kernel/Makefile | 1 | ||||
-rw-r--r-- | arch/sparc/kernel/irq_64.c | 68 | ||||
-rw-r--r-- | arch/sparc/kernel/nmi.c | 224 | ||||
-rw-r--r-- | arch/sparc/kernel/pcr.c | 17 |
4 files changed, 245 insertions, 65 deletions
diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile index cb182d9c2f2b..54742e58831c 100644 --- a/arch/sparc/kernel/Makefile +++ b/arch/sparc/kernel/Makefile | |||
@@ -53,6 +53,7 @@ obj-$(CONFIG_SPARC64) += hvapi.o | |||
53 | obj-$(CONFIG_SPARC64) += sstate.o | 53 | obj-$(CONFIG_SPARC64) += sstate.o |
54 | obj-$(CONFIG_SPARC64) += mdesc.o | 54 | obj-$(CONFIG_SPARC64) += mdesc.o |
55 | obj-$(CONFIG_SPARC64) += pcr.o | 55 | obj-$(CONFIG_SPARC64) += pcr.o |
56 | obj-$(CONFIG_SPARC64) += nmi.o | ||
56 | 57 | ||
57 | # sparc32 do not use GENERIC_HARDIRQS but uses the generic devres implementation | 58 | # sparc32 do not use GENERIC_HARDIRQS but uses the generic devres implementation |
58 | obj-$(CONFIG_SPARC32) += devres.o | 59 | obj-$(CONFIG_SPARC32) += devres.o |
diff --git a/arch/sparc/kernel/irq_64.c b/arch/sparc/kernel/irq_64.c index cab8e0286871..e289376198eb 100644 --- a/arch/sparc/kernel/irq_64.c +++ b/arch/sparc/kernel/irq_64.c | |||
@@ -196,6 +196,11 @@ int show_interrupts(struct seq_file *p, void *v) | |||
196 | seq_putc(p, '\n'); | 196 | seq_putc(p, '\n'); |
197 | skip: | 197 | skip: |
198 | spin_unlock_irqrestore(&irq_desc[i].lock, flags); | 198 | spin_unlock_irqrestore(&irq_desc[i].lock, flags); |
199 | } else if (i == NR_IRQS) { | ||
200 | seq_printf(p, "NMI: "); | ||
201 | for_each_online_cpu(j) | ||
202 | seq_printf(p, "%10u ", cpu_data(j).__nmi_count); | ||
203 | seq_printf(p, " Non-maskable interrupts\n"); | ||
199 | } | 204 | } |
200 | return 0; | 205 | return 0; |
201 | } | 206 | } |
@@ -778,69 +783,6 @@ void do_softirq(void) | |||
778 | local_irq_restore(flags); | 783 | local_irq_restore(flags); |
779 | } | 784 | } |
780 | 785 | ||
781 | static void unhandled_perf_irq(struct pt_regs *regs) | ||
782 | { | ||
783 | unsigned long pcr, pic; | ||
784 | |||
785 | read_pcr(pcr); | ||
786 | read_pic(pic); | ||
787 | |||
788 | write_pcr(0); | ||
789 | |||
790 | printk(KERN_EMERG "CPU %d: Got unexpected perf counter IRQ.\n", | ||
791 | smp_processor_id()); | ||
792 | printk(KERN_EMERG "CPU %d: PCR[%016lx] PIC[%016lx]\n", | ||
793 | smp_processor_id(), pcr, pic); | ||
794 | } | ||
795 | |||
796 | /* Almost a direct copy of the powerpc PMC code. */ | ||
797 | static DEFINE_SPINLOCK(perf_irq_lock); | ||
798 | static void *perf_irq_owner_caller; /* mostly for debugging */ | ||
799 | static void (*perf_irq)(struct pt_regs *regs) = unhandled_perf_irq; | ||
800 | |||
801 | /* Invoked from level 15 PIL handler in trap table. */ | ||
802 | void perfctr_irq(int irq, struct pt_regs *regs) | ||
803 | { | ||
804 | clear_softint(1 << irq); | ||
805 | perf_irq(regs); | ||
806 | } | ||
807 | |||
808 | int register_perfctr_intr(void (*handler)(struct pt_regs *)) | ||
809 | { | ||
810 | int ret; | ||
811 | |||
812 | if (!handler) | ||
813 | return -EINVAL; | ||
814 | |||
815 | spin_lock(&perf_irq_lock); | ||
816 | if (perf_irq != unhandled_perf_irq) { | ||
817 | printk(KERN_WARNING "register_perfctr_intr: " | ||
818 | "perf IRQ busy (reserved by caller %p)\n", | ||
819 | perf_irq_owner_caller); | ||
820 | ret = -EBUSY; | ||
821 | goto out; | ||
822 | } | ||
823 | |||
824 | perf_irq_owner_caller = __builtin_return_address(0); | ||
825 | perf_irq = handler; | ||
826 | |||
827 | ret = 0; | ||
828 | out: | ||
829 | spin_unlock(&perf_irq_lock); | ||
830 | |||
831 | return ret; | ||
832 | } | ||
833 | EXPORT_SYMBOL_GPL(register_perfctr_intr); | ||
834 | |||
835 | void release_perfctr_intr(void (*handler)(struct pt_regs *)) | ||
836 | { | ||
837 | spin_lock(&perf_irq_lock); | ||
838 | perf_irq_owner_caller = NULL; | ||
839 | perf_irq = unhandled_perf_irq; | ||
840 | spin_unlock(&perf_irq_lock); | ||
841 | } | ||
842 | EXPORT_SYMBOL_GPL(release_perfctr_intr); | ||
843 | |||
844 | #ifdef CONFIG_HOTPLUG_CPU | 786 | #ifdef CONFIG_HOTPLUG_CPU |
845 | void fixup_irqs(void) | 787 | void fixup_irqs(void) |
846 | { | 788 | { |
diff --git a/arch/sparc/kernel/nmi.c b/arch/sparc/kernel/nmi.c new file mode 100644 index 000000000000..ffc690093343 --- /dev/null +++ b/arch/sparc/kernel/nmi.c | |||
@@ -0,0 +1,224 @@ | |||
1 | /* Pseudo NMI support on sparc64 systems. | ||
2 | * | ||
3 | * Copyright (C) 2009 David S. Miller <davem@davemloft.net> | ||
4 | * | ||
5 | * The NMI watchdog support and infrastructure is based almost | ||
6 | * entirely upon the x86 NMI support code. | ||
7 | */ | ||
8 | #include <linux/kernel.h> | ||
9 | #include <linux/param.h> | ||
10 | #include <linux/init.h> | ||
11 | #include <linux/percpu.h> | ||
12 | #include <linux/nmi.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/kprobes.h> | ||
15 | #include <linux/kernel_stat.h> | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/kdebug.h> | ||
18 | #include <linux/delay.h> | ||
19 | #include <linux/smp.h> | ||
20 | |||
21 | #include <asm/ptrace.h> | ||
22 | #include <asm/local.h> | ||
23 | #include <asm/pcr.h> | ||
24 | |||
25 | /* We don't have a real NMI on sparc64, but we can fake one | ||
26 | * up using profiling counter overflow interrupts and interrupt | ||
27 | * levels. | ||
28 | * | ||
29 | * The profile overflow interrupts at level 15, so we use | ||
30 | * level 14 as our IRQ off level. | ||
31 | */ | ||
32 | |||
33 | static int nmi_watchdog_active; | ||
34 | static int panic_on_timeout; | ||
35 | |||
36 | int nmi_usable; | ||
37 | EXPORT_SYMBOL_GPL(nmi_usable); | ||
38 | |||
39 | static unsigned int nmi_hz = HZ; | ||
40 | |||
41 | static DEFINE_PER_CPU(unsigned int, last_irq_sum); | ||
42 | static DEFINE_PER_CPU(local_t, alert_counter); | ||
43 | static DEFINE_PER_CPU(int, nmi_touch); | ||
44 | |||
45 | void touch_nmi_watchdog(void) | ||
46 | { | ||
47 | if (nmi_watchdog_active) { | ||
48 | int cpu; | ||
49 | |||
50 | for_each_present_cpu(cpu) { | ||
51 | if (per_cpu(nmi_touch, cpu) != 1) | ||
52 | per_cpu(nmi_touch, cpu) = 1; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | touch_softlockup_watchdog(); | ||
57 | } | ||
58 | EXPORT_SYMBOL(touch_nmi_watchdog); | ||
59 | |||
60 | static void die_nmi(const char *str, struct pt_regs *regs, int do_panic) | ||
61 | { | ||
62 | if (notify_die(DIE_NMIWATCHDOG, str, regs, 0, | ||
63 | pt_regs_trap_type(regs), SIGINT) == NOTIFY_STOP) | ||
64 | return; | ||
65 | |||
66 | console_verbose(); | ||
67 | bust_spinlocks(1); | ||
68 | |||
69 | printk(KERN_EMERG "%s", str); | ||
70 | printk(" on CPU%d, ip %08lx, registers:\n", | ||
71 | smp_processor_id(), regs->tpc); | ||
72 | show_regs(regs); | ||
73 | |||
74 | bust_spinlocks(0); | ||
75 | |||
76 | if (do_panic || panic_on_oops) | ||
77 | panic("Non maskable interrupt"); | ||
78 | |||
79 | local_irq_enable(); | ||
80 | do_exit(SIGBUS); | ||
81 | } | ||
82 | |||
83 | notrace __kprobes void perfctr_irq(int irq, struct pt_regs *regs) | ||
84 | { | ||
85 | unsigned int sum, touched = 0; | ||
86 | int cpu = smp_processor_id(); | ||
87 | |||
88 | clear_softint(1 << irq); | ||
89 | pcr_ops->write(PCR_PIC_PRIV); | ||
90 | |||
91 | local_cpu_data().__nmi_count++; | ||
92 | |||
93 | if (notify_die(DIE_NMI, "nmi", regs, 0, | ||
94 | pt_regs_trap_type(regs), SIGINT) == NOTIFY_STOP) | ||
95 | touched = 1; | ||
96 | |||
97 | sum = kstat_cpu(cpu).irqs[0]; | ||
98 | if (__get_cpu_var(nmi_touch)) { | ||
99 | __get_cpu_var(nmi_touch) = 0; | ||
100 | touched = 1; | ||
101 | } | ||
102 | if (!touched && __get_cpu_var(last_irq_sum) == sum) { | ||
103 | local_inc(&__get_cpu_var(alert_counter)); | ||
104 | if (local_read(&__get_cpu_var(alert_counter)) == 5 * nmi_hz) | ||
105 | die_nmi("BUG: NMI Watchdog detected LOCKUP", | ||
106 | regs, panic_on_timeout); | ||
107 | } else { | ||
108 | __get_cpu_var(last_irq_sum) = sum; | ||
109 | local_set(&__get_cpu_var(alert_counter), 0); | ||
110 | } | ||
111 | if (nmi_usable) { | ||
112 | write_pic(picl_value(nmi_hz)); | ||
113 | pcr_ops->write(pcr_enable); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | static inline unsigned int get_nmi_count(int cpu) | ||
118 | { | ||
119 | return cpu_data(cpu).__nmi_count; | ||
120 | } | ||
121 | |||
122 | static int endflag __initdata; | ||
123 | |||
124 | static __init void nmi_cpu_busy(void *data) | ||
125 | { | ||
126 | local_irq_enable_in_hardirq(); | ||
127 | while (endflag == 0) | ||
128 | mb(); | ||
129 | } | ||
130 | |||
131 | static void report_broken_nmi(int cpu, int *prev_nmi_count) | ||
132 | { | ||
133 | printk(KERN_CONT "\n"); | ||
134 | |||
135 | printk(KERN_WARNING | ||
136 | "WARNING: CPU#%d: NMI appears to be stuck (%d->%d)!\n", | ||
137 | cpu, prev_nmi_count[cpu], get_nmi_count(cpu)); | ||
138 | |||
139 | printk(KERN_WARNING | ||
140 | "Please report this to bugzilla.kernel.org,\n"); | ||
141 | printk(KERN_WARNING | ||
142 | "and attach the output of the 'dmesg' command.\n"); | ||
143 | |||
144 | nmi_usable = 0; | ||
145 | } | ||
146 | |||
147 | static void stop_watchdog(void *unused) | ||
148 | { | ||
149 | pcr_ops->write(PCR_PIC_PRIV); | ||
150 | } | ||
151 | |||
152 | static int __init check_nmi_watchdog(void) | ||
153 | { | ||
154 | unsigned int *prev_nmi_count; | ||
155 | int cpu, err; | ||
156 | |||
157 | prev_nmi_count = kmalloc(nr_cpu_ids * sizeof(unsigned int), GFP_KERNEL); | ||
158 | if (!prev_nmi_count) { | ||
159 | err = -ENOMEM; | ||
160 | goto error; | ||
161 | } | ||
162 | |||
163 | printk(KERN_INFO "Testing NMI watchdog ... "); | ||
164 | |||
165 | smp_call_function(nmi_cpu_busy, (void *)&endflag, 0); | ||
166 | |||
167 | for_each_possible_cpu(cpu) | ||
168 | prev_nmi_count[cpu] = get_nmi_count(cpu); | ||
169 | local_irq_enable(); | ||
170 | mdelay((20 * 1000) / nmi_hz); /* wait 20 ticks */ | ||
171 | |||
172 | for_each_online_cpu(cpu) { | ||
173 | if (get_nmi_count(cpu) - prev_nmi_count[cpu] <= 5) | ||
174 | report_broken_nmi(cpu, prev_nmi_count); | ||
175 | } | ||
176 | endflag = 1; | ||
177 | if (!nmi_usable) { | ||
178 | kfree(prev_nmi_count); | ||
179 | err = -ENODEV; | ||
180 | goto error; | ||
181 | } | ||
182 | printk("OK.\n"); | ||
183 | |||
184 | nmi_hz = 1; | ||
185 | |||
186 | kfree(prev_nmi_count); | ||
187 | return 0; | ||
188 | error: | ||
189 | on_each_cpu(stop_watchdog, NULL, 1); | ||
190 | return err; | ||
191 | } | ||
192 | |||
193 | static void start_watchdog(void *unused) | ||
194 | { | ||
195 | pcr_ops->write(PCR_PIC_PRIV); | ||
196 | write_pic(picl_value(nmi_hz)); | ||
197 | |||
198 | pcr_ops->write(pcr_enable); | ||
199 | } | ||
200 | |||
201 | void nmi_adjust_hz(unsigned int new_hz) | ||
202 | { | ||
203 | nmi_hz = new_hz; | ||
204 | on_each_cpu(start_watchdog, NULL, 1); | ||
205 | } | ||
206 | EXPORT_SYMBOL_GPL(nmi_adjust_hz); | ||
207 | |||
208 | int __init nmi_init(void) | ||
209 | { | ||
210 | nmi_usable = 1; | ||
211 | |||
212 | on_each_cpu(start_watchdog, NULL, 1); | ||
213 | |||
214 | return check_nmi_watchdog(); | ||
215 | } | ||
216 | |||
217 | static int __init setup_nmi_watchdog(char *str) | ||
218 | { | ||
219 | if (!strncmp(str, "panic", 5)) | ||
220 | panic_on_timeout = 1; | ||
221 | |||
222 | return 0; | ||
223 | } | ||
224 | __setup("nmi_watchdog=", setup_nmi_watchdog); | ||
diff --git a/arch/sparc/kernel/pcr.c b/arch/sparc/kernel/pcr.c index c4f24703b165..92e0dda141a4 100644 --- a/arch/sparc/kernel/pcr.c +++ b/arch/sparc/kernel/pcr.c | |||
@@ -9,12 +9,22 @@ | |||
9 | 9 | ||
10 | #include <asm/pil.h> | 10 | #include <asm/pil.h> |
11 | #include <asm/pcr.h> | 11 | #include <asm/pcr.h> |
12 | #include <asm/nmi.h> | ||
12 | 13 | ||
13 | /* This code is shared between various users of the performance | 14 | /* This code is shared between various users of the performance |
14 | * counters. Users will be oprofile, pseudo-NMI watchdog, and the | 15 | * counters. Users will be oprofile, pseudo-NMI watchdog, and the |
15 | * perf_counter support layer. | 16 | * perf_counter support layer. |
16 | */ | 17 | */ |
17 | 18 | ||
19 | #define PCR_SUN4U_ENABLE (PCR_PIC_PRIV | PCR_STRACE | PCR_UTRACE) | ||
20 | #define PCR_N2_ENABLE (PCR_PIC_PRIV | PCR_STRACE | PCR_UTRACE | \ | ||
21 | PCR_N2_TOE_OV1 | \ | ||
22 | (2 << PCR_N2_SL1_SHIFT) | \ | ||
23 | (0xff << PCR_N2_MASK1_SHIFT)) | ||
24 | |||
25 | u64 pcr_enable; | ||
26 | unsigned int picl_shift; | ||
27 | |||
18 | /* Performance counter interrupts run unmasked at PIL level 15. | 28 | /* Performance counter interrupts run unmasked at PIL level 15. |
19 | * Therefore we can't do things like wakeups and other work | 29 | * Therefore we can't do things like wakeups and other work |
20 | * that expects IRQ disabling to be adhered to in locking etc. | 30 | * that expects IRQ disabling to be adhered to in locking etc. |
@@ -117,12 +127,15 @@ int __init pcr_arch_init(void) | |||
117 | switch (tlb_type) { | 127 | switch (tlb_type) { |
118 | case hypervisor: | 128 | case hypervisor: |
119 | pcr_ops = &n2_pcr_ops; | 129 | pcr_ops = &n2_pcr_ops; |
130 | pcr_enable = PCR_N2_ENABLE; | ||
131 | picl_shift = 2; | ||
120 | break; | 132 | break; |
121 | 133 | ||
122 | case spitfire: | ||
123 | case cheetah: | 134 | case cheetah: |
124 | case cheetah_plus: | 135 | case cheetah_plus: |
136 | case spitfire: | ||
125 | pcr_ops = &direct_pcr_ops; | 137 | pcr_ops = &direct_pcr_ops; |
138 | pcr_enable = PCR_SUN4U_ENABLE; | ||
126 | break; | 139 | break; |
127 | 140 | ||
128 | default: | 141 | default: |
@@ -130,7 +143,7 @@ int __init pcr_arch_init(void) | |||
130 | goto out_unregister; | 143 | goto out_unregister; |
131 | } | 144 | } |
132 | 145 | ||
133 | return 0; | 146 | return nmi_init(); |
134 | 147 | ||
135 | out_unregister: | 148 | out_unregister: |
136 | unregister_perf_hsvc(); | 149 | unregister_perf_hsvc(); |