nmi_int.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /**
  2. * @file nmi_int.c
  3. *
  4. * @remark Copyright 2002-2009 OProfile authors
  5. * @remark Read the file COPYING
  6. *
  7. * @author John Levon <levon@movementarian.org>
  8. * @author Robert Richter <robert.richter@amd.com>
  9. * @author Barry Kasindorf <barry.kasindorf@amd.com>
  10. * @author Jason Yeh <jason.yeh@amd.com>
  11. * @author Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
  12. */
  13. #include <linux/init.h>
  14. #include <linux/notifier.h>
  15. #include <linux/smp.h>
  16. #include <linux/oprofile.h>
  17. #include <linux/sysdev.h>
  18. #include <linux/slab.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kdebug.h>
  21. #include <linux/cpu.h>
  22. #include <asm/nmi.h>
  23. #include <asm/msr.h>
  24. #include <asm/apic.h>
  25. #include "op_counter.h"
  26. #include "op_x86_model.h"
  27. static struct op_x86_model_spec *model;
  28. static DEFINE_PER_CPU(struct op_msrs, cpu_msrs);
  29. static DEFINE_PER_CPU(unsigned long, saved_lvtpc);
  30. /* 0 == registered but off, 1 == registered and on */
  31. static int nmi_enabled = 0;
  32. struct op_counter_config counter_config[OP_MAX_COUNTER];
  33. /* common functions */
  34. u64 op_x86_get_ctrl(struct op_x86_model_spec const *model,
  35. struct op_counter_config *counter_config)
  36. {
  37. u64 val = 0;
  38. u16 event = (u16)counter_config->event;
  39. val |= ARCH_PERFMON_EVENTSEL_INT;
  40. val |= counter_config->user ? ARCH_PERFMON_EVENTSEL_USR : 0;
  41. val |= counter_config->kernel ? ARCH_PERFMON_EVENTSEL_OS : 0;
  42. val |= (counter_config->unit_mask & 0xFF) << 8;
  43. event &= model->event_mask ? model->event_mask : 0xFF;
  44. val |= event & 0xFF;
  45. val |= (event & 0x0F00) << 24;
  46. return val;
  47. }
  48. static int profile_exceptions_notify(struct notifier_block *self,
  49. unsigned long val, void *data)
  50. {
  51. struct die_args *args = (struct die_args *)data;
  52. int ret = NOTIFY_DONE;
  53. int cpu = smp_processor_id();
  54. switch (val) {
  55. case DIE_NMI:
  56. case DIE_NMI_IPI:
  57. model->check_ctrs(args->regs, &per_cpu(cpu_msrs, cpu));
  58. ret = NOTIFY_STOP;
  59. break;
  60. default:
  61. break;
  62. }
  63. return ret;
  64. }
  65. static void nmi_cpu_save_registers(struct op_msrs *msrs)
  66. {
  67. struct op_msr *counters = msrs->counters;
  68. struct op_msr *controls = msrs->controls;
  69. unsigned int i;
  70. for (i = 0; i < model->num_counters; ++i) {
  71. if (counters[i].addr)
  72. rdmsrl(counters[i].addr, counters[i].saved);
  73. }
  74. for (i = 0; i < model->num_controls; ++i) {
  75. if (controls[i].addr)
  76. rdmsrl(controls[i].addr, controls[i].saved);
  77. }
  78. }
  79. static void nmi_cpu_start(void *dummy)
  80. {
  81. struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs);
  82. model->start(msrs);
  83. }
  84. static int nmi_start(void)
  85. {
  86. on_each_cpu(nmi_cpu_start, NULL, 1);
  87. return 0;
  88. }
  89. static void nmi_cpu_stop(void *dummy)
  90. {
  91. struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs);
  92. model->stop(msrs);
  93. }
  94. static void nmi_stop(void)
  95. {
  96. on_each_cpu(nmi_cpu_stop, NULL, 1);
  97. }
  98. #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
  99. static DEFINE_PER_CPU(int, switch_index);
  100. static inline int has_mux(void)
  101. {
  102. return !!model->switch_ctrl;
  103. }
  104. inline int op_x86_phys_to_virt(int phys)
  105. {
  106. return __get_cpu_var(switch_index) + phys;
  107. }
  108. inline int op_x86_virt_to_phys(int virt)
  109. {
  110. return virt % model->num_counters;
  111. }
  112. static void nmi_shutdown_mux(void)
  113. {
  114. int i;
  115. if (!has_mux())
  116. return;
  117. for_each_possible_cpu(i) {
  118. kfree(per_cpu(cpu_msrs, i).multiplex);
  119. per_cpu(cpu_msrs, i).multiplex = NULL;
  120. per_cpu(switch_index, i) = 0;
  121. }
  122. }
  123. static int nmi_setup_mux(void)
  124. {
  125. size_t multiplex_size =
  126. sizeof(struct op_msr) * model->num_virt_counters;
  127. int i;
  128. if (!has_mux())
  129. return 1;
  130. for_each_possible_cpu(i) {
  131. per_cpu(cpu_msrs, i).multiplex =
  132. kmalloc(multiplex_size, GFP_KERNEL);
  133. if (!per_cpu(cpu_msrs, i).multiplex)
  134. return 0;
  135. }
  136. return 1;
  137. }
  138. static void nmi_cpu_setup_mux(int cpu, struct op_msrs const * const msrs)
  139. {
  140. int i;
  141. struct op_msr *multiplex = msrs->multiplex;
  142. if (!has_mux())
  143. return;
  144. for (i = 0; i < model->num_virt_counters; ++i) {
  145. if (counter_config[i].enabled) {
  146. multiplex[i].saved = -(u64)counter_config[i].count;
  147. } else {
  148. multiplex[i].addr = 0;
  149. multiplex[i].saved = 0;
  150. }
  151. }
  152. per_cpu(switch_index, cpu) = 0;
  153. }
  154. static void nmi_cpu_save_mpx_registers(struct op_msrs *msrs)
  155. {
  156. struct op_msr *multiplex = msrs->multiplex;
  157. int i;
  158. for (i = 0; i < model->num_counters; ++i) {
  159. int virt = op_x86_phys_to_virt(i);
  160. if (multiplex[virt].addr)
  161. rdmsrl(multiplex[virt].addr, multiplex[virt].saved);
  162. }
  163. }
  164. static void nmi_cpu_restore_mpx_registers(struct op_msrs *msrs)
  165. {
  166. struct op_msr *multiplex = msrs->multiplex;
  167. int i;
  168. for (i = 0; i < model->num_counters; ++i) {
  169. int virt = op_x86_phys_to_virt(i);
  170. if (multiplex[virt].addr)
  171. wrmsrl(multiplex[virt].addr, multiplex[virt].saved);
  172. }
  173. }
  174. static void nmi_cpu_switch(void *dummy)
  175. {
  176. int cpu = smp_processor_id();
  177. int si = per_cpu(switch_index, cpu);
  178. struct op_msrs *msrs = &per_cpu(cpu_msrs, cpu);
  179. nmi_cpu_stop(NULL);
  180. nmi_cpu_save_mpx_registers(msrs);
  181. /* move to next set */
  182. si += model->num_counters;
  183. if ((si > model->num_virt_counters) || (counter_config[si].count == 0))
  184. per_cpu(switch_index, cpu) = 0;
  185. else
  186. per_cpu(switch_index, cpu) = si;
  187. model->switch_ctrl(model, msrs);
  188. nmi_cpu_restore_mpx_registers(msrs);
  189. nmi_cpu_start(NULL);
  190. }
  191. /*
  192. * Quick check to see if multiplexing is necessary.
  193. * The check should be sufficient since counters are used
  194. * in ordre.
  195. */
  196. static int nmi_multiplex_on(void)
  197. {
  198. return counter_config[model->num_counters].count ? 0 : -EINVAL;
  199. }
  200. static int nmi_switch_event(void)
  201. {
  202. if (!has_mux())
  203. return -ENOSYS; /* not implemented */
  204. if (nmi_multiplex_on() < 0)
  205. return -EINVAL; /* not necessary */
  206. on_each_cpu(nmi_cpu_switch, NULL, 1);
  207. return 0;
  208. }
  209. static inline void mux_init(struct oprofile_operations *ops)
  210. {
  211. if (has_mux())
  212. ops->switch_events = nmi_switch_event;
  213. }
  214. static void mux_clone(int cpu)
  215. {
  216. if (!has_mux())
  217. return;
  218. memcpy(per_cpu(cpu_msrs, cpu).multiplex,
  219. per_cpu(cpu_msrs, 0).multiplex,
  220. sizeof(struct op_msr) * model->num_virt_counters);
  221. }
  222. #else
  223. inline int op_x86_phys_to_virt(int phys) { return phys; }
  224. inline int op_x86_virt_to_phys(int virt) { return virt; }
  225. static inline void nmi_shutdown_mux(void) { }
  226. static inline int nmi_setup_mux(void) { return 1; }
  227. static inline void
  228. nmi_cpu_setup_mux(int cpu, struct op_msrs const * const msrs) { }
  229. static inline void mux_init(struct oprofile_operations *ops) { }
  230. static void mux_clone(int cpu) { }
  231. #endif
  232. static void free_msrs(void)
  233. {
  234. int i;
  235. for_each_possible_cpu(i) {
  236. kfree(per_cpu(cpu_msrs, i).counters);
  237. per_cpu(cpu_msrs, i).counters = NULL;
  238. kfree(per_cpu(cpu_msrs, i).controls);
  239. per_cpu(cpu_msrs, i).controls = NULL;
  240. }
  241. }
  242. static int allocate_msrs(void)
  243. {
  244. size_t controls_size = sizeof(struct op_msr) * model->num_controls;
  245. size_t counters_size = sizeof(struct op_msr) * model->num_counters;
  246. int i;
  247. for_each_possible_cpu(i) {
  248. per_cpu(cpu_msrs, i).counters = kmalloc(counters_size,
  249. GFP_KERNEL);
  250. if (!per_cpu(cpu_msrs, i).counters)
  251. return 0;
  252. per_cpu(cpu_msrs, i).controls = kmalloc(controls_size,
  253. GFP_KERNEL);
  254. if (!per_cpu(cpu_msrs, i).controls)
  255. return 0;
  256. }
  257. return 1;
  258. }
  259. static void nmi_cpu_setup(void *dummy)
  260. {
  261. int cpu = smp_processor_id();
  262. struct op_msrs *msrs = &per_cpu(cpu_msrs, cpu);
  263. nmi_cpu_save_registers(msrs);
  264. spin_lock(&oprofilefs_lock);
  265. model->setup_ctrs(model, msrs);
  266. nmi_cpu_setup_mux(cpu, msrs);
  267. spin_unlock(&oprofilefs_lock);
  268. per_cpu(saved_lvtpc, cpu) = apic_read(APIC_LVTPC);
  269. apic_write(APIC_LVTPC, APIC_DM_NMI);
  270. }
  271. static struct notifier_block profile_exceptions_nb = {
  272. .notifier_call = profile_exceptions_notify,
  273. .next = NULL,
  274. .priority = 2
  275. };
  276. static int nmi_setup(void)
  277. {
  278. int err = 0;
  279. int cpu;
  280. if (!allocate_msrs())
  281. err = -ENOMEM;
  282. else if (!nmi_setup_mux())
  283. err = -ENOMEM;
  284. else
  285. err = register_die_notifier(&profile_exceptions_nb);
  286. if (err) {
  287. free_msrs();
  288. nmi_shutdown_mux();
  289. return err;
  290. }
  291. /* We need to serialize save and setup for HT because the subset
  292. * of msrs are distinct for save and setup operations
  293. */
  294. /* Assume saved/restored counters are the same on all CPUs */
  295. model->fill_in_addresses(&per_cpu(cpu_msrs, 0));
  296. for_each_possible_cpu(cpu) {
  297. if (!cpu)
  298. continue;
  299. memcpy(per_cpu(cpu_msrs, cpu).counters,
  300. per_cpu(cpu_msrs, 0).counters,
  301. sizeof(struct op_msr) * model->num_counters);
  302. memcpy(per_cpu(cpu_msrs, cpu).controls,
  303. per_cpu(cpu_msrs, 0).controls,
  304. sizeof(struct op_msr) * model->num_controls);
  305. mux_clone(cpu);
  306. }
  307. on_each_cpu(nmi_cpu_setup, NULL, 1);
  308. nmi_enabled = 1;
  309. return 0;
  310. }
  311. static void nmi_cpu_restore_registers(struct op_msrs *msrs)
  312. {
  313. struct op_msr *counters = msrs->counters;
  314. struct op_msr *controls = msrs->controls;
  315. unsigned int i;
  316. for (i = 0; i < model->num_controls; ++i) {
  317. if (controls[i].addr)
  318. wrmsrl(controls[i].addr, controls[i].saved);
  319. }
  320. for (i = 0; i < model->num_counters; ++i) {
  321. if (counters[i].addr)
  322. wrmsrl(counters[i].addr, counters[i].saved);
  323. }
  324. }
  325. static void nmi_cpu_shutdown(void *dummy)
  326. {
  327. unsigned int v;
  328. int cpu = smp_processor_id();
  329. struct op_msrs *msrs = &per_cpu(cpu_msrs, cpu);
  330. /* restoring APIC_LVTPC can trigger an apic error because the delivery
  331. * mode and vector nr combination can be illegal. That's by design: on
  332. * power on apic lvt contain a zero vector nr which are legal only for
  333. * NMI delivery mode. So inhibit apic err before restoring lvtpc
  334. */
  335. v = apic_read(APIC_LVTERR);
  336. apic_write(APIC_LVTERR, v | APIC_LVT_MASKED);
  337. apic_write(APIC_LVTPC, per_cpu(saved_lvtpc, cpu));
  338. apic_write(APIC_LVTERR, v);
  339. nmi_cpu_restore_registers(msrs);
  340. }
  341. static void nmi_shutdown(void)
  342. {
  343. struct op_msrs *msrs;
  344. nmi_enabled = 0;
  345. on_each_cpu(nmi_cpu_shutdown, NULL, 1);
  346. unregister_die_notifier(&profile_exceptions_nb);
  347. nmi_shutdown_mux();
  348. msrs = &get_cpu_var(cpu_msrs);
  349. model->shutdown(msrs);
  350. free_msrs();
  351. put_cpu_var(cpu_msrs);
  352. }
  353. static int nmi_create_files(struct super_block *sb, struct dentry *root)
  354. {
  355. unsigned int i;
  356. for (i = 0; i < model->num_virt_counters; ++i) {
  357. struct dentry *dir;
  358. char buf[4];
  359. #ifndef CONFIG_OPROFILE_EVENT_MULTIPLEX
  360. /* quick little hack to _not_ expose a counter if it is not
  361. * available for use. This should protect userspace app.
  362. * NOTE: assumes 1:1 mapping here (that counters are organized
  363. * sequentially in their struct assignment).
  364. */
  365. if (unlikely(!avail_to_resrv_perfctr_nmi_bit(i)))
  366. continue;
  367. #endif /* CONFIG_OPROFILE_EVENT_MULTIPLEX */
  368. snprintf(buf, sizeof(buf), "%d", i);
  369. dir = oprofilefs_mkdir(sb, root, buf);
  370. oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled);
  371. oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event);
  372. oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count);
  373. oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask);
  374. oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel);
  375. oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user);
  376. }
  377. return 0;
  378. }
  379. #ifdef CONFIG_SMP
  380. static int oprofile_cpu_notifier(struct notifier_block *b, unsigned long action,
  381. void *data)
  382. {
  383. int cpu = (unsigned long)data;
  384. switch (action) {
  385. case CPU_DOWN_FAILED:
  386. case CPU_ONLINE:
  387. smp_call_function_single(cpu, nmi_cpu_start, NULL, 0);
  388. break;
  389. case CPU_DOWN_PREPARE:
  390. smp_call_function_single(cpu, nmi_cpu_stop, NULL, 1);
  391. break;
  392. }
  393. return NOTIFY_DONE;
  394. }
  395. static struct notifier_block oprofile_cpu_nb = {
  396. .notifier_call = oprofile_cpu_notifier
  397. };
  398. #endif
  399. #ifdef CONFIG_PM
  400. static int nmi_suspend(struct sys_device *dev, pm_message_t state)
  401. {
  402. /* Only one CPU left, just stop that one */
  403. if (nmi_enabled == 1)
  404. nmi_cpu_stop(NULL);
  405. return 0;
  406. }
  407. static int nmi_resume(struct sys_device *dev)
  408. {
  409. if (nmi_enabled == 1)
  410. nmi_cpu_start(NULL);
  411. return 0;
  412. }
  413. static struct sysdev_class oprofile_sysclass = {
  414. .name = "oprofile",
  415. .resume = nmi_resume,
  416. .suspend = nmi_suspend,
  417. };
  418. static struct sys_device device_oprofile = {
  419. .id = 0,
  420. .cls = &oprofile_sysclass,
  421. };
  422. static int __init init_sysfs(void)
  423. {
  424. int error;
  425. error = sysdev_class_register(&oprofile_sysclass);
  426. if (!error)
  427. error = sysdev_register(&device_oprofile);
  428. return error;
  429. }
  430. static void exit_sysfs(void)
  431. {
  432. sysdev_unregister(&device_oprofile);
  433. sysdev_class_unregister(&oprofile_sysclass);
  434. }
  435. #else
  436. #define init_sysfs() do { } while (0)
  437. #define exit_sysfs() do { } while (0)
  438. #endif /* CONFIG_PM */
  439. static int __init p4_init(char **cpu_type)
  440. {
  441. __u8 cpu_model = boot_cpu_data.x86_model;
  442. if (cpu_model > 6 || cpu_model == 5)
  443. return 0;
  444. #ifndef CONFIG_SMP
  445. *cpu_type = "i386/p4";
  446. model = &op_p4_spec;
  447. return 1;
  448. #else
  449. switch (smp_num_siblings) {
  450. case 1:
  451. *cpu_type = "i386/p4";
  452. model = &op_p4_spec;
  453. return 1;
  454. case 2:
  455. *cpu_type = "i386/p4-ht";
  456. model = &op_p4_ht2_spec;
  457. return 1;
  458. }
  459. #endif
  460. printk(KERN_INFO "oprofile: P4 HyperThreading detected with > 2 threads\n");
  461. printk(KERN_INFO "oprofile: Reverting to timer mode.\n");
  462. return 0;
  463. }
  464. static int force_arch_perfmon;
  465. static int force_cpu_type(const char *str, struct kernel_param *kp)
  466. {
  467. if (!strcmp(str, "arch_perfmon")) {
  468. force_arch_perfmon = 1;
  469. printk(KERN_INFO "oprofile: forcing architectural perfmon\n");
  470. }
  471. return 0;
  472. }
  473. module_param_call(cpu_type, force_cpu_type, NULL, NULL, 0);
  474. static int __init ppro_init(char **cpu_type)
  475. {
  476. __u8 cpu_model = boot_cpu_data.x86_model;
  477. struct op_x86_model_spec *spec = &op_ppro_spec; /* default */
  478. if (force_arch_perfmon && cpu_has_arch_perfmon)
  479. return 0;
  480. switch (cpu_model) {
  481. case 0 ... 2:
  482. *cpu_type = "i386/ppro";
  483. break;
  484. case 3 ... 5:
  485. *cpu_type = "i386/pii";
  486. break;
  487. case 6 ... 8:
  488. case 10 ... 11:
  489. *cpu_type = "i386/piii";
  490. break;
  491. case 9:
  492. case 13:
  493. *cpu_type = "i386/p6_mobile";
  494. break;
  495. case 14:
  496. *cpu_type = "i386/core";
  497. break;
  498. case 15: case 23:
  499. *cpu_type = "i386/core_2";
  500. break;
  501. case 26:
  502. spec = &op_arch_perfmon_spec;
  503. *cpu_type = "i386/core_i7";
  504. break;
  505. case 28:
  506. *cpu_type = "i386/atom";
  507. break;
  508. default:
  509. /* Unknown */
  510. return 0;
  511. }
  512. model = spec;
  513. return 1;
  514. }
  515. /* in order to get sysfs right */
  516. static int using_nmi;
  517. int __init op_nmi_init(struct oprofile_operations *ops)
  518. {
  519. __u8 vendor = boot_cpu_data.x86_vendor;
  520. __u8 family = boot_cpu_data.x86;
  521. char *cpu_type = NULL;
  522. int ret = 0;
  523. if (!cpu_has_apic)
  524. return -ENODEV;
  525. switch (vendor) {
  526. case X86_VENDOR_AMD:
  527. /* Needs to be at least an Athlon (or hammer in 32bit mode) */
  528. switch (family) {
  529. case 6:
  530. cpu_type = "i386/athlon";
  531. break;
  532. case 0xf:
  533. /*
  534. * Actually it could be i386/hammer too, but
  535. * give user space an consistent name.
  536. */
  537. cpu_type = "x86-64/hammer";
  538. break;
  539. case 0x10:
  540. cpu_type = "x86-64/family10";
  541. break;
  542. case 0x11:
  543. cpu_type = "x86-64/family11h";
  544. break;
  545. default:
  546. return -ENODEV;
  547. }
  548. model = &op_amd_spec;
  549. break;
  550. case X86_VENDOR_INTEL:
  551. switch (family) {
  552. /* Pentium IV */
  553. case 0xf:
  554. p4_init(&cpu_type);
  555. break;
  556. /* A P6-class processor */
  557. case 6:
  558. ppro_init(&cpu_type);
  559. break;
  560. default:
  561. break;
  562. }
  563. if (cpu_type)
  564. break;
  565. if (!cpu_has_arch_perfmon)
  566. return -ENODEV;
  567. /* use arch perfmon as fallback */
  568. cpu_type = "i386/arch_perfmon";
  569. model = &op_arch_perfmon_spec;
  570. break;
  571. default:
  572. return -ENODEV;
  573. }
  574. #ifdef CONFIG_SMP
  575. register_cpu_notifier(&oprofile_cpu_nb);
  576. #endif
  577. /* default values, can be overwritten by model */
  578. ops->create_files = nmi_create_files;
  579. ops->setup = nmi_setup;
  580. ops->shutdown = nmi_shutdown;
  581. ops->start = nmi_start;
  582. ops->stop = nmi_stop;
  583. ops->cpu_type = cpu_type;
  584. if (model->init)
  585. ret = model->init(ops);
  586. if (ret)
  587. return ret;
  588. if (!model->num_virt_counters)
  589. model->num_virt_counters = model->num_counters;
  590. mux_init(ops);
  591. init_sysfs();
  592. using_nmi = 1;
  593. printk(KERN_INFO "oprofile: using NMI interrupt.\n");
  594. return 0;
  595. }
  596. void op_nmi_exit(void)
  597. {
  598. if (using_nmi) {
  599. exit_sysfs();
  600. #ifdef CONFIG_SMP
  601. unregister_cpu_notifier(&oprofile_cpu_nb);
  602. #endif
  603. }
  604. if (model->exit)
  605. model->exit();
  606. }