power7-pmu.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. /*
  2. * Performance counter support for POWER7 processors.
  3. *
  4. * Copyright 2009 Paul Mackerras, IBM Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/perf_event.h>
  13. #include <linux/string.h>
  14. #include <asm/reg.h>
  15. #include <asm/cputable.h>
  16. /*
  17. * Bits in event code for POWER7
  18. */
  19. #define PM_PMC_SH 16 /* PMC number (1-based) for direct events */
  20. #define PM_PMC_MSK 0xf
  21. #define PM_PMC_MSKS (PM_PMC_MSK << PM_PMC_SH)
  22. #define PM_UNIT_SH 12 /* TTMMUX number and setting - unit select */
  23. #define PM_UNIT_MSK 0xf
  24. #define PM_COMBINE_SH 11 /* Combined event bit */
  25. #define PM_COMBINE_MSK 1
  26. #define PM_COMBINE_MSKS 0x800
  27. #define PM_L2SEL_SH 8 /* L2 event select */
  28. #define PM_L2SEL_MSK 7
  29. #define PM_PMCSEL_MSK 0xff
  30. /*
  31. * Bits in MMCR1 for POWER7
  32. */
  33. #define MMCR1_TTM0SEL_SH 60
  34. #define MMCR1_TTM1SEL_SH 56
  35. #define MMCR1_TTM2SEL_SH 52
  36. #define MMCR1_TTM3SEL_SH 48
  37. #define MMCR1_TTMSEL_MSK 0xf
  38. #define MMCR1_L2SEL_SH 45
  39. #define MMCR1_L2SEL_MSK 7
  40. #define MMCR1_PMC1_COMBINE_SH 35
  41. #define MMCR1_PMC2_COMBINE_SH 34
  42. #define MMCR1_PMC3_COMBINE_SH 33
  43. #define MMCR1_PMC4_COMBINE_SH 32
  44. #define MMCR1_PMC1SEL_SH 24
  45. #define MMCR1_PMC2SEL_SH 16
  46. #define MMCR1_PMC3SEL_SH 8
  47. #define MMCR1_PMC4SEL_SH 0
  48. #define MMCR1_PMCSEL_SH(n) (MMCR1_PMC1SEL_SH - (n) * 8)
  49. #define MMCR1_PMCSEL_MSK 0xff
  50. /*
  51. * Power7 event codes.
  52. */
  53. #define PME_PM_CYC 0x1e
  54. #define PME_PM_GCT_NOSLOT_CYC 0x100f8
  55. #define PME_PM_CMPLU_STALL 0x4000a
  56. #define PME_PM_INST_CMPL 0x2
  57. #define PME_PM_LD_REF_L1 0xc880
  58. #define PME_PM_LD_MISS_L1 0x400f0
  59. #define PME_PM_BRU_FIN 0x10068
  60. #define PME_PM_BR_MPRED 0x400f6
  61. #define PME_PM_CMPLU_STALL_FXU 0x20014
  62. #define PME_PM_CMPLU_STALL_DIV 0x40014
  63. #define PME_PM_CMPLU_STALL_SCALAR 0x40012
  64. #define PME_PM_CMPLU_STALL_SCALAR_LONG 0x20018
  65. #define PME_PM_CMPLU_STALL_VECTOR 0x2001c
  66. #define PME_PM_CMPLU_STALL_VECTOR_LONG 0x4004a
  67. #define PME_PM_CMPLU_STALL_LSU 0x20012
  68. #define PME_PM_CMPLU_STALL_REJECT 0x40016
  69. #define PME_PM_CMPLU_STALL_ERAT_MISS 0x40018
  70. #define PME_PM_CMPLU_STALL_DCACHE_MISS 0x20016
  71. #define PME_PM_CMPLU_STALL_STORE 0x2004a
  72. #define PME_PM_CMPLU_STALL_THRD 0x1001c
  73. #define PME_PM_CMPLU_STALL_IFU 0x4004c
  74. #define PME_PM_CMPLU_STALL_BRU 0x4004e
  75. #define PME_PM_GCT_NOSLOT_IC_MISS 0x2001a
  76. #define PME_PM_GCT_NOSLOT_BR_MPRED 0x4001a
  77. #define PME_PM_GCT_NOSLOT_BR_MPRED_IC_MISS 0x4001c
  78. #define PME_PM_GRP_CMPL 0x30004
  79. #define PME_PM_1PLUS_PPC_CMPL 0x100f2
  80. #define PME_PM_CMPLU_STALL_DFU 0x2003c
  81. #define PME_PM_RUN_CYC 0x200f4
  82. #define PME_PM_RUN_INST_CMPL 0x400fa
  83. /*
  84. * Layout of constraint bits:
  85. * 6666555555555544444444443333333333222222222211111111110000000000
  86. * 3210987654321098765432109876543210987654321098765432109876543210
  87. * < >< ><><><><><><>
  88. * L2 NC P6P5P4P3P2P1
  89. *
  90. * L2 - 16-18 - Required L2SEL value (select field)
  91. *
  92. * NC - number of counters
  93. * 15: NC error 0x8000
  94. * 12-14: number of events needing PMC1-4 0x7000
  95. *
  96. * P6
  97. * 11: P6 error 0x800
  98. * 10-11: Count of events needing PMC6
  99. *
  100. * P1..P5
  101. * 0-9: Count of events needing PMC1..PMC5
  102. */
  103. static int power7_get_constraint(u64 event, unsigned long *maskp,
  104. unsigned long *valp)
  105. {
  106. int pmc, sh, unit;
  107. unsigned long mask = 0, value = 0;
  108. pmc = (event >> PM_PMC_SH) & PM_PMC_MSK;
  109. if (pmc) {
  110. if (pmc > 6)
  111. return -1;
  112. sh = (pmc - 1) * 2;
  113. mask |= 2 << sh;
  114. value |= 1 << sh;
  115. if (pmc >= 5 && !(event == 0x500fa || event == 0x600f4))
  116. return -1;
  117. }
  118. if (pmc < 5) {
  119. /* need a counter from PMC1-4 set */
  120. mask |= 0x8000;
  121. value |= 0x1000;
  122. }
  123. unit = (event >> PM_UNIT_SH) & PM_UNIT_MSK;
  124. if (unit == 6) {
  125. /* L2SEL must be identical across events */
  126. int l2sel = (event >> PM_L2SEL_SH) & PM_L2SEL_MSK;
  127. mask |= 0x7 << 16;
  128. value |= l2sel << 16;
  129. }
  130. *maskp = mask;
  131. *valp = value;
  132. return 0;
  133. }
  134. #define MAX_ALT 2 /* at most 2 alternatives for any event */
  135. static const unsigned int event_alternatives[][MAX_ALT] = {
  136. { 0x200f2, 0x300f2 }, /* PM_INST_DISP */
  137. { 0x200f4, 0x600f4 }, /* PM_RUN_CYC */
  138. { 0x400fa, 0x500fa }, /* PM_RUN_INST_CMPL */
  139. };
  140. /*
  141. * Scan the alternatives table for a match and return the
  142. * index into the alternatives table if found, else -1.
  143. */
  144. static int find_alternative(u64 event)
  145. {
  146. int i, j;
  147. for (i = 0; i < ARRAY_SIZE(event_alternatives); ++i) {
  148. if (event < event_alternatives[i][0])
  149. break;
  150. for (j = 0; j < MAX_ALT && event_alternatives[i][j]; ++j)
  151. if (event == event_alternatives[i][j])
  152. return i;
  153. }
  154. return -1;
  155. }
  156. static s64 find_alternative_decode(u64 event)
  157. {
  158. int pmc, psel;
  159. /* this only handles the 4x decode events */
  160. pmc = (event >> PM_PMC_SH) & PM_PMC_MSK;
  161. psel = event & PM_PMCSEL_MSK;
  162. if ((pmc == 2 || pmc == 4) && (psel & ~7) == 0x40)
  163. return event - (1 << PM_PMC_SH) + 8;
  164. if ((pmc == 1 || pmc == 3) && (psel & ~7) == 0x48)
  165. return event + (1 << PM_PMC_SH) - 8;
  166. return -1;
  167. }
  168. static int power7_get_alternatives(u64 event, unsigned int flags, u64 alt[])
  169. {
  170. int i, j, nalt = 1;
  171. s64 ae;
  172. alt[0] = event;
  173. nalt = 1;
  174. i = find_alternative(event);
  175. if (i >= 0) {
  176. for (j = 0; j < MAX_ALT; ++j) {
  177. ae = event_alternatives[i][j];
  178. if (ae && ae != event)
  179. alt[nalt++] = ae;
  180. }
  181. } else {
  182. ae = find_alternative_decode(event);
  183. if (ae > 0)
  184. alt[nalt++] = ae;
  185. }
  186. if (flags & PPMU_ONLY_COUNT_RUN) {
  187. /*
  188. * We're only counting in RUN state,
  189. * so PM_CYC is equivalent to PM_RUN_CYC
  190. * and PM_INST_CMPL === PM_RUN_INST_CMPL.
  191. * This doesn't include alternatives that don't provide
  192. * any extra flexibility in assigning PMCs.
  193. */
  194. j = nalt;
  195. for (i = 0; i < nalt; ++i) {
  196. switch (alt[i]) {
  197. case 0x1e: /* PM_CYC */
  198. alt[j++] = 0x600f4; /* PM_RUN_CYC */
  199. break;
  200. case 0x600f4: /* PM_RUN_CYC */
  201. alt[j++] = 0x1e;
  202. break;
  203. case 0x2: /* PM_PPC_CMPL */
  204. alt[j++] = 0x500fa; /* PM_RUN_INST_CMPL */
  205. break;
  206. case 0x500fa: /* PM_RUN_INST_CMPL */
  207. alt[j++] = 0x2; /* PM_PPC_CMPL */
  208. break;
  209. }
  210. }
  211. nalt = j;
  212. }
  213. return nalt;
  214. }
  215. /*
  216. * Returns 1 if event counts things relating to marked instructions
  217. * and thus needs the MMCRA_SAMPLE_ENABLE bit set, or 0 if not.
  218. */
  219. static int power7_marked_instr_event(u64 event)
  220. {
  221. int pmc, psel;
  222. int unit;
  223. pmc = (event >> PM_PMC_SH) & PM_PMC_MSK;
  224. unit = (event >> PM_UNIT_SH) & PM_UNIT_MSK;
  225. psel = event & PM_PMCSEL_MSK & ~1; /* trim off edge/level bit */
  226. if (pmc >= 5)
  227. return 0;
  228. switch (psel >> 4) {
  229. case 2:
  230. return pmc == 2 || pmc == 4;
  231. case 3:
  232. if (psel == 0x3c)
  233. return pmc == 1;
  234. if (psel == 0x3e)
  235. return pmc != 2;
  236. return 1;
  237. case 4:
  238. case 5:
  239. return unit == 0xd;
  240. case 6:
  241. if (psel == 0x64)
  242. return pmc >= 3;
  243. case 8:
  244. return unit == 0xd;
  245. }
  246. return 0;
  247. }
  248. static int power7_compute_mmcr(u64 event[], int n_ev,
  249. unsigned int hwc[], unsigned long mmcr[])
  250. {
  251. unsigned long mmcr1 = 0;
  252. unsigned long mmcra = MMCRA_SDAR_DCACHE_MISS | MMCRA_SDAR_ERAT_MISS;
  253. unsigned int pmc, unit, combine, l2sel, psel;
  254. unsigned int pmc_inuse = 0;
  255. int i;
  256. /* First pass to count resource use */
  257. for (i = 0; i < n_ev; ++i) {
  258. pmc = (event[i] >> PM_PMC_SH) & PM_PMC_MSK;
  259. if (pmc) {
  260. if (pmc > 6)
  261. return -1;
  262. if (pmc_inuse & (1 << (pmc - 1)))
  263. return -1;
  264. pmc_inuse |= 1 << (pmc - 1);
  265. }
  266. }
  267. /* Second pass: assign PMCs, set all MMCR1 fields */
  268. for (i = 0; i < n_ev; ++i) {
  269. pmc = (event[i] >> PM_PMC_SH) & PM_PMC_MSK;
  270. unit = (event[i] >> PM_UNIT_SH) & PM_UNIT_MSK;
  271. combine = (event[i] >> PM_COMBINE_SH) & PM_COMBINE_MSK;
  272. l2sel = (event[i] >> PM_L2SEL_SH) & PM_L2SEL_MSK;
  273. psel = event[i] & PM_PMCSEL_MSK;
  274. if (!pmc) {
  275. /* Bus event or any-PMC direct event */
  276. for (pmc = 0; pmc < 4; ++pmc) {
  277. if (!(pmc_inuse & (1 << pmc)))
  278. break;
  279. }
  280. if (pmc >= 4)
  281. return -1;
  282. pmc_inuse |= 1 << pmc;
  283. } else {
  284. /* Direct or decoded event */
  285. --pmc;
  286. }
  287. if (pmc <= 3) {
  288. mmcr1 |= (unsigned long) unit
  289. << (MMCR1_TTM0SEL_SH - 4 * pmc);
  290. mmcr1 |= (unsigned long) combine
  291. << (MMCR1_PMC1_COMBINE_SH - pmc);
  292. mmcr1 |= psel << MMCR1_PMCSEL_SH(pmc);
  293. if (unit == 6) /* L2 events */
  294. mmcr1 |= (unsigned long) l2sel
  295. << MMCR1_L2SEL_SH;
  296. }
  297. if (power7_marked_instr_event(event[i]))
  298. mmcra |= MMCRA_SAMPLE_ENABLE;
  299. hwc[i] = pmc;
  300. }
  301. /* Return MMCRx values */
  302. mmcr[0] = 0;
  303. if (pmc_inuse & 1)
  304. mmcr[0] = MMCR0_PMC1CE;
  305. if (pmc_inuse & 0x3e)
  306. mmcr[0] |= MMCR0_PMCjCE;
  307. mmcr[1] = mmcr1;
  308. mmcr[2] = mmcra;
  309. return 0;
  310. }
  311. static void power7_disable_pmc(unsigned int pmc, unsigned long mmcr[])
  312. {
  313. if (pmc <= 3)
  314. mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SH(pmc));
  315. }
  316. static int power7_generic_events[] = {
  317. [PERF_COUNT_HW_CPU_CYCLES] = PME_PM_CYC,
  318. [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = PME_PM_GCT_NOSLOT_CYC,
  319. [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = PME_PM_CMPLU_STALL,
  320. [PERF_COUNT_HW_INSTRUCTIONS] = PME_PM_INST_CMPL,
  321. [PERF_COUNT_HW_CACHE_REFERENCES] = PME_PM_LD_REF_L1,
  322. [PERF_COUNT_HW_CACHE_MISSES] = PME_PM_LD_MISS_L1,
  323. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = PME_PM_BRU_FIN,
  324. [PERF_COUNT_HW_BRANCH_MISSES] = PME_PM_BR_MPRED,
  325. };
  326. #define C(x) PERF_COUNT_HW_CACHE_##x
  327. /*
  328. * Table of generalized cache-related events.
  329. * 0 means not supported, -1 means nonsensical, other values
  330. * are event codes.
  331. */
  332. static int power7_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
  333. [C(L1D)] = { /* RESULT_ACCESS RESULT_MISS */
  334. [C(OP_READ)] = { 0xc880, 0x400f0 },
  335. [C(OP_WRITE)] = { 0, 0x300f0 },
  336. [C(OP_PREFETCH)] = { 0xd8b8, 0 },
  337. },
  338. [C(L1I)] = { /* RESULT_ACCESS RESULT_MISS */
  339. [C(OP_READ)] = { 0, 0x200fc },
  340. [C(OP_WRITE)] = { -1, -1 },
  341. [C(OP_PREFETCH)] = { 0x408a, 0 },
  342. },
  343. [C(LL)] = { /* RESULT_ACCESS RESULT_MISS */
  344. [C(OP_READ)] = { 0x16080, 0x26080 },
  345. [C(OP_WRITE)] = { 0x16082, 0x26082 },
  346. [C(OP_PREFETCH)] = { 0, 0 },
  347. },
  348. [C(DTLB)] = { /* RESULT_ACCESS RESULT_MISS */
  349. [C(OP_READ)] = { 0, 0x300fc },
  350. [C(OP_WRITE)] = { -1, -1 },
  351. [C(OP_PREFETCH)] = { -1, -1 },
  352. },
  353. [C(ITLB)] = { /* RESULT_ACCESS RESULT_MISS */
  354. [C(OP_READ)] = { 0, 0x400fc },
  355. [C(OP_WRITE)] = { -1, -1 },
  356. [C(OP_PREFETCH)] = { -1, -1 },
  357. },
  358. [C(BPU)] = { /* RESULT_ACCESS RESULT_MISS */
  359. [C(OP_READ)] = { 0x10068, 0x400f6 },
  360. [C(OP_WRITE)] = { -1, -1 },
  361. [C(OP_PREFETCH)] = { -1, -1 },
  362. },
  363. [C(NODE)] = { /* RESULT_ACCESS RESULT_MISS */
  364. [C(OP_READ)] = { -1, -1 },
  365. [C(OP_WRITE)] = { -1, -1 },
  366. [C(OP_PREFETCH)] = { -1, -1 },
  367. },
  368. };
  369. GENERIC_EVENT_ATTR(cpu-cycles, CYC);
  370. GENERIC_EVENT_ATTR(stalled-cycles-frontend, GCT_NOSLOT_CYC);
  371. GENERIC_EVENT_ATTR(stalled-cycles-backend, CMPLU_STALL);
  372. GENERIC_EVENT_ATTR(instructions, INST_CMPL);
  373. GENERIC_EVENT_ATTR(cache-references, LD_REF_L1);
  374. GENERIC_EVENT_ATTR(cache-misses, LD_MISS_L1);
  375. GENERIC_EVENT_ATTR(branch-instructions, BRU_FIN);
  376. GENERIC_EVENT_ATTR(branch-misses, BR_MPRED);
  377. POWER_EVENT_ATTR(CYC, CYC);
  378. POWER_EVENT_ATTR(GCT_NOSLOT_CYC, GCT_NOSLOT_CYC);
  379. POWER_EVENT_ATTR(CMPLU_STALL, CMPLU_STALL);
  380. POWER_EVENT_ATTR(INST_CMPL, INST_CMPL);
  381. POWER_EVENT_ATTR(LD_REF_L1, LD_REF_L1);
  382. POWER_EVENT_ATTR(LD_MISS_L1, LD_MISS_L1);
  383. POWER_EVENT_ATTR(BRU_FIN, BRU_FIN)
  384. POWER_EVENT_ATTR(BR_MPRED, BR_MPRED);
  385. POWER_EVENT_ATTR(CMPLU_STALL_FXU, CMPLU_STALL_FXU);
  386. POWER_EVENT_ATTR(CMPLU_STALL_DIV, CMPLU_STALL_DIV);
  387. POWER_EVENT_ATTR(CMPLU_STALL_SCALAR, CMPLU_STALL_SCALAR);
  388. POWER_EVENT_ATTR(CMPLU_STALL_SCALAR_LONG, CMPLU_STALL_SCALAR_LONG);
  389. POWER_EVENT_ATTR(CMPLU_STALL_VECTOR, CMPLU_STALL_VECTOR);
  390. POWER_EVENT_ATTR(CMPLU_STALL_VECTOR_LONG, CMPLU_STALL_VECTOR_LONG);
  391. POWER_EVENT_ATTR(CMPLU_STALL_LSU, CMPLU_STALL_LSU);
  392. POWER_EVENT_ATTR(CMPLU_STALL_REJECT, CMPLU_STALL_REJECT);
  393. POWER_EVENT_ATTR(CMPLU_STALL_ERAT_MISS, CMPLU_STALL_ERAT_MISS);
  394. POWER_EVENT_ATTR(CMPLU_STALL_DCACHE_MISS, CMPLU_STALL_DCACHE_MISS);
  395. POWER_EVENT_ATTR(CMPLU_STALL_STORE, CMPLU_STALL_STORE);
  396. POWER_EVENT_ATTR(CMPLU_STALL_THRD, CMPLU_STALL_THRD);
  397. POWER_EVENT_ATTR(CMPLU_STALL_IFU, CMPLU_STALL_IFU);
  398. POWER_EVENT_ATTR(CMPLU_STALL_BRU, CMPLU_STALL_BRU);
  399. POWER_EVENT_ATTR(GCT_NOSLOT_IC_MISS, GCT_NOSLOT_IC_MISS);
  400. POWER_EVENT_ATTR(GCT_NOSLOT_BR_MPRED, GCT_NOSLOT_BR_MPRED);
  401. POWER_EVENT_ATTR(GCT_NOSLOT_BR_MPRED_IC_MISS, GCT_NOSLOT_BR_MPRED_IC_MISS);
  402. POWER_EVENT_ATTR(GRP_CMPL, GRP_CMPL);
  403. POWER_EVENT_ATTR(1PLUS_PPC_CMPL, 1PLUS_PPC_CMPL);
  404. POWER_EVENT_ATTR(CMPLU_STALL_DFU, CMPLU_STALL_DFU);
  405. POWER_EVENT_ATTR(RUN_CYC, RUN_CYC);
  406. POWER_EVENT_ATTR(RUN_INST_CMPL, RUN_INST_CMPL);
  407. static struct attribute *power7_events_attr[] = {
  408. GENERIC_EVENT_PTR(CYC),
  409. GENERIC_EVENT_PTR(GCT_NOSLOT_CYC),
  410. GENERIC_EVENT_PTR(CMPLU_STALL),
  411. GENERIC_EVENT_PTR(INST_CMPL),
  412. GENERIC_EVENT_PTR(LD_REF_L1),
  413. GENERIC_EVENT_PTR(LD_MISS_L1),
  414. GENERIC_EVENT_PTR(BRU_FIN),
  415. GENERIC_EVENT_PTR(BR_MPRED),
  416. POWER_EVENT_PTR(CYC),
  417. POWER_EVENT_PTR(GCT_NOSLOT_CYC),
  418. POWER_EVENT_PTR(CMPLU_STALL),
  419. POWER_EVENT_PTR(INST_CMPL),
  420. POWER_EVENT_PTR(LD_REF_L1),
  421. POWER_EVENT_PTR(LD_MISS_L1),
  422. POWER_EVENT_PTR(BRU_FIN),
  423. POWER_EVENT_PTR(BR_MPRED),
  424. POWER_EVENT_PTR(CMPLU_STALL_FXU),
  425. POWER_EVENT_PTR(CMPLU_STALL_DIV),
  426. POWER_EVENT_PTR(CMPLU_STALL_SCALAR),
  427. POWER_EVENT_PTR(CMPLU_STALL_SCALAR_LONG),
  428. POWER_EVENT_PTR(CMPLU_STALL_VECTOR),
  429. POWER_EVENT_PTR(CMPLU_STALL_VECTOR_LONG),
  430. POWER_EVENT_PTR(CMPLU_STALL_LSU),
  431. POWER_EVENT_PTR(CMPLU_STALL_REJECT),
  432. POWER_EVENT_PTR(CMPLU_STALL_ERAT_MISS),
  433. POWER_EVENT_PTR(CMPLU_STALL_DCACHE_MISS),
  434. POWER_EVENT_PTR(CMPLU_STALL_STORE),
  435. POWER_EVENT_PTR(CMPLU_STALL_THRD),
  436. POWER_EVENT_PTR(CMPLU_STALL_IFU),
  437. POWER_EVENT_PTR(CMPLU_STALL_BRU),
  438. POWER_EVENT_PTR(GCT_NOSLOT_IC_MISS),
  439. POWER_EVENT_PTR(GCT_NOSLOT_BR_MPRED),
  440. POWER_EVENT_PTR(GCT_NOSLOT_BR_MPRED_IC_MISS),
  441. POWER_EVENT_PTR(GRP_CMPL),
  442. POWER_EVENT_PTR(1PLUS_PPC_CMPL),
  443. POWER_EVENT_PTR(CMPLU_STALL_DFU),
  444. POWER_EVENT_PTR(RUN_CYC),
  445. POWER_EVENT_PTR(RUN_INST_CMPL),
  446. NULL
  447. };
  448. static struct attribute_group power7_pmu_events_group = {
  449. .name = "events",
  450. .attrs = power7_events_attr,
  451. };
  452. PMU_FORMAT_ATTR(event, "config:0-19");
  453. static struct attribute *power7_pmu_format_attr[] = {
  454. &format_attr_event.attr,
  455. NULL,
  456. };
  457. struct attribute_group power7_pmu_format_group = {
  458. .name = "format",
  459. .attrs = power7_pmu_format_attr,
  460. };
  461. static const struct attribute_group *power7_pmu_attr_groups[] = {
  462. &power7_pmu_format_group,
  463. &power7_pmu_events_group,
  464. NULL,
  465. };
  466. static struct power_pmu power7_pmu = {
  467. .name = "POWER7",
  468. .n_counter = 6,
  469. .max_alternatives = MAX_ALT + 1,
  470. .add_fields = 0x1555ul,
  471. .test_adder = 0x3000ul,
  472. .compute_mmcr = power7_compute_mmcr,
  473. .get_constraint = power7_get_constraint,
  474. .get_alternatives = power7_get_alternatives,
  475. .disable_pmc = power7_disable_pmc,
  476. .flags = PPMU_ALT_SIPR,
  477. .attr_groups = power7_pmu_attr_groups,
  478. .n_generic = ARRAY_SIZE(power7_generic_events),
  479. .generic_events = power7_generic_events,
  480. .cache_events = &power7_cache_events,
  481. };
  482. static int __init init_power7_pmu(void)
  483. {
  484. if (!cur_cpu_spec->oprofile_cpu_type ||
  485. strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power7"))
  486. return -ENODEV;
  487. if (pvr_version_is(PVR_POWER7p))
  488. power7_pmu.flags |= PPMU_SIAR_VALID;
  489. return register_power_pmu(&power7_pmu);
  490. }
  491. early_initcall(init_power7_pmu);