power10-pmu.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Performance counter support for POWER10 processors.
  4. *
  5. * Copyright 2020 Madhavan Srinivasan, IBM Corporation.
  6. * Copyright 2020 Athira Rajeev, IBM Corporation.
  7. */
  8. #define pr_fmt(fmt) "power10-pmu: " fmt
  9. #include "isa207-common.h"
  10. /*
  11. * Raw event encoding for Power10:
  12. *
  13. * 60 56 52 48 44 40 36 32
  14. * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
  15. * | | [ ] [ src_match ] [ src_mask ] | [ ] [ l2l3_sel ] [ thresh_ctl ]
  16. * | | | | | |
  17. * | | *- IFM (Linux) | | thresh start/stop -*
  18. * | *- BHRB (Linux) | src_sel
  19. * *- EBB (Linux) *invert_bit
  20. *
  21. * 28 24 20 16 12 8 4 0
  22. * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
  23. * [ ] [ sample ] [ ] [ ] [ pmc ] [unit ] [ ] | m [ pmcxsel ]
  24. * | | | | | | |
  25. * | | | | | | *- mark
  26. * | | | *- L1/L2/L3 cache_sel | |*-radix_scope_qual
  27. * | | sdar_mode |
  28. * | *- sampling mode for marked events *- combine
  29. * |
  30. * *- thresh_sel
  31. *
  32. * Below uses IBM bit numbering.
  33. *
  34. * MMCR1[x:y] = unit (PMCxUNIT)
  35. * MMCR1[24] = pmc1combine[0]
  36. * MMCR1[25] = pmc1combine[1]
  37. * MMCR1[26] = pmc2combine[0]
  38. * MMCR1[27] = pmc2combine[1]
  39. * MMCR1[28] = pmc3combine[0]
  40. * MMCR1[29] = pmc3combine[1]
  41. * MMCR1[30] = pmc4combine[0]
  42. * MMCR1[31] = pmc4combine[1]
  43. *
  44. * if pmc == 3 and unit == 0 and pmcxsel[0:6] == 0b0101011
  45. * MMCR1[20:27] = thresh_ctl
  46. * else if pmc == 4 and unit == 0xf and pmcxsel[0:6] == 0b0101001
  47. * MMCR1[20:27] = thresh_ctl
  48. * else
  49. * MMCRA[48:55] = thresh_ctl (THRESH START/END)
  50. *
  51. * if thresh_sel:
  52. * MMCRA[45:47] = thresh_sel
  53. *
  54. * if l2l3_sel:
  55. * MMCR2[56:60] = l2l3_sel[0:4]
  56. *
  57. * MMCR1[16] = cache_sel[0]
  58. * MMCR1[17] = cache_sel[1]
  59. * MMCR1[18] = radix_scope_qual
  60. *
  61. * if mark:
  62. * MMCRA[63] = 1 (SAMPLE_ENABLE)
  63. * MMCRA[57:59] = sample[0:2] (RAND_SAMP_ELIG)
  64. * MMCRA[61:62] = sample[3:4] (RAND_SAMP_MODE)
  65. *
  66. * if EBB and BHRB:
  67. * MMCRA[32:33] = IFM
  68. *
  69. * MMCRA[SDAR_MODE] = sdar_mode[0:1]
  70. */
  71. /*
  72. * Some power10 event codes.
  73. */
  74. #define EVENT(_name, _code) enum{_name = _code}
  75. #include "power10-events-list.h"
  76. #undef EVENT
  77. /* MMCRA IFM bits - POWER10 */
  78. #define POWER10_MMCRA_IFM1 0x0000000040000000UL
  79. #define POWER10_MMCRA_IFM2 0x0000000080000000UL
  80. #define POWER10_MMCRA_IFM3 0x00000000C0000000UL
  81. #define POWER10_MMCRA_BHRB_MASK 0x00000000C0000000UL
  82. extern u64 PERF_REG_EXTENDED_MASK;
  83. /* Table of alternatives, sorted by column 0 */
  84. static const unsigned int power10_event_alternatives[][MAX_ALT] = {
  85. { PM_INST_CMPL_ALT, PM_INST_CMPL },
  86. { PM_CYC_ALT, PM_CYC },
  87. };
  88. static int power10_get_alternatives(u64 event, unsigned int flags, u64 alt[])
  89. {
  90. int num_alt = 0;
  91. num_alt = isa207_get_alternatives(event, alt,
  92. ARRAY_SIZE(power10_event_alternatives), flags,
  93. power10_event_alternatives);
  94. return num_alt;
  95. }
  96. static int power10_check_attr_config(struct perf_event *ev)
  97. {
  98. u64 val;
  99. u64 event = ev->attr.config;
  100. val = (event >> EVENT_SAMPLE_SHIFT) & EVENT_SAMPLE_MASK;
  101. if (val == 0x10 || isa3XX_check_attr_config(ev))
  102. return -EINVAL;
  103. return 0;
  104. }
  105. GENERIC_EVENT_ATTR(cpu-cycles, PM_CYC);
  106. GENERIC_EVENT_ATTR(instructions, PM_INST_CMPL);
  107. GENERIC_EVENT_ATTR(branch-instructions, PM_BR_CMPL);
  108. GENERIC_EVENT_ATTR(branch-misses, PM_BR_MPRED_CMPL);
  109. GENERIC_EVENT_ATTR(cache-references, PM_LD_REF_L1);
  110. GENERIC_EVENT_ATTR(cache-misses, PM_LD_MISS_L1);
  111. GENERIC_EVENT_ATTR(mem-loads, MEM_LOADS);
  112. GENERIC_EVENT_ATTR(mem-stores, MEM_STORES);
  113. GENERIC_EVENT_ATTR(branch-instructions, PM_BR_FIN);
  114. GENERIC_EVENT_ATTR(branch-misses, PM_MPRED_BR_FIN);
  115. GENERIC_EVENT_ATTR(cache-misses, PM_LD_DEMAND_MISS_L1_FIN);
  116. CACHE_EVENT_ATTR(L1-dcache-load-misses, PM_LD_MISS_L1);
  117. CACHE_EVENT_ATTR(L1-dcache-loads, PM_LD_REF_L1);
  118. CACHE_EVENT_ATTR(L1-dcache-prefetches, PM_LD_PREFETCH_CACHE_LINE_MISS);
  119. CACHE_EVENT_ATTR(L1-dcache-store-misses, PM_ST_MISS_L1);
  120. CACHE_EVENT_ATTR(L1-icache-load-misses, PM_L1_ICACHE_MISS);
  121. CACHE_EVENT_ATTR(L1-icache-loads, PM_INST_FROM_L1);
  122. CACHE_EVENT_ATTR(L1-icache-prefetches, PM_IC_PREF_REQ);
  123. CACHE_EVENT_ATTR(LLC-load-misses, PM_DATA_FROM_L3MISS);
  124. CACHE_EVENT_ATTR(LLC-loads, PM_DATA_FROM_L3);
  125. CACHE_EVENT_ATTR(LLC-prefetches, PM_L3_PF_MISS_L3);
  126. CACHE_EVENT_ATTR(LLC-store-misses, PM_L2_ST_MISS);
  127. CACHE_EVENT_ATTR(LLC-stores, PM_L2_ST);
  128. CACHE_EVENT_ATTR(branch-load-misses, PM_BR_MPRED_CMPL);
  129. CACHE_EVENT_ATTR(branch-loads, PM_BR_CMPL);
  130. CACHE_EVENT_ATTR(dTLB-load-misses, PM_DTLB_MISS);
  131. CACHE_EVENT_ATTR(iTLB-load-misses, PM_ITLB_MISS);
  132. static struct attribute *power10_events_attr_dd1[] = {
  133. GENERIC_EVENT_PTR(PM_CYC),
  134. GENERIC_EVENT_PTR(PM_INST_CMPL),
  135. GENERIC_EVENT_PTR(PM_BR_CMPL),
  136. GENERIC_EVENT_PTR(PM_BR_MPRED_CMPL),
  137. GENERIC_EVENT_PTR(PM_LD_REF_L1),
  138. GENERIC_EVENT_PTR(PM_LD_MISS_L1),
  139. GENERIC_EVENT_PTR(MEM_LOADS),
  140. GENERIC_EVENT_PTR(MEM_STORES),
  141. CACHE_EVENT_PTR(PM_LD_MISS_L1),
  142. CACHE_EVENT_PTR(PM_LD_REF_L1),
  143. CACHE_EVENT_PTR(PM_LD_PREFETCH_CACHE_LINE_MISS),
  144. CACHE_EVENT_PTR(PM_ST_MISS_L1),
  145. CACHE_EVENT_PTR(PM_L1_ICACHE_MISS),
  146. CACHE_EVENT_PTR(PM_INST_FROM_L1),
  147. CACHE_EVENT_PTR(PM_IC_PREF_REQ),
  148. CACHE_EVENT_PTR(PM_DATA_FROM_L3MISS),
  149. CACHE_EVENT_PTR(PM_DATA_FROM_L3),
  150. CACHE_EVENT_PTR(PM_BR_MPRED_CMPL),
  151. CACHE_EVENT_PTR(PM_BR_CMPL),
  152. CACHE_EVENT_PTR(PM_DTLB_MISS),
  153. CACHE_EVENT_PTR(PM_ITLB_MISS),
  154. NULL
  155. };
  156. static struct attribute *power10_events_attr[] = {
  157. GENERIC_EVENT_PTR(PM_CYC),
  158. GENERIC_EVENT_PTR(PM_INST_CMPL),
  159. GENERIC_EVENT_PTR(PM_BR_FIN),
  160. GENERIC_EVENT_PTR(PM_MPRED_BR_FIN),
  161. GENERIC_EVENT_PTR(PM_LD_REF_L1),
  162. GENERIC_EVENT_PTR(PM_LD_DEMAND_MISS_L1_FIN),
  163. GENERIC_EVENT_PTR(MEM_LOADS),
  164. GENERIC_EVENT_PTR(MEM_STORES),
  165. CACHE_EVENT_PTR(PM_LD_MISS_L1),
  166. CACHE_EVENT_PTR(PM_LD_REF_L1),
  167. CACHE_EVENT_PTR(PM_LD_PREFETCH_CACHE_LINE_MISS),
  168. CACHE_EVENT_PTR(PM_ST_MISS_L1),
  169. CACHE_EVENT_PTR(PM_L1_ICACHE_MISS),
  170. CACHE_EVENT_PTR(PM_INST_FROM_L1),
  171. CACHE_EVENT_PTR(PM_IC_PREF_REQ),
  172. CACHE_EVENT_PTR(PM_DATA_FROM_L3MISS),
  173. CACHE_EVENT_PTR(PM_DATA_FROM_L3),
  174. CACHE_EVENT_PTR(PM_L3_PF_MISS_L3),
  175. CACHE_EVENT_PTR(PM_L2_ST_MISS),
  176. CACHE_EVENT_PTR(PM_L2_ST),
  177. CACHE_EVENT_PTR(PM_BR_MPRED_CMPL),
  178. CACHE_EVENT_PTR(PM_BR_CMPL),
  179. CACHE_EVENT_PTR(PM_DTLB_MISS),
  180. CACHE_EVENT_PTR(PM_ITLB_MISS),
  181. NULL
  182. };
  183. static const struct attribute_group power10_pmu_events_group_dd1 = {
  184. .name = "events",
  185. .attrs = power10_events_attr_dd1,
  186. };
  187. static const struct attribute_group power10_pmu_events_group = {
  188. .name = "events",
  189. .attrs = power10_events_attr,
  190. };
  191. PMU_FORMAT_ATTR(event, "config:0-59");
  192. PMU_FORMAT_ATTR(pmcxsel, "config:0-7");
  193. PMU_FORMAT_ATTR(mark, "config:8");
  194. PMU_FORMAT_ATTR(combine, "config:10-11");
  195. PMU_FORMAT_ATTR(unit, "config:12-15");
  196. PMU_FORMAT_ATTR(pmc, "config:16-19");
  197. PMU_FORMAT_ATTR(cache_sel, "config:20-21");
  198. PMU_FORMAT_ATTR(sdar_mode, "config:22-23");
  199. PMU_FORMAT_ATTR(sample_mode, "config:24-28");
  200. PMU_FORMAT_ATTR(thresh_sel, "config:29-31");
  201. PMU_FORMAT_ATTR(thresh_stop, "config:32-35");
  202. PMU_FORMAT_ATTR(thresh_start, "config:36-39");
  203. PMU_FORMAT_ATTR(l2l3_sel, "config:40-44");
  204. PMU_FORMAT_ATTR(src_sel, "config:45-46");
  205. PMU_FORMAT_ATTR(invert_bit, "config:47");
  206. PMU_FORMAT_ATTR(src_mask, "config:48-53");
  207. PMU_FORMAT_ATTR(src_match, "config:54-59");
  208. PMU_FORMAT_ATTR(radix_scope, "config:9");
  209. PMU_FORMAT_ATTR(thresh_cmp, "config1:0-17");
  210. static struct attribute *power10_pmu_format_attr[] = {
  211. &format_attr_event.attr,
  212. &format_attr_pmcxsel.attr,
  213. &format_attr_mark.attr,
  214. &format_attr_combine.attr,
  215. &format_attr_unit.attr,
  216. &format_attr_pmc.attr,
  217. &format_attr_cache_sel.attr,
  218. &format_attr_sdar_mode.attr,
  219. &format_attr_sample_mode.attr,
  220. &format_attr_thresh_sel.attr,
  221. &format_attr_thresh_stop.attr,
  222. &format_attr_thresh_start.attr,
  223. &format_attr_l2l3_sel.attr,
  224. &format_attr_src_sel.attr,
  225. &format_attr_invert_bit.attr,
  226. &format_attr_src_mask.attr,
  227. &format_attr_src_match.attr,
  228. &format_attr_radix_scope.attr,
  229. &format_attr_thresh_cmp.attr,
  230. NULL,
  231. };
  232. static const struct attribute_group power10_pmu_format_group = {
  233. .name = "format",
  234. .attrs = power10_pmu_format_attr,
  235. };
  236. static struct attribute *power10_pmu_caps_attrs[] = {
  237. NULL
  238. };
  239. static struct attribute_group power10_pmu_caps_group = {
  240. .name = "caps",
  241. .attrs = power10_pmu_caps_attrs,
  242. };
  243. static const struct attribute_group *power10_pmu_attr_groups_dd1[] = {
  244. &power10_pmu_format_group,
  245. &power10_pmu_events_group_dd1,
  246. &power10_pmu_caps_group,
  247. NULL,
  248. };
  249. static const struct attribute_group *power10_pmu_attr_groups[] = {
  250. &power10_pmu_format_group,
  251. &power10_pmu_events_group,
  252. &power10_pmu_caps_group,
  253. NULL,
  254. };
  255. static int power10_generic_events_dd1[] = {
  256. [PERF_COUNT_HW_CPU_CYCLES] = PM_CYC,
  257. [PERF_COUNT_HW_INSTRUCTIONS] = PM_INST_CMPL,
  258. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = PM_BR_CMPL,
  259. [PERF_COUNT_HW_BRANCH_MISSES] = PM_BR_MPRED_CMPL,
  260. [PERF_COUNT_HW_CACHE_REFERENCES] = PM_LD_REF_L1,
  261. [PERF_COUNT_HW_CACHE_MISSES] = PM_LD_MISS_L1,
  262. };
  263. static int power10_generic_events[] = {
  264. [PERF_COUNT_HW_CPU_CYCLES] = PM_CYC,
  265. [PERF_COUNT_HW_INSTRUCTIONS] = PM_INST_CMPL,
  266. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = PM_BR_FIN,
  267. [PERF_COUNT_HW_BRANCH_MISSES] = PM_MPRED_BR_FIN,
  268. [PERF_COUNT_HW_CACHE_REFERENCES] = PM_LD_REF_L1,
  269. [PERF_COUNT_HW_CACHE_MISSES] = PM_LD_DEMAND_MISS_L1_FIN,
  270. };
  271. static u64 power10_bhrb_filter_map(u64 branch_sample_type)
  272. {
  273. u64 pmu_bhrb_filter = 0;
  274. /* BHRB and regular PMU events share the same privilege state
  275. * filter configuration. BHRB is always recorded along with a
  276. * regular PMU event. As the privilege state filter is handled
  277. * in the basic PMC configuration of the accompanying regular
  278. * PMU event, we ignore any separate BHRB specific request.
  279. */
  280. /* No branch filter requested */
  281. if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY)
  282. return pmu_bhrb_filter;
  283. /* Invalid branch filter options - HW does not support */
  284. if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_RETURN)
  285. return -1;
  286. if (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL) {
  287. pmu_bhrb_filter |= POWER10_MMCRA_IFM2;
  288. return pmu_bhrb_filter;
  289. }
  290. if (branch_sample_type & PERF_SAMPLE_BRANCH_COND) {
  291. pmu_bhrb_filter |= POWER10_MMCRA_IFM3;
  292. return pmu_bhrb_filter;
  293. }
  294. if (branch_sample_type & PERF_SAMPLE_BRANCH_CALL)
  295. return -1;
  296. if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_CALL) {
  297. pmu_bhrb_filter |= POWER10_MMCRA_IFM1;
  298. return pmu_bhrb_filter;
  299. }
  300. /* Every thing else is unsupported */
  301. return -1;
  302. }
  303. static void power10_config_bhrb(u64 pmu_bhrb_filter)
  304. {
  305. pmu_bhrb_filter &= POWER10_MMCRA_BHRB_MASK;
  306. /* Enable BHRB filter in PMU */
  307. mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter));
  308. }
  309. #define C(x) PERF_COUNT_HW_CACHE_##x
  310. /*
  311. * Table of generalized cache-related events.
  312. * 0 means not supported, -1 means nonsensical, other values
  313. * are event codes.
  314. */
  315. static u64 power10_cache_events_dd1[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
  316. [C(L1D)] = {
  317. [C(OP_READ)] = {
  318. [C(RESULT_ACCESS)] = PM_LD_REF_L1,
  319. [C(RESULT_MISS)] = PM_LD_MISS_L1,
  320. },
  321. [C(OP_WRITE)] = {
  322. [C(RESULT_ACCESS)] = 0,
  323. [C(RESULT_MISS)] = PM_ST_MISS_L1,
  324. },
  325. [C(OP_PREFETCH)] = {
  326. [C(RESULT_ACCESS)] = PM_LD_PREFETCH_CACHE_LINE_MISS,
  327. [C(RESULT_MISS)] = 0,
  328. },
  329. },
  330. [C(L1I)] = {
  331. [C(OP_READ)] = {
  332. [C(RESULT_ACCESS)] = PM_INST_FROM_L1,
  333. [C(RESULT_MISS)] = PM_L1_ICACHE_MISS,
  334. },
  335. [C(OP_WRITE)] = {
  336. [C(RESULT_ACCESS)] = PM_INST_FROM_L1MISS,
  337. [C(RESULT_MISS)] = -1,
  338. },
  339. [C(OP_PREFETCH)] = {
  340. [C(RESULT_ACCESS)] = PM_IC_PREF_REQ,
  341. [C(RESULT_MISS)] = 0,
  342. },
  343. },
  344. [C(LL)] = {
  345. [C(OP_READ)] = {
  346. [C(RESULT_ACCESS)] = PM_DATA_FROM_L3,
  347. [C(RESULT_MISS)] = PM_DATA_FROM_L3MISS,
  348. },
  349. [C(OP_WRITE)] = {
  350. [C(RESULT_ACCESS)] = -1,
  351. [C(RESULT_MISS)] = -1,
  352. },
  353. [C(OP_PREFETCH)] = {
  354. [C(RESULT_ACCESS)] = -1,
  355. [C(RESULT_MISS)] = 0,
  356. },
  357. },
  358. [C(DTLB)] = {
  359. [C(OP_READ)] = {
  360. [C(RESULT_ACCESS)] = 0,
  361. [C(RESULT_MISS)] = PM_DTLB_MISS,
  362. },
  363. [C(OP_WRITE)] = {
  364. [C(RESULT_ACCESS)] = -1,
  365. [C(RESULT_MISS)] = -1,
  366. },
  367. [C(OP_PREFETCH)] = {
  368. [C(RESULT_ACCESS)] = -1,
  369. [C(RESULT_MISS)] = -1,
  370. },
  371. },
  372. [C(ITLB)] = {
  373. [C(OP_READ)] = {
  374. [C(RESULT_ACCESS)] = 0,
  375. [C(RESULT_MISS)] = PM_ITLB_MISS,
  376. },
  377. [C(OP_WRITE)] = {
  378. [C(RESULT_ACCESS)] = -1,
  379. [C(RESULT_MISS)] = -1,
  380. },
  381. [C(OP_PREFETCH)] = {
  382. [C(RESULT_ACCESS)] = -1,
  383. [C(RESULT_MISS)] = -1,
  384. },
  385. },
  386. [C(BPU)] = {
  387. [C(OP_READ)] = {
  388. [C(RESULT_ACCESS)] = PM_BR_CMPL,
  389. [C(RESULT_MISS)] = PM_BR_MPRED_CMPL,
  390. },
  391. [C(OP_WRITE)] = {
  392. [C(RESULT_ACCESS)] = -1,
  393. [C(RESULT_MISS)] = -1,
  394. },
  395. [C(OP_PREFETCH)] = {
  396. [C(RESULT_ACCESS)] = -1,
  397. [C(RESULT_MISS)] = -1,
  398. },
  399. },
  400. [C(NODE)] = {
  401. [C(OP_READ)] = {
  402. [C(RESULT_ACCESS)] = -1,
  403. [C(RESULT_MISS)] = -1,
  404. },
  405. [C(OP_WRITE)] = {
  406. [C(RESULT_ACCESS)] = -1,
  407. [C(RESULT_MISS)] = -1,
  408. },
  409. [C(OP_PREFETCH)] = {
  410. [C(RESULT_ACCESS)] = -1,
  411. [C(RESULT_MISS)] = -1,
  412. },
  413. },
  414. };
  415. static u64 power10_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
  416. [C(L1D)] = {
  417. [C(OP_READ)] = {
  418. [C(RESULT_ACCESS)] = PM_LD_REF_L1,
  419. [C(RESULT_MISS)] = PM_LD_MISS_L1,
  420. },
  421. [C(OP_WRITE)] = {
  422. [C(RESULT_ACCESS)] = 0,
  423. [C(RESULT_MISS)] = PM_ST_MISS_L1,
  424. },
  425. [C(OP_PREFETCH)] = {
  426. [C(RESULT_ACCESS)] = PM_LD_PREFETCH_CACHE_LINE_MISS,
  427. [C(RESULT_MISS)] = 0,
  428. },
  429. },
  430. [C(L1I)] = {
  431. [C(OP_READ)] = {
  432. [C(RESULT_ACCESS)] = PM_INST_FROM_L1,
  433. [C(RESULT_MISS)] = PM_L1_ICACHE_MISS,
  434. },
  435. [C(OP_WRITE)] = {
  436. [C(RESULT_ACCESS)] = PM_INST_FROM_L1MISS,
  437. [C(RESULT_MISS)] = -1,
  438. },
  439. [C(OP_PREFETCH)] = {
  440. [C(RESULT_ACCESS)] = PM_IC_PREF_REQ,
  441. [C(RESULT_MISS)] = 0,
  442. },
  443. },
  444. [C(LL)] = {
  445. [C(OP_READ)] = {
  446. [C(RESULT_ACCESS)] = PM_DATA_FROM_L3,
  447. [C(RESULT_MISS)] = PM_DATA_FROM_L3MISS,
  448. },
  449. [C(OP_WRITE)] = {
  450. [C(RESULT_ACCESS)] = PM_L2_ST,
  451. [C(RESULT_MISS)] = PM_L2_ST_MISS,
  452. },
  453. [C(OP_PREFETCH)] = {
  454. [C(RESULT_ACCESS)] = PM_L3_PF_MISS_L3,
  455. [C(RESULT_MISS)] = 0,
  456. },
  457. },
  458. [C(DTLB)] = {
  459. [C(OP_READ)] = {
  460. [C(RESULT_ACCESS)] = 0,
  461. [C(RESULT_MISS)] = PM_DTLB_MISS,
  462. },
  463. [C(OP_WRITE)] = {
  464. [C(RESULT_ACCESS)] = -1,
  465. [C(RESULT_MISS)] = -1,
  466. },
  467. [C(OP_PREFETCH)] = {
  468. [C(RESULT_ACCESS)] = -1,
  469. [C(RESULT_MISS)] = -1,
  470. },
  471. },
  472. [C(ITLB)] = {
  473. [C(OP_READ)] = {
  474. [C(RESULT_ACCESS)] = 0,
  475. [C(RESULT_MISS)] = PM_ITLB_MISS,
  476. },
  477. [C(OP_WRITE)] = {
  478. [C(RESULT_ACCESS)] = -1,
  479. [C(RESULT_MISS)] = -1,
  480. },
  481. [C(OP_PREFETCH)] = {
  482. [C(RESULT_ACCESS)] = -1,
  483. [C(RESULT_MISS)] = -1,
  484. },
  485. },
  486. [C(BPU)] = {
  487. [C(OP_READ)] = {
  488. [C(RESULT_ACCESS)] = PM_BR_CMPL,
  489. [C(RESULT_MISS)] = PM_BR_MPRED_CMPL,
  490. },
  491. [C(OP_WRITE)] = {
  492. [C(RESULT_ACCESS)] = -1,
  493. [C(RESULT_MISS)] = -1,
  494. },
  495. [C(OP_PREFETCH)] = {
  496. [C(RESULT_ACCESS)] = -1,
  497. [C(RESULT_MISS)] = -1,
  498. },
  499. },
  500. [C(NODE)] = {
  501. [C(OP_READ)] = {
  502. [C(RESULT_ACCESS)] = -1,
  503. [C(RESULT_MISS)] = -1,
  504. },
  505. [C(OP_WRITE)] = {
  506. [C(RESULT_ACCESS)] = -1,
  507. [C(RESULT_MISS)] = -1,
  508. },
  509. [C(OP_PREFETCH)] = {
  510. [C(RESULT_ACCESS)] = -1,
  511. [C(RESULT_MISS)] = -1,
  512. },
  513. },
  514. };
  515. #undef C
  516. /*
  517. * Set the MMCR0[CC56RUN] bit to enable counting for
  518. * PMC5 and PMC6 regardless of the state of CTRL[RUN],
  519. * so that we can use counters 5 and 6 as PM_INST_CMPL and
  520. * PM_CYC.
  521. */
  522. static int power10_compute_mmcr(u64 event[], int n_ev,
  523. unsigned int hwc[], struct mmcr_regs *mmcr,
  524. struct perf_event *pevents[], u32 flags)
  525. {
  526. int ret;
  527. ret = isa207_compute_mmcr(event, n_ev, hwc, mmcr, pevents, flags);
  528. if (!ret)
  529. mmcr->mmcr0 |= MMCR0_C56RUN;
  530. return ret;
  531. }
  532. static struct power_pmu power10_pmu = {
  533. .name = "POWER10",
  534. .n_counter = MAX_PMU_COUNTERS,
  535. .add_fields = ISA207_ADD_FIELDS,
  536. .test_adder = ISA207_TEST_ADDER,
  537. .group_constraint_mask = CNST_CACHE_PMC4_MASK,
  538. .group_constraint_val = CNST_CACHE_PMC4_VAL,
  539. .compute_mmcr = power10_compute_mmcr,
  540. .config_bhrb = power10_config_bhrb,
  541. .bhrb_filter_map = power10_bhrb_filter_map,
  542. .get_constraint = isa207_get_constraint,
  543. .get_alternatives = power10_get_alternatives,
  544. .get_mem_data_src = isa207_get_mem_data_src,
  545. .get_mem_weight = isa207_get_mem_weight,
  546. .disable_pmc = isa207_disable_pmc,
  547. .flags = PPMU_HAS_SIER | PPMU_ARCH_207S |
  548. PPMU_ARCH_31 | PPMU_HAS_ATTR_CONFIG1,
  549. .n_generic = ARRAY_SIZE(power10_generic_events),
  550. .generic_events = power10_generic_events,
  551. .cache_events = &power10_cache_events,
  552. .attr_groups = power10_pmu_attr_groups,
  553. .bhrb_nr = 32,
  554. .capabilities = PERF_PMU_CAP_EXTENDED_REGS,
  555. .check_attr_config = power10_check_attr_config,
  556. };
  557. int __init init_power10_pmu(void)
  558. {
  559. unsigned int pvr;
  560. int rc;
  561. pvr = mfspr(SPRN_PVR);
  562. if (PVR_VER(pvr) != PVR_POWER10)
  563. return -ENODEV;
  564. /* Add the ppmu flag for power10 DD1 */
  565. if ((PVR_CFG(pvr) == 1))
  566. power10_pmu.flags |= PPMU_P10_DD1;
  567. /* Set the PERF_REG_EXTENDED_MASK here */
  568. PERF_REG_EXTENDED_MASK = PERF_REG_PMU_MASK_31;
  569. if ((PVR_CFG(pvr) == 1)) {
  570. power10_pmu.generic_events = power10_generic_events_dd1;
  571. power10_pmu.attr_groups = power10_pmu_attr_groups_dd1;
  572. power10_pmu.cache_events = &power10_cache_events_dd1;
  573. }
  574. rc = register_power_pmu(&power10_pmu);
  575. if (rc)
  576. return rc;
  577. /* Tell userspace that EBB is supported */
  578. cur_cpu_spec->cpu_user_features2 |= PPC_FEATURE2_EBB;
  579. return 0;
  580. }