perf_event_amd.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. #ifdef CONFIG_CPU_SUP_AMD
  2. static __initconst const u64 amd_hw_cache_event_ids
  3. [PERF_COUNT_HW_CACHE_MAX]
  4. [PERF_COUNT_HW_CACHE_OP_MAX]
  5. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  6. {
  7. [ C(L1D) ] = {
  8. [ C(OP_READ) ] = {
  9. [ C(RESULT_ACCESS) ] = 0x0040, /* Data Cache Accesses */
  10. [ C(RESULT_MISS) ] = 0x0141, /* Data Cache Misses */
  11. },
  12. [ C(OP_WRITE) ] = {
  13. [ C(RESULT_ACCESS) ] = 0x0142, /* Data Cache Refills :system */
  14. [ C(RESULT_MISS) ] = 0,
  15. },
  16. [ C(OP_PREFETCH) ] = {
  17. [ C(RESULT_ACCESS) ] = 0x0267, /* Data Prefetcher :attempts */
  18. [ C(RESULT_MISS) ] = 0x0167, /* Data Prefetcher :cancelled */
  19. },
  20. },
  21. [ C(L1I ) ] = {
  22. [ C(OP_READ) ] = {
  23. [ C(RESULT_ACCESS) ] = 0x0080, /* Instruction cache fetches */
  24. [ C(RESULT_MISS) ] = 0x0081, /* Instruction cache misses */
  25. },
  26. [ C(OP_WRITE) ] = {
  27. [ C(RESULT_ACCESS) ] = -1,
  28. [ C(RESULT_MISS) ] = -1,
  29. },
  30. [ C(OP_PREFETCH) ] = {
  31. [ C(RESULT_ACCESS) ] = 0x014B, /* Prefetch Instructions :Load */
  32. [ C(RESULT_MISS) ] = 0,
  33. },
  34. },
  35. [ C(LL ) ] = {
  36. [ C(OP_READ) ] = {
  37. [ C(RESULT_ACCESS) ] = 0x037D, /* Requests to L2 Cache :IC+DC */
  38. [ C(RESULT_MISS) ] = 0x037E, /* L2 Cache Misses : IC+DC */
  39. },
  40. [ C(OP_WRITE) ] = {
  41. [ C(RESULT_ACCESS) ] = 0x017F, /* L2 Fill/Writeback */
  42. [ C(RESULT_MISS) ] = 0,
  43. },
  44. [ C(OP_PREFETCH) ] = {
  45. [ C(RESULT_ACCESS) ] = 0,
  46. [ C(RESULT_MISS) ] = 0,
  47. },
  48. },
  49. [ C(DTLB) ] = {
  50. [ C(OP_READ) ] = {
  51. [ C(RESULT_ACCESS) ] = 0x0040, /* Data Cache Accesses */
  52. [ C(RESULT_MISS) ] = 0x0746, /* L1_DTLB_AND_L2_DLTB_MISS.ALL */
  53. },
  54. [ C(OP_WRITE) ] = {
  55. [ C(RESULT_ACCESS) ] = 0,
  56. [ C(RESULT_MISS) ] = 0,
  57. },
  58. [ C(OP_PREFETCH) ] = {
  59. [ C(RESULT_ACCESS) ] = 0,
  60. [ C(RESULT_MISS) ] = 0,
  61. },
  62. },
  63. [ C(ITLB) ] = {
  64. [ C(OP_READ) ] = {
  65. [ C(RESULT_ACCESS) ] = 0x0080, /* Instruction fecthes */
  66. [ C(RESULT_MISS) ] = 0x0385, /* L1_ITLB_AND_L2_ITLB_MISS.ALL */
  67. },
  68. [ C(OP_WRITE) ] = {
  69. [ C(RESULT_ACCESS) ] = -1,
  70. [ C(RESULT_MISS) ] = -1,
  71. },
  72. [ C(OP_PREFETCH) ] = {
  73. [ C(RESULT_ACCESS) ] = -1,
  74. [ C(RESULT_MISS) ] = -1,
  75. },
  76. },
  77. [ C(BPU ) ] = {
  78. [ C(OP_READ) ] = {
  79. [ C(RESULT_ACCESS) ] = 0x00c2, /* Retired Branch Instr. */
  80. [ C(RESULT_MISS) ] = 0x00c3, /* Retired Mispredicted BI */
  81. },
  82. [ C(OP_WRITE) ] = {
  83. [ C(RESULT_ACCESS) ] = -1,
  84. [ C(RESULT_MISS) ] = -1,
  85. },
  86. [ C(OP_PREFETCH) ] = {
  87. [ C(RESULT_ACCESS) ] = -1,
  88. [ C(RESULT_MISS) ] = -1,
  89. },
  90. },
  91. [ C(NODE) ] = {
  92. [ C(OP_READ) ] = {
  93. [ C(RESULT_ACCESS) ] = 0xb8e9, /* CPU Request to Memory, l+r */
  94. [ C(RESULT_MISS) ] = 0x98e9, /* CPU Request to Memory, r */
  95. },
  96. [ C(OP_WRITE) ] = {
  97. [ C(RESULT_ACCESS) ] = -1,
  98. [ C(RESULT_MISS) ] = -1,
  99. },
  100. [ C(OP_PREFETCH) ] = {
  101. [ C(RESULT_ACCESS) ] = -1,
  102. [ C(RESULT_MISS) ] = -1,
  103. },
  104. },
  105. };
  106. /*
  107. * AMD Performance Monitor K7 and later.
  108. */
  109. static const u64 amd_perfmon_event_map[] =
  110. {
  111. [PERF_COUNT_HW_CPU_CYCLES] = 0x0076,
  112. [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0,
  113. [PERF_COUNT_HW_CACHE_REFERENCES] = 0x0080,
  114. [PERF_COUNT_HW_CACHE_MISSES] = 0x0081,
  115. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c2,
  116. [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c3,
  117. [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x00d0, /* "Decoder empty" event */
  118. [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x00d1, /* "Dispatch stalls" event */
  119. };
  120. static u64 amd_pmu_event_map(int hw_event)
  121. {
  122. return amd_perfmon_event_map[hw_event];
  123. }
  124. static int amd_pmu_hw_config(struct perf_event *event)
  125. {
  126. int ret = x86_pmu_hw_config(event);
  127. if (ret)
  128. return ret;
  129. if (event->attr.type != PERF_TYPE_RAW)
  130. return 0;
  131. event->hw.config |= event->attr.config & AMD64_RAW_EVENT_MASK;
  132. return 0;
  133. }
  134. /*
  135. * AMD64 events are detected based on their event codes.
  136. */
  137. static inline unsigned int amd_get_event_code(struct hw_perf_event *hwc)
  138. {
  139. return ((hwc->config >> 24) & 0x0f00) | (hwc->config & 0x00ff);
  140. }
  141. static inline int amd_is_nb_event(struct hw_perf_event *hwc)
  142. {
  143. return (hwc->config & 0xe0) == 0xe0;
  144. }
  145. static inline int amd_has_nb(struct cpu_hw_events *cpuc)
  146. {
  147. struct amd_nb *nb = cpuc->amd_nb;
  148. return nb && nb->nb_id != -1;
  149. }
  150. static void amd_put_event_constraints(struct cpu_hw_events *cpuc,
  151. struct perf_event *event)
  152. {
  153. struct hw_perf_event *hwc = &event->hw;
  154. struct amd_nb *nb = cpuc->amd_nb;
  155. int i;
  156. /*
  157. * only care about NB events
  158. */
  159. if (!(amd_has_nb(cpuc) && amd_is_nb_event(hwc)))
  160. return;
  161. /*
  162. * need to scan whole list because event may not have
  163. * been assigned during scheduling
  164. *
  165. * no race condition possible because event can only
  166. * be removed on one CPU at a time AND PMU is disabled
  167. * when we come here
  168. */
  169. for (i = 0; i < x86_pmu.num_counters; i++) {
  170. if (nb->owners[i] == event) {
  171. cmpxchg(nb->owners+i, event, NULL);
  172. break;
  173. }
  174. }
  175. }
  176. /*
  177. * AMD64 NorthBridge events need special treatment because
  178. * counter access needs to be synchronized across all cores
  179. * of a package. Refer to BKDG section 3.12
  180. *
  181. * NB events are events measuring L3 cache, Hypertransport
  182. * traffic. They are identified by an event code >= 0xe00.
  183. * They measure events on the NorthBride which is shared
  184. * by all cores on a package. NB events are counted on a
  185. * shared set of counters. When a NB event is programmed
  186. * in a counter, the data actually comes from a shared
  187. * counter. Thus, access to those counters needs to be
  188. * synchronized.
  189. *
  190. * We implement the synchronization such that no two cores
  191. * can be measuring NB events using the same counters. Thus,
  192. * we maintain a per-NB allocation table. The available slot
  193. * is propagated using the event_constraint structure.
  194. *
  195. * We provide only one choice for each NB event based on
  196. * the fact that only NB events have restrictions. Consequently,
  197. * if a counter is available, there is a guarantee the NB event
  198. * will be assigned to it. If no slot is available, an empty
  199. * constraint is returned and scheduling will eventually fail
  200. * for this event.
  201. *
  202. * Note that all cores attached the same NB compete for the same
  203. * counters to host NB events, this is why we use atomic ops. Some
  204. * multi-chip CPUs may have more than one NB.
  205. *
  206. * Given that resources are allocated (cmpxchg), they must be
  207. * eventually freed for others to use. This is accomplished by
  208. * calling amd_put_event_constraints().
  209. *
  210. * Non NB events are not impacted by this restriction.
  211. */
  212. static struct event_constraint *
  213. amd_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event)
  214. {
  215. struct hw_perf_event *hwc = &event->hw;
  216. struct amd_nb *nb = cpuc->amd_nb;
  217. struct perf_event *old = NULL;
  218. int max = x86_pmu.num_counters;
  219. int i, j, k = -1;
  220. /*
  221. * if not NB event or no NB, then no constraints
  222. */
  223. if (!(amd_has_nb(cpuc) && amd_is_nb_event(hwc)))
  224. return &unconstrained;
  225. /*
  226. * detect if already present, if so reuse
  227. *
  228. * cannot merge with actual allocation
  229. * because of possible holes
  230. *
  231. * event can already be present yet not assigned (in hwc->idx)
  232. * because of successive calls to x86_schedule_events() from
  233. * hw_perf_group_sched_in() without hw_perf_enable()
  234. */
  235. for (i = 0; i < max; i++) {
  236. /*
  237. * keep track of first free slot
  238. */
  239. if (k == -1 && !nb->owners[i])
  240. k = i;
  241. /* already present, reuse */
  242. if (nb->owners[i] == event)
  243. goto done;
  244. }
  245. /*
  246. * not present, so grab a new slot
  247. * starting either at:
  248. */
  249. if (hwc->idx != -1) {
  250. /* previous assignment */
  251. i = hwc->idx;
  252. } else if (k != -1) {
  253. /* start from free slot found */
  254. i = k;
  255. } else {
  256. /*
  257. * event not found, no slot found in
  258. * first pass, try again from the
  259. * beginning
  260. */
  261. i = 0;
  262. }
  263. j = i;
  264. do {
  265. old = cmpxchg(nb->owners+i, NULL, event);
  266. if (!old)
  267. break;
  268. if (++i == max)
  269. i = 0;
  270. } while (i != j);
  271. done:
  272. if (!old)
  273. return &nb->event_constraints[i];
  274. return &emptyconstraint;
  275. }
  276. static struct amd_nb *amd_alloc_nb(int cpu)
  277. {
  278. struct amd_nb *nb;
  279. int i;
  280. nb = kmalloc_node(sizeof(struct amd_nb), GFP_KERNEL | __GFP_ZERO,
  281. cpu_to_node(cpu));
  282. if (!nb)
  283. return NULL;
  284. nb->nb_id = -1;
  285. /*
  286. * initialize all possible NB constraints
  287. */
  288. for (i = 0; i < x86_pmu.num_counters; i++) {
  289. __set_bit(i, nb->event_constraints[i].idxmsk);
  290. nb->event_constraints[i].weight = 1;
  291. }
  292. return nb;
  293. }
  294. static int amd_pmu_cpu_prepare(int cpu)
  295. {
  296. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  297. WARN_ON_ONCE(cpuc->amd_nb);
  298. if (boot_cpu_data.x86_max_cores < 2)
  299. return NOTIFY_OK;
  300. cpuc->amd_nb = amd_alloc_nb(cpu);
  301. if (!cpuc->amd_nb)
  302. return NOTIFY_BAD;
  303. return NOTIFY_OK;
  304. }
  305. static void amd_pmu_cpu_starting(int cpu)
  306. {
  307. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  308. struct amd_nb *nb;
  309. int i, nb_id;
  310. if (boot_cpu_data.x86_max_cores < 2)
  311. return;
  312. nb_id = amd_get_nb_id(cpu);
  313. WARN_ON_ONCE(nb_id == BAD_APICID);
  314. for_each_online_cpu(i) {
  315. nb = per_cpu(cpu_hw_events, i).amd_nb;
  316. if (WARN_ON_ONCE(!nb))
  317. continue;
  318. if (nb->nb_id == nb_id) {
  319. kfree(cpuc->amd_nb);
  320. cpuc->amd_nb = nb;
  321. break;
  322. }
  323. }
  324. cpuc->amd_nb->nb_id = nb_id;
  325. cpuc->amd_nb->refcnt++;
  326. }
  327. static void amd_pmu_cpu_dead(int cpu)
  328. {
  329. struct cpu_hw_events *cpuhw;
  330. if (boot_cpu_data.x86_max_cores < 2)
  331. return;
  332. cpuhw = &per_cpu(cpu_hw_events, cpu);
  333. if (cpuhw->amd_nb) {
  334. struct amd_nb *nb = cpuhw->amd_nb;
  335. if (nb->nb_id == -1 || --nb->refcnt == 0)
  336. kfree(nb);
  337. cpuhw->amd_nb = NULL;
  338. }
  339. }
  340. static __initconst const struct x86_pmu amd_pmu = {
  341. .name = "AMD",
  342. .handle_irq = x86_pmu_handle_irq,
  343. .disable_all = x86_pmu_disable_all,
  344. .enable_all = x86_pmu_enable_all,
  345. .enable = x86_pmu_enable_event,
  346. .disable = x86_pmu_disable_event,
  347. .hw_config = amd_pmu_hw_config,
  348. .schedule_events = x86_schedule_events,
  349. .eventsel = MSR_K7_EVNTSEL0,
  350. .perfctr = MSR_K7_PERFCTR0,
  351. .event_map = amd_pmu_event_map,
  352. .max_events = ARRAY_SIZE(amd_perfmon_event_map),
  353. .num_counters = 4,
  354. .cntval_bits = 48,
  355. .cntval_mask = (1ULL << 48) - 1,
  356. .apic = 1,
  357. /* use highest bit to detect overflow */
  358. .max_period = (1ULL << 47) - 1,
  359. .get_event_constraints = amd_get_event_constraints,
  360. .put_event_constraints = amd_put_event_constraints,
  361. .cpu_prepare = amd_pmu_cpu_prepare,
  362. .cpu_starting = amd_pmu_cpu_starting,
  363. .cpu_dead = amd_pmu_cpu_dead,
  364. };
  365. /* AMD Family 15h */
  366. #define AMD_EVENT_TYPE_MASK 0x000000F0ULL
  367. #define AMD_EVENT_FP 0x00000000ULL ... 0x00000010ULL
  368. #define AMD_EVENT_LS 0x00000020ULL ... 0x00000030ULL
  369. #define AMD_EVENT_DC 0x00000040ULL ... 0x00000050ULL
  370. #define AMD_EVENT_CU 0x00000060ULL ... 0x00000070ULL
  371. #define AMD_EVENT_IC_DE 0x00000080ULL ... 0x00000090ULL
  372. #define AMD_EVENT_EX_LS 0x000000C0ULL
  373. #define AMD_EVENT_DE 0x000000D0ULL
  374. #define AMD_EVENT_NB 0x000000E0ULL ... 0x000000F0ULL
  375. /*
  376. * AMD family 15h event code/PMC mappings:
  377. *
  378. * type = event_code & 0x0F0:
  379. *
  380. * 0x000 FP PERF_CTL[5:3]
  381. * 0x010 FP PERF_CTL[5:3]
  382. * 0x020 LS PERF_CTL[5:0]
  383. * 0x030 LS PERF_CTL[5:0]
  384. * 0x040 DC PERF_CTL[5:0]
  385. * 0x050 DC PERF_CTL[5:0]
  386. * 0x060 CU PERF_CTL[2:0]
  387. * 0x070 CU PERF_CTL[2:0]
  388. * 0x080 IC/DE PERF_CTL[2:0]
  389. * 0x090 IC/DE PERF_CTL[2:0]
  390. * 0x0A0 ---
  391. * 0x0B0 ---
  392. * 0x0C0 EX/LS PERF_CTL[5:0]
  393. * 0x0D0 DE PERF_CTL[2:0]
  394. * 0x0E0 NB NB_PERF_CTL[3:0]
  395. * 0x0F0 NB NB_PERF_CTL[3:0]
  396. *
  397. * Exceptions:
  398. *
  399. * 0x000 FP PERF_CTL[3], PERF_CTL[5:3] (*)
  400. * 0x003 FP PERF_CTL[3]
  401. * 0x004 FP PERF_CTL[3], PERF_CTL[5:3] (*)
  402. * 0x00B FP PERF_CTL[3]
  403. * 0x00D FP PERF_CTL[3]
  404. * 0x023 DE PERF_CTL[2:0]
  405. * 0x02D LS PERF_CTL[3]
  406. * 0x02E LS PERF_CTL[3,0]
  407. * 0x043 CU PERF_CTL[2:0]
  408. * 0x045 CU PERF_CTL[2:0]
  409. * 0x046 CU PERF_CTL[2:0]
  410. * 0x054 CU PERF_CTL[2:0]
  411. * 0x055 CU PERF_CTL[2:0]
  412. * 0x08F IC PERF_CTL[0]
  413. * 0x187 DE PERF_CTL[0]
  414. * 0x188 DE PERF_CTL[0]
  415. * 0x0DB EX PERF_CTL[5:0]
  416. * 0x0DC LS PERF_CTL[5:0]
  417. * 0x0DD LS PERF_CTL[5:0]
  418. * 0x0DE LS PERF_CTL[5:0]
  419. * 0x0DF LS PERF_CTL[5:0]
  420. * 0x1D6 EX PERF_CTL[5:0]
  421. * 0x1D8 EX PERF_CTL[5:0]
  422. *
  423. * (*) depending on the umask all FPU counters may be used
  424. */
  425. static struct event_constraint amd_f15_PMC0 = EVENT_CONSTRAINT(0, 0x01, 0);
  426. static struct event_constraint amd_f15_PMC20 = EVENT_CONSTRAINT(0, 0x07, 0);
  427. static struct event_constraint amd_f15_PMC3 = EVENT_CONSTRAINT(0, 0x08, 0);
  428. static struct event_constraint amd_f15_PMC30 = EVENT_CONSTRAINT(0, 0x09, 0);
  429. static struct event_constraint amd_f15_PMC50 = EVENT_CONSTRAINT(0, 0x3F, 0);
  430. static struct event_constraint amd_f15_PMC53 = EVENT_CONSTRAINT(0, 0x38, 0);
  431. static struct event_constraint *
  432. amd_get_event_constraints_f15h(struct cpu_hw_events *cpuc, struct perf_event *event)
  433. {
  434. struct hw_perf_event *hwc = &event->hw;
  435. unsigned int event_code = amd_get_event_code(hwc);
  436. switch (event_code & AMD_EVENT_TYPE_MASK) {
  437. case AMD_EVENT_FP:
  438. switch (event_code) {
  439. case 0x000:
  440. if (!(hwc->config & 0x0000F000ULL))
  441. break;
  442. if (!(hwc->config & 0x00000F00ULL))
  443. break;
  444. return &amd_f15_PMC3;
  445. case 0x004:
  446. if (hweight_long(hwc->config & ARCH_PERFMON_EVENTSEL_UMASK) <= 1)
  447. break;
  448. return &amd_f15_PMC3;
  449. case 0x003:
  450. case 0x00B:
  451. case 0x00D:
  452. return &amd_f15_PMC3;
  453. }
  454. return &amd_f15_PMC53;
  455. case AMD_EVENT_LS:
  456. case AMD_EVENT_DC:
  457. case AMD_EVENT_EX_LS:
  458. switch (event_code) {
  459. case 0x023:
  460. case 0x043:
  461. case 0x045:
  462. case 0x046:
  463. case 0x054:
  464. case 0x055:
  465. return &amd_f15_PMC20;
  466. case 0x02D:
  467. return &amd_f15_PMC3;
  468. case 0x02E:
  469. return &amd_f15_PMC30;
  470. default:
  471. return &amd_f15_PMC50;
  472. }
  473. case AMD_EVENT_CU:
  474. case AMD_EVENT_IC_DE:
  475. case AMD_EVENT_DE:
  476. switch (event_code) {
  477. case 0x08F:
  478. case 0x187:
  479. case 0x188:
  480. return &amd_f15_PMC0;
  481. case 0x0DB ... 0x0DF:
  482. case 0x1D6:
  483. case 0x1D8:
  484. return &amd_f15_PMC50;
  485. default:
  486. return &amd_f15_PMC20;
  487. }
  488. case AMD_EVENT_NB:
  489. /* not yet implemented */
  490. return &emptyconstraint;
  491. default:
  492. return &emptyconstraint;
  493. }
  494. }
  495. static __initconst const struct x86_pmu amd_pmu_f15h = {
  496. .name = "AMD Family 15h",
  497. .handle_irq = x86_pmu_handle_irq,
  498. .disable_all = x86_pmu_disable_all,
  499. .enable_all = x86_pmu_enable_all,
  500. .enable = x86_pmu_enable_event,
  501. .disable = x86_pmu_disable_event,
  502. .hw_config = amd_pmu_hw_config,
  503. .schedule_events = x86_schedule_events,
  504. .eventsel = MSR_F15H_PERF_CTL,
  505. .perfctr = MSR_F15H_PERF_CTR,
  506. .event_map = amd_pmu_event_map,
  507. .max_events = ARRAY_SIZE(amd_perfmon_event_map),
  508. .num_counters = 6,
  509. .cntval_bits = 48,
  510. .cntval_mask = (1ULL << 48) - 1,
  511. .apic = 1,
  512. /* use highest bit to detect overflow */
  513. .max_period = (1ULL << 47) - 1,
  514. .get_event_constraints = amd_get_event_constraints_f15h,
  515. /* nortbridge counters not yet implemented: */
  516. #if 0
  517. .put_event_constraints = amd_put_event_constraints,
  518. .cpu_prepare = amd_pmu_cpu_prepare,
  519. .cpu_starting = amd_pmu_cpu_starting,
  520. .cpu_dead = amd_pmu_cpu_dead,
  521. #endif
  522. };
  523. static __init int amd_pmu_init(void)
  524. {
  525. /* Performance-monitoring supported from K7 and later: */
  526. if (boot_cpu_data.x86 < 6)
  527. return -ENODEV;
  528. /*
  529. * If core performance counter extensions exists, it must be
  530. * family 15h, otherwise fail. See x86_pmu_addr_offset().
  531. */
  532. switch (boot_cpu_data.x86) {
  533. case 0x15:
  534. if (!cpu_has_perfctr_core)
  535. return -ENODEV;
  536. x86_pmu = amd_pmu_f15h;
  537. break;
  538. default:
  539. if (cpu_has_perfctr_core)
  540. return -ENODEV;
  541. x86_pmu = amd_pmu;
  542. break;
  543. }
  544. /* Events are common for all AMDs */
  545. memcpy(hw_cache_event_ids, amd_hw_cache_event_ids,
  546. sizeof(hw_cache_event_ids));
  547. return 0;
  548. }
  549. #else /* CONFIG_CPU_SUP_AMD */
  550. static int amd_pmu_init(void)
  551. {
  552. return 0;
  553. }
  554. #endif