perf_event_intel.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. #ifdef CONFIG_CPU_SUP_INTEL
  2. /*
  3. * Intel PerfMon, used on Core and later.
  4. */
  5. static const u64 intel_perfmon_event_map[] =
  6. {
  7. [PERF_COUNT_HW_CPU_CYCLES] = 0x003c,
  8. [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0,
  9. [PERF_COUNT_HW_CACHE_REFERENCES] = 0x4f2e,
  10. [PERF_COUNT_HW_CACHE_MISSES] = 0x412e,
  11. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c4,
  12. [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c5,
  13. [PERF_COUNT_HW_BUS_CYCLES] = 0x013c,
  14. };
  15. static struct event_constraint intel_core_event_constraints[] =
  16. {
  17. INTEL_EVENT_CONSTRAINT(0x11, 0x2), /* FP_ASSIST */
  18. INTEL_EVENT_CONSTRAINT(0x12, 0x2), /* MUL */
  19. INTEL_EVENT_CONSTRAINT(0x13, 0x2), /* DIV */
  20. INTEL_EVENT_CONSTRAINT(0x14, 0x1), /* CYCLES_DIV_BUSY */
  21. INTEL_EVENT_CONSTRAINT(0x19, 0x2), /* DELAYED_BYPASS */
  22. INTEL_EVENT_CONSTRAINT(0xc1, 0x1), /* FP_COMP_INSTR_RET */
  23. EVENT_CONSTRAINT_END
  24. };
  25. static struct event_constraint intel_core2_event_constraints[] =
  26. {
  27. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  28. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  29. /*
  30. * Core2 has Fixed Counter 2 listed as CPU_CLK_UNHALTED.REF and event
  31. * 0x013c as CPU_CLK_UNHALTED.BUS and specifies there is a fixed
  32. * ratio between these counters.
  33. */
  34. /* FIXED_EVENT_CONSTRAINT(0x013c, 2), CPU_CLK_UNHALTED.REF */
  35. INTEL_EVENT_CONSTRAINT(0x10, 0x1), /* FP_COMP_OPS_EXE */
  36. INTEL_EVENT_CONSTRAINT(0x11, 0x2), /* FP_ASSIST */
  37. INTEL_EVENT_CONSTRAINT(0x12, 0x2), /* MUL */
  38. INTEL_EVENT_CONSTRAINT(0x13, 0x2), /* DIV */
  39. INTEL_EVENT_CONSTRAINT(0x14, 0x1), /* CYCLES_DIV_BUSY */
  40. INTEL_EVENT_CONSTRAINT(0x18, 0x1), /* IDLE_DURING_DIV */
  41. INTEL_EVENT_CONSTRAINT(0x19, 0x2), /* DELAYED_BYPASS */
  42. INTEL_EVENT_CONSTRAINT(0xa1, 0x1), /* RS_UOPS_DISPATCH_CYCLES */
  43. INTEL_EVENT_CONSTRAINT(0xc9, 0x1), /* ITLB_MISS_RETIRED (T30-9) */
  44. INTEL_EVENT_CONSTRAINT(0xcb, 0x1), /* MEM_LOAD_RETIRED */
  45. EVENT_CONSTRAINT_END
  46. };
  47. static struct event_constraint intel_nehalem_event_constraints[] =
  48. {
  49. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  50. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  51. /* FIXED_EVENT_CONSTRAINT(0x013c, 2), CPU_CLK_UNHALTED.REF */
  52. INTEL_EVENT_CONSTRAINT(0x40, 0x3), /* L1D_CACHE_LD */
  53. INTEL_EVENT_CONSTRAINT(0x41, 0x3), /* L1D_CACHE_ST */
  54. INTEL_EVENT_CONSTRAINT(0x42, 0x3), /* L1D_CACHE_LOCK */
  55. INTEL_EVENT_CONSTRAINT(0x43, 0x3), /* L1D_ALL_REF */
  56. INTEL_EVENT_CONSTRAINT(0x48, 0x3), /* L1D_PEND_MISS */
  57. INTEL_EVENT_CONSTRAINT(0x4e, 0x3), /* L1D_PREFETCH */
  58. INTEL_EVENT_CONSTRAINT(0x51, 0x3), /* L1D */
  59. INTEL_EVENT_CONSTRAINT(0x63, 0x3), /* CACHE_LOCK_CYCLES */
  60. EVENT_CONSTRAINT_END
  61. };
  62. static struct event_constraint intel_westmere_event_constraints[] =
  63. {
  64. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  65. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  66. /* FIXED_EVENT_CONSTRAINT(0x013c, 2), CPU_CLK_UNHALTED.REF */
  67. INTEL_EVENT_CONSTRAINT(0x51, 0x3), /* L1D */
  68. INTEL_EVENT_CONSTRAINT(0x60, 0x1), /* OFFCORE_REQUESTS_OUTSTANDING */
  69. INTEL_EVENT_CONSTRAINT(0x63, 0x3), /* CACHE_LOCK_CYCLES */
  70. INTEL_EVENT_CONSTRAINT(0xb3, 0x1), /* SNOOPQ_REQUEST_OUTSTANDING */
  71. EVENT_CONSTRAINT_END
  72. };
  73. static struct event_constraint intel_snb_event_constraints[] =
  74. {
  75. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  76. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  77. /* FIXED_EVENT_CONSTRAINT(0x013c, 2), CPU_CLK_UNHALTED.REF */
  78. INTEL_EVENT_CONSTRAINT(0x48, 0x4), /* L1D_PEND_MISS.PENDING */
  79. INTEL_EVENT_CONSTRAINT(0xb7, 0x1), /* OFF_CORE_RESPONSE_0 */
  80. INTEL_EVENT_CONSTRAINT(0xbb, 0x8), /* OFF_CORE_RESPONSE_1 */
  81. INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */
  82. INTEL_EVENT_CONSTRAINT(0xcd, 0x8), /* MEM_TRANS_RETIRED.LOAD_LATENCY */
  83. EVENT_CONSTRAINT_END
  84. };
  85. static struct event_constraint intel_gen_event_constraints[] =
  86. {
  87. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  88. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  89. /* FIXED_EVENT_CONSTRAINT(0x013c, 2), CPU_CLK_UNHALTED.REF */
  90. EVENT_CONSTRAINT_END
  91. };
  92. static u64 intel_pmu_event_map(int hw_event)
  93. {
  94. return intel_perfmon_event_map[hw_event];
  95. }
  96. static __initconst const u64 snb_hw_cache_event_ids
  97. [PERF_COUNT_HW_CACHE_MAX]
  98. [PERF_COUNT_HW_CACHE_OP_MAX]
  99. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  100. {
  101. [ C(L1D) ] = {
  102. [ C(OP_READ) ] = {
  103. [ C(RESULT_ACCESS) ] = 0xf1d0, /* MEM_UOP_RETIRED.LOADS */
  104. [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPLACEMENT */
  105. },
  106. [ C(OP_WRITE) ] = {
  107. [ C(RESULT_ACCESS) ] = 0xf2d0, /* MEM_UOP_RETIRED.STORES */
  108. [ C(RESULT_MISS) ] = 0x0851, /* L1D.ALL_M_REPLACEMENT */
  109. },
  110. [ C(OP_PREFETCH) ] = {
  111. [ C(RESULT_ACCESS) ] = 0x0,
  112. [ C(RESULT_MISS) ] = 0x024e, /* HW_PRE_REQ.DL1_MISS */
  113. },
  114. },
  115. [ C(L1I ) ] = {
  116. [ C(OP_READ) ] = {
  117. [ C(RESULT_ACCESS) ] = 0x0,
  118. [ C(RESULT_MISS) ] = 0x0280, /* ICACHE.MISSES */
  119. },
  120. [ C(OP_WRITE) ] = {
  121. [ C(RESULT_ACCESS) ] = -1,
  122. [ C(RESULT_MISS) ] = -1,
  123. },
  124. [ C(OP_PREFETCH) ] = {
  125. [ C(RESULT_ACCESS) ] = 0x0,
  126. [ C(RESULT_MISS) ] = 0x0,
  127. },
  128. },
  129. [ C(LL ) ] = {
  130. /*
  131. * TBD: Need Off-core Response Performance Monitoring support
  132. */
  133. [ C(OP_READ) ] = {
  134. /* OFFCORE_RESPONSE_0.ANY_DATA.LOCAL_CACHE */
  135. [ C(RESULT_ACCESS) ] = 0x01b7,
  136. /* OFFCORE_RESPONSE_1.ANY_DATA.ANY_LLC_MISS */
  137. [ C(RESULT_MISS) ] = 0x01bb,
  138. },
  139. [ C(OP_WRITE) ] = {
  140. /* OFFCORE_RESPONSE_0.ANY_RFO.LOCAL_CACHE */
  141. [ C(RESULT_ACCESS) ] = 0x01b7,
  142. /* OFFCORE_RESPONSE_1.ANY_RFO.ANY_LLC_MISS */
  143. [ C(RESULT_MISS) ] = 0x01bb,
  144. },
  145. [ C(OP_PREFETCH) ] = {
  146. /* OFFCORE_RESPONSE_0.PREFETCH.LOCAL_CACHE */
  147. [ C(RESULT_ACCESS) ] = 0x01b7,
  148. /* OFFCORE_RESPONSE_1.PREFETCH.ANY_LLC_MISS */
  149. [ C(RESULT_MISS) ] = 0x01bb,
  150. },
  151. },
  152. [ C(DTLB) ] = {
  153. [ C(OP_READ) ] = {
  154. [ C(RESULT_ACCESS) ] = 0x81d0, /* MEM_UOP_RETIRED.ALL_LOADS */
  155. [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.CAUSES_A_WALK */
  156. },
  157. [ C(OP_WRITE) ] = {
  158. [ C(RESULT_ACCESS) ] = 0x82d0, /* MEM_UOP_RETIRED.ALL_STORES */
  159. [ C(RESULT_MISS) ] = 0x0149, /* DTLB_STORE_MISSES.MISS_CAUSES_A_WALK */
  160. },
  161. [ C(OP_PREFETCH) ] = {
  162. [ C(RESULT_ACCESS) ] = 0x0,
  163. [ C(RESULT_MISS) ] = 0x0,
  164. },
  165. },
  166. [ C(ITLB) ] = {
  167. [ C(OP_READ) ] = {
  168. [ C(RESULT_ACCESS) ] = 0x1085, /* ITLB_MISSES.STLB_HIT */
  169. [ C(RESULT_MISS) ] = 0x0185, /* ITLB_MISSES.CAUSES_A_WALK */
  170. },
  171. [ C(OP_WRITE) ] = {
  172. [ C(RESULT_ACCESS) ] = -1,
  173. [ C(RESULT_MISS) ] = -1,
  174. },
  175. [ C(OP_PREFETCH) ] = {
  176. [ C(RESULT_ACCESS) ] = -1,
  177. [ C(RESULT_MISS) ] = -1,
  178. },
  179. },
  180. [ C(BPU ) ] = {
  181. [ C(OP_READ) ] = {
  182. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */
  183. [ C(RESULT_MISS) ] = 0x00c5, /* BR_MISP_RETIRED.ALL_BRANCHES */
  184. },
  185. [ C(OP_WRITE) ] = {
  186. [ C(RESULT_ACCESS) ] = -1,
  187. [ C(RESULT_MISS) ] = -1,
  188. },
  189. [ C(OP_PREFETCH) ] = {
  190. [ C(RESULT_ACCESS) ] = -1,
  191. [ C(RESULT_MISS) ] = -1,
  192. },
  193. },
  194. };
  195. static __initconst const u64 westmere_hw_cache_event_ids
  196. [PERF_COUNT_HW_CACHE_MAX]
  197. [PERF_COUNT_HW_CACHE_OP_MAX]
  198. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  199. {
  200. [ C(L1D) ] = {
  201. [ C(OP_READ) ] = {
  202. [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */
  203. [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPL */
  204. },
  205. [ C(OP_WRITE) ] = {
  206. [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */
  207. [ C(RESULT_MISS) ] = 0x0251, /* L1D.M_REPL */
  208. },
  209. [ C(OP_PREFETCH) ] = {
  210. [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */
  211. [ C(RESULT_MISS) ] = 0x024e, /* L1D_PREFETCH.MISS */
  212. },
  213. },
  214. [ C(L1I ) ] = {
  215. [ C(OP_READ) ] = {
  216. [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */
  217. [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */
  218. },
  219. [ C(OP_WRITE) ] = {
  220. [ C(RESULT_ACCESS) ] = -1,
  221. [ C(RESULT_MISS) ] = -1,
  222. },
  223. [ C(OP_PREFETCH) ] = {
  224. [ C(RESULT_ACCESS) ] = 0x0,
  225. [ C(RESULT_MISS) ] = 0x0,
  226. },
  227. },
  228. [ C(LL ) ] = {
  229. [ C(OP_READ) ] = {
  230. [ C(RESULT_ACCESS) ] = 0x0324, /* L2_RQSTS.LOADS */
  231. [ C(RESULT_MISS) ] = 0x0224, /* L2_RQSTS.LD_MISS */
  232. },
  233. [ C(OP_WRITE) ] = {
  234. [ C(RESULT_ACCESS) ] = 0x0c24, /* L2_RQSTS.RFOS */
  235. [ C(RESULT_MISS) ] = 0x0824, /* L2_RQSTS.RFO_MISS */
  236. },
  237. [ C(OP_PREFETCH) ] = {
  238. [ C(RESULT_ACCESS) ] = 0x4f2e, /* LLC Reference */
  239. [ C(RESULT_MISS) ] = 0x412e, /* LLC Misses */
  240. },
  241. },
  242. [ C(DTLB) ] = {
  243. [ C(OP_READ) ] = {
  244. [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */
  245. [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.ANY */
  246. },
  247. [ C(OP_WRITE) ] = {
  248. [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */
  249. [ C(RESULT_MISS) ] = 0x010c, /* MEM_STORE_RETIRED.DTLB_MISS */
  250. },
  251. [ C(OP_PREFETCH) ] = {
  252. [ C(RESULT_ACCESS) ] = 0x0,
  253. [ C(RESULT_MISS) ] = 0x0,
  254. },
  255. },
  256. [ C(ITLB) ] = {
  257. [ C(OP_READ) ] = {
  258. [ C(RESULT_ACCESS) ] = 0x01c0, /* INST_RETIRED.ANY_P */
  259. [ C(RESULT_MISS) ] = 0x0185, /* ITLB_MISSES.ANY */
  260. },
  261. [ C(OP_WRITE) ] = {
  262. [ C(RESULT_ACCESS) ] = -1,
  263. [ C(RESULT_MISS) ] = -1,
  264. },
  265. [ C(OP_PREFETCH) ] = {
  266. [ C(RESULT_ACCESS) ] = -1,
  267. [ C(RESULT_MISS) ] = -1,
  268. },
  269. },
  270. [ C(BPU ) ] = {
  271. [ C(OP_READ) ] = {
  272. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */
  273. [ C(RESULT_MISS) ] = 0x03e8, /* BPU_CLEARS.ANY */
  274. },
  275. [ C(OP_WRITE) ] = {
  276. [ C(RESULT_ACCESS) ] = -1,
  277. [ C(RESULT_MISS) ] = -1,
  278. },
  279. [ C(OP_PREFETCH) ] = {
  280. [ C(RESULT_ACCESS) ] = -1,
  281. [ C(RESULT_MISS) ] = -1,
  282. },
  283. },
  284. };
  285. static __initconst const u64 nehalem_hw_cache_event_ids
  286. [PERF_COUNT_HW_CACHE_MAX]
  287. [PERF_COUNT_HW_CACHE_OP_MAX]
  288. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  289. {
  290. [ C(L1D) ] = {
  291. [ C(OP_READ) ] = {
  292. [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI */
  293. [ C(RESULT_MISS) ] = 0x0140, /* L1D_CACHE_LD.I_STATE */
  294. },
  295. [ C(OP_WRITE) ] = {
  296. [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI */
  297. [ C(RESULT_MISS) ] = 0x0141, /* L1D_CACHE_ST.I_STATE */
  298. },
  299. [ C(OP_PREFETCH) ] = {
  300. [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */
  301. [ C(RESULT_MISS) ] = 0x024e, /* L1D_PREFETCH.MISS */
  302. },
  303. },
  304. [ C(L1I ) ] = {
  305. [ C(OP_READ) ] = {
  306. [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */
  307. [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */
  308. },
  309. [ C(OP_WRITE) ] = {
  310. [ C(RESULT_ACCESS) ] = -1,
  311. [ C(RESULT_MISS) ] = -1,
  312. },
  313. [ C(OP_PREFETCH) ] = {
  314. [ C(RESULT_ACCESS) ] = 0x0,
  315. [ C(RESULT_MISS) ] = 0x0,
  316. },
  317. },
  318. [ C(LL ) ] = {
  319. [ C(OP_READ) ] = {
  320. [ C(RESULT_ACCESS) ] = 0x0324, /* L2_RQSTS.LOADS */
  321. [ C(RESULT_MISS) ] = 0x0224, /* L2_RQSTS.LD_MISS */
  322. },
  323. [ C(OP_WRITE) ] = {
  324. [ C(RESULT_ACCESS) ] = 0x0c24, /* L2_RQSTS.RFOS */
  325. [ C(RESULT_MISS) ] = 0x0824, /* L2_RQSTS.RFO_MISS */
  326. },
  327. [ C(OP_PREFETCH) ] = {
  328. [ C(RESULT_ACCESS) ] = 0x4f2e, /* LLC Reference */
  329. [ C(RESULT_MISS) ] = 0x412e, /* LLC Misses */
  330. },
  331. },
  332. [ C(DTLB) ] = {
  333. [ C(OP_READ) ] = {
  334. [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI (alias) */
  335. [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.ANY */
  336. },
  337. [ C(OP_WRITE) ] = {
  338. [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI (alias) */
  339. [ C(RESULT_MISS) ] = 0x010c, /* MEM_STORE_RETIRED.DTLB_MISS */
  340. },
  341. [ C(OP_PREFETCH) ] = {
  342. [ C(RESULT_ACCESS) ] = 0x0,
  343. [ C(RESULT_MISS) ] = 0x0,
  344. },
  345. },
  346. [ C(ITLB) ] = {
  347. [ C(OP_READ) ] = {
  348. [ C(RESULT_ACCESS) ] = 0x01c0, /* INST_RETIRED.ANY_P */
  349. [ C(RESULT_MISS) ] = 0x20c8, /* ITLB_MISS_RETIRED */
  350. },
  351. [ C(OP_WRITE) ] = {
  352. [ C(RESULT_ACCESS) ] = -1,
  353. [ C(RESULT_MISS) ] = -1,
  354. },
  355. [ C(OP_PREFETCH) ] = {
  356. [ C(RESULT_ACCESS) ] = -1,
  357. [ C(RESULT_MISS) ] = -1,
  358. },
  359. },
  360. [ C(BPU ) ] = {
  361. [ C(OP_READ) ] = {
  362. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */
  363. [ C(RESULT_MISS) ] = 0x03e8, /* BPU_CLEARS.ANY */
  364. },
  365. [ C(OP_WRITE) ] = {
  366. [ C(RESULT_ACCESS) ] = -1,
  367. [ C(RESULT_MISS) ] = -1,
  368. },
  369. [ C(OP_PREFETCH) ] = {
  370. [ C(RESULT_ACCESS) ] = -1,
  371. [ C(RESULT_MISS) ] = -1,
  372. },
  373. },
  374. };
  375. static __initconst const u64 core2_hw_cache_event_ids
  376. [PERF_COUNT_HW_CACHE_MAX]
  377. [PERF_COUNT_HW_CACHE_OP_MAX]
  378. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  379. {
  380. [ C(L1D) ] = {
  381. [ C(OP_READ) ] = {
  382. [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI */
  383. [ C(RESULT_MISS) ] = 0x0140, /* L1D_CACHE_LD.I_STATE */
  384. },
  385. [ C(OP_WRITE) ] = {
  386. [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI */
  387. [ C(RESULT_MISS) ] = 0x0141, /* L1D_CACHE_ST.I_STATE */
  388. },
  389. [ C(OP_PREFETCH) ] = {
  390. [ C(RESULT_ACCESS) ] = 0x104e, /* L1D_PREFETCH.REQUESTS */
  391. [ C(RESULT_MISS) ] = 0,
  392. },
  393. },
  394. [ C(L1I ) ] = {
  395. [ C(OP_READ) ] = {
  396. [ C(RESULT_ACCESS) ] = 0x0080, /* L1I.READS */
  397. [ C(RESULT_MISS) ] = 0x0081, /* L1I.MISSES */
  398. },
  399. [ C(OP_WRITE) ] = {
  400. [ C(RESULT_ACCESS) ] = -1,
  401. [ C(RESULT_MISS) ] = -1,
  402. },
  403. [ C(OP_PREFETCH) ] = {
  404. [ C(RESULT_ACCESS) ] = 0,
  405. [ C(RESULT_MISS) ] = 0,
  406. },
  407. },
  408. [ C(LL ) ] = {
  409. [ C(OP_READ) ] = {
  410. [ C(RESULT_ACCESS) ] = 0x4f29, /* L2_LD.MESI */
  411. [ C(RESULT_MISS) ] = 0x4129, /* L2_LD.ISTATE */
  412. },
  413. [ C(OP_WRITE) ] = {
  414. [ C(RESULT_ACCESS) ] = 0x4f2A, /* L2_ST.MESI */
  415. [ C(RESULT_MISS) ] = 0x412A, /* L2_ST.ISTATE */
  416. },
  417. [ C(OP_PREFETCH) ] = {
  418. [ C(RESULT_ACCESS) ] = 0,
  419. [ C(RESULT_MISS) ] = 0,
  420. },
  421. },
  422. [ C(DTLB) ] = {
  423. [ C(OP_READ) ] = {
  424. [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI (alias) */
  425. [ C(RESULT_MISS) ] = 0x0208, /* DTLB_MISSES.MISS_LD */
  426. },
  427. [ C(OP_WRITE) ] = {
  428. [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI (alias) */
  429. [ C(RESULT_MISS) ] = 0x0808, /* DTLB_MISSES.MISS_ST */
  430. },
  431. [ C(OP_PREFETCH) ] = {
  432. [ C(RESULT_ACCESS) ] = 0,
  433. [ C(RESULT_MISS) ] = 0,
  434. },
  435. },
  436. [ C(ITLB) ] = {
  437. [ C(OP_READ) ] = {
  438. [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */
  439. [ C(RESULT_MISS) ] = 0x1282, /* ITLBMISSES */
  440. },
  441. [ C(OP_WRITE) ] = {
  442. [ C(RESULT_ACCESS) ] = -1,
  443. [ C(RESULT_MISS) ] = -1,
  444. },
  445. [ C(OP_PREFETCH) ] = {
  446. [ C(RESULT_ACCESS) ] = -1,
  447. [ C(RESULT_MISS) ] = -1,
  448. },
  449. },
  450. [ C(BPU ) ] = {
  451. [ C(OP_READ) ] = {
  452. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */
  453. [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */
  454. },
  455. [ C(OP_WRITE) ] = {
  456. [ C(RESULT_ACCESS) ] = -1,
  457. [ C(RESULT_MISS) ] = -1,
  458. },
  459. [ C(OP_PREFETCH) ] = {
  460. [ C(RESULT_ACCESS) ] = -1,
  461. [ C(RESULT_MISS) ] = -1,
  462. },
  463. },
  464. };
  465. static __initconst const u64 atom_hw_cache_event_ids
  466. [PERF_COUNT_HW_CACHE_MAX]
  467. [PERF_COUNT_HW_CACHE_OP_MAX]
  468. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  469. {
  470. [ C(L1D) ] = {
  471. [ C(OP_READ) ] = {
  472. [ C(RESULT_ACCESS) ] = 0x2140, /* L1D_CACHE.LD */
  473. [ C(RESULT_MISS) ] = 0,
  474. },
  475. [ C(OP_WRITE) ] = {
  476. [ C(RESULT_ACCESS) ] = 0x2240, /* L1D_CACHE.ST */
  477. [ C(RESULT_MISS) ] = 0,
  478. },
  479. [ C(OP_PREFETCH) ] = {
  480. [ C(RESULT_ACCESS) ] = 0x0,
  481. [ C(RESULT_MISS) ] = 0,
  482. },
  483. },
  484. [ C(L1I ) ] = {
  485. [ C(OP_READ) ] = {
  486. [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */
  487. [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */
  488. },
  489. [ C(OP_WRITE) ] = {
  490. [ C(RESULT_ACCESS) ] = -1,
  491. [ C(RESULT_MISS) ] = -1,
  492. },
  493. [ C(OP_PREFETCH) ] = {
  494. [ C(RESULT_ACCESS) ] = 0,
  495. [ C(RESULT_MISS) ] = 0,
  496. },
  497. },
  498. [ C(LL ) ] = {
  499. [ C(OP_READ) ] = {
  500. [ C(RESULT_ACCESS) ] = 0x4f29, /* L2_LD.MESI */
  501. [ C(RESULT_MISS) ] = 0x4129, /* L2_LD.ISTATE */
  502. },
  503. [ C(OP_WRITE) ] = {
  504. [ C(RESULT_ACCESS) ] = 0x4f2A, /* L2_ST.MESI */
  505. [ C(RESULT_MISS) ] = 0x412A, /* L2_ST.ISTATE */
  506. },
  507. [ C(OP_PREFETCH) ] = {
  508. [ C(RESULT_ACCESS) ] = 0,
  509. [ C(RESULT_MISS) ] = 0,
  510. },
  511. },
  512. [ C(DTLB) ] = {
  513. [ C(OP_READ) ] = {
  514. [ C(RESULT_ACCESS) ] = 0x2140, /* L1D_CACHE_LD.MESI (alias) */
  515. [ C(RESULT_MISS) ] = 0x0508, /* DTLB_MISSES.MISS_LD */
  516. },
  517. [ C(OP_WRITE) ] = {
  518. [ C(RESULT_ACCESS) ] = 0x2240, /* L1D_CACHE_ST.MESI (alias) */
  519. [ C(RESULT_MISS) ] = 0x0608, /* DTLB_MISSES.MISS_ST */
  520. },
  521. [ C(OP_PREFETCH) ] = {
  522. [ C(RESULT_ACCESS) ] = 0,
  523. [ C(RESULT_MISS) ] = 0,
  524. },
  525. },
  526. [ C(ITLB) ] = {
  527. [ C(OP_READ) ] = {
  528. [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */
  529. [ C(RESULT_MISS) ] = 0x0282, /* ITLB.MISSES */
  530. },
  531. [ C(OP_WRITE) ] = {
  532. [ C(RESULT_ACCESS) ] = -1,
  533. [ C(RESULT_MISS) ] = -1,
  534. },
  535. [ C(OP_PREFETCH) ] = {
  536. [ C(RESULT_ACCESS) ] = -1,
  537. [ C(RESULT_MISS) ] = -1,
  538. },
  539. },
  540. [ C(BPU ) ] = {
  541. [ C(OP_READ) ] = {
  542. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */
  543. [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */
  544. },
  545. [ C(OP_WRITE) ] = {
  546. [ C(RESULT_ACCESS) ] = -1,
  547. [ C(RESULT_MISS) ] = -1,
  548. },
  549. [ C(OP_PREFETCH) ] = {
  550. [ C(RESULT_ACCESS) ] = -1,
  551. [ C(RESULT_MISS) ] = -1,
  552. },
  553. },
  554. };
  555. static void intel_pmu_disable_all(void)
  556. {
  557. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  558. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0);
  559. if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask))
  560. intel_pmu_disable_bts();
  561. intel_pmu_pebs_disable_all();
  562. intel_pmu_lbr_disable_all();
  563. }
  564. static void intel_pmu_enable_all(int added)
  565. {
  566. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  567. intel_pmu_pebs_enable_all();
  568. intel_pmu_lbr_enable_all();
  569. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, x86_pmu.intel_ctrl);
  570. if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask)) {
  571. struct perf_event *event =
  572. cpuc->events[X86_PMC_IDX_FIXED_BTS];
  573. if (WARN_ON_ONCE(!event))
  574. return;
  575. intel_pmu_enable_bts(event->hw.config);
  576. }
  577. }
  578. /*
  579. * Workaround for:
  580. * Intel Errata AAK100 (model 26)
  581. * Intel Errata AAP53 (model 30)
  582. * Intel Errata BD53 (model 44)
  583. *
  584. * The official story:
  585. * These chips need to be 'reset' when adding counters by programming the
  586. * magic three (non-counting) events 0x4300B5, 0x4300D2, and 0x4300B1 either
  587. * in sequence on the same PMC or on different PMCs.
  588. *
  589. * In practise it appears some of these events do in fact count, and
  590. * we need to programm all 4 events.
  591. */
  592. static void intel_pmu_nhm_workaround(void)
  593. {
  594. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  595. static const unsigned long nhm_magic[4] = {
  596. 0x4300B5,
  597. 0x4300D2,
  598. 0x4300B1,
  599. 0x4300B1
  600. };
  601. struct perf_event *event;
  602. int i;
  603. /*
  604. * The Errata requires below steps:
  605. * 1) Clear MSR_IA32_PEBS_ENABLE and MSR_CORE_PERF_GLOBAL_CTRL;
  606. * 2) Configure 4 PERFEVTSELx with the magic events and clear
  607. * the corresponding PMCx;
  608. * 3) set bit0~bit3 of MSR_CORE_PERF_GLOBAL_CTRL;
  609. * 4) Clear MSR_CORE_PERF_GLOBAL_CTRL;
  610. * 5) Clear 4 pairs of ERFEVTSELx and PMCx;
  611. */
  612. /*
  613. * The real steps we choose are a little different from above.
  614. * A) To reduce MSR operations, we don't run step 1) as they
  615. * are already cleared before this function is called;
  616. * B) Call x86_perf_event_update to save PMCx before configuring
  617. * PERFEVTSELx with magic number;
  618. * C) With step 5), we do clear only when the PERFEVTSELx is
  619. * not used currently.
  620. * D) Call x86_perf_event_set_period to restore PMCx;
  621. */
  622. /* We always operate 4 pairs of PERF Counters */
  623. for (i = 0; i < 4; i++) {
  624. event = cpuc->events[i];
  625. if (event)
  626. x86_perf_event_update(event);
  627. }
  628. for (i = 0; i < 4; i++) {
  629. wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, nhm_magic[i]);
  630. wrmsrl(MSR_ARCH_PERFMON_PERFCTR0 + i, 0x0);
  631. }
  632. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0xf);
  633. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x0);
  634. for (i = 0; i < 4; i++) {
  635. event = cpuc->events[i];
  636. if (event) {
  637. x86_perf_event_set_period(event);
  638. __x86_pmu_enable_event(&event->hw,
  639. ARCH_PERFMON_EVENTSEL_ENABLE);
  640. } else
  641. wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, 0x0);
  642. }
  643. }
  644. static void intel_pmu_nhm_enable_all(int added)
  645. {
  646. if (added)
  647. intel_pmu_nhm_workaround();
  648. intel_pmu_enable_all(added);
  649. }
  650. static inline u64 intel_pmu_get_status(void)
  651. {
  652. u64 status;
  653. rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status);
  654. return status;
  655. }
  656. static inline void intel_pmu_ack_status(u64 ack)
  657. {
  658. wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack);
  659. }
  660. static void intel_pmu_disable_fixed(struct hw_perf_event *hwc)
  661. {
  662. int idx = hwc->idx - X86_PMC_IDX_FIXED;
  663. u64 ctrl_val, mask;
  664. mask = 0xfULL << (idx * 4);
  665. rdmsrl(hwc->config_base, ctrl_val);
  666. ctrl_val &= ~mask;
  667. wrmsrl(hwc->config_base, ctrl_val);
  668. }
  669. static void intel_pmu_disable_event(struct perf_event *event)
  670. {
  671. struct hw_perf_event *hwc = &event->hw;
  672. if (unlikely(hwc->idx == X86_PMC_IDX_FIXED_BTS)) {
  673. intel_pmu_disable_bts();
  674. intel_pmu_drain_bts_buffer();
  675. return;
  676. }
  677. if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) {
  678. intel_pmu_disable_fixed(hwc);
  679. return;
  680. }
  681. x86_pmu_disable_event(event);
  682. if (unlikely(event->attr.precise_ip))
  683. intel_pmu_pebs_disable(event);
  684. }
  685. static void intel_pmu_enable_fixed(struct hw_perf_event *hwc)
  686. {
  687. int idx = hwc->idx - X86_PMC_IDX_FIXED;
  688. u64 ctrl_val, bits, mask;
  689. /*
  690. * Enable IRQ generation (0x8),
  691. * and enable ring-3 counting (0x2) and ring-0 counting (0x1)
  692. * if requested:
  693. */
  694. bits = 0x8ULL;
  695. if (hwc->config & ARCH_PERFMON_EVENTSEL_USR)
  696. bits |= 0x2;
  697. if (hwc->config & ARCH_PERFMON_EVENTSEL_OS)
  698. bits |= 0x1;
  699. /*
  700. * ANY bit is supported in v3 and up
  701. */
  702. if (x86_pmu.version > 2 && hwc->config & ARCH_PERFMON_EVENTSEL_ANY)
  703. bits |= 0x4;
  704. bits <<= (idx * 4);
  705. mask = 0xfULL << (idx * 4);
  706. rdmsrl(hwc->config_base, ctrl_val);
  707. ctrl_val &= ~mask;
  708. ctrl_val |= bits;
  709. wrmsrl(hwc->config_base, ctrl_val);
  710. }
  711. static void intel_pmu_enable_event(struct perf_event *event)
  712. {
  713. struct hw_perf_event *hwc = &event->hw;
  714. if (unlikely(hwc->idx == X86_PMC_IDX_FIXED_BTS)) {
  715. if (!__this_cpu_read(cpu_hw_events.enabled))
  716. return;
  717. intel_pmu_enable_bts(hwc->config);
  718. return;
  719. }
  720. if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) {
  721. intel_pmu_enable_fixed(hwc);
  722. return;
  723. }
  724. if (unlikely(event->attr.precise_ip))
  725. intel_pmu_pebs_enable(event);
  726. __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE);
  727. }
  728. /*
  729. * Save and restart an expired event. Called by NMI contexts,
  730. * so it has to be careful about preempting normal event ops:
  731. */
  732. static int intel_pmu_save_and_restart(struct perf_event *event)
  733. {
  734. x86_perf_event_update(event);
  735. return x86_perf_event_set_period(event);
  736. }
  737. static void intel_pmu_reset(void)
  738. {
  739. struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds);
  740. unsigned long flags;
  741. int idx;
  742. if (!x86_pmu.num_counters)
  743. return;
  744. local_irq_save(flags);
  745. printk("clearing PMU state on CPU#%d\n", smp_processor_id());
  746. for (idx = 0; idx < x86_pmu.num_counters; idx++) {
  747. checking_wrmsrl(x86_pmu.eventsel + idx, 0ull);
  748. checking_wrmsrl(x86_pmu.perfctr + idx, 0ull);
  749. }
  750. for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++)
  751. checking_wrmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull);
  752. if (ds)
  753. ds->bts_index = ds->bts_buffer_base;
  754. local_irq_restore(flags);
  755. }
  756. /*
  757. * This handler is triggered by the local APIC, so the APIC IRQ handling
  758. * rules apply:
  759. */
  760. static int intel_pmu_handle_irq(struct pt_regs *regs)
  761. {
  762. struct perf_sample_data data;
  763. struct cpu_hw_events *cpuc;
  764. int bit, loops;
  765. u64 status;
  766. int handled;
  767. perf_sample_data_init(&data, 0);
  768. cpuc = &__get_cpu_var(cpu_hw_events);
  769. intel_pmu_disable_all();
  770. handled = intel_pmu_drain_bts_buffer();
  771. status = intel_pmu_get_status();
  772. if (!status) {
  773. intel_pmu_enable_all(0);
  774. return handled;
  775. }
  776. loops = 0;
  777. again:
  778. intel_pmu_ack_status(status);
  779. if (++loops > 100) {
  780. WARN_ONCE(1, "perfevents: irq loop stuck!\n");
  781. perf_event_print_debug();
  782. intel_pmu_reset();
  783. goto done;
  784. }
  785. inc_irq_stat(apic_perf_irqs);
  786. intel_pmu_lbr_read();
  787. /*
  788. * PEBS overflow sets bit 62 in the global status register
  789. */
  790. if (__test_and_clear_bit(62, (unsigned long *)&status)) {
  791. handled++;
  792. x86_pmu.drain_pebs(regs);
  793. }
  794. for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) {
  795. struct perf_event *event = cpuc->events[bit];
  796. handled++;
  797. if (!test_bit(bit, cpuc->active_mask))
  798. continue;
  799. if (!intel_pmu_save_and_restart(event))
  800. continue;
  801. data.period = event->hw.last_period;
  802. if (perf_event_overflow(event, 1, &data, regs))
  803. x86_pmu_stop(event, 0);
  804. }
  805. /*
  806. * Repeat if there is more work to be done:
  807. */
  808. status = intel_pmu_get_status();
  809. if (status)
  810. goto again;
  811. done:
  812. intel_pmu_enable_all(0);
  813. return handled;
  814. }
  815. static struct event_constraint *
  816. intel_bts_constraints(struct perf_event *event)
  817. {
  818. struct hw_perf_event *hwc = &event->hw;
  819. unsigned int hw_event, bts_event;
  820. hw_event = hwc->config & INTEL_ARCH_EVENT_MASK;
  821. bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS);
  822. if (unlikely(hw_event == bts_event && hwc->sample_period == 1))
  823. return &bts_constraint;
  824. return NULL;
  825. }
  826. static struct event_constraint *
  827. intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event)
  828. {
  829. struct event_constraint *c;
  830. c = intel_bts_constraints(event);
  831. if (c)
  832. return c;
  833. c = intel_pebs_constraints(event);
  834. if (c)
  835. return c;
  836. return x86_get_event_constraints(cpuc, event);
  837. }
  838. static int intel_pmu_hw_config(struct perf_event *event)
  839. {
  840. int ret = x86_pmu_hw_config(event);
  841. if (ret)
  842. return ret;
  843. if (event->attr.precise_ip &&
  844. (event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) {
  845. /*
  846. * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P
  847. * (0x003c) so that we can use it with PEBS.
  848. *
  849. * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't
  850. * PEBS capable. However we can use INST_RETIRED.ANY_P
  851. * (0x00c0), which is a PEBS capable event, to get the same
  852. * count.
  853. *
  854. * INST_RETIRED.ANY_P counts the number of cycles that retires
  855. * CNTMASK instructions. By setting CNTMASK to a value (16)
  856. * larger than the maximum number of instructions that can be
  857. * retired per cycle (4) and then inverting the condition, we
  858. * count all cycles that retire 16 or less instructions, which
  859. * is every cycle.
  860. *
  861. * Thereby we gain a PEBS capable cycle counter.
  862. */
  863. u64 alt_config = 0x108000c0; /* INST_RETIRED.TOTAL_CYCLES */
  864. alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK);
  865. event->hw.config = alt_config;
  866. }
  867. if (event->attr.type != PERF_TYPE_RAW)
  868. return 0;
  869. if (!(event->attr.config & ARCH_PERFMON_EVENTSEL_ANY))
  870. return 0;
  871. if (x86_pmu.version < 3)
  872. return -EINVAL;
  873. if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
  874. return -EACCES;
  875. event->hw.config |= ARCH_PERFMON_EVENTSEL_ANY;
  876. return 0;
  877. }
  878. static __initconst const struct x86_pmu core_pmu = {
  879. .name = "core",
  880. .handle_irq = x86_pmu_handle_irq,
  881. .disable_all = x86_pmu_disable_all,
  882. .enable_all = x86_pmu_enable_all,
  883. .enable = x86_pmu_enable_event,
  884. .disable = x86_pmu_disable_event,
  885. .hw_config = x86_pmu_hw_config,
  886. .schedule_events = x86_schedule_events,
  887. .eventsel = MSR_ARCH_PERFMON_EVENTSEL0,
  888. .perfctr = MSR_ARCH_PERFMON_PERFCTR0,
  889. .event_map = intel_pmu_event_map,
  890. .max_events = ARRAY_SIZE(intel_perfmon_event_map),
  891. .apic = 1,
  892. /*
  893. * Intel PMCs cannot be accessed sanely above 32 bit width,
  894. * so we install an artificial 1<<31 period regardless of
  895. * the generic event period:
  896. */
  897. .max_period = (1ULL << 31) - 1,
  898. .get_event_constraints = intel_get_event_constraints,
  899. .event_constraints = intel_core_event_constraints,
  900. };
  901. static void intel_pmu_cpu_starting(int cpu)
  902. {
  903. init_debug_store_on_cpu(cpu);
  904. /*
  905. * Deal with CPUs that don't clear their LBRs on power-up.
  906. */
  907. intel_pmu_lbr_reset();
  908. }
  909. static void intel_pmu_cpu_dying(int cpu)
  910. {
  911. fini_debug_store_on_cpu(cpu);
  912. }
  913. static __initconst const struct x86_pmu intel_pmu = {
  914. .name = "Intel",
  915. .handle_irq = intel_pmu_handle_irq,
  916. .disable_all = intel_pmu_disable_all,
  917. .enable_all = intel_pmu_enable_all,
  918. .enable = intel_pmu_enable_event,
  919. .disable = intel_pmu_disable_event,
  920. .hw_config = intel_pmu_hw_config,
  921. .schedule_events = x86_schedule_events,
  922. .eventsel = MSR_ARCH_PERFMON_EVENTSEL0,
  923. .perfctr = MSR_ARCH_PERFMON_PERFCTR0,
  924. .event_map = intel_pmu_event_map,
  925. .max_events = ARRAY_SIZE(intel_perfmon_event_map),
  926. .apic = 1,
  927. /*
  928. * Intel PMCs cannot be accessed sanely above 32 bit width,
  929. * so we install an artificial 1<<31 period regardless of
  930. * the generic event period:
  931. */
  932. .max_period = (1ULL << 31) - 1,
  933. .get_event_constraints = intel_get_event_constraints,
  934. .cpu_starting = intel_pmu_cpu_starting,
  935. .cpu_dying = intel_pmu_cpu_dying,
  936. };
  937. static void intel_clovertown_quirks(void)
  938. {
  939. /*
  940. * PEBS is unreliable due to:
  941. *
  942. * AJ67 - PEBS may experience CPL leaks
  943. * AJ68 - PEBS PMI may be delayed by one event
  944. * AJ69 - GLOBAL_STATUS[62] will only be set when DEBUGCTL[12]
  945. * AJ106 - FREEZE_LBRS_ON_PMI doesn't work in combination with PEBS
  946. *
  947. * AJ67 could be worked around by restricting the OS/USR flags.
  948. * AJ69 could be worked around by setting PMU_FREEZE_ON_PMI.
  949. *
  950. * AJ106 could possibly be worked around by not allowing LBR
  951. * usage from PEBS, including the fixup.
  952. * AJ68 could possibly be worked around by always programming
  953. * a pebs_event_reset[0] value and coping with the lost events.
  954. *
  955. * But taken together it might just make sense to not enable PEBS on
  956. * these chips.
  957. */
  958. printk(KERN_WARNING "PEBS disabled due to CPU errata.\n");
  959. x86_pmu.pebs = 0;
  960. x86_pmu.pebs_constraints = NULL;
  961. }
  962. static __init int intel_pmu_init(void)
  963. {
  964. union cpuid10_edx edx;
  965. union cpuid10_eax eax;
  966. unsigned int unused;
  967. unsigned int ebx;
  968. int version;
  969. if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) {
  970. switch (boot_cpu_data.x86) {
  971. case 0x6:
  972. return p6_pmu_init();
  973. case 0xf:
  974. return p4_pmu_init();
  975. }
  976. return -ENODEV;
  977. }
  978. /*
  979. * Check whether the Architectural PerfMon supports
  980. * Branch Misses Retired hw_event or not.
  981. */
  982. cpuid(10, &eax.full, &ebx, &unused, &edx.full);
  983. if (eax.split.mask_length <= ARCH_PERFMON_BRANCH_MISSES_RETIRED)
  984. return -ENODEV;
  985. version = eax.split.version_id;
  986. if (version < 2)
  987. x86_pmu = core_pmu;
  988. else
  989. x86_pmu = intel_pmu;
  990. x86_pmu.version = version;
  991. x86_pmu.num_counters = eax.split.num_counters;
  992. x86_pmu.cntval_bits = eax.split.bit_width;
  993. x86_pmu.cntval_mask = (1ULL << eax.split.bit_width) - 1;
  994. /*
  995. * Quirk: v2 perfmon does not report fixed-purpose events, so
  996. * assume at least 3 events:
  997. */
  998. if (version > 1)
  999. x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
  1000. /*
  1001. * v2 and above have a perf capabilities MSR
  1002. */
  1003. if (version > 1) {
  1004. u64 capabilities;
  1005. rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
  1006. x86_pmu.intel_cap.capabilities = capabilities;
  1007. }
  1008. intel_ds_init();
  1009. /*
  1010. * Install the hw-cache-events table:
  1011. */
  1012. switch (boot_cpu_data.x86_model) {
  1013. case 14: /* 65 nm core solo/duo, "Yonah" */
  1014. pr_cont("Core events, ");
  1015. break;
  1016. case 15: /* original 65 nm celeron/pentium/core2/xeon, "Merom"/"Conroe" */
  1017. x86_pmu.quirks = intel_clovertown_quirks;
  1018. case 22: /* single-core 65 nm celeron/core2solo "Merom-L"/"Conroe-L" */
  1019. case 23: /* current 45 nm celeron/core2/xeon "Penryn"/"Wolfdale" */
  1020. case 29: /* six-core 45 nm xeon "Dunnington" */
  1021. memcpy(hw_cache_event_ids, core2_hw_cache_event_ids,
  1022. sizeof(hw_cache_event_ids));
  1023. intel_pmu_lbr_init_core();
  1024. x86_pmu.event_constraints = intel_core2_event_constraints;
  1025. pr_cont("Core2 events, ");
  1026. break;
  1027. case 26: /* 45 nm nehalem, "Bloomfield" */
  1028. case 30: /* 45 nm nehalem, "Lynnfield" */
  1029. case 46: /* 45 nm nehalem-ex, "Beckton" */
  1030. memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids,
  1031. sizeof(hw_cache_event_ids));
  1032. intel_pmu_lbr_init_nhm();
  1033. x86_pmu.event_constraints = intel_nehalem_event_constraints;
  1034. x86_pmu.enable_all = intel_pmu_nhm_enable_all;
  1035. pr_cont("Nehalem events, ");
  1036. break;
  1037. case 28: /* Atom */
  1038. memcpy(hw_cache_event_ids, atom_hw_cache_event_ids,
  1039. sizeof(hw_cache_event_ids));
  1040. intel_pmu_lbr_init_atom();
  1041. x86_pmu.event_constraints = intel_gen_event_constraints;
  1042. pr_cont("Atom events, ");
  1043. break;
  1044. case 37: /* 32 nm nehalem, "Clarkdale" */
  1045. case 44: /* 32 nm nehalem, "Gulftown" */
  1046. memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids,
  1047. sizeof(hw_cache_event_ids));
  1048. intel_pmu_lbr_init_nhm();
  1049. x86_pmu.event_constraints = intel_westmere_event_constraints;
  1050. x86_pmu.enable_all = intel_pmu_nhm_enable_all;
  1051. pr_cont("Westmere events, ");
  1052. break;
  1053. case 42: /* SandyBridge */
  1054. memcpy(hw_cache_event_ids, snb_hw_cache_event_ids,
  1055. sizeof(hw_cache_event_ids));
  1056. intel_pmu_lbr_init_nhm();
  1057. x86_pmu.event_constraints = intel_snb_event_constraints;
  1058. x86_pmu.pebs_constraints = intel_snb_pebs_events;
  1059. pr_cont("SandyBridge events, ");
  1060. break;
  1061. default:
  1062. /*
  1063. * default constraints for v2 and up
  1064. */
  1065. x86_pmu.event_constraints = intel_gen_event_constraints;
  1066. pr_cont("generic architected perfmon, ");
  1067. }
  1068. return 0;
  1069. }
  1070. #else /* CONFIG_CPU_SUP_INTEL */
  1071. static int intel_pmu_init(void)
  1072. {
  1073. return 0;
  1074. }
  1075. #endif /* CONFIG_CPU_SUP_INTEL */