perf_event_intel.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533
  1. #ifdef CONFIG_CPU_SUP_INTEL
  2. #define MAX_EXTRA_REGS 2
  3. /*
  4. * Per register state.
  5. */
  6. struct er_account {
  7. int ref; /* reference count */
  8. unsigned int extra_reg; /* extra MSR number */
  9. u64 extra_config; /* extra MSR config */
  10. };
  11. /*
  12. * Per core state
  13. * This used to coordinate shared registers for HT threads.
  14. */
  15. struct intel_percore {
  16. raw_spinlock_t lock; /* protect structure */
  17. struct er_account regs[MAX_EXTRA_REGS];
  18. int refcnt; /* number of threads */
  19. unsigned core_id;
  20. };
  21. /*
  22. * Intel PerfMon, used on Core and later.
  23. */
  24. static u64 intel_perfmon_event_map[PERF_COUNT_HW_MAX] __read_mostly =
  25. {
  26. [PERF_COUNT_HW_CPU_CYCLES] = 0x003c,
  27. [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0,
  28. [PERF_COUNT_HW_CACHE_REFERENCES] = 0x4f2e,
  29. [PERF_COUNT_HW_CACHE_MISSES] = 0x412e,
  30. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c4,
  31. [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c5,
  32. [PERF_COUNT_HW_BUS_CYCLES] = 0x013c,
  33. };
  34. static struct event_constraint intel_core_event_constraints[] __read_mostly =
  35. {
  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(0x19, 0x2), /* DELAYED_BYPASS */
  41. INTEL_EVENT_CONSTRAINT(0xc1, 0x1), /* FP_COMP_INSTR_RET */
  42. EVENT_CONSTRAINT_END
  43. };
  44. static struct event_constraint intel_core2_event_constraints[] __read_mostly =
  45. {
  46. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  47. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  48. /*
  49. * Core2 has Fixed Counter 2 listed as CPU_CLK_UNHALTED.REF and event
  50. * 0x013c as CPU_CLK_UNHALTED.BUS and specifies there is a fixed
  51. * ratio between these counters.
  52. */
  53. /* FIXED_EVENT_CONSTRAINT(0x013c, 2), CPU_CLK_UNHALTED.REF */
  54. INTEL_EVENT_CONSTRAINT(0x10, 0x1), /* FP_COMP_OPS_EXE */
  55. INTEL_EVENT_CONSTRAINT(0x11, 0x2), /* FP_ASSIST */
  56. INTEL_EVENT_CONSTRAINT(0x12, 0x2), /* MUL */
  57. INTEL_EVENT_CONSTRAINT(0x13, 0x2), /* DIV */
  58. INTEL_EVENT_CONSTRAINT(0x14, 0x1), /* CYCLES_DIV_BUSY */
  59. INTEL_EVENT_CONSTRAINT(0x18, 0x1), /* IDLE_DURING_DIV */
  60. INTEL_EVENT_CONSTRAINT(0x19, 0x2), /* DELAYED_BYPASS */
  61. INTEL_EVENT_CONSTRAINT(0xa1, 0x1), /* RS_UOPS_DISPATCH_CYCLES */
  62. INTEL_EVENT_CONSTRAINT(0xc9, 0x1), /* ITLB_MISS_RETIRED (T30-9) */
  63. INTEL_EVENT_CONSTRAINT(0xcb, 0x1), /* MEM_LOAD_RETIRED */
  64. EVENT_CONSTRAINT_END
  65. };
  66. static struct event_constraint intel_nehalem_event_constraints[] __read_mostly =
  67. {
  68. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  69. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  70. /* FIXED_EVENT_CONSTRAINT(0x013c, 2), CPU_CLK_UNHALTED.REF */
  71. INTEL_EVENT_CONSTRAINT(0x40, 0x3), /* L1D_CACHE_LD */
  72. INTEL_EVENT_CONSTRAINT(0x41, 0x3), /* L1D_CACHE_ST */
  73. INTEL_EVENT_CONSTRAINT(0x42, 0x3), /* L1D_CACHE_LOCK */
  74. INTEL_EVENT_CONSTRAINT(0x43, 0x3), /* L1D_ALL_REF */
  75. INTEL_EVENT_CONSTRAINT(0x48, 0x3), /* L1D_PEND_MISS */
  76. INTEL_EVENT_CONSTRAINT(0x4e, 0x3), /* L1D_PREFETCH */
  77. INTEL_EVENT_CONSTRAINT(0x51, 0x3), /* L1D */
  78. INTEL_EVENT_CONSTRAINT(0x63, 0x3), /* CACHE_LOCK_CYCLES */
  79. EVENT_CONSTRAINT_END
  80. };
  81. static struct extra_reg intel_nehalem_extra_regs[] __read_mostly =
  82. {
  83. INTEL_EVENT_EXTRA_REG(0xb7, MSR_OFFCORE_RSP_0, 0xffff),
  84. EVENT_EXTRA_END
  85. };
  86. static struct event_constraint intel_nehalem_percore_constraints[] __read_mostly =
  87. {
  88. INTEL_EVENT_CONSTRAINT(0xb7, 0),
  89. EVENT_CONSTRAINT_END
  90. };
  91. static struct event_constraint intel_westmere_event_constraints[] __read_mostly =
  92. {
  93. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  94. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  95. /* FIXED_EVENT_CONSTRAINT(0x013c, 2), CPU_CLK_UNHALTED.REF */
  96. INTEL_EVENT_CONSTRAINT(0x51, 0x3), /* L1D */
  97. INTEL_EVENT_CONSTRAINT(0x60, 0x1), /* OFFCORE_REQUESTS_OUTSTANDING */
  98. INTEL_EVENT_CONSTRAINT(0x63, 0x3), /* CACHE_LOCK_CYCLES */
  99. INTEL_EVENT_CONSTRAINT(0xb3, 0x1), /* SNOOPQ_REQUEST_OUTSTANDING */
  100. EVENT_CONSTRAINT_END
  101. };
  102. static struct event_constraint intel_snb_event_constraints[] __read_mostly =
  103. {
  104. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  105. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  106. /* FIXED_EVENT_CONSTRAINT(0x013c, 2), CPU_CLK_UNHALTED.REF */
  107. INTEL_EVENT_CONSTRAINT(0x48, 0x4), /* L1D_PEND_MISS.PENDING */
  108. INTEL_EVENT_CONSTRAINT(0xb7, 0x1), /* OFF_CORE_RESPONSE_0 */
  109. INTEL_EVENT_CONSTRAINT(0xbb, 0x8), /* OFF_CORE_RESPONSE_1 */
  110. INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */
  111. INTEL_EVENT_CONSTRAINT(0xcd, 0x8), /* MEM_TRANS_RETIRED.LOAD_LATENCY */
  112. EVENT_CONSTRAINT_END
  113. };
  114. static struct extra_reg intel_westmere_extra_regs[] __read_mostly =
  115. {
  116. INTEL_EVENT_EXTRA_REG(0xb7, MSR_OFFCORE_RSP_0, 0xffff),
  117. INTEL_EVENT_EXTRA_REG(0xbb, MSR_OFFCORE_RSP_1, 0xffff),
  118. EVENT_EXTRA_END
  119. };
  120. static struct event_constraint intel_westmere_percore_constraints[] __read_mostly =
  121. {
  122. INTEL_EVENT_CONSTRAINT(0xb7, 0),
  123. INTEL_EVENT_CONSTRAINT(0xbb, 0),
  124. EVENT_CONSTRAINT_END
  125. };
  126. static struct event_constraint intel_gen_event_constraints[] __read_mostly =
  127. {
  128. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  129. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  130. /* FIXED_EVENT_CONSTRAINT(0x013c, 2), CPU_CLK_UNHALTED.REF */
  131. EVENT_CONSTRAINT_END
  132. };
  133. static u64 intel_pmu_event_map(int hw_event)
  134. {
  135. return intel_perfmon_event_map[hw_event];
  136. }
  137. static __initconst const u64 snb_hw_cache_event_ids
  138. [PERF_COUNT_HW_CACHE_MAX]
  139. [PERF_COUNT_HW_CACHE_OP_MAX]
  140. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  141. {
  142. [ C(L1D) ] = {
  143. [ C(OP_READ) ] = {
  144. [ C(RESULT_ACCESS) ] = 0xf1d0, /* MEM_UOP_RETIRED.LOADS */
  145. [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPLACEMENT */
  146. },
  147. [ C(OP_WRITE) ] = {
  148. [ C(RESULT_ACCESS) ] = 0xf2d0, /* MEM_UOP_RETIRED.STORES */
  149. [ C(RESULT_MISS) ] = 0x0851, /* L1D.ALL_M_REPLACEMENT */
  150. },
  151. [ C(OP_PREFETCH) ] = {
  152. [ C(RESULT_ACCESS) ] = 0x0,
  153. [ C(RESULT_MISS) ] = 0x024e, /* HW_PRE_REQ.DL1_MISS */
  154. },
  155. },
  156. [ C(L1I ) ] = {
  157. [ C(OP_READ) ] = {
  158. [ C(RESULT_ACCESS) ] = 0x0,
  159. [ C(RESULT_MISS) ] = 0x0280, /* ICACHE.MISSES */
  160. },
  161. [ C(OP_WRITE) ] = {
  162. [ C(RESULT_ACCESS) ] = -1,
  163. [ C(RESULT_MISS) ] = -1,
  164. },
  165. [ C(OP_PREFETCH) ] = {
  166. [ C(RESULT_ACCESS) ] = 0x0,
  167. [ C(RESULT_MISS) ] = 0x0,
  168. },
  169. },
  170. [ C(LL ) ] = {
  171. [ C(OP_READ) ] = {
  172. /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */
  173. [ C(RESULT_ACCESS) ] = 0x01b7,
  174. /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */
  175. [ C(RESULT_MISS) ] = 0x01b7,
  176. },
  177. [ C(OP_WRITE) ] = {
  178. /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */
  179. [ C(RESULT_ACCESS) ] = 0x01b7,
  180. /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */
  181. [ C(RESULT_MISS) ] = 0x01b7,
  182. },
  183. [ C(OP_PREFETCH) ] = {
  184. /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */
  185. [ C(RESULT_ACCESS) ] = 0x01b7,
  186. /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */
  187. [ C(RESULT_MISS) ] = 0x01b7,
  188. },
  189. },
  190. [ C(DTLB) ] = {
  191. [ C(OP_READ) ] = {
  192. [ C(RESULT_ACCESS) ] = 0x81d0, /* MEM_UOP_RETIRED.ALL_LOADS */
  193. [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.CAUSES_A_WALK */
  194. },
  195. [ C(OP_WRITE) ] = {
  196. [ C(RESULT_ACCESS) ] = 0x82d0, /* MEM_UOP_RETIRED.ALL_STORES */
  197. [ C(RESULT_MISS) ] = 0x0149, /* DTLB_STORE_MISSES.MISS_CAUSES_A_WALK */
  198. },
  199. [ C(OP_PREFETCH) ] = {
  200. [ C(RESULT_ACCESS) ] = 0x0,
  201. [ C(RESULT_MISS) ] = 0x0,
  202. },
  203. },
  204. [ C(ITLB) ] = {
  205. [ C(OP_READ) ] = {
  206. [ C(RESULT_ACCESS) ] = 0x1085, /* ITLB_MISSES.STLB_HIT */
  207. [ C(RESULT_MISS) ] = 0x0185, /* ITLB_MISSES.CAUSES_A_WALK */
  208. },
  209. [ C(OP_WRITE) ] = {
  210. [ C(RESULT_ACCESS) ] = -1,
  211. [ C(RESULT_MISS) ] = -1,
  212. },
  213. [ C(OP_PREFETCH) ] = {
  214. [ C(RESULT_ACCESS) ] = -1,
  215. [ C(RESULT_MISS) ] = -1,
  216. },
  217. },
  218. [ C(BPU ) ] = {
  219. [ C(OP_READ) ] = {
  220. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */
  221. [ C(RESULT_MISS) ] = 0x00c5, /* BR_MISP_RETIRED.ALL_BRANCHES */
  222. },
  223. [ C(OP_WRITE) ] = {
  224. [ C(RESULT_ACCESS) ] = -1,
  225. [ C(RESULT_MISS) ] = -1,
  226. },
  227. [ C(OP_PREFETCH) ] = {
  228. [ C(RESULT_ACCESS) ] = -1,
  229. [ C(RESULT_MISS) ] = -1,
  230. },
  231. },
  232. };
  233. static __initconst const u64 westmere_hw_cache_event_ids
  234. [PERF_COUNT_HW_CACHE_MAX]
  235. [PERF_COUNT_HW_CACHE_OP_MAX]
  236. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  237. {
  238. [ C(L1D) ] = {
  239. [ C(OP_READ) ] = {
  240. [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */
  241. [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPL */
  242. },
  243. [ C(OP_WRITE) ] = {
  244. [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */
  245. [ C(RESULT_MISS) ] = 0x0251, /* L1D.M_REPL */
  246. },
  247. [ C(OP_PREFETCH) ] = {
  248. [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */
  249. [ C(RESULT_MISS) ] = 0x024e, /* L1D_PREFETCH.MISS */
  250. },
  251. },
  252. [ C(L1I ) ] = {
  253. [ C(OP_READ) ] = {
  254. [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */
  255. [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */
  256. },
  257. [ C(OP_WRITE) ] = {
  258. [ C(RESULT_ACCESS) ] = -1,
  259. [ C(RESULT_MISS) ] = -1,
  260. },
  261. [ C(OP_PREFETCH) ] = {
  262. [ C(RESULT_ACCESS) ] = 0x0,
  263. [ C(RESULT_MISS) ] = 0x0,
  264. },
  265. },
  266. [ C(LL ) ] = {
  267. [ C(OP_READ) ] = {
  268. /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */
  269. [ C(RESULT_ACCESS) ] = 0x01b7,
  270. /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */
  271. [ C(RESULT_MISS) ] = 0x01b7,
  272. },
  273. /*
  274. * Use RFO, not WRITEBACK, because a write miss would typically occur
  275. * on RFO.
  276. */
  277. [ C(OP_WRITE) ] = {
  278. /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */
  279. [ C(RESULT_ACCESS) ] = 0x01b7,
  280. /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */
  281. [ C(RESULT_MISS) ] = 0x01b7,
  282. },
  283. [ C(OP_PREFETCH) ] = {
  284. /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */
  285. [ C(RESULT_ACCESS) ] = 0x01b7,
  286. /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */
  287. [ C(RESULT_MISS) ] = 0x01b7,
  288. },
  289. },
  290. [ C(DTLB) ] = {
  291. [ C(OP_READ) ] = {
  292. [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */
  293. [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.ANY */
  294. },
  295. [ C(OP_WRITE) ] = {
  296. [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */
  297. [ C(RESULT_MISS) ] = 0x010c, /* MEM_STORE_RETIRED.DTLB_MISS */
  298. },
  299. [ C(OP_PREFETCH) ] = {
  300. [ C(RESULT_ACCESS) ] = 0x0,
  301. [ C(RESULT_MISS) ] = 0x0,
  302. },
  303. },
  304. [ C(ITLB) ] = {
  305. [ C(OP_READ) ] = {
  306. [ C(RESULT_ACCESS) ] = 0x01c0, /* INST_RETIRED.ANY_P */
  307. [ C(RESULT_MISS) ] = 0x0185, /* ITLB_MISSES.ANY */
  308. },
  309. [ C(OP_WRITE) ] = {
  310. [ C(RESULT_ACCESS) ] = -1,
  311. [ C(RESULT_MISS) ] = -1,
  312. },
  313. [ C(OP_PREFETCH) ] = {
  314. [ C(RESULT_ACCESS) ] = -1,
  315. [ C(RESULT_MISS) ] = -1,
  316. },
  317. },
  318. [ C(BPU ) ] = {
  319. [ C(OP_READ) ] = {
  320. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */
  321. [ C(RESULT_MISS) ] = 0x03e8, /* BPU_CLEARS.ANY */
  322. },
  323. [ C(OP_WRITE) ] = {
  324. [ C(RESULT_ACCESS) ] = -1,
  325. [ C(RESULT_MISS) ] = -1,
  326. },
  327. [ C(OP_PREFETCH) ] = {
  328. [ C(RESULT_ACCESS) ] = -1,
  329. [ C(RESULT_MISS) ] = -1,
  330. },
  331. },
  332. };
  333. /*
  334. * Nehalem/Westmere MSR_OFFCORE_RESPONSE bits;
  335. * See IA32 SDM Vol 3B 30.6.1.3
  336. */
  337. #define NHM_DMND_DATA_RD (1 << 0)
  338. #define NHM_DMND_RFO (1 << 1)
  339. #define NHM_DMND_IFETCH (1 << 2)
  340. #define NHM_DMND_WB (1 << 3)
  341. #define NHM_PF_DATA_RD (1 << 4)
  342. #define NHM_PF_DATA_RFO (1 << 5)
  343. #define NHM_PF_IFETCH (1 << 6)
  344. #define NHM_OFFCORE_OTHER (1 << 7)
  345. #define NHM_UNCORE_HIT (1 << 8)
  346. #define NHM_OTHER_CORE_HIT_SNP (1 << 9)
  347. #define NHM_OTHER_CORE_HITM (1 << 10)
  348. /* reserved */
  349. #define NHM_REMOTE_CACHE_FWD (1 << 12)
  350. #define NHM_REMOTE_DRAM (1 << 13)
  351. #define NHM_LOCAL_DRAM (1 << 14)
  352. #define NHM_NON_DRAM (1 << 15)
  353. #define NHM_ALL_DRAM (NHM_REMOTE_DRAM|NHM_LOCAL_DRAM)
  354. #define NHM_DMND_READ (NHM_DMND_DATA_RD)
  355. #define NHM_DMND_WRITE (NHM_DMND_RFO|NHM_DMND_WB)
  356. #define NHM_DMND_PREFETCH (NHM_PF_DATA_RD|NHM_PF_DATA_RFO)
  357. #define NHM_L3_HIT (NHM_UNCORE_HIT|NHM_OTHER_CORE_HIT_SNP|NHM_OTHER_CORE_HITM)
  358. #define NHM_L3_MISS (NHM_NON_DRAM|NHM_ALL_DRAM|NHM_REMOTE_CACHE_FWD)
  359. #define NHM_L3_ACCESS (NHM_L3_HIT|NHM_L3_MISS)
  360. static __initconst const u64 nehalem_hw_cache_extra_regs
  361. [PERF_COUNT_HW_CACHE_MAX]
  362. [PERF_COUNT_HW_CACHE_OP_MAX]
  363. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  364. {
  365. [ C(LL ) ] = {
  366. [ C(OP_READ) ] = {
  367. [ C(RESULT_ACCESS) ] = NHM_DMND_READ|NHM_L3_ACCESS,
  368. [ C(RESULT_MISS) ] = NHM_DMND_READ|NHM_L3_MISS,
  369. },
  370. [ C(OP_WRITE) ] = {
  371. [ C(RESULT_ACCESS) ] = NHM_DMND_WRITE|NHM_L3_ACCESS,
  372. [ C(RESULT_MISS) ] = NHM_DMND_WRITE|NHM_L3_MISS,
  373. },
  374. [ C(OP_PREFETCH) ] = {
  375. [ C(RESULT_ACCESS) ] = NHM_DMND_PREFETCH|NHM_L3_ACCESS,
  376. [ C(RESULT_MISS) ] = NHM_DMND_PREFETCH|NHM_L3_MISS,
  377. },
  378. }
  379. };
  380. static __initconst const u64 nehalem_hw_cache_event_ids
  381. [PERF_COUNT_HW_CACHE_MAX]
  382. [PERF_COUNT_HW_CACHE_OP_MAX]
  383. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  384. {
  385. [ C(L1D) ] = {
  386. [ C(OP_READ) ] = {
  387. [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */
  388. [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPL */
  389. },
  390. [ C(OP_WRITE) ] = {
  391. [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */
  392. [ C(RESULT_MISS) ] = 0x0251, /* L1D.M_REPL */
  393. },
  394. [ C(OP_PREFETCH) ] = {
  395. [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */
  396. [ C(RESULT_MISS) ] = 0x024e, /* L1D_PREFETCH.MISS */
  397. },
  398. },
  399. [ C(L1I ) ] = {
  400. [ C(OP_READ) ] = {
  401. [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */
  402. [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */
  403. },
  404. [ C(OP_WRITE) ] = {
  405. [ C(RESULT_ACCESS) ] = -1,
  406. [ C(RESULT_MISS) ] = -1,
  407. },
  408. [ C(OP_PREFETCH) ] = {
  409. [ C(RESULT_ACCESS) ] = 0x0,
  410. [ C(RESULT_MISS) ] = 0x0,
  411. },
  412. },
  413. [ C(LL ) ] = {
  414. [ C(OP_READ) ] = {
  415. /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */
  416. [ C(RESULT_ACCESS) ] = 0x01b7,
  417. /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */
  418. [ C(RESULT_MISS) ] = 0x01b7,
  419. },
  420. /*
  421. * Use RFO, not WRITEBACK, because a write miss would typically occur
  422. * on RFO.
  423. */
  424. [ C(OP_WRITE) ] = {
  425. /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */
  426. [ C(RESULT_ACCESS) ] = 0x01b7,
  427. /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */
  428. [ C(RESULT_MISS) ] = 0x01b7,
  429. },
  430. [ C(OP_PREFETCH) ] = {
  431. /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */
  432. [ C(RESULT_ACCESS) ] = 0x01b7,
  433. /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */
  434. [ C(RESULT_MISS) ] = 0x01b7,
  435. },
  436. },
  437. [ C(DTLB) ] = {
  438. [ C(OP_READ) ] = {
  439. [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI (alias) */
  440. [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.ANY */
  441. },
  442. [ C(OP_WRITE) ] = {
  443. [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI (alias) */
  444. [ C(RESULT_MISS) ] = 0x010c, /* MEM_STORE_RETIRED.DTLB_MISS */
  445. },
  446. [ C(OP_PREFETCH) ] = {
  447. [ C(RESULT_ACCESS) ] = 0x0,
  448. [ C(RESULT_MISS) ] = 0x0,
  449. },
  450. },
  451. [ C(ITLB) ] = {
  452. [ C(OP_READ) ] = {
  453. [ C(RESULT_ACCESS) ] = 0x01c0, /* INST_RETIRED.ANY_P */
  454. [ C(RESULT_MISS) ] = 0x20c8, /* ITLB_MISS_RETIRED */
  455. },
  456. [ C(OP_WRITE) ] = {
  457. [ C(RESULT_ACCESS) ] = -1,
  458. [ C(RESULT_MISS) ] = -1,
  459. },
  460. [ C(OP_PREFETCH) ] = {
  461. [ C(RESULT_ACCESS) ] = -1,
  462. [ C(RESULT_MISS) ] = -1,
  463. },
  464. },
  465. [ C(BPU ) ] = {
  466. [ C(OP_READ) ] = {
  467. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */
  468. [ C(RESULT_MISS) ] = 0x03e8, /* BPU_CLEARS.ANY */
  469. },
  470. [ C(OP_WRITE) ] = {
  471. [ C(RESULT_ACCESS) ] = -1,
  472. [ C(RESULT_MISS) ] = -1,
  473. },
  474. [ C(OP_PREFETCH) ] = {
  475. [ C(RESULT_ACCESS) ] = -1,
  476. [ C(RESULT_MISS) ] = -1,
  477. },
  478. },
  479. };
  480. static __initconst const u64 core2_hw_cache_event_ids
  481. [PERF_COUNT_HW_CACHE_MAX]
  482. [PERF_COUNT_HW_CACHE_OP_MAX]
  483. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  484. {
  485. [ C(L1D) ] = {
  486. [ C(OP_READ) ] = {
  487. [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI */
  488. [ C(RESULT_MISS) ] = 0x0140, /* L1D_CACHE_LD.I_STATE */
  489. },
  490. [ C(OP_WRITE) ] = {
  491. [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI */
  492. [ C(RESULT_MISS) ] = 0x0141, /* L1D_CACHE_ST.I_STATE */
  493. },
  494. [ C(OP_PREFETCH) ] = {
  495. [ C(RESULT_ACCESS) ] = 0x104e, /* L1D_PREFETCH.REQUESTS */
  496. [ C(RESULT_MISS) ] = 0,
  497. },
  498. },
  499. [ C(L1I ) ] = {
  500. [ C(OP_READ) ] = {
  501. [ C(RESULT_ACCESS) ] = 0x0080, /* L1I.READS */
  502. [ C(RESULT_MISS) ] = 0x0081, /* L1I.MISSES */
  503. },
  504. [ C(OP_WRITE) ] = {
  505. [ C(RESULT_ACCESS) ] = -1,
  506. [ C(RESULT_MISS) ] = -1,
  507. },
  508. [ C(OP_PREFETCH) ] = {
  509. [ C(RESULT_ACCESS) ] = 0,
  510. [ C(RESULT_MISS) ] = 0,
  511. },
  512. },
  513. [ C(LL ) ] = {
  514. [ C(OP_READ) ] = {
  515. [ C(RESULT_ACCESS) ] = 0x4f29, /* L2_LD.MESI */
  516. [ C(RESULT_MISS) ] = 0x4129, /* L2_LD.ISTATE */
  517. },
  518. [ C(OP_WRITE) ] = {
  519. [ C(RESULT_ACCESS) ] = 0x4f2A, /* L2_ST.MESI */
  520. [ C(RESULT_MISS) ] = 0x412A, /* L2_ST.ISTATE */
  521. },
  522. [ C(OP_PREFETCH) ] = {
  523. [ C(RESULT_ACCESS) ] = 0,
  524. [ C(RESULT_MISS) ] = 0,
  525. },
  526. },
  527. [ C(DTLB) ] = {
  528. [ C(OP_READ) ] = {
  529. [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI (alias) */
  530. [ C(RESULT_MISS) ] = 0x0208, /* DTLB_MISSES.MISS_LD */
  531. },
  532. [ C(OP_WRITE) ] = {
  533. [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI (alias) */
  534. [ C(RESULT_MISS) ] = 0x0808, /* DTLB_MISSES.MISS_ST */
  535. },
  536. [ C(OP_PREFETCH) ] = {
  537. [ C(RESULT_ACCESS) ] = 0,
  538. [ C(RESULT_MISS) ] = 0,
  539. },
  540. },
  541. [ C(ITLB) ] = {
  542. [ C(OP_READ) ] = {
  543. [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */
  544. [ C(RESULT_MISS) ] = 0x1282, /* ITLBMISSES */
  545. },
  546. [ C(OP_WRITE) ] = {
  547. [ C(RESULT_ACCESS) ] = -1,
  548. [ C(RESULT_MISS) ] = -1,
  549. },
  550. [ C(OP_PREFETCH) ] = {
  551. [ C(RESULT_ACCESS) ] = -1,
  552. [ C(RESULT_MISS) ] = -1,
  553. },
  554. },
  555. [ C(BPU ) ] = {
  556. [ C(OP_READ) ] = {
  557. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */
  558. [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */
  559. },
  560. [ C(OP_WRITE) ] = {
  561. [ C(RESULT_ACCESS) ] = -1,
  562. [ C(RESULT_MISS) ] = -1,
  563. },
  564. [ C(OP_PREFETCH) ] = {
  565. [ C(RESULT_ACCESS) ] = -1,
  566. [ C(RESULT_MISS) ] = -1,
  567. },
  568. },
  569. };
  570. static __initconst const u64 atom_hw_cache_event_ids
  571. [PERF_COUNT_HW_CACHE_MAX]
  572. [PERF_COUNT_HW_CACHE_OP_MAX]
  573. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  574. {
  575. [ C(L1D) ] = {
  576. [ C(OP_READ) ] = {
  577. [ C(RESULT_ACCESS) ] = 0x2140, /* L1D_CACHE.LD */
  578. [ C(RESULT_MISS) ] = 0,
  579. },
  580. [ C(OP_WRITE) ] = {
  581. [ C(RESULT_ACCESS) ] = 0x2240, /* L1D_CACHE.ST */
  582. [ C(RESULT_MISS) ] = 0,
  583. },
  584. [ C(OP_PREFETCH) ] = {
  585. [ C(RESULT_ACCESS) ] = 0x0,
  586. [ C(RESULT_MISS) ] = 0,
  587. },
  588. },
  589. [ C(L1I ) ] = {
  590. [ C(OP_READ) ] = {
  591. [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */
  592. [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */
  593. },
  594. [ C(OP_WRITE) ] = {
  595. [ C(RESULT_ACCESS) ] = -1,
  596. [ C(RESULT_MISS) ] = -1,
  597. },
  598. [ C(OP_PREFETCH) ] = {
  599. [ C(RESULT_ACCESS) ] = 0,
  600. [ C(RESULT_MISS) ] = 0,
  601. },
  602. },
  603. [ C(LL ) ] = {
  604. [ C(OP_READ) ] = {
  605. [ C(RESULT_ACCESS) ] = 0x4f29, /* L2_LD.MESI */
  606. [ C(RESULT_MISS) ] = 0x4129, /* L2_LD.ISTATE */
  607. },
  608. [ C(OP_WRITE) ] = {
  609. [ C(RESULT_ACCESS) ] = 0x4f2A, /* L2_ST.MESI */
  610. [ C(RESULT_MISS) ] = 0x412A, /* L2_ST.ISTATE */
  611. },
  612. [ C(OP_PREFETCH) ] = {
  613. [ C(RESULT_ACCESS) ] = 0,
  614. [ C(RESULT_MISS) ] = 0,
  615. },
  616. },
  617. [ C(DTLB) ] = {
  618. [ C(OP_READ) ] = {
  619. [ C(RESULT_ACCESS) ] = 0x2140, /* L1D_CACHE_LD.MESI (alias) */
  620. [ C(RESULT_MISS) ] = 0x0508, /* DTLB_MISSES.MISS_LD */
  621. },
  622. [ C(OP_WRITE) ] = {
  623. [ C(RESULT_ACCESS) ] = 0x2240, /* L1D_CACHE_ST.MESI (alias) */
  624. [ C(RESULT_MISS) ] = 0x0608, /* DTLB_MISSES.MISS_ST */
  625. },
  626. [ C(OP_PREFETCH) ] = {
  627. [ C(RESULT_ACCESS) ] = 0,
  628. [ C(RESULT_MISS) ] = 0,
  629. },
  630. },
  631. [ C(ITLB) ] = {
  632. [ C(OP_READ) ] = {
  633. [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */
  634. [ C(RESULT_MISS) ] = 0x0282, /* ITLB.MISSES */
  635. },
  636. [ C(OP_WRITE) ] = {
  637. [ C(RESULT_ACCESS) ] = -1,
  638. [ C(RESULT_MISS) ] = -1,
  639. },
  640. [ C(OP_PREFETCH) ] = {
  641. [ C(RESULT_ACCESS) ] = -1,
  642. [ C(RESULT_MISS) ] = -1,
  643. },
  644. },
  645. [ C(BPU ) ] = {
  646. [ C(OP_READ) ] = {
  647. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */
  648. [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */
  649. },
  650. [ C(OP_WRITE) ] = {
  651. [ C(RESULT_ACCESS) ] = -1,
  652. [ C(RESULT_MISS) ] = -1,
  653. },
  654. [ C(OP_PREFETCH) ] = {
  655. [ C(RESULT_ACCESS) ] = -1,
  656. [ C(RESULT_MISS) ] = -1,
  657. },
  658. },
  659. };
  660. static void intel_pmu_disable_all(void)
  661. {
  662. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  663. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0);
  664. if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask))
  665. intel_pmu_disable_bts();
  666. intel_pmu_pebs_disable_all();
  667. intel_pmu_lbr_disable_all();
  668. }
  669. static void intel_pmu_enable_all(int added)
  670. {
  671. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  672. intel_pmu_pebs_enable_all();
  673. intel_pmu_lbr_enable_all();
  674. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, x86_pmu.intel_ctrl);
  675. if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask)) {
  676. struct perf_event *event =
  677. cpuc->events[X86_PMC_IDX_FIXED_BTS];
  678. if (WARN_ON_ONCE(!event))
  679. return;
  680. intel_pmu_enable_bts(event->hw.config);
  681. }
  682. }
  683. /*
  684. * Workaround for:
  685. * Intel Errata AAK100 (model 26)
  686. * Intel Errata AAP53 (model 30)
  687. * Intel Errata BD53 (model 44)
  688. *
  689. * The official story:
  690. * These chips need to be 'reset' when adding counters by programming the
  691. * magic three (non-counting) events 0x4300B5, 0x4300D2, and 0x4300B1 either
  692. * in sequence on the same PMC or on different PMCs.
  693. *
  694. * In practise it appears some of these events do in fact count, and
  695. * we need to programm all 4 events.
  696. */
  697. static void intel_pmu_nhm_workaround(void)
  698. {
  699. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  700. static const unsigned long nhm_magic[4] = {
  701. 0x4300B5,
  702. 0x4300D2,
  703. 0x4300B1,
  704. 0x4300B1
  705. };
  706. struct perf_event *event;
  707. int i;
  708. /*
  709. * The Errata requires below steps:
  710. * 1) Clear MSR_IA32_PEBS_ENABLE and MSR_CORE_PERF_GLOBAL_CTRL;
  711. * 2) Configure 4 PERFEVTSELx with the magic events and clear
  712. * the corresponding PMCx;
  713. * 3) set bit0~bit3 of MSR_CORE_PERF_GLOBAL_CTRL;
  714. * 4) Clear MSR_CORE_PERF_GLOBAL_CTRL;
  715. * 5) Clear 4 pairs of ERFEVTSELx and PMCx;
  716. */
  717. /*
  718. * The real steps we choose are a little different from above.
  719. * A) To reduce MSR operations, we don't run step 1) as they
  720. * are already cleared before this function is called;
  721. * B) Call x86_perf_event_update to save PMCx before configuring
  722. * PERFEVTSELx with magic number;
  723. * C) With step 5), we do clear only when the PERFEVTSELx is
  724. * not used currently.
  725. * D) Call x86_perf_event_set_period to restore PMCx;
  726. */
  727. /* We always operate 4 pairs of PERF Counters */
  728. for (i = 0; i < 4; i++) {
  729. event = cpuc->events[i];
  730. if (event)
  731. x86_perf_event_update(event);
  732. }
  733. for (i = 0; i < 4; i++) {
  734. wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, nhm_magic[i]);
  735. wrmsrl(MSR_ARCH_PERFMON_PERFCTR0 + i, 0x0);
  736. }
  737. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0xf);
  738. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x0);
  739. for (i = 0; i < 4; i++) {
  740. event = cpuc->events[i];
  741. if (event) {
  742. x86_perf_event_set_period(event);
  743. __x86_pmu_enable_event(&event->hw,
  744. ARCH_PERFMON_EVENTSEL_ENABLE);
  745. } else
  746. wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, 0x0);
  747. }
  748. }
  749. static void intel_pmu_nhm_enable_all(int added)
  750. {
  751. if (added)
  752. intel_pmu_nhm_workaround();
  753. intel_pmu_enable_all(added);
  754. }
  755. static inline u64 intel_pmu_get_status(void)
  756. {
  757. u64 status;
  758. rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status);
  759. return status;
  760. }
  761. static inline void intel_pmu_ack_status(u64 ack)
  762. {
  763. wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack);
  764. }
  765. static void intel_pmu_disable_fixed(struct hw_perf_event *hwc)
  766. {
  767. int idx = hwc->idx - X86_PMC_IDX_FIXED;
  768. u64 ctrl_val, mask;
  769. mask = 0xfULL << (idx * 4);
  770. rdmsrl(hwc->config_base, ctrl_val);
  771. ctrl_val &= ~mask;
  772. wrmsrl(hwc->config_base, ctrl_val);
  773. }
  774. static void intel_pmu_disable_event(struct perf_event *event)
  775. {
  776. struct hw_perf_event *hwc = &event->hw;
  777. if (unlikely(hwc->idx == X86_PMC_IDX_FIXED_BTS)) {
  778. intel_pmu_disable_bts();
  779. intel_pmu_drain_bts_buffer();
  780. return;
  781. }
  782. if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) {
  783. intel_pmu_disable_fixed(hwc);
  784. return;
  785. }
  786. x86_pmu_disable_event(event);
  787. if (unlikely(event->attr.precise_ip))
  788. intel_pmu_pebs_disable(event);
  789. }
  790. static void intel_pmu_enable_fixed(struct hw_perf_event *hwc)
  791. {
  792. int idx = hwc->idx - X86_PMC_IDX_FIXED;
  793. u64 ctrl_val, bits, mask;
  794. /*
  795. * Enable IRQ generation (0x8),
  796. * and enable ring-3 counting (0x2) and ring-0 counting (0x1)
  797. * if requested:
  798. */
  799. bits = 0x8ULL;
  800. if (hwc->config & ARCH_PERFMON_EVENTSEL_USR)
  801. bits |= 0x2;
  802. if (hwc->config & ARCH_PERFMON_EVENTSEL_OS)
  803. bits |= 0x1;
  804. /*
  805. * ANY bit is supported in v3 and up
  806. */
  807. if (x86_pmu.version > 2 && hwc->config & ARCH_PERFMON_EVENTSEL_ANY)
  808. bits |= 0x4;
  809. bits <<= (idx * 4);
  810. mask = 0xfULL << (idx * 4);
  811. rdmsrl(hwc->config_base, ctrl_val);
  812. ctrl_val &= ~mask;
  813. ctrl_val |= bits;
  814. wrmsrl(hwc->config_base, ctrl_val);
  815. }
  816. static void intel_pmu_enable_event(struct perf_event *event)
  817. {
  818. struct hw_perf_event *hwc = &event->hw;
  819. if (unlikely(hwc->idx == X86_PMC_IDX_FIXED_BTS)) {
  820. if (!__this_cpu_read(cpu_hw_events.enabled))
  821. return;
  822. intel_pmu_enable_bts(hwc->config);
  823. return;
  824. }
  825. if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) {
  826. intel_pmu_enable_fixed(hwc);
  827. return;
  828. }
  829. if (unlikely(event->attr.precise_ip))
  830. intel_pmu_pebs_enable(event);
  831. __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE);
  832. }
  833. /*
  834. * Save and restart an expired event. Called by NMI contexts,
  835. * so it has to be careful about preempting normal event ops:
  836. */
  837. static int intel_pmu_save_and_restart(struct perf_event *event)
  838. {
  839. x86_perf_event_update(event);
  840. return x86_perf_event_set_period(event);
  841. }
  842. static void intel_pmu_reset(void)
  843. {
  844. struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds);
  845. unsigned long flags;
  846. int idx;
  847. if (!x86_pmu.num_counters)
  848. return;
  849. local_irq_save(flags);
  850. printk("clearing PMU state on CPU#%d\n", smp_processor_id());
  851. for (idx = 0; idx < x86_pmu.num_counters; idx++) {
  852. checking_wrmsrl(x86_pmu_config_addr(idx), 0ull);
  853. checking_wrmsrl(x86_pmu_event_addr(idx), 0ull);
  854. }
  855. for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++)
  856. checking_wrmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull);
  857. if (ds)
  858. ds->bts_index = ds->bts_buffer_base;
  859. local_irq_restore(flags);
  860. }
  861. /*
  862. * This handler is triggered by the local APIC, so the APIC IRQ handling
  863. * rules apply:
  864. */
  865. static int intel_pmu_handle_irq(struct pt_regs *regs)
  866. {
  867. struct perf_sample_data data;
  868. struct cpu_hw_events *cpuc;
  869. int bit, loops;
  870. u64 status;
  871. int handled;
  872. perf_sample_data_init(&data, 0);
  873. cpuc = &__get_cpu_var(cpu_hw_events);
  874. /*
  875. * Some chipsets need to unmask the LVTPC in a particular spot
  876. * inside the nmi handler. As a result, the unmasking was pushed
  877. * into all the nmi handlers.
  878. *
  879. * This handler doesn't seem to have any issues with the unmasking
  880. * so it was left at the top.
  881. */
  882. apic_write(APIC_LVTPC, APIC_DM_NMI);
  883. intel_pmu_disable_all();
  884. handled = intel_pmu_drain_bts_buffer();
  885. status = intel_pmu_get_status();
  886. if (!status) {
  887. intel_pmu_enable_all(0);
  888. return handled;
  889. }
  890. loops = 0;
  891. again:
  892. intel_pmu_ack_status(status);
  893. if (++loops > 100) {
  894. WARN_ONCE(1, "perfevents: irq loop stuck!\n");
  895. perf_event_print_debug();
  896. intel_pmu_reset();
  897. goto done;
  898. }
  899. inc_irq_stat(apic_perf_irqs);
  900. intel_pmu_lbr_read();
  901. /*
  902. * PEBS overflow sets bit 62 in the global status register
  903. */
  904. if (__test_and_clear_bit(62, (unsigned long *)&status)) {
  905. handled++;
  906. x86_pmu.drain_pebs(regs);
  907. }
  908. for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) {
  909. struct perf_event *event = cpuc->events[bit];
  910. handled++;
  911. if (!test_bit(bit, cpuc->active_mask))
  912. continue;
  913. if (!intel_pmu_save_and_restart(event))
  914. continue;
  915. data.period = event->hw.last_period;
  916. if (perf_event_overflow(event, 1, &data, regs))
  917. x86_pmu_stop(event, 0);
  918. }
  919. /*
  920. * Repeat if there is more work to be done:
  921. */
  922. status = intel_pmu_get_status();
  923. if (status)
  924. goto again;
  925. done:
  926. intel_pmu_enable_all(0);
  927. return handled;
  928. }
  929. static struct event_constraint *
  930. intel_bts_constraints(struct perf_event *event)
  931. {
  932. struct hw_perf_event *hwc = &event->hw;
  933. unsigned int hw_event, bts_event;
  934. if (event->attr.freq)
  935. return NULL;
  936. hw_event = hwc->config & INTEL_ARCH_EVENT_MASK;
  937. bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS);
  938. if (unlikely(hw_event == bts_event && hwc->sample_period == 1))
  939. return &bts_constraint;
  940. return NULL;
  941. }
  942. static struct event_constraint *
  943. intel_percore_constraints(struct cpu_hw_events *cpuc, struct perf_event *event)
  944. {
  945. struct hw_perf_event *hwc = &event->hw;
  946. unsigned int e = hwc->config & ARCH_PERFMON_EVENTSEL_EVENT;
  947. struct event_constraint *c;
  948. struct intel_percore *pc;
  949. struct er_account *era;
  950. int i;
  951. int free_slot;
  952. int found;
  953. if (!x86_pmu.percore_constraints || hwc->extra_alloc)
  954. return NULL;
  955. for (c = x86_pmu.percore_constraints; c->cmask; c++) {
  956. if (e != c->code)
  957. continue;
  958. /*
  959. * Allocate resource per core.
  960. */
  961. pc = cpuc->per_core;
  962. if (!pc)
  963. break;
  964. c = &emptyconstraint;
  965. raw_spin_lock(&pc->lock);
  966. free_slot = -1;
  967. found = 0;
  968. for (i = 0; i < MAX_EXTRA_REGS; i++) {
  969. era = &pc->regs[i];
  970. if (era->ref > 0 && hwc->extra_reg == era->extra_reg) {
  971. /* Allow sharing same config */
  972. if (hwc->extra_config == era->extra_config) {
  973. era->ref++;
  974. cpuc->percore_used = 1;
  975. hwc->extra_alloc = 1;
  976. c = NULL;
  977. }
  978. /* else conflict */
  979. found = 1;
  980. break;
  981. } else if (era->ref == 0 && free_slot == -1)
  982. free_slot = i;
  983. }
  984. if (!found && free_slot != -1) {
  985. era = &pc->regs[free_slot];
  986. era->ref = 1;
  987. era->extra_reg = hwc->extra_reg;
  988. era->extra_config = hwc->extra_config;
  989. cpuc->percore_used = 1;
  990. hwc->extra_alloc = 1;
  991. c = NULL;
  992. }
  993. raw_spin_unlock(&pc->lock);
  994. return c;
  995. }
  996. return NULL;
  997. }
  998. static struct event_constraint *
  999. intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event)
  1000. {
  1001. struct event_constraint *c;
  1002. c = intel_bts_constraints(event);
  1003. if (c)
  1004. return c;
  1005. c = intel_pebs_constraints(event);
  1006. if (c)
  1007. return c;
  1008. c = intel_percore_constraints(cpuc, event);
  1009. if (c)
  1010. return c;
  1011. return x86_get_event_constraints(cpuc, event);
  1012. }
  1013. static void intel_put_event_constraints(struct cpu_hw_events *cpuc,
  1014. struct perf_event *event)
  1015. {
  1016. struct extra_reg *er;
  1017. struct intel_percore *pc;
  1018. struct er_account *era;
  1019. struct hw_perf_event *hwc = &event->hw;
  1020. int i, allref;
  1021. if (!cpuc->percore_used)
  1022. return;
  1023. for (er = x86_pmu.extra_regs; er->msr; er++) {
  1024. if (er->event != (hwc->config & er->config_mask))
  1025. continue;
  1026. pc = cpuc->per_core;
  1027. raw_spin_lock(&pc->lock);
  1028. for (i = 0; i < MAX_EXTRA_REGS; i++) {
  1029. era = &pc->regs[i];
  1030. if (era->ref > 0 &&
  1031. era->extra_config == hwc->extra_config &&
  1032. era->extra_reg == er->msr) {
  1033. era->ref--;
  1034. hwc->extra_alloc = 0;
  1035. break;
  1036. }
  1037. }
  1038. allref = 0;
  1039. for (i = 0; i < MAX_EXTRA_REGS; i++)
  1040. allref += pc->regs[i].ref;
  1041. if (allref == 0)
  1042. cpuc->percore_used = 0;
  1043. raw_spin_unlock(&pc->lock);
  1044. break;
  1045. }
  1046. }
  1047. static int intel_pmu_hw_config(struct perf_event *event)
  1048. {
  1049. int ret = x86_pmu_hw_config(event);
  1050. if (ret)
  1051. return ret;
  1052. if (event->attr.precise_ip &&
  1053. (event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) {
  1054. /*
  1055. * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P
  1056. * (0x003c) so that we can use it with PEBS.
  1057. *
  1058. * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't
  1059. * PEBS capable. However we can use INST_RETIRED.ANY_P
  1060. * (0x00c0), which is a PEBS capable event, to get the same
  1061. * count.
  1062. *
  1063. * INST_RETIRED.ANY_P counts the number of cycles that retires
  1064. * CNTMASK instructions. By setting CNTMASK to a value (16)
  1065. * larger than the maximum number of instructions that can be
  1066. * retired per cycle (4) and then inverting the condition, we
  1067. * count all cycles that retire 16 or less instructions, which
  1068. * is every cycle.
  1069. *
  1070. * Thereby we gain a PEBS capable cycle counter.
  1071. */
  1072. u64 alt_config = 0x108000c0; /* INST_RETIRED.TOTAL_CYCLES */
  1073. alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK);
  1074. event->hw.config = alt_config;
  1075. }
  1076. if (event->attr.type != PERF_TYPE_RAW)
  1077. return 0;
  1078. if (!(event->attr.config & ARCH_PERFMON_EVENTSEL_ANY))
  1079. return 0;
  1080. if (x86_pmu.version < 3)
  1081. return -EINVAL;
  1082. if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
  1083. return -EACCES;
  1084. event->hw.config |= ARCH_PERFMON_EVENTSEL_ANY;
  1085. return 0;
  1086. }
  1087. static __initconst const struct x86_pmu core_pmu = {
  1088. .name = "core",
  1089. .handle_irq = x86_pmu_handle_irq,
  1090. .disable_all = x86_pmu_disable_all,
  1091. .enable_all = x86_pmu_enable_all,
  1092. .enable = x86_pmu_enable_event,
  1093. .disable = x86_pmu_disable_event,
  1094. .hw_config = x86_pmu_hw_config,
  1095. .schedule_events = x86_schedule_events,
  1096. .eventsel = MSR_ARCH_PERFMON_EVENTSEL0,
  1097. .perfctr = MSR_ARCH_PERFMON_PERFCTR0,
  1098. .event_map = intel_pmu_event_map,
  1099. .max_events = ARRAY_SIZE(intel_perfmon_event_map),
  1100. .apic = 1,
  1101. /*
  1102. * Intel PMCs cannot be accessed sanely above 32 bit width,
  1103. * so we install an artificial 1<<31 period regardless of
  1104. * the generic event period:
  1105. */
  1106. .max_period = (1ULL << 31) - 1,
  1107. .get_event_constraints = intel_get_event_constraints,
  1108. .put_event_constraints = intel_put_event_constraints,
  1109. .event_constraints = intel_core_event_constraints,
  1110. };
  1111. static int intel_pmu_cpu_prepare(int cpu)
  1112. {
  1113. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  1114. if (!cpu_has_ht_siblings())
  1115. return NOTIFY_OK;
  1116. cpuc->per_core = kzalloc_node(sizeof(struct intel_percore),
  1117. GFP_KERNEL, cpu_to_node(cpu));
  1118. if (!cpuc->per_core)
  1119. return NOTIFY_BAD;
  1120. raw_spin_lock_init(&cpuc->per_core->lock);
  1121. cpuc->per_core->core_id = -1;
  1122. return NOTIFY_OK;
  1123. }
  1124. static void intel_pmu_cpu_starting(int cpu)
  1125. {
  1126. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  1127. int core_id = topology_core_id(cpu);
  1128. int i;
  1129. init_debug_store_on_cpu(cpu);
  1130. /*
  1131. * Deal with CPUs that don't clear their LBRs on power-up.
  1132. */
  1133. intel_pmu_lbr_reset();
  1134. if (!cpu_has_ht_siblings())
  1135. return;
  1136. for_each_cpu(i, topology_thread_cpumask(cpu)) {
  1137. struct intel_percore *pc = per_cpu(cpu_hw_events, i).per_core;
  1138. if (pc && pc->core_id == core_id) {
  1139. kfree(cpuc->per_core);
  1140. cpuc->per_core = pc;
  1141. break;
  1142. }
  1143. }
  1144. cpuc->per_core->core_id = core_id;
  1145. cpuc->per_core->refcnt++;
  1146. }
  1147. static void intel_pmu_cpu_dying(int cpu)
  1148. {
  1149. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  1150. struct intel_percore *pc = cpuc->per_core;
  1151. if (pc) {
  1152. if (pc->core_id == -1 || --pc->refcnt == 0)
  1153. kfree(pc);
  1154. cpuc->per_core = NULL;
  1155. }
  1156. fini_debug_store_on_cpu(cpu);
  1157. }
  1158. static __initconst const struct x86_pmu intel_pmu = {
  1159. .name = "Intel",
  1160. .handle_irq = intel_pmu_handle_irq,
  1161. .disable_all = intel_pmu_disable_all,
  1162. .enable_all = intel_pmu_enable_all,
  1163. .enable = intel_pmu_enable_event,
  1164. .disable = intel_pmu_disable_event,
  1165. .hw_config = intel_pmu_hw_config,
  1166. .schedule_events = x86_schedule_events,
  1167. .eventsel = MSR_ARCH_PERFMON_EVENTSEL0,
  1168. .perfctr = MSR_ARCH_PERFMON_PERFCTR0,
  1169. .event_map = intel_pmu_event_map,
  1170. .max_events = ARRAY_SIZE(intel_perfmon_event_map),
  1171. .apic = 1,
  1172. /*
  1173. * Intel PMCs cannot be accessed sanely above 32 bit width,
  1174. * so we install an artificial 1<<31 period regardless of
  1175. * the generic event period:
  1176. */
  1177. .max_period = (1ULL << 31) - 1,
  1178. .get_event_constraints = intel_get_event_constraints,
  1179. .put_event_constraints = intel_put_event_constraints,
  1180. .cpu_prepare = intel_pmu_cpu_prepare,
  1181. .cpu_starting = intel_pmu_cpu_starting,
  1182. .cpu_dying = intel_pmu_cpu_dying,
  1183. };
  1184. static void intel_clovertown_quirks(void)
  1185. {
  1186. /*
  1187. * PEBS is unreliable due to:
  1188. *
  1189. * AJ67 - PEBS may experience CPL leaks
  1190. * AJ68 - PEBS PMI may be delayed by one event
  1191. * AJ69 - GLOBAL_STATUS[62] will only be set when DEBUGCTL[12]
  1192. * AJ106 - FREEZE_LBRS_ON_PMI doesn't work in combination with PEBS
  1193. *
  1194. * AJ67 could be worked around by restricting the OS/USR flags.
  1195. * AJ69 could be worked around by setting PMU_FREEZE_ON_PMI.
  1196. *
  1197. * AJ106 could possibly be worked around by not allowing LBR
  1198. * usage from PEBS, including the fixup.
  1199. * AJ68 could possibly be worked around by always programming
  1200. * a pebs_event_reset[0] value and coping with the lost events.
  1201. *
  1202. * But taken together it might just make sense to not enable PEBS on
  1203. * these chips.
  1204. */
  1205. printk(KERN_WARNING "PEBS disabled due to CPU errata.\n");
  1206. x86_pmu.pebs = 0;
  1207. x86_pmu.pebs_constraints = NULL;
  1208. }
  1209. static __init int intel_pmu_init(void)
  1210. {
  1211. union cpuid10_edx edx;
  1212. union cpuid10_eax eax;
  1213. unsigned int unused;
  1214. unsigned int ebx;
  1215. int version;
  1216. if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) {
  1217. switch (boot_cpu_data.x86) {
  1218. case 0x6:
  1219. return p6_pmu_init();
  1220. case 0xf:
  1221. return p4_pmu_init();
  1222. }
  1223. return -ENODEV;
  1224. }
  1225. /*
  1226. * Check whether the Architectural PerfMon supports
  1227. * Branch Misses Retired hw_event or not.
  1228. */
  1229. cpuid(10, &eax.full, &ebx, &unused, &edx.full);
  1230. if (eax.split.mask_length <= ARCH_PERFMON_BRANCH_MISSES_RETIRED)
  1231. return -ENODEV;
  1232. version = eax.split.version_id;
  1233. if (version < 2)
  1234. x86_pmu = core_pmu;
  1235. else
  1236. x86_pmu = intel_pmu;
  1237. x86_pmu.version = version;
  1238. x86_pmu.num_counters = eax.split.num_counters;
  1239. x86_pmu.cntval_bits = eax.split.bit_width;
  1240. x86_pmu.cntval_mask = (1ULL << eax.split.bit_width) - 1;
  1241. /*
  1242. * Quirk: v2 perfmon does not report fixed-purpose events, so
  1243. * assume at least 3 events:
  1244. */
  1245. if (version > 1)
  1246. x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
  1247. /*
  1248. * v2 and above have a perf capabilities MSR
  1249. */
  1250. if (version > 1) {
  1251. u64 capabilities;
  1252. rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
  1253. x86_pmu.intel_cap.capabilities = capabilities;
  1254. }
  1255. intel_ds_init();
  1256. /*
  1257. * Install the hw-cache-events table:
  1258. */
  1259. switch (boot_cpu_data.x86_model) {
  1260. case 14: /* 65 nm core solo/duo, "Yonah" */
  1261. pr_cont("Core events, ");
  1262. break;
  1263. case 15: /* original 65 nm celeron/pentium/core2/xeon, "Merom"/"Conroe" */
  1264. x86_pmu.quirks = intel_clovertown_quirks;
  1265. case 22: /* single-core 65 nm celeron/core2solo "Merom-L"/"Conroe-L" */
  1266. case 23: /* current 45 nm celeron/core2/xeon "Penryn"/"Wolfdale" */
  1267. case 29: /* six-core 45 nm xeon "Dunnington" */
  1268. memcpy(hw_cache_event_ids, core2_hw_cache_event_ids,
  1269. sizeof(hw_cache_event_ids));
  1270. intel_pmu_lbr_init_core();
  1271. x86_pmu.event_constraints = intel_core2_event_constraints;
  1272. x86_pmu.pebs_constraints = intel_core2_pebs_event_constraints;
  1273. pr_cont("Core2 events, ");
  1274. break;
  1275. case 26: /* 45 nm nehalem, "Bloomfield" */
  1276. case 30: /* 45 nm nehalem, "Lynnfield" */
  1277. case 46: /* 45 nm nehalem-ex, "Beckton" */
  1278. memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids,
  1279. sizeof(hw_cache_event_ids));
  1280. memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs,
  1281. sizeof(hw_cache_extra_regs));
  1282. intel_pmu_lbr_init_nhm();
  1283. x86_pmu.event_constraints = intel_nehalem_event_constraints;
  1284. x86_pmu.pebs_constraints = intel_nehalem_pebs_event_constraints;
  1285. x86_pmu.percore_constraints = intel_nehalem_percore_constraints;
  1286. x86_pmu.enable_all = intel_pmu_nhm_enable_all;
  1287. x86_pmu.extra_regs = intel_nehalem_extra_regs;
  1288. /* UOPS_ISSUED.STALLED_CYCLES */
  1289. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x180010e;
  1290. /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */
  1291. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x1803fb1;
  1292. if (ebx & 0x40) {
  1293. /*
  1294. * Erratum AAJ80 detected, we work it around by using
  1295. * the BR_MISP_EXEC.ANY event. This will over-count
  1296. * branch-misses, but it's still much better than the
  1297. * architectural event which is often completely bogus:
  1298. */
  1299. intel_perfmon_event_map[PERF_COUNT_HW_BRANCH_MISSES] = 0x7f89;
  1300. pr_cont("erratum AAJ80 worked around, ");
  1301. }
  1302. pr_cont("Nehalem events, ");
  1303. break;
  1304. case 28: /* Atom */
  1305. memcpy(hw_cache_event_ids, atom_hw_cache_event_ids,
  1306. sizeof(hw_cache_event_ids));
  1307. intel_pmu_lbr_init_atom();
  1308. x86_pmu.event_constraints = intel_gen_event_constraints;
  1309. x86_pmu.pebs_constraints = intel_atom_pebs_event_constraints;
  1310. pr_cont("Atom events, ");
  1311. break;
  1312. case 37: /* 32 nm nehalem, "Clarkdale" */
  1313. case 44: /* 32 nm nehalem, "Gulftown" */
  1314. case 47: /* 32 nm Xeon E7 */
  1315. memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids,
  1316. sizeof(hw_cache_event_ids));
  1317. memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs,
  1318. sizeof(hw_cache_extra_regs));
  1319. intel_pmu_lbr_init_nhm();
  1320. x86_pmu.event_constraints = intel_westmere_event_constraints;
  1321. x86_pmu.percore_constraints = intel_westmere_percore_constraints;
  1322. x86_pmu.enable_all = intel_pmu_nhm_enable_all;
  1323. x86_pmu.pebs_constraints = intel_westmere_pebs_event_constraints;
  1324. x86_pmu.extra_regs = intel_westmere_extra_regs;
  1325. /* UOPS_ISSUED.STALLED_CYCLES */
  1326. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x180010e;
  1327. /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */
  1328. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x1803fb1;
  1329. pr_cont("Westmere events, ");
  1330. break;
  1331. case 42: /* SandyBridge */
  1332. case 45: /* SandyBridge, "Romely-EP" */
  1333. memcpy(hw_cache_event_ids, snb_hw_cache_event_ids,
  1334. sizeof(hw_cache_event_ids));
  1335. intel_pmu_lbr_init_nhm();
  1336. x86_pmu.event_constraints = intel_snb_event_constraints;
  1337. x86_pmu.pebs_constraints = intel_snb_pebs_events;
  1338. /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
  1339. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = 0x180010e;
  1340. /* UOPS_DISPATCHED.THREAD,c=1,i=1 to count stall cycles*/
  1341. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = 0x18001b1;
  1342. pr_cont("SandyBridge events, ");
  1343. break;
  1344. default:
  1345. /*
  1346. * default constraints for v2 and up
  1347. */
  1348. x86_pmu.event_constraints = intel_gen_event_constraints;
  1349. pr_cont("generic architected perfmon, ");
  1350. }
  1351. return 0;
  1352. }
  1353. #else /* CONFIG_CPU_SUP_INTEL */
  1354. static int intel_pmu_init(void)
  1355. {
  1356. return 0;
  1357. }
  1358. #endif /* CONFIG_CPU_SUP_INTEL */