perf_event_p4.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191
  1. /*
  2. * Netburst Perfomance Events (P4, old Xeon)
  3. *
  4. * Copyright (C) 2010 Parallels, Inc., Cyrill Gorcunov <gorcunov@openvz.org>
  5. * Copyright (C) 2010 Intel Corporation, Lin Ming <ming.m.lin@intel.com>
  6. *
  7. * For licencing details see kernel-base/COPYING
  8. */
  9. #ifdef CONFIG_CPU_SUP_INTEL
  10. #include <asm/perf_event_p4.h>
  11. #define P4_CNTR_LIMIT 3
  12. /*
  13. * array indices: 0,1 - HT threads, used with HT enabled cpu
  14. */
  15. struct p4_event_bind {
  16. unsigned int opcode; /* Event code and ESCR selector */
  17. unsigned int escr_msr[2]; /* ESCR MSR for this event */
  18. unsigned int escr_emask; /* valid ESCR EventMask bits */
  19. unsigned int shared; /* event is shared across threads */
  20. char cntr[2][P4_CNTR_LIMIT]; /* counter index (offset), -1 on abscence */
  21. };
  22. struct p4_pebs_bind {
  23. unsigned int metric_pebs;
  24. unsigned int metric_vert;
  25. };
  26. /* it sets P4_PEBS_ENABLE_UOP_TAG as well */
  27. #define P4_GEN_PEBS_BIND(name, pebs, vert) \
  28. [P4_PEBS_METRIC__##name] = { \
  29. .metric_pebs = pebs | P4_PEBS_ENABLE_UOP_TAG, \
  30. .metric_vert = vert, \
  31. }
  32. /*
  33. * note we have P4_PEBS_ENABLE_UOP_TAG always set here
  34. *
  35. * it's needed for mapping P4_PEBS_CONFIG_METRIC_MASK bits of
  36. * event configuration to find out which values are to be
  37. * written into MSR_IA32_PEBS_ENABLE and MSR_P4_PEBS_MATRIX_VERT
  38. * resgisters
  39. */
  40. static struct p4_pebs_bind p4_pebs_bind_map[] = {
  41. P4_GEN_PEBS_BIND(1stl_cache_load_miss_retired, 0x0000001, 0x0000001),
  42. P4_GEN_PEBS_BIND(2ndl_cache_load_miss_retired, 0x0000002, 0x0000001),
  43. P4_GEN_PEBS_BIND(dtlb_load_miss_retired, 0x0000004, 0x0000001),
  44. P4_GEN_PEBS_BIND(dtlb_store_miss_retired, 0x0000004, 0x0000002),
  45. P4_GEN_PEBS_BIND(dtlb_all_miss_retired, 0x0000004, 0x0000003),
  46. P4_GEN_PEBS_BIND(tagged_mispred_branch, 0x0018000, 0x0000010),
  47. P4_GEN_PEBS_BIND(mob_load_replay_retired, 0x0000200, 0x0000001),
  48. P4_GEN_PEBS_BIND(split_load_retired, 0x0000400, 0x0000001),
  49. P4_GEN_PEBS_BIND(split_store_retired, 0x0000400, 0x0000002),
  50. };
  51. /*
  52. * Note that we don't use CCCR1 here, there is an
  53. * exception for P4_BSQ_ALLOCATION but we just have
  54. * no workaround
  55. *
  56. * consider this binding as resources which particular
  57. * event may borrow, it doesn't contain EventMask,
  58. * Tags and friends -- they are left to a caller
  59. */
  60. static struct p4_event_bind p4_event_bind_map[] = {
  61. [P4_EVENT_TC_DELIVER_MODE] = {
  62. .opcode = P4_OPCODE(P4_EVENT_TC_DELIVER_MODE),
  63. .escr_msr = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 },
  64. .escr_emask =
  65. P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, DD) |
  66. P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, DB) |
  67. P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, DI) |
  68. P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, BD) |
  69. P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, BB) |
  70. P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, BI) |
  71. P4_ESCR_EMASK_BIT(P4_EVENT_TC_DELIVER_MODE, ID),
  72. .shared = 1,
  73. .cntr = { {4, 5, -1}, {6, 7, -1} },
  74. },
  75. [P4_EVENT_BPU_FETCH_REQUEST] = {
  76. .opcode = P4_OPCODE(P4_EVENT_BPU_FETCH_REQUEST),
  77. .escr_msr = { MSR_P4_BPU_ESCR0, MSR_P4_BPU_ESCR1 },
  78. .escr_emask =
  79. P4_ESCR_EMASK_BIT(P4_EVENT_BPU_FETCH_REQUEST, TCMISS),
  80. .cntr = { {0, -1, -1}, {2, -1, -1} },
  81. },
  82. [P4_EVENT_ITLB_REFERENCE] = {
  83. .opcode = P4_OPCODE(P4_EVENT_ITLB_REFERENCE),
  84. .escr_msr = { MSR_P4_ITLB_ESCR0, MSR_P4_ITLB_ESCR1 },
  85. .escr_emask =
  86. P4_ESCR_EMASK_BIT(P4_EVENT_ITLB_REFERENCE, HIT) |
  87. P4_ESCR_EMASK_BIT(P4_EVENT_ITLB_REFERENCE, MISS) |
  88. P4_ESCR_EMASK_BIT(P4_EVENT_ITLB_REFERENCE, HIT_UK),
  89. .cntr = { {0, -1, -1}, {2, -1, -1} },
  90. },
  91. [P4_EVENT_MEMORY_CANCEL] = {
  92. .opcode = P4_OPCODE(P4_EVENT_MEMORY_CANCEL),
  93. .escr_msr = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 },
  94. .escr_emask =
  95. P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_CANCEL, ST_RB_FULL) |
  96. P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_CANCEL, 64K_CONF),
  97. .cntr = { {8, 9, -1}, {10, 11, -1} },
  98. },
  99. [P4_EVENT_MEMORY_COMPLETE] = {
  100. .opcode = P4_OPCODE(P4_EVENT_MEMORY_COMPLETE),
  101. .escr_msr = { MSR_P4_SAAT_ESCR0 , MSR_P4_SAAT_ESCR1 },
  102. .escr_emask =
  103. P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_COMPLETE, LSC) |
  104. P4_ESCR_EMASK_BIT(P4_EVENT_MEMORY_COMPLETE, SSC),
  105. .cntr = { {8, 9, -1}, {10, 11, -1} },
  106. },
  107. [P4_EVENT_LOAD_PORT_REPLAY] = {
  108. .opcode = P4_OPCODE(P4_EVENT_LOAD_PORT_REPLAY),
  109. .escr_msr = { MSR_P4_SAAT_ESCR0, MSR_P4_SAAT_ESCR1 },
  110. .escr_emask =
  111. P4_ESCR_EMASK_BIT(P4_EVENT_LOAD_PORT_REPLAY, SPLIT_LD),
  112. .cntr = { {8, 9, -1}, {10, 11, -1} },
  113. },
  114. [P4_EVENT_STORE_PORT_REPLAY] = {
  115. .opcode = P4_OPCODE(P4_EVENT_STORE_PORT_REPLAY),
  116. .escr_msr = { MSR_P4_SAAT_ESCR0 , MSR_P4_SAAT_ESCR1 },
  117. .escr_emask =
  118. P4_ESCR_EMASK_BIT(P4_EVENT_STORE_PORT_REPLAY, SPLIT_ST),
  119. .cntr = { {8, 9, -1}, {10, 11, -1} },
  120. },
  121. [P4_EVENT_MOB_LOAD_REPLAY] = {
  122. .opcode = P4_OPCODE(P4_EVENT_MOB_LOAD_REPLAY),
  123. .escr_msr = { MSR_P4_MOB_ESCR0, MSR_P4_MOB_ESCR1 },
  124. .escr_emask =
  125. P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY, NO_STA) |
  126. P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY, NO_STD) |
  127. P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY, PARTIAL_DATA) |
  128. P4_ESCR_EMASK_BIT(P4_EVENT_MOB_LOAD_REPLAY, UNALGN_ADDR),
  129. .cntr = { {0, -1, -1}, {2, -1, -1} },
  130. },
  131. [P4_EVENT_PAGE_WALK_TYPE] = {
  132. .opcode = P4_OPCODE(P4_EVENT_PAGE_WALK_TYPE),
  133. .escr_msr = { MSR_P4_PMH_ESCR0, MSR_P4_PMH_ESCR1 },
  134. .escr_emask =
  135. P4_ESCR_EMASK_BIT(P4_EVENT_PAGE_WALK_TYPE, DTMISS) |
  136. P4_ESCR_EMASK_BIT(P4_EVENT_PAGE_WALK_TYPE, ITMISS),
  137. .shared = 1,
  138. .cntr = { {0, -1, -1}, {2, -1, -1} },
  139. },
  140. [P4_EVENT_BSQ_CACHE_REFERENCE] = {
  141. .opcode = P4_OPCODE(P4_EVENT_BSQ_CACHE_REFERENCE),
  142. .escr_msr = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR1 },
  143. .escr_emask =
  144. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITS) |
  145. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITE) |
  146. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITM) |
  147. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITS) |
  148. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITE) |
  149. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITM) |
  150. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_MISS) |
  151. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_MISS) |
  152. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, WR_2ndL_MISS),
  153. .cntr = { {0, -1, -1}, {2, -1, -1} },
  154. },
  155. [P4_EVENT_IOQ_ALLOCATION] = {
  156. .opcode = P4_OPCODE(P4_EVENT_IOQ_ALLOCATION),
  157. .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
  158. .escr_emask =
  159. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, DEFAULT) |
  160. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, ALL_READ) |
  161. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, ALL_WRITE) |
  162. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, MEM_UC) |
  163. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, MEM_WC) |
  164. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, MEM_WT) |
  165. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, MEM_WP) |
  166. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, MEM_WB) |
  167. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, OWN) |
  168. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, OTHER) |
  169. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ALLOCATION, PREFETCH),
  170. .cntr = { {0, -1, -1}, {2, -1, -1} },
  171. },
  172. [P4_EVENT_IOQ_ACTIVE_ENTRIES] = { /* shared ESCR */
  173. .opcode = P4_OPCODE(P4_EVENT_IOQ_ACTIVE_ENTRIES),
  174. .escr_msr = { MSR_P4_FSB_ESCR1, MSR_P4_FSB_ESCR1 },
  175. .escr_emask =
  176. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, DEFAULT) |
  177. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, ALL_READ) |
  178. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, ALL_WRITE) |
  179. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_UC) |
  180. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WC) |
  181. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WT) |
  182. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WP) |
  183. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WB) |
  184. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, OWN) |
  185. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, OTHER) |
  186. P4_ESCR_EMASK_BIT(P4_EVENT_IOQ_ACTIVE_ENTRIES, PREFETCH),
  187. .cntr = { {2, -1, -1}, {3, -1, -1} },
  188. },
  189. [P4_EVENT_FSB_DATA_ACTIVITY] = {
  190. .opcode = P4_OPCODE(P4_EVENT_FSB_DATA_ACTIVITY),
  191. .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
  192. .escr_emask =
  193. P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_DRV) |
  194. P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OWN) |
  195. P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OTHER) |
  196. P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_DRV) |
  197. P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_OWN) |
  198. P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_OTHER),
  199. .shared = 1,
  200. .cntr = { {0, -1, -1}, {2, -1, -1} },
  201. },
  202. [P4_EVENT_BSQ_ALLOCATION] = { /* shared ESCR, broken CCCR1 */
  203. .opcode = P4_OPCODE(P4_EVENT_BSQ_ALLOCATION),
  204. .escr_msr = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR0 },
  205. .escr_emask =
  206. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_TYPE0) |
  207. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_TYPE1) |
  208. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_LEN0) |
  209. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_LEN1) |
  210. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_IO_TYPE) |
  211. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_LOCK_TYPE) |
  212. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_CACHE_TYPE) |
  213. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_SPLIT_TYPE) |
  214. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_DEM_TYPE) |
  215. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, REQ_ORD_TYPE) |
  216. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE0) |
  217. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE1) |
  218. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE2),
  219. .cntr = { {0, -1, -1}, {1, -1, -1} },
  220. },
  221. [P4_EVENT_BSQ_ACTIVE_ENTRIES] = { /* shared ESCR */
  222. .opcode = P4_OPCODE(P4_EVENT_BSQ_ACTIVE_ENTRIES),
  223. .escr_msr = { MSR_P4_BSU_ESCR1 , MSR_P4_BSU_ESCR1 },
  224. .escr_emask =
  225. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_TYPE0) |
  226. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_TYPE1) |
  227. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LEN0) |
  228. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LEN1) |
  229. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_IO_TYPE) |
  230. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LOCK_TYPE) |
  231. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_CACHE_TYPE) |
  232. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_SPLIT_TYPE) |
  233. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_DEM_TYPE) |
  234. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_ORD_TYPE) |
  235. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE0) |
  236. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE1) |
  237. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE2),
  238. .cntr = { {2, -1, -1}, {3, -1, -1} },
  239. },
  240. [P4_EVENT_SSE_INPUT_ASSIST] = {
  241. .opcode = P4_OPCODE(P4_EVENT_SSE_INPUT_ASSIST),
  242. .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
  243. .escr_emask =
  244. P4_ESCR_EMASK_BIT(P4_EVENT_SSE_INPUT_ASSIST, ALL),
  245. .shared = 1,
  246. .cntr = { {8, 9, -1}, {10, 11, -1} },
  247. },
  248. [P4_EVENT_PACKED_SP_UOP] = {
  249. .opcode = P4_OPCODE(P4_EVENT_PACKED_SP_UOP),
  250. .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
  251. .escr_emask =
  252. P4_ESCR_EMASK_BIT(P4_EVENT_PACKED_SP_UOP, ALL),
  253. .shared = 1,
  254. .cntr = { {8, 9, -1}, {10, 11, -1} },
  255. },
  256. [P4_EVENT_PACKED_DP_UOP] = {
  257. .opcode = P4_OPCODE(P4_EVENT_PACKED_DP_UOP),
  258. .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
  259. .escr_emask =
  260. P4_ESCR_EMASK_BIT(P4_EVENT_PACKED_DP_UOP, ALL),
  261. .shared = 1,
  262. .cntr = { {8, 9, -1}, {10, 11, -1} },
  263. },
  264. [P4_EVENT_SCALAR_SP_UOP] = {
  265. .opcode = P4_OPCODE(P4_EVENT_SCALAR_SP_UOP),
  266. .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
  267. .escr_emask =
  268. P4_ESCR_EMASK_BIT(P4_EVENT_SCALAR_SP_UOP, ALL),
  269. .shared = 1,
  270. .cntr = { {8, 9, -1}, {10, 11, -1} },
  271. },
  272. [P4_EVENT_SCALAR_DP_UOP] = {
  273. .opcode = P4_OPCODE(P4_EVENT_SCALAR_DP_UOP),
  274. .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
  275. .escr_emask =
  276. P4_ESCR_EMASK_BIT(P4_EVENT_SCALAR_DP_UOP, ALL),
  277. .shared = 1,
  278. .cntr = { {8, 9, -1}, {10, 11, -1} },
  279. },
  280. [P4_EVENT_64BIT_MMX_UOP] = {
  281. .opcode = P4_OPCODE(P4_EVENT_64BIT_MMX_UOP),
  282. .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
  283. .escr_emask =
  284. P4_ESCR_EMASK_BIT(P4_EVENT_64BIT_MMX_UOP, ALL),
  285. .shared = 1,
  286. .cntr = { {8, 9, -1}, {10, 11, -1} },
  287. },
  288. [P4_EVENT_128BIT_MMX_UOP] = {
  289. .opcode = P4_OPCODE(P4_EVENT_128BIT_MMX_UOP),
  290. .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
  291. .escr_emask =
  292. P4_ESCR_EMASK_BIT(P4_EVENT_128BIT_MMX_UOP, ALL),
  293. .shared = 1,
  294. .cntr = { {8, 9, -1}, {10, 11, -1} },
  295. },
  296. [P4_EVENT_X87_FP_UOP] = {
  297. .opcode = P4_OPCODE(P4_EVENT_X87_FP_UOP),
  298. .escr_msr = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
  299. .escr_emask =
  300. P4_ESCR_EMASK_BIT(P4_EVENT_X87_FP_UOP, ALL),
  301. .shared = 1,
  302. .cntr = { {8, 9, -1}, {10, 11, -1} },
  303. },
  304. [P4_EVENT_TC_MISC] = {
  305. .opcode = P4_OPCODE(P4_EVENT_TC_MISC),
  306. .escr_msr = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 },
  307. .escr_emask =
  308. P4_ESCR_EMASK_BIT(P4_EVENT_TC_MISC, FLUSH),
  309. .cntr = { {4, 5, -1}, {6, 7, -1} },
  310. },
  311. [P4_EVENT_GLOBAL_POWER_EVENTS] = {
  312. .opcode = P4_OPCODE(P4_EVENT_GLOBAL_POWER_EVENTS),
  313. .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
  314. .escr_emask =
  315. P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING),
  316. .cntr = { {0, -1, -1}, {2, -1, -1} },
  317. },
  318. [P4_EVENT_TC_MS_XFER] = {
  319. .opcode = P4_OPCODE(P4_EVENT_TC_MS_XFER),
  320. .escr_msr = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 },
  321. .escr_emask =
  322. P4_ESCR_EMASK_BIT(P4_EVENT_TC_MS_XFER, CISC),
  323. .cntr = { {4, 5, -1}, {6, 7, -1} },
  324. },
  325. [P4_EVENT_UOP_QUEUE_WRITES] = {
  326. .opcode = P4_OPCODE(P4_EVENT_UOP_QUEUE_WRITES),
  327. .escr_msr = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 },
  328. .escr_emask =
  329. P4_ESCR_EMASK_BIT(P4_EVENT_UOP_QUEUE_WRITES, FROM_TC_BUILD) |
  330. P4_ESCR_EMASK_BIT(P4_EVENT_UOP_QUEUE_WRITES, FROM_TC_DELIVER) |
  331. P4_ESCR_EMASK_BIT(P4_EVENT_UOP_QUEUE_WRITES, FROM_ROM),
  332. .cntr = { {4, 5, -1}, {6, 7, -1} },
  333. },
  334. [P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE] = {
  335. .opcode = P4_OPCODE(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE),
  336. .escr_msr = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR0 },
  337. .escr_emask =
  338. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, CONDITIONAL) |
  339. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, CALL) |
  340. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, RETURN) |
  341. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, INDIRECT),
  342. .cntr = { {4, 5, -1}, {6, 7, -1} },
  343. },
  344. [P4_EVENT_RETIRED_BRANCH_TYPE] = {
  345. .opcode = P4_OPCODE(P4_EVENT_RETIRED_BRANCH_TYPE),
  346. .escr_msr = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR1 },
  347. .escr_emask =
  348. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CONDITIONAL) |
  349. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CALL) |
  350. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, RETURN) |
  351. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, INDIRECT),
  352. .cntr = { {4, 5, -1}, {6, 7, -1} },
  353. },
  354. [P4_EVENT_RESOURCE_STALL] = {
  355. .opcode = P4_OPCODE(P4_EVENT_RESOURCE_STALL),
  356. .escr_msr = { MSR_P4_ALF_ESCR0, MSR_P4_ALF_ESCR1 },
  357. .escr_emask =
  358. P4_ESCR_EMASK_BIT(P4_EVENT_RESOURCE_STALL, SBFULL),
  359. .cntr = { {12, 13, 16}, {14, 15, 17} },
  360. },
  361. [P4_EVENT_WC_BUFFER] = {
  362. .opcode = P4_OPCODE(P4_EVENT_WC_BUFFER),
  363. .escr_msr = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 },
  364. .escr_emask =
  365. P4_ESCR_EMASK_BIT(P4_EVENT_WC_BUFFER, WCB_EVICTS) |
  366. P4_ESCR_EMASK_BIT(P4_EVENT_WC_BUFFER, WCB_FULL_EVICTS),
  367. .shared = 1,
  368. .cntr = { {8, 9, -1}, {10, 11, -1} },
  369. },
  370. [P4_EVENT_B2B_CYCLES] = {
  371. .opcode = P4_OPCODE(P4_EVENT_B2B_CYCLES),
  372. .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
  373. .escr_emask = 0,
  374. .cntr = { {0, -1, -1}, {2, -1, -1} },
  375. },
  376. [P4_EVENT_BNR] = {
  377. .opcode = P4_OPCODE(P4_EVENT_BNR),
  378. .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
  379. .escr_emask = 0,
  380. .cntr = { {0, -1, -1}, {2, -1, -1} },
  381. },
  382. [P4_EVENT_SNOOP] = {
  383. .opcode = P4_OPCODE(P4_EVENT_SNOOP),
  384. .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
  385. .escr_emask = 0,
  386. .cntr = { {0, -1, -1}, {2, -1, -1} },
  387. },
  388. [P4_EVENT_RESPONSE] = {
  389. .opcode = P4_OPCODE(P4_EVENT_RESPONSE),
  390. .escr_msr = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
  391. .escr_emask = 0,
  392. .cntr = { {0, -1, -1}, {2, -1, -1} },
  393. },
  394. [P4_EVENT_FRONT_END_EVENT] = {
  395. .opcode = P4_OPCODE(P4_EVENT_FRONT_END_EVENT),
  396. .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
  397. .escr_emask =
  398. P4_ESCR_EMASK_BIT(P4_EVENT_FRONT_END_EVENT, NBOGUS) |
  399. P4_ESCR_EMASK_BIT(P4_EVENT_FRONT_END_EVENT, BOGUS),
  400. .cntr = { {12, 13, 16}, {14, 15, 17} },
  401. },
  402. [P4_EVENT_EXECUTION_EVENT] = {
  403. .opcode = P4_OPCODE(P4_EVENT_EXECUTION_EVENT),
  404. .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
  405. .escr_emask =
  406. P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS0) |
  407. P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS1) |
  408. P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS2) |
  409. P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS3) |
  410. P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS0) |
  411. P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS1) |
  412. P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS2) |
  413. P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS3),
  414. .cntr = { {12, 13, 16}, {14, 15, 17} },
  415. },
  416. [P4_EVENT_REPLAY_EVENT] = {
  417. .opcode = P4_OPCODE(P4_EVENT_REPLAY_EVENT),
  418. .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
  419. .escr_emask =
  420. P4_ESCR_EMASK_BIT(P4_EVENT_REPLAY_EVENT, NBOGUS) |
  421. P4_ESCR_EMASK_BIT(P4_EVENT_REPLAY_EVENT, BOGUS),
  422. .cntr = { {12, 13, 16}, {14, 15, 17} },
  423. },
  424. [P4_EVENT_INSTR_RETIRED] = {
  425. .opcode = P4_OPCODE(P4_EVENT_INSTR_RETIRED),
  426. .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 },
  427. .escr_emask =
  428. P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, NBOGUSNTAG) |
  429. P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, NBOGUSTAG) |
  430. P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, BOGUSNTAG) |
  431. P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, BOGUSTAG),
  432. .cntr = { {12, 13, 16}, {14, 15, 17} },
  433. },
  434. [P4_EVENT_UOPS_RETIRED] = {
  435. .opcode = P4_OPCODE(P4_EVENT_UOPS_RETIRED),
  436. .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 },
  437. .escr_emask =
  438. P4_ESCR_EMASK_BIT(P4_EVENT_UOPS_RETIRED, NBOGUS) |
  439. P4_ESCR_EMASK_BIT(P4_EVENT_UOPS_RETIRED, BOGUS),
  440. .cntr = { {12, 13, 16}, {14, 15, 17} },
  441. },
  442. [P4_EVENT_UOP_TYPE] = {
  443. .opcode = P4_OPCODE(P4_EVENT_UOP_TYPE),
  444. .escr_msr = { MSR_P4_RAT_ESCR0, MSR_P4_RAT_ESCR1 },
  445. .escr_emask =
  446. P4_ESCR_EMASK_BIT(P4_EVENT_UOP_TYPE, TAGLOADS) |
  447. P4_ESCR_EMASK_BIT(P4_EVENT_UOP_TYPE, TAGSTORES),
  448. .cntr = { {12, 13, 16}, {14, 15, 17} },
  449. },
  450. [P4_EVENT_BRANCH_RETIRED] = {
  451. .opcode = P4_OPCODE(P4_EVENT_BRANCH_RETIRED),
  452. .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
  453. .escr_emask =
  454. P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED, MMNP) |
  455. P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED, MMNM) |
  456. P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED, MMTP) |
  457. P4_ESCR_EMASK_BIT(P4_EVENT_BRANCH_RETIRED, MMTM),
  458. .cntr = { {12, 13, 16}, {14, 15, 17} },
  459. },
  460. [P4_EVENT_MISPRED_BRANCH_RETIRED] = {
  461. .opcode = P4_OPCODE(P4_EVENT_MISPRED_BRANCH_RETIRED),
  462. .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 },
  463. .escr_emask =
  464. P4_ESCR_EMASK_BIT(P4_EVENT_MISPRED_BRANCH_RETIRED, NBOGUS),
  465. .cntr = { {12, 13, 16}, {14, 15, 17} },
  466. },
  467. [P4_EVENT_X87_ASSIST] = {
  468. .opcode = P4_OPCODE(P4_EVENT_X87_ASSIST),
  469. .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
  470. .escr_emask =
  471. P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST, FPSU) |
  472. P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST, FPSO) |
  473. P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST, POAO) |
  474. P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST, POAU) |
  475. P4_ESCR_EMASK_BIT(P4_EVENT_X87_ASSIST, PREA),
  476. .cntr = { {12, 13, 16}, {14, 15, 17} },
  477. },
  478. [P4_EVENT_MACHINE_CLEAR] = {
  479. .opcode = P4_OPCODE(P4_EVENT_MACHINE_CLEAR),
  480. .escr_msr = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
  481. .escr_emask =
  482. P4_ESCR_EMASK_BIT(P4_EVENT_MACHINE_CLEAR, CLEAR) |
  483. P4_ESCR_EMASK_BIT(P4_EVENT_MACHINE_CLEAR, MOCLEAR) |
  484. P4_ESCR_EMASK_BIT(P4_EVENT_MACHINE_CLEAR, SMCLEAR),
  485. .cntr = { {12, 13, 16}, {14, 15, 17} },
  486. },
  487. [P4_EVENT_INSTR_COMPLETED] = {
  488. .opcode = P4_OPCODE(P4_EVENT_INSTR_COMPLETED),
  489. .escr_msr = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 },
  490. .escr_emask =
  491. P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_COMPLETED, NBOGUS) |
  492. P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_COMPLETED, BOGUS),
  493. .cntr = { {12, 13, 16}, {14, 15, 17} },
  494. },
  495. };
  496. #define P4_GEN_CACHE_EVENT(event, bit, metric) \
  497. p4_config_pack_escr(P4_ESCR_EVENT(event) | \
  498. P4_ESCR_EMASK_BIT(event, bit)) | \
  499. p4_config_pack_cccr(metric | \
  500. P4_CCCR_ESEL(P4_OPCODE_ESEL(P4_OPCODE(event))))
  501. static __initconst const u64 p4_hw_cache_event_ids
  502. [PERF_COUNT_HW_CACHE_MAX]
  503. [PERF_COUNT_HW_CACHE_OP_MAX]
  504. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  505. {
  506. [ C(L1D ) ] = {
  507. [ C(OP_READ) ] = {
  508. [ C(RESULT_ACCESS) ] = 0x0,
  509. [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS,
  510. P4_PEBS_METRIC__1stl_cache_load_miss_retired),
  511. },
  512. },
  513. [ C(LL ) ] = {
  514. [ C(OP_READ) ] = {
  515. [ C(RESULT_ACCESS) ] = 0x0,
  516. [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS,
  517. P4_PEBS_METRIC__2ndl_cache_load_miss_retired),
  518. },
  519. },
  520. [ C(DTLB) ] = {
  521. [ C(OP_READ) ] = {
  522. [ C(RESULT_ACCESS) ] = 0x0,
  523. [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS,
  524. P4_PEBS_METRIC__dtlb_load_miss_retired),
  525. },
  526. [ C(OP_WRITE) ] = {
  527. [ C(RESULT_ACCESS) ] = 0x0,
  528. [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS,
  529. P4_PEBS_METRIC__dtlb_store_miss_retired),
  530. },
  531. },
  532. [ C(ITLB) ] = {
  533. [ C(OP_READ) ] = {
  534. [ C(RESULT_ACCESS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_ITLB_REFERENCE, HIT,
  535. P4_PEBS_METRIC__none),
  536. [ C(RESULT_MISS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_ITLB_REFERENCE, MISS,
  537. P4_PEBS_METRIC__none),
  538. },
  539. [ C(OP_WRITE) ] = {
  540. [ C(RESULT_ACCESS) ] = -1,
  541. [ C(RESULT_MISS) ] = -1,
  542. },
  543. [ C(OP_PREFETCH) ] = {
  544. [ C(RESULT_ACCESS) ] = -1,
  545. [ C(RESULT_MISS) ] = -1,
  546. },
  547. },
  548. };
  549. static u64 p4_general_events[PERF_COUNT_HW_MAX] = {
  550. /* non-halted CPU clocks */
  551. [PERF_COUNT_HW_CPU_CYCLES] =
  552. p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_GLOBAL_POWER_EVENTS) |
  553. P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING)),
  554. /*
  555. * retired instructions
  556. * in a sake of simplicity we don't use the FSB tagging
  557. */
  558. [PERF_COUNT_HW_INSTRUCTIONS] =
  559. p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_INSTR_RETIRED) |
  560. P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, NBOGUSNTAG) |
  561. P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, BOGUSNTAG)),
  562. /* cache hits */
  563. [PERF_COUNT_HW_CACHE_REFERENCES] =
  564. p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_BSQ_CACHE_REFERENCE) |
  565. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITS) |
  566. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITE) |
  567. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITM) |
  568. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITS) |
  569. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITE) |
  570. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITM)),
  571. /* cache misses */
  572. [PERF_COUNT_HW_CACHE_MISSES] =
  573. p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_BSQ_CACHE_REFERENCE) |
  574. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_MISS) |
  575. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_MISS) |
  576. P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, WR_2ndL_MISS)),
  577. /* branch instructions retired */
  578. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] =
  579. p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_RETIRED_BRANCH_TYPE) |
  580. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CONDITIONAL) |
  581. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CALL) |
  582. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, RETURN) |
  583. P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, INDIRECT)),
  584. /* mispredicted branches retired */
  585. [PERF_COUNT_HW_BRANCH_MISSES] =
  586. p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_MISPRED_BRANCH_RETIRED) |
  587. P4_ESCR_EMASK_BIT(P4_EVENT_MISPRED_BRANCH_RETIRED, NBOGUS)),
  588. /* bus ready clocks (cpu is driving #DRDY_DRV\#DRDY_OWN): */
  589. [PERF_COUNT_HW_BUS_CYCLES] =
  590. p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_FSB_DATA_ACTIVITY) |
  591. P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_DRV) |
  592. P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OWN)) |
  593. p4_config_pack_cccr(P4_CCCR_EDGE | P4_CCCR_COMPARE),
  594. };
  595. static struct p4_event_bind *p4_config_get_bind(u64 config)
  596. {
  597. unsigned int evnt = p4_config_unpack_event(config);
  598. struct p4_event_bind *bind = NULL;
  599. if (evnt < ARRAY_SIZE(p4_event_bind_map))
  600. bind = &p4_event_bind_map[evnt];
  601. return bind;
  602. }
  603. static u64 p4_pmu_event_map(int hw_event)
  604. {
  605. struct p4_event_bind *bind;
  606. unsigned int esel;
  607. u64 config;
  608. config = p4_general_events[hw_event];
  609. bind = p4_config_get_bind(config);
  610. esel = P4_OPCODE_ESEL(bind->opcode);
  611. config |= p4_config_pack_cccr(P4_CCCR_ESEL(esel));
  612. return config;
  613. }
  614. /* check cpu model specifics */
  615. static bool p4_event_match_cpu_model(unsigned int event_idx)
  616. {
  617. /* INSTR_COMPLETED event only exist for model 3, 4, 6 (Prescott) */
  618. if (event_idx == P4_EVENT_INSTR_COMPLETED) {
  619. if (boot_cpu_data.x86_model != 3 &&
  620. boot_cpu_data.x86_model != 4 &&
  621. boot_cpu_data.x86_model != 6)
  622. return false;
  623. }
  624. /*
  625. * For info
  626. * - IQ_ESCR0, IQ_ESCR1 only for models 1 and 2
  627. */
  628. return true;
  629. }
  630. static int p4_validate_raw_event(struct perf_event *event)
  631. {
  632. unsigned int v, emask;
  633. /* User data may have out-of-bound event index */
  634. v = p4_config_unpack_event(event->attr.config);
  635. if (v >= ARRAY_SIZE(p4_event_bind_map))
  636. return -EINVAL;
  637. /* It may be unsupported: */
  638. if (!p4_event_match_cpu_model(v))
  639. return -EINVAL;
  640. /*
  641. * NOTE: P4_CCCR_THREAD_ANY has not the same meaning as
  642. * in Architectural Performance Monitoring, it means not
  643. * on _which_ logical cpu to count but rather _when_, ie it
  644. * depends on logical cpu state -- count event if one cpu active,
  645. * none, both or any, so we just allow user to pass any value
  646. * desired.
  647. *
  648. * In turn we always set Tx_OS/Tx_USR bits bound to logical
  649. * cpu without their propagation to another cpu
  650. */
  651. /*
  652. * if an event is shared accross the logical threads
  653. * the user needs special permissions to be able to use it
  654. */
  655. if (p4_event_bind_map[v].shared) {
  656. if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
  657. return -EACCES;
  658. }
  659. /* ESCR EventMask bits may be invalid */
  660. emask = p4_config_unpack_escr(event->attr.config) & P4_ESCR_EVENTMASK_MASK;
  661. if (emask & ~p4_event_bind_map[v].escr_emask)
  662. return -EINVAL;
  663. /*
  664. * it may have some invalid PEBS bits
  665. */
  666. if (p4_config_pebs_has(event->attr.config, P4_PEBS_CONFIG_ENABLE))
  667. return -EINVAL;
  668. v = p4_config_unpack_metric(event->attr.config);
  669. if (v >= ARRAY_SIZE(p4_pebs_bind_map))
  670. return -EINVAL;
  671. return 0;
  672. }
  673. static int p4_hw_config(struct perf_event *event)
  674. {
  675. int cpu = get_cpu();
  676. int rc = 0;
  677. u32 escr, cccr;
  678. /*
  679. * the reason we use cpu that early is that: if we get scheduled
  680. * first time on the same cpu -- we will not need swap thread
  681. * specific flags in config (and will save some cpu cycles)
  682. */
  683. cccr = p4_default_cccr_conf(cpu);
  684. escr = p4_default_escr_conf(cpu, event->attr.exclude_kernel,
  685. event->attr.exclude_user);
  686. event->hw.config = p4_config_pack_escr(escr) |
  687. p4_config_pack_cccr(cccr);
  688. if (p4_ht_active() && p4_ht_thread(cpu))
  689. event->hw.config = p4_set_ht_bit(event->hw.config);
  690. if (event->attr.type == PERF_TYPE_RAW) {
  691. /*
  692. * Clear bits we reserve to be managed by kernel itself
  693. * and never allowed from a user space
  694. */
  695. event->attr.config &= P4_CONFIG_MASK;
  696. rc = p4_validate_raw_event(event);
  697. if (rc)
  698. goto out;
  699. /*
  700. * Note that for RAW events we allow user to use P4_CCCR_RESERVED
  701. * bits since we keep additional info here (for cache events and etc)
  702. */
  703. event->hw.config |= event->attr.config;
  704. }
  705. rc = x86_setup_perfctr(event);
  706. out:
  707. put_cpu();
  708. return rc;
  709. }
  710. static inline int p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc)
  711. {
  712. int overflow = 0;
  713. u32 low, high;
  714. rdmsr(hwc->config_base + hwc->idx, low, high);
  715. /* we need to check high bit for unflagged overflows */
  716. if ((low & P4_CCCR_OVF) || !(high & (1 << 31))) {
  717. overflow = 1;
  718. (void)checking_wrmsrl(hwc->config_base + hwc->idx,
  719. ((u64)low) & ~P4_CCCR_OVF);
  720. }
  721. return overflow;
  722. }
  723. static void p4_pmu_disable_pebs(void)
  724. {
  725. /*
  726. * FIXME
  727. *
  728. * It's still allowed that two threads setup same cache
  729. * events so we can't simply clear metrics until we knew
  730. * noone is depending on us, so we need kind of counter
  731. * for "ReplayEvent" users.
  732. *
  733. * What is more complex -- RAW events, if user (for some
  734. * reason) will pass some cache event metric with improper
  735. * event opcode -- it's fine from hardware point of view
  736. * but completely nonsence from "meaning" of such action.
  737. *
  738. * So at moment let leave metrics turned on forever -- it's
  739. * ok for now but need to be revisited!
  740. *
  741. * (void)checking_wrmsrl(MSR_IA32_PEBS_ENABLE, (u64)0);
  742. * (void)checking_wrmsrl(MSR_P4_PEBS_MATRIX_VERT, (u64)0);
  743. */
  744. }
  745. static inline void p4_pmu_disable_event(struct perf_event *event)
  746. {
  747. struct hw_perf_event *hwc = &event->hw;
  748. /*
  749. * If event gets disabled while counter is in overflowed
  750. * state we need to clear P4_CCCR_OVF, otherwise interrupt get
  751. * asserted again and again
  752. */
  753. (void)checking_wrmsrl(hwc->config_base + hwc->idx,
  754. (u64)(p4_config_unpack_cccr(hwc->config)) &
  755. ~P4_CCCR_ENABLE & ~P4_CCCR_OVF & ~P4_CCCR_RESERVED);
  756. }
  757. static void p4_pmu_disable_all(void)
  758. {
  759. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  760. int idx;
  761. for (idx = 0; idx < x86_pmu.num_counters; idx++) {
  762. struct perf_event *event = cpuc->events[idx];
  763. if (!test_bit(idx, cpuc->active_mask))
  764. continue;
  765. p4_pmu_disable_event(event);
  766. }
  767. p4_pmu_disable_pebs();
  768. }
  769. /* configuration must be valid */
  770. static void p4_pmu_enable_pebs(u64 config)
  771. {
  772. struct p4_pebs_bind *bind;
  773. unsigned int idx;
  774. BUILD_BUG_ON(P4_PEBS_METRIC__max > P4_PEBS_CONFIG_METRIC_MASK);
  775. idx = p4_config_unpack_metric(config);
  776. if (idx == P4_PEBS_METRIC__none)
  777. return;
  778. bind = &p4_pebs_bind_map[idx];
  779. (void)checking_wrmsrl(MSR_IA32_PEBS_ENABLE, (u64)bind->metric_pebs);
  780. (void)checking_wrmsrl(MSR_P4_PEBS_MATRIX_VERT, (u64)bind->metric_vert);
  781. }
  782. static void p4_pmu_enable_event(struct perf_event *event)
  783. {
  784. struct hw_perf_event *hwc = &event->hw;
  785. int thread = p4_ht_config_thread(hwc->config);
  786. u64 escr_conf = p4_config_unpack_escr(p4_clear_ht_bit(hwc->config));
  787. unsigned int idx = p4_config_unpack_event(hwc->config);
  788. struct p4_event_bind *bind;
  789. u64 escr_addr, cccr;
  790. bind = &p4_event_bind_map[idx];
  791. escr_addr = (u64)bind->escr_msr[thread];
  792. /*
  793. * - we dont support cascaded counters yet
  794. * - and counter 1 is broken (erratum)
  795. */
  796. WARN_ON_ONCE(p4_is_event_cascaded(hwc->config));
  797. WARN_ON_ONCE(hwc->idx == 1);
  798. /* we need a real Event value */
  799. escr_conf &= ~P4_ESCR_EVENT_MASK;
  800. escr_conf |= P4_ESCR_EVENT(P4_OPCODE_EVNT(bind->opcode));
  801. cccr = p4_config_unpack_cccr(hwc->config);
  802. /*
  803. * it could be Cache event so we need to write metrics
  804. * into additional MSRs
  805. */
  806. p4_pmu_enable_pebs(hwc->config);
  807. (void)checking_wrmsrl(escr_addr, escr_conf);
  808. (void)checking_wrmsrl(hwc->config_base + hwc->idx,
  809. (cccr & ~P4_CCCR_RESERVED) | P4_CCCR_ENABLE);
  810. }
  811. static void p4_pmu_enable_all(int added)
  812. {
  813. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  814. int idx;
  815. for (idx = 0; idx < x86_pmu.num_counters; idx++) {
  816. struct perf_event *event = cpuc->events[idx];
  817. if (!test_bit(idx, cpuc->active_mask))
  818. continue;
  819. p4_pmu_enable_event(event);
  820. }
  821. }
  822. static int p4_pmu_handle_irq(struct pt_regs *regs)
  823. {
  824. struct perf_sample_data data;
  825. struct cpu_hw_events *cpuc;
  826. struct perf_event *event;
  827. struct hw_perf_event *hwc;
  828. int idx, handled = 0;
  829. u64 val;
  830. data.addr = 0;
  831. data.raw = NULL;
  832. cpuc = &__get_cpu_var(cpu_hw_events);
  833. for (idx = 0; idx < x86_pmu.num_counters; idx++) {
  834. int overflow;
  835. if (!test_bit(idx, cpuc->active_mask))
  836. continue;
  837. event = cpuc->events[idx];
  838. hwc = &event->hw;
  839. WARN_ON_ONCE(hwc->idx != idx);
  840. /* it might be unflagged overflow */
  841. overflow = p4_pmu_clear_cccr_ovf(hwc);
  842. val = x86_perf_event_update(event);
  843. if (!overflow && (val & (1ULL << (x86_pmu.cntval_bits - 1))))
  844. continue;
  845. handled += overflow;
  846. /* event overflow for sure */
  847. data.period = event->hw.last_period;
  848. if (!x86_perf_event_set_period(event))
  849. continue;
  850. if (perf_event_overflow(event, 1, &data, regs))
  851. p4_pmu_disable_event(event);
  852. }
  853. if (handled) {
  854. /* p4 quirk: unmask it again */
  855. apic_write(APIC_LVTPC, apic_read(APIC_LVTPC) & ~APIC_LVT_MASKED);
  856. inc_irq_stat(apic_perf_irqs);
  857. }
  858. return handled;
  859. }
  860. /*
  861. * swap thread specific fields according to a thread
  862. * we are going to run on
  863. */
  864. static void p4_pmu_swap_config_ts(struct hw_perf_event *hwc, int cpu)
  865. {
  866. u32 escr, cccr;
  867. /*
  868. * we either lucky and continue on same cpu or no HT support
  869. */
  870. if (!p4_should_swap_ts(hwc->config, cpu))
  871. return;
  872. /*
  873. * the event is migrated from an another logical
  874. * cpu, so we need to swap thread specific flags
  875. */
  876. escr = p4_config_unpack_escr(hwc->config);
  877. cccr = p4_config_unpack_cccr(hwc->config);
  878. if (p4_ht_thread(cpu)) {
  879. cccr &= ~P4_CCCR_OVF_PMI_T0;
  880. cccr |= P4_CCCR_OVF_PMI_T1;
  881. if (escr & P4_ESCR_T0_OS) {
  882. escr &= ~P4_ESCR_T0_OS;
  883. escr |= P4_ESCR_T1_OS;
  884. }
  885. if (escr & P4_ESCR_T0_USR) {
  886. escr &= ~P4_ESCR_T0_USR;
  887. escr |= P4_ESCR_T1_USR;
  888. }
  889. hwc->config = p4_config_pack_escr(escr);
  890. hwc->config |= p4_config_pack_cccr(cccr);
  891. hwc->config |= P4_CONFIG_HT;
  892. } else {
  893. cccr &= ~P4_CCCR_OVF_PMI_T1;
  894. cccr |= P4_CCCR_OVF_PMI_T0;
  895. if (escr & P4_ESCR_T1_OS) {
  896. escr &= ~P4_ESCR_T1_OS;
  897. escr |= P4_ESCR_T0_OS;
  898. }
  899. if (escr & P4_ESCR_T1_USR) {
  900. escr &= ~P4_ESCR_T1_USR;
  901. escr |= P4_ESCR_T0_USR;
  902. }
  903. hwc->config = p4_config_pack_escr(escr);
  904. hwc->config |= p4_config_pack_cccr(cccr);
  905. hwc->config &= ~P4_CONFIG_HT;
  906. }
  907. }
  908. /*
  909. * ESCR address hashing is tricky, ESCRs are not sequential
  910. * in memory but all starts from MSR_P4_BSU_ESCR0 (0x03a0) and
  911. * the metric between any ESCRs is laid in range [0xa0,0xe1]
  912. *
  913. * so we make ~70% filled hashtable
  914. */
  915. #define P4_ESCR_MSR_BASE 0x000003a0
  916. #define P4_ESCR_MSR_MAX 0x000003e1
  917. #define P4_ESCR_MSR_TABLE_SIZE (P4_ESCR_MSR_MAX - P4_ESCR_MSR_BASE + 1)
  918. #define P4_ESCR_MSR_IDX(msr) (msr - P4_ESCR_MSR_BASE)
  919. #define P4_ESCR_MSR_TABLE_ENTRY(msr) [P4_ESCR_MSR_IDX(msr)] = msr
  920. static const unsigned int p4_escr_table[P4_ESCR_MSR_TABLE_SIZE] = {
  921. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ALF_ESCR0),
  922. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ALF_ESCR1),
  923. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BPU_ESCR0),
  924. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BPU_ESCR1),
  925. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BSU_ESCR0),
  926. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BSU_ESCR1),
  927. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR0),
  928. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR1),
  929. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR2),
  930. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR3),
  931. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR4),
  932. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR5),
  933. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_DAC_ESCR0),
  934. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_DAC_ESCR1),
  935. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FIRM_ESCR0),
  936. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FIRM_ESCR1),
  937. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FLAME_ESCR0),
  938. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FLAME_ESCR1),
  939. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FSB_ESCR0),
  940. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FSB_ESCR1),
  941. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IQ_ESCR0),
  942. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IQ_ESCR1),
  943. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IS_ESCR0),
  944. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IS_ESCR1),
  945. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ITLB_ESCR0),
  946. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ITLB_ESCR1),
  947. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IX_ESCR0),
  948. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IX_ESCR1),
  949. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MOB_ESCR0),
  950. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MOB_ESCR1),
  951. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MS_ESCR0),
  952. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MS_ESCR1),
  953. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_PMH_ESCR0),
  954. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_PMH_ESCR1),
  955. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_RAT_ESCR0),
  956. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_RAT_ESCR1),
  957. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SAAT_ESCR0),
  958. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SAAT_ESCR1),
  959. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SSU_ESCR0),
  960. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SSU_ESCR1),
  961. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TBPU_ESCR0),
  962. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TBPU_ESCR1),
  963. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TC_ESCR0),
  964. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TC_ESCR1),
  965. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_U2L_ESCR0),
  966. P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_U2L_ESCR1),
  967. };
  968. static int p4_get_escr_idx(unsigned int addr)
  969. {
  970. unsigned int idx = P4_ESCR_MSR_IDX(addr);
  971. if (unlikely(idx >= P4_ESCR_MSR_TABLE_SIZE ||
  972. !p4_escr_table[idx] ||
  973. p4_escr_table[idx] != addr)) {
  974. WARN_ONCE(1, "P4 PMU: Wrong address passed: %x\n", addr);
  975. return -1;
  976. }
  977. return idx;
  978. }
  979. static int p4_next_cntr(int thread, unsigned long *used_mask,
  980. struct p4_event_bind *bind)
  981. {
  982. int i, j;
  983. for (i = 0; i < P4_CNTR_LIMIT; i++) {
  984. j = bind->cntr[thread][i];
  985. if (j != -1 && !test_bit(j, used_mask))
  986. return j;
  987. }
  988. return -1;
  989. }
  990. static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign)
  991. {
  992. unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
  993. unsigned long escr_mask[BITS_TO_LONGS(P4_ESCR_MSR_TABLE_SIZE)];
  994. int cpu = smp_processor_id();
  995. struct hw_perf_event *hwc;
  996. struct p4_event_bind *bind;
  997. unsigned int i, thread, num;
  998. int cntr_idx, escr_idx;
  999. bitmap_zero(used_mask, X86_PMC_IDX_MAX);
  1000. bitmap_zero(escr_mask, P4_ESCR_MSR_TABLE_SIZE);
  1001. for (i = 0, num = n; i < n; i++, num--) {
  1002. hwc = &cpuc->event_list[i]->hw;
  1003. thread = p4_ht_thread(cpu);
  1004. bind = p4_config_get_bind(hwc->config);
  1005. escr_idx = p4_get_escr_idx(bind->escr_msr[thread]);
  1006. if (unlikely(escr_idx == -1))
  1007. goto done;
  1008. if (hwc->idx != -1 && !p4_should_swap_ts(hwc->config, cpu)) {
  1009. cntr_idx = hwc->idx;
  1010. if (assign)
  1011. assign[i] = hwc->idx;
  1012. goto reserve;
  1013. }
  1014. cntr_idx = p4_next_cntr(thread, used_mask, bind);
  1015. if (cntr_idx == -1 || test_bit(escr_idx, escr_mask))
  1016. goto done;
  1017. p4_pmu_swap_config_ts(hwc, cpu);
  1018. if (assign)
  1019. assign[i] = cntr_idx;
  1020. reserve:
  1021. set_bit(cntr_idx, used_mask);
  1022. set_bit(escr_idx, escr_mask);
  1023. }
  1024. done:
  1025. return num ? -ENOSPC : 0;
  1026. }
  1027. static __initconst const struct x86_pmu p4_pmu = {
  1028. .name = "Netburst P4/Xeon",
  1029. .handle_irq = p4_pmu_handle_irq,
  1030. .disable_all = p4_pmu_disable_all,
  1031. .enable_all = p4_pmu_enable_all,
  1032. .enable = p4_pmu_enable_event,
  1033. .disable = p4_pmu_disable_event,
  1034. .eventsel = MSR_P4_BPU_CCCR0,
  1035. .perfctr = MSR_P4_BPU_PERFCTR0,
  1036. .event_map = p4_pmu_event_map,
  1037. .max_events = ARRAY_SIZE(p4_general_events),
  1038. .get_event_constraints = x86_get_event_constraints,
  1039. /*
  1040. * IF HT disabled we may need to use all
  1041. * ARCH_P4_MAX_CCCR counters simulaneously
  1042. * though leave it restricted at moment assuming
  1043. * HT is on
  1044. */
  1045. .num_counters = ARCH_P4_MAX_CCCR,
  1046. .apic = 1,
  1047. .cntval_bits = 40,
  1048. .cntval_mask = (1ULL << 40) - 1,
  1049. .max_period = (1ULL << 39) - 1,
  1050. .hw_config = p4_hw_config,
  1051. .schedule_events = p4_pmu_schedule_events,
  1052. /*
  1053. * This handles erratum N15 in intel doc 249199-029,
  1054. * the counter may not be updated correctly on write
  1055. * so we need a second write operation to do the trick
  1056. * (the official workaround didn't work)
  1057. *
  1058. * the former idea is taken from OProfile code
  1059. */
  1060. .perfctr_second_write = 1,
  1061. };
  1062. static __init int p4_pmu_init(void)
  1063. {
  1064. unsigned int low, high;
  1065. /* If we get stripped -- indexig fails */
  1066. BUILD_BUG_ON(ARCH_P4_MAX_CCCR > X86_PMC_MAX_GENERIC);
  1067. rdmsr(MSR_IA32_MISC_ENABLE, low, high);
  1068. if (!(low & (1 << 7))) {
  1069. pr_cont("unsupported Netburst CPU model %d ",
  1070. boot_cpu_data.x86_model);
  1071. return -ENODEV;
  1072. }
  1073. memcpy(hw_cache_event_ids, p4_hw_cache_event_ids,
  1074. sizeof(hw_cache_event_ids));
  1075. pr_cont("Netburst events, ");
  1076. x86_pmu = p4_pmu;
  1077. return 0;
  1078. }
  1079. #endif /* CONFIG_CPU_SUP_INTEL */