nmi_int.c 17 KB

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