aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDon Zickus <dzickus@redhat.com>2010-02-16 17:04:52 -0500
committerIngo Molnar <mingo@elte.hu>2010-02-17 02:16:02 -0500
commit6081b6cd9702967889de34fe5da1f96bb96d0ab8 (patch)
treec3d8999c09b21debe493dc60afef1ebc7d9cfa93
parentcf454aecb31741a0438ed1201b3dd153c7c7b19a (diff)
nmi_watchdog: support for oprofile
Re-arrange the code so that when someone disables nmi_watchdog with: echo 0 > /proc/sys/kernel/nmi_watchdog it releases the hardware reservation on the PMUs. This allows the oprofile module to grab those PMUs and do its thing. Otherwise oprofile fails to load because the hardware is reserved by the perf_events subsystem. Tested using: oprofile --vm-linux --start and watched it failed when nmi_watchdog is enabled and succeed when: oprofile --deinit && echo 0 > /proc/sys/kernel/nmi_watchdog is run. Note: this has the side quirk of having the nmi_watchdog latch onto the software events instead of hardware events if oprofile has already reserved the hardware first. User beware! :-) Signed-off-by: Don Zickus <dzickus@redhat.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: gorcunov@gmail.com Cc: aris@redhat.com Cc: eranian@google.com LKML-Reference: <1266357892-30504-1-git-send-email-dzickus@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--kernel/nmi_watchdog.c144
1 files changed, 82 insertions, 62 deletions
diff --git a/kernel/nmi_watchdog.c b/kernel/nmi_watchdog.c
index 4f23505d887d..633b230c2319 100644
--- a/kernel/nmi_watchdog.c
+++ b/kernel/nmi_watchdog.c
@@ -61,50 +61,6 @@ static int __init setup_nmi_watchdog(char *str)
61} 61}
62__setup("nmi_watchdog=", setup_nmi_watchdog); 62__setup("nmi_watchdog=", setup_nmi_watchdog);
63 63
64#ifdef CONFIG_SYSCTL
65/*
66 * proc handler for /proc/sys/kernel/nmi_watchdog
67 */
68int nmi_watchdog_enabled;
69
70int proc_nmi_enabled(struct ctl_table *table, int write,
71 void __user *buffer, size_t *length, loff_t *ppos)
72{
73 int cpu;
74
75 if (!write) {
76 struct perf_event *event;
77 for_each_online_cpu(cpu) {
78 event = per_cpu(nmi_watchdog_ev, cpu);
79 if (event->state > PERF_EVENT_STATE_OFF) {
80 nmi_watchdog_enabled = 1;
81 break;
82 }
83 }
84 proc_dointvec(table, write, buffer, length, ppos);
85 return 0;
86 }
87
88 if (per_cpu(nmi_watchdog_ev, smp_processor_id()) == NULL) {
89 nmi_watchdog_enabled = 0;
90 proc_dointvec(table, write, buffer, length, ppos);
91 printk("NMI watchdog failed configuration, can not be enabled\n");
92 return 0;
93 }
94
95 touch_all_nmi_watchdog();
96 proc_dointvec(table, write, buffer, length, ppos);
97 if (nmi_watchdog_enabled)
98 for_each_online_cpu(cpu)
99 perf_event_enable(per_cpu(nmi_watchdog_ev, cpu));
100 else
101 for_each_online_cpu(cpu)
102 perf_event_disable(per_cpu(nmi_watchdog_ev, cpu));
103 return 0;
104}
105
106#endif /* CONFIG_SYSCTL */
107
108struct perf_event_attr wd_attr = { 64struct perf_event_attr wd_attr = {
109 .type = PERF_TYPE_HARDWARE, 65 .type = PERF_TYPE_HARDWARE,
110 .config = PERF_COUNT_HW_CPU_CYCLES, 66 .config = PERF_COUNT_HW_CPU_CYCLES,
@@ -146,6 +102,85 @@ void wd_overflow(struct perf_event *event, int nmi,
146 return; 102 return;
147} 103}
148 104
105static int enable_nmi_watchdog(int cpu)
106{
107 struct perf_event *event;
108
109 event = per_cpu(nmi_watchdog_ev, cpu);
110 if (event && event->state > PERF_EVENT_STATE_OFF)
111 return 0;
112
113 if (event == NULL) {
114 /* Try to register using hardware perf events first */
115 wd_attr.sample_period = hw_nmi_get_sample_period();
116 event = perf_event_create_kernel_counter(&wd_attr, cpu, -1, wd_overflow);
117 if (IS_ERR(event)) {
118 wd_attr.type = PERF_TYPE_SOFTWARE;
119 event = perf_event_create_kernel_counter(&wd_attr, cpu, -1, wd_overflow);
120 if (IS_ERR(event)) {
121 printk(KERN_ERR "nmi watchdog failed to create perf event on %i: %p\n", cpu, event);
122 return -1;
123 }
124 }
125 per_cpu(nmi_watchdog_ev, cpu) = event;
126 }
127 perf_event_enable(per_cpu(nmi_watchdog_ev, cpu));
128 return 0;
129}
130
131static void disable_nmi_watchdog(int cpu)
132{
133 struct perf_event *event;
134
135 event = per_cpu(nmi_watchdog_ev, cpu);
136 if (event) {
137 perf_event_disable(per_cpu(nmi_watchdog_ev, cpu));
138 per_cpu(nmi_watchdog_ev, cpu) = NULL;
139 perf_event_release_kernel(event);
140 }
141}
142
143#ifdef CONFIG_SYSCTL
144/*
145 * proc handler for /proc/sys/kernel/nmi_watchdog
146 */
147int nmi_watchdog_enabled;
148
149int proc_nmi_enabled(struct ctl_table *table, int write,
150 void __user *buffer, size_t *length, loff_t *ppos)
151{
152 int cpu;
153
154 if (!write) {
155 struct perf_event *event;
156 for_each_online_cpu(cpu) {
157 event = per_cpu(nmi_watchdog_ev, cpu);
158 if (event && event->state > PERF_EVENT_STATE_OFF) {
159 nmi_watchdog_enabled = 1;
160 break;
161 }
162 }
163 proc_dointvec(table, write, buffer, length, ppos);
164 return 0;
165 }
166
167 touch_all_nmi_watchdog();
168 proc_dointvec(table, write, buffer, length, ppos);
169 if (nmi_watchdog_enabled) {
170 for_each_online_cpu(cpu)
171 if (enable_nmi_watchdog(cpu)) {
172 printk("NMI watchdog failed configuration, "
173 " can not be enabled\n");
174 }
175 } else {
176 for_each_online_cpu(cpu)
177 disable_nmi_watchdog(cpu);
178 }
179 return 0;
180}
181
182#endif /* CONFIG_SYSCTL */
183
149/* 184/*
150 * Create/destroy watchdog threads as CPUs come and go: 185 * Create/destroy watchdog threads as CPUs come and go:
151 */ 186 */
@@ -153,7 +188,6 @@ static int __cpuinit
153cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) 188cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
154{ 189{
155 int hotcpu = (unsigned long)hcpu; 190 int hotcpu = (unsigned long)hcpu;
156 struct perf_event *event;
157 191
158 switch (action) { 192 switch (action) {
159 case CPU_UP_PREPARE: 193 case CPU_UP_PREPARE:
@@ -162,29 +196,15 @@ cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
162 break; 196 break;
163 case CPU_ONLINE: 197 case CPU_ONLINE:
164 case CPU_ONLINE_FROZEN: 198 case CPU_ONLINE_FROZEN:
165 /* originally wanted the below chunk to be in CPU_UP_PREPARE, but caps is unpriv for non-CPU0 */ 199 if (enable_nmi_watchdog(hotcpu))
166 wd_attr.sample_period = hw_nmi_get_sample_period(); 200 return NOTIFY_BAD;
167 event = perf_event_create_kernel_counter(&wd_attr, hotcpu, -1, wd_overflow);
168 if (IS_ERR(event)) {
169 wd_attr.type = PERF_TYPE_SOFTWARE;
170 event = perf_event_create_kernel_counter(&wd_attr, hotcpu, -1, wd_overflow);
171 if (IS_ERR(event)) {
172 printk(KERN_ERR "nmi watchdog failed to create perf event on %i: %p\n", hotcpu, event);
173 return NOTIFY_BAD;
174 }
175 }
176 per_cpu(nmi_watchdog_ev, hotcpu) = event;
177 perf_event_enable(per_cpu(nmi_watchdog_ev, hotcpu));
178 break; 201 break;
179#ifdef CONFIG_HOTPLUG_CPU 202#ifdef CONFIG_HOTPLUG_CPU
180 case CPU_UP_CANCELED: 203 case CPU_UP_CANCELED:
181 case CPU_UP_CANCELED_FROZEN: 204 case CPU_UP_CANCELED_FROZEN:
182 perf_event_disable(per_cpu(nmi_watchdog_ev, hotcpu)); 205 disable_nmi_watchdog(hotcpu);
183 case CPU_DEAD: 206 case CPU_DEAD:
184 case CPU_DEAD_FROZEN: 207 case CPU_DEAD_FROZEN:
185 event = per_cpu(nmi_watchdog_ev, hotcpu);
186 per_cpu(nmi_watchdog_ev, hotcpu) = NULL;
187 perf_event_release_kernel(event);
188 break; 208 break;
189#endif /* CONFIG_HOTPLUG_CPU */ 209#endif /* CONFIG_HOTPLUG_CPU */
190 } 210 }