blob: 3238ad32ffd8a1f2c7c75c53696a2fde8b65f321 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
2 * @file nmi_int.c
3 *
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
6 *
7 * @author John Levon <levon@movementarian.org>
8 */
9
10#include <linux/init.h>
11#include <linux/notifier.h>
12#include <linux/smp.h>
13#include <linux/oprofile.h>
14#include <linux/sysdev.h>
15#include <linux/slab.h>
Andi Kleen1cfcea12006-07-10 17:06:21 +020016#include <linux/moduleparam.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070017#include <linux/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/nmi.h>
19#include <asm/msr.h>
20#include <asm/apic.h>
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +010021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "op_counter.h"
23#include "op_x86_model.h"
Don Zickus2fbe7b22006-09-26 10:52:27 +020024
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +010025static struct op_x86_model_spec const *model;
Mike Travisd18d00f2008-03-25 15:06:59 -070026static DEFINE_PER_CPU(struct op_msrs, cpu_msrs);
27static DEFINE_PER_CPU(unsigned long, saved_lvtpc);
Don Zickus2fbe7b22006-09-26 10:52:27 +020028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static int nmi_start(void);
30static void nmi_stop(void);
31
32/* 0 == registered but off, 1 == registered and on */
33static int nmi_enabled = 0;
34
35#ifdef CONFIG_PM
36
Pavel Machek438510f2005-04-16 15:25:24 -070037static int nmi_suspend(struct sys_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
39 if (nmi_enabled == 1)
40 nmi_stop();
41 return 0;
42}
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static int nmi_resume(struct sys_device *dev)
45{
46 if (nmi_enabled == 1)
47 nmi_start();
48 return 0;
49}
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static struct sysdev_class oprofile_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +010052 .name = "oprofile",
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 .resume = nmi_resume,
54 .suspend = nmi_suspend,
55};
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057static struct sys_device device_oprofile = {
58 .id = 0,
59 .cls = &oprofile_sysclass,
60};
61
Robert P. J. Day405ae7d2007-02-17 19:13:42 +010062static int __init init_sysfs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 int error;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +010065
66 error = sysdev_class_register(&oprofile_sysclass);
67 if (!error)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 error = sysdev_register(&device_oprofile);
69 return error;
70}
71
Robert P. J. Day405ae7d2007-02-17 19:13:42 +010072static void exit_sysfs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74 sysdev_unregister(&device_oprofile);
75 sysdev_class_unregister(&oprofile_sysclass);
76}
77
78#else
Robert P. J. Day405ae7d2007-02-17 19:13:42 +010079#define init_sysfs() do { } while (0)
80#define exit_sysfs() do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#endif /* CONFIG_PM */
82
Adrian Bunkc7c19f82006-09-26 10:52:27 +020083static int profile_exceptions_notify(struct notifier_block *self,
84 unsigned long val, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Don Zickus2fbe7b22006-09-26 10:52:27 +020086 struct die_args *args = (struct die_args *)data;
87 int ret = NOTIFY_DONE;
88 int cpu = smp_processor_id();
89
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +010090 switch (val) {
Don Zickus2fbe7b22006-09-26 10:52:27 +020091 case DIE_NMI:
Mike Travisd18d00f2008-03-25 15:06:59 -070092 if (model->check_ctrs(args->regs, &per_cpu(cpu_msrs, cpu)))
Don Zickus2fbe7b22006-09-26 10:52:27 +020093 ret = NOTIFY_STOP;
94 break;
95 default:
96 break;
97 }
98 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
Don Zickus2fbe7b22006-09-26 10:52:27 +0200100
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100101static void nmi_cpu_save_registers(struct op_msrs *msrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
103 unsigned int const nr_ctrs = model->num_counters;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100104 unsigned int const nr_ctrls = model->num_controls;
105 struct op_msr *counters = msrs->counters;
106 struct op_msr *controls = msrs->controls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 unsigned int i;
108
109 for (i = 0; i < nr_ctrs; ++i) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100110 if (counters[i].addr) {
Don Zickuscb9c4482006-09-26 10:52:26 +0200111 rdmsr(counters[i].addr,
112 counters[i].saved.low,
113 counters[i].saved.high);
114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 }
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 for (i = 0; i < nr_ctrls; ++i) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100118 if (controls[i].addr) {
Don Zickuscb9c4482006-09-26 10:52:26 +0200119 rdmsr(controls[i].addr,
120 controls[i].saved.low,
121 controls[i].saved.high);
122 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
124}
125
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100126static void nmi_save_registers(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
128 int cpu = smp_processor_id();
Mike Travisd18d00f2008-03-25 15:06:59 -0700129 struct op_msrs *msrs = &per_cpu(cpu_msrs, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 nmi_cpu_save_registers(msrs);
131}
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133static void free_msrs(void)
134{
135 int i;
KAMEZAWA Hiroyukic89125992006-03-28 01:56:39 -0800136 for_each_possible_cpu(i) {
Mike Travisd18d00f2008-03-25 15:06:59 -0700137 kfree(per_cpu(cpu_msrs, i).counters);
138 per_cpu(cpu_msrs, i).counters = NULL;
139 kfree(per_cpu(cpu_msrs, i).controls);
140 per_cpu(cpu_msrs, i).controls = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142}
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144static int allocate_msrs(void)
145{
146 int success = 1;
147 size_t controls_size = sizeof(struct op_msr) * model->num_controls;
148 size_t counters_size = sizeof(struct op_msr) * model->num_counters;
149
150 int i;
Chris Wright0939c172007-06-01 00:46:39 -0700151 for_each_possible_cpu(i) {
Mike Travisd18d00f2008-03-25 15:06:59 -0700152 per_cpu(cpu_msrs, i).counters = kmalloc(counters_size,
153 GFP_KERNEL);
154 if (!per_cpu(cpu_msrs, i).counters) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 success = 0;
156 break;
157 }
Mike Travisd18d00f2008-03-25 15:06:59 -0700158 per_cpu(cpu_msrs, i).controls = kmalloc(controls_size,
159 GFP_KERNEL);
160 if (!per_cpu(cpu_msrs, i).controls) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 success = 0;
162 break;
163 }
164 }
165
166 if (!success)
167 free_msrs();
168
169 return success;
170}
171
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100172static void nmi_cpu_setup(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 int cpu = smp_processor_id();
Mike Travisd18d00f2008-03-25 15:06:59 -0700175 struct op_msrs *msrs = &per_cpu(cpu_msrs, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 spin_lock(&oprofilefs_lock);
177 model->setup_ctrs(msrs);
178 spin_unlock(&oprofilefs_lock);
Mike Travisd18d00f2008-03-25 15:06:59 -0700179 per_cpu(saved_lvtpc, cpu) = apic_read(APIC_LVTPC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 apic_write(APIC_LVTPC, APIC_DM_NMI);
181}
182
Don Zickus2fbe7b22006-09-26 10:52:27 +0200183static struct notifier_block profile_exceptions_nb = {
184 .notifier_call = profile_exceptions_notify,
185 .next = NULL,
186 .priority = 0
187};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189static int nmi_setup(void)
190{
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100191 int err = 0;
Andi Kleen6c977aa2007-05-21 14:31:45 +0200192 int cpu;
Don Zickus2fbe7b22006-09-26 10:52:27 +0200193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 if (!allocate_msrs())
195 return -ENOMEM;
196
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100197 err = register_die_notifier(&profile_exceptions_nb);
198 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 free_msrs();
Don Zickus2fbe7b22006-09-26 10:52:27 +0200200 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 }
Don Zickus2fbe7b22006-09-26 10:52:27 +0200202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 /* We need to serialize save and setup for HT because the subset
204 * of msrs are distinct for save and setup operations
205 */
Andi Kleen6c977aa2007-05-21 14:31:45 +0200206
207 /* Assume saved/restored counters are the same on all CPUs */
Mike Travisd18d00f2008-03-25 15:06:59 -0700208 model->fill_in_addresses(&per_cpu(cpu_msrs, 0));
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100209 for_each_possible_cpu(cpu) {
Chris Wright0939c172007-06-01 00:46:39 -0700210 if (cpu != 0) {
Mike Travisd18d00f2008-03-25 15:06:59 -0700211 memcpy(per_cpu(cpu_msrs, cpu).counters,
212 per_cpu(cpu_msrs, 0).counters,
Chris Wright0939c172007-06-01 00:46:39 -0700213 sizeof(struct op_msr) * model->num_counters);
214
Mike Travisd18d00f2008-03-25 15:06:59 -0700215 memcpy(per_cpu(cpu_msrs, cpu).controls,
216 per_cpu(cpu_msrs, 0).controls,
Chris Wright0939c172007-06-01 00:46:39 -0700217 sizeof(struct op_msr) * model->num_controls);
218 }
219
Andi Kleen6c977aa2007-05-21 14:31:45 +0200220 }
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200221 on_each_cpu(nmi_save_registers, NULL, 1);
222 on_each_cpu(nmi_cpu_setup, NULL, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 nmi_enabled = 1;
224 return 0;
225}
226
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100227static void nmi_restore_registers(struct op_msrs *msrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
229 unsigned int const nr_ctrs = model->num_counters;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100230 unsigned int const nr_ctrls = model->num_controls;
231 struct op_msr *counters = msrs->counters;
232 struct op_msr *controls = msrs->controls;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 unsigned int i;
234
235 for (i = 0; i < nr_ctrls; ++i) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100236 if (controls[i].addr) {
Don Zickuscb9c4482006-09-26 10:52:26 +0200237 wrmsr(controls[i].addr,
238 controls[i].saved.low,
239 controls[i].saved.high);
240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 for (i = 0; i < nr_ctrs; ++i) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100244 if (counters[i].addr) {
Don Zickuscb9c4482006-09-26 10:52:26 +0200245 wrmsr(counters[i].addr,
246 counters[i].saved.low,
247 counters[i].saved.high);
248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
250}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100252static void nmi_cpu_shutdown(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
254 unsigned int v;
255 int cpu = smp_processor_id();
Mike Travisd18d00f2008-03-25 15:06:59 -0700256 struct op_msrs *msrs = &__get_cpu_var(cpu_msrs);
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 /* restoring APIC_LVTPC can trigger an apic error because the delivery
259 * mode and vector nr combination can be illegal. That's by design: on
260 * power on apic lvt contain a zero vector nr which are legal only for
261 * NMI delivery mode. So inhibit apic err before restoring lvtpc
262 */
263 v = apic_read(APIC_LVTERR);
264 apic_write(APIC_LVTERR, v | APIC_LVT_MASKED);
Mike Travisd18d00f2008-03-25 15:06:59 -0700265 apic_write(APIC_LVTPC, per_cpu(saved_lvtpc, cpu));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 apic_write(APIC_LVTERR, v);
267 nmi_restore_registers(msrs);
268}
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270static void nmi_shutdown(void)
271{
Mike Travisd18d00f2008-03-25 15:06:59 -0700272 struct op_msrs *msrs = &__get_cpu_var(cpu_msrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 nmi_enabled = 0;
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200274 on_each_cpu(nmi_cpu_shutdown, NULL, 1);
Don Zickus2fbe7b22006-09-26 10:52:27 +0200275 unregister_die_notifier(&profile_exceptions_nb);
Mike Travisd18d00f2008-03-25 15:06:59 -0700276 model->shutdown(msrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 free_msrs();
278}
279
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100280static void nmi_cpu_start(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Mike Travisd18d00f2008-03-25 15:06:59 -0700282 struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 model->start(msrs);
284}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286static int nmi_start(void)
287{
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200288 on_each_cpu(nmi_cpu_start, NULL, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 return 0;
290}
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100291
292static void nmi_cpu_stop(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
Mike Travisd18d00f2008-03-25 15:06:59 -0700294 struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 model->stop(msrs);
296}
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298static void nmi_stop(void)
299{
Jens Axboe15c8b6c2008-05-09 09:39:44 +0200300 on_each_cpu(nmi_cpu_stop, NULL, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301}
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303struct op_counter_config counter_config[OP_MAX_COUNTER];
304
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100305static int nmi_create_files(struct super_block *sb, struct dentry *root)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
307 unsigned int i;
308
309 for (i = 0; i < model->num_counters; ++i) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100310 struct dentry *dir;
Markus Armbruster0c6856f2006-06-26 00:24:34 -0700311 char buf[4];
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100312
313 /* quick little hack to _not_ expose a counter if it is not
Don Zickuscb9c4482006-09-26 10:52:26 +0200314 * available for use. This should protect userspace app.
315 * NOTE: assumes 1:1 mapping here (that counters are organized
316 * sequentially in their struct assignment).
317 */
318 if (unlikely(!avail_to_resrv_perfctr_nmi_bit(i)))
319 continue;
320
Markus Armbruster0c6856f2006-06-26 00:24:34 -0700321 snprintf(buf, sizeof(buf), "%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 dir = oprofilefs_mkdir(sb, root, buf);
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100323 oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled);
324 oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event);
325 oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count);
326 oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask);
327 oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel);
328 oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 }
330
331 return 0;
332}
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100333
Andi Kleen1cfcea12006-07-10 17:06:21 +0200334static int p4force;
335module_param(p4force, int, 0);
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100336
337static int __init p4_init(char **cpu_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
339 __u8 cpu_model = boot_cpu_data.x86_model;
340
Andi Kleen1cfcea12006-07-10 17:06:21 +0200341 if (!p4force && (cpu_model > 6 || cpu_model == 5))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 return 0;
343
344#ifndef CONFIG_SMP
345 *cpu_type = "i386/p4";
346 model = &op_p4_spec;
347 return 1;
348#else
349 switch (smp_num_siblings) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100350 case 1:
351 *cpu_type = "i386/p4";
352 model = &op_p4_spec;
353 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100355 case 2:
356 *cpu_type = "i386/p4-ht";
357 model = &op_p4_ht2_spec;
358 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 }
360#endif
361
362 printk(KERN_INFO "oprofile: P4 HyperThreading detected with > 2 threads\n");
363 printk(KERN_INFO "oprofile: Reverting to timer mode.\n");
364 return 0;
365}
366
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100367static int __init ppro_init(char **cpu_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
369 __u8 cpu_model = boot_cpu_data.x86_model;
370
Benjamin LaHaise64471eb2006-05-15 09:44:24 -0700371 if (cpu_model == 14)
372 *cpu_type = "i386/core";
Arjan van de Vene107ebe2008-01-18 22:49:33 +0100373 else if (cpu_model == 15 || cpu_model == 23)
Benjamin LaHaisef04b92e2006-09-16 16:35:46 -0700374 *cpu_type = "i386/core_2";
Benjamin LaHaise64471eb2006-05-15 09:44:24 -0700375 else if (cpu_model > 0xd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return 0;
Benjamin LaHaise64471eb2006-05-15 09:44:24 -0700377 else if (cpu_model == 9) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 *cpu_type = "i386/p6_mobile";
379 } else if (cpu_model > 5) {
380 *cpu_type = "i386/piii";
381 } else if (cpu_model > 2) {
382 *cpu_type = "i386/pii";
383 } else {
384 *cpu_type = "i386/ppro";
385 }
386
387 model = &op_ppro_spec;
388 return 1;
389}
390
Robert P. J. Day405ae7d2007-02-17 19:13:42 +0100391/* in order to get sysfs right */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392static int using_nmi;
393
David Gibson96d08212005-09-06 15:17:26 -0700394int __init op_nmi_init(struct oprofile_operations *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396 __u8 vendor = boot_cpu_data.x86_vendor;
397 __u8 family = boot_cpu_data.x86;
398 char *cpu_type;
399
400 if (!cpu_has_apic)
401 return -ENODEV;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 switch (vendor) {
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100404 case X86_VENDOR_AMD:
405 /* Needs to be at least an Athlon (or hammer in 32bit mode) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100407 switch (family) {
408 default:
409 return -ENODEV;
410 case 6:
411 model = &op_athlon_spec;
412 cpu_type = "i386/athlon";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 break;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100414 case 0xf:
415 model = &op_athlon_spec;
416 /* Actually it could be i386/hammer too, but give
417 user space an consistent name. */
418 cpu_type = "x86-64/hammer";
419 break;
420 case 0x10:
421 model = &op_athlon_spec;
422 cpu_type = "x86-64/family10";
423 break;
424 }
425 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100427 case X86_VENDOR_INTEL:
428 switch (family) {
429 /* Pentium IV */
430 case 0xf:
431 if (!p4_init(&cpu_type))
432 return -ENODEV;
433 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100435 /* A P6-class processor */
436 case 6:
437 if (!ppro_init(&cpu_type))
438 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 break;
440
441 default:
442 return -ENODEV;
Carlos R. Mafrab75f53d2008-01-30 13:32:33 +0100443 }
444 break;
445
446 default:
447 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 }
449
Robert P. J. Day405ae7d2007-02-17 19:13:42 +0100450 init_sysfs();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 using_nmi = 1;
452 ops->create_files = nmi_create_files;
453 ops->setup = nmi_setup;
454 ops->shutdown = nmi_shutdown;
455 ops->start = nmi_start;
456 ops->stop = nmi_stop;
457 ops->cpu_type = cpu_type;
458 printk(KERN_INFO "oprofile: using NMI interrupt.\n");
459 return 0;
460}
461
David Gibson96d08212005-09-06 15:17:26 -0700462void op_nmi_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
464 if (using_nmi)
Robert P. J. Day405ae7d2007-02-17 19:13:42 +0100465 exit_sysfs();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466}