nmi_int.c 17 KB

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