perf_event_intel.c 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423
  1. /*
  2. * Per core/cpu state
  3. *
  4. * Used to coordinate shared registers between HT threads or
  5. * among events on a single PMU.
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8. #include <linux/stddef.h>
  9. #include <linux/types.h>
  10. #include <linux/init.h>
  11. #include <linux/slab.h>
  12. #include <linux/export.h>
  13. #include <linux/watchdog.h>
  14. #include <asm/cpufeature.h>
  15. #include <asm/hardirq.h>
  16. #include <asm/apic.h>
  17. #include "perf_event.h"
  18. /*
  19. * Intel PerfMon, used on Core and later.
  20. */
  21. static u64 intel_perfmon_event_map[PERF_COUNT_HW_MAX] __read_mostly =
  22. {
  23. [PERF_COUNT_HW_CPU_CYCLES] = 0x003c,
  24. [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0,
  25. [PERF_COUNT_HW_CACHE_REFERENCES] = 0x4f2e,
  26. [PERF_COUNT_HW_CACHE_MISSES] = 0x412e,
  27. [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c4,
  28. [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c5,
  29. [PERF_COUNT_HW_BUS_CYCLES] = 0x013c,
  30. [PERF_COUNT_HW_REF_CPU_CYCLES] = 0x0300, /* pseudo-encoding */
  31. };
  32. static struct event_constraint intel_core_event_constraints[] __read_mostly =
  33. {
  34. INTEL_EVENT_CONSTRAINT(0x11, 0x2), /* FP_ASSIST */
  35. INTEL_EVENT_CONSTRAINT(0x12, 0x2), /* MUL */
  36. INTEL_EVENT_CONSTRAINT(0x13, 0x2), /* DIV */
  37. INTEL_EVENT_CONSTRAINT(0x14, 0x1), /* CYCLES_DIV_BUSY */
  38. INTEL_EVENT_CONSTRAINT(0x19, 0x2), /* DELAYED_BYPASS */
  39. INTEL_EVENT_CONSTRAINT(0xc1, 0x1), /* FP_COMP_INSTR_RET */
  40. EVENT_CONSTRAINT_END
  41. };
  42. static struct event_constraint intel_core2_event_constraints[] __read_mostly =
  43. {
  44. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  45. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  46. FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */
  47. INTEL_EVENT_CONSTRAINT(0x10, 0x1), /* FP_COMP_OPS_EXE */
  48. INTEL_EVENT_CONSTRAINT(0x11, 0x2), /* FP_ASSIST */
  49. INTEL_EVENT_CONSTRAINT(0x12, 0x2), /* MUL */
  50. INTEL_EVENT_CONSTRAINT(0x13, 0x2), /* DIV */
  51. INTEL_EVENT_CONSTRAINT(0x14, 0x1), /* CYCLES_DIV_BUSY */
  52. INTEL_EVENT_CONSTRAINT(0x18, 0x1), /* IDLE_DURING_DIV */
  53. INTEL_EVENT_CONSTRAINT(0x19, 0x2), /* DELAYED_BYPASS */
  54. INTEL_EVENT_CONSTRAINT(0xa1, 0x1), /* RS_UOPS_DISPATCH_CYCLES */
  55. INTEL_EVENT_CONSTRAINT(0xc9, 0x1), /* ITLB_MISS_RETIRED (T30-9) */
  56. INTEL_EVENT_CONSTRAINT(0xcb, 0x1), /* MEM_LOAD_RETIRED */
  57. EVENT_CONSTRAINT_END
  58. };
  59. static struct event_constraint intel_nehalem_event_constraints[] __read_mostly =
  60. {
  61. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  62. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  63. FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */
  64. INTEL_EVENT_CONSTRAINT(0x40, 0x3), /* L1D_CACHE_LD */
  65. INTEL_EVENT_CONSTRAINT(0x41, 0x3), /* L1D_CACHE_ST */
  66. INTEL_EVENT_CONSTRAINT(0x42, 0x3), /* L1D_CACHE_LOCK */
  67. INTEL_EVENT_CONSTRAINT(0x43, 0x3), /* L1D_ALL_REF */
  68. INTEL_EVENT_CONSTRAINT(0x48, 0x3), /* L1D_PEND_MISS */
  69. INTEL_EVENT_CONSTRAINT(0x4e, 0x3), /* L1D_PREFETCH */
  70. INTEL_EVENT_CONSTRAINT(0x51, 0x3), /* L1D */
  71. INTEL_EVENT_CONSTRAINT(0x63, 0x3), /* CACHE_LOCK_CYCLES */
  72. EVENT_CONSTRAINT_END
  73. };
  74. static struct extra_reg intel_nehalem_extra_regs[] __read_mostly =
  75. {
  76. /* must define OFFCORE_RSP_X first, see intel_fixup_er() */
  77. INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0xffff, RSP_0),
  78. INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x100b),
  79. EVENT_EXTRA_END
  80. };
  81. static struct event_constraint intel_westmere_event_constraints[] __read_mostly =
  82. {
  83. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  84. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  85. FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */
  86. INTEL_EVENT_CONSTRAINT(0x51, 0x3), /* L1D */
  87. INTEL_EVENT_CONSTRAINT(0x60, 0x1), /* OFFCORE_REQUESTS_OUTSTANDING */
  88. INTEL_EVENT_CONSTRAINT(0x63, 0x3), /* CACHE_LOCK_CYCLES */
  89. INTEL_EVENT_CONSTRAINT(0xb3, 0x1), /* SNOOPQ_REQUEST_OUTSTANDING */
  90. EVENT_CONSTRAINT_END
  91. };
  92. static struct event_constraint intel_snb_event_constraints[] __read_mostly =
  93. {
  94. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  95. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  96. FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */
  97. INTEL_UEVENT_CONSTRAINT(0x04a3, 0xf), /* CYCLE_ACTIVITY.CYCLES_NO_DISPATCH */
  98. INTEL_UEVENT_CONSTRAINT(0x05a3, 0xf), /* CYCLE_ACTIVITY.STALLS_L2_PENDING */
  99. INTEL_UEVENT_CONSTRAINT(0x02a3, 0x4), /* CYCLE_ACTIVITY.CYCLES_L1D_PENDING */
  100. INTEL_UEVENT_CONSTRAINT(0x06a3, 0x4), /* CYCLE_ACTIVITY.STALLS_L1D_PENDING */
  101. INTEL_EVENT_CONSTRAINT(0x48, 0x4), /* L1D_PEND_MISS.PENDING */
  102. INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */
  103. INTEL_EVENT_CONSTRAINT(0xcd, 0x8), /* MEM_TRANS_RETIRED.LOAD_LATENCY */
  104. INTEL_UEVENT_CONSTRAINT(0x04a3, 0xf), /* CYCLE_ACTIVITY.CYCLES_NO_DISPATCH */
  105. INTEL_UEVENT_CONSTRAINT(0x02a3, 0x4), /* CYCLE_ACTIVITY.CYCLES_L1D_PENDING */
  106. INTEL_EXCLEVT_CONSTRAINT(0xd0, 0xf), /* MEM_UOPS_RETIRED.* */
  107. INTEL_EXCLEVT_CONSTRAINT(0xd1, 0xf), /* MEM_LOAD_UOPS_RETIRED.* */
  108. INTEL_EXCLEVT_CONSTRAINT(0xd2, 0xf), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
  109. INTEL_EXCLEVT_CONSTRAINT(0xd3, 0xf), /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.* */
  110. EVENT_CONSTRAINT_END
  111. };
  112. static struct event_constraint intel_ivb_event_constraints[] __read_mostly =
  113. {
  114. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  115. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  116. FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */
  117. INTEL_UEVENT_CONSTRAINT(0x0148, 0x4), /* L1D_PEND_MISS.PENDING */
  118. INTEL_UEVENT_CONSTRAINT(0x0279, 0xf), /* IDQ.EMTPY */
  119. INTEL_UEVENT_CONSTRAINT(0x019c, 0xf), /* IDQ_UOPS_NOT_DELIVERED.CORE */
  120. INTEL_UEVENT_CONSTRAINT(0x02a3, 0xf), /* CYCLE_ACTIVITY.CYCLES_LDM_PENDING */
  121. INTEL_UEVENT_CONSTRAINT(0x04a3, 0xf), /* CYCLE_ACTIVITY.CYCLES_NO_EXECUTE */
  122. INTEL_UEVENT_CONSTRAINT(0x05a3, 0xf), /* CYCLE_ACTIVITY.STALLS_L2_PENDING */
  123. INTEL_UEVENT_CONSTRAINT(0x06a3, 0xf), /* CYCLE_ACTIVITY.STALLS_LDM_PENDING */
  124. INTEL_UEVENT_CONSTRAINT(0x08a3, 0x4), /* CYCLE_ACTIVITY.CYCLES_L1D_PENDING */
  125. INTEL_UEVENT_CONSTRAINT(0x0ca3, 0x4), /* CYCLE_ACTIVITY.STALLS_L1D_PENDING */
  126. INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */
  127. INTEL_EXCLEVT_CONSTRAINT(0xd0, 0xf), /* MEM_UOPS_RETIRED.* */
  128. INTEL_EXCLEVT_CONSTRAINT(0xd1, 0xf), /* MEM_LOAD_UOPS_RETIRED.* */
  129. INTEL_EXCLEVT_CONSTRAINT(0xd2, 0xf), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
  130. INTEL_EXCLEVT_CONSTRAINT(0xd3, 0xf), /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.* */
  131. EVENT_CONSTRAINT_END
  132. };
  133. static struct extra_reg intel_westmere_extra_regs[] __read_mostly =
  134. {
  135. /* must define OFFCORE_RSP_X first, see intel_fixup_er() */
  136. INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0xffff, RSP_0),
  137. INTEL_UEVENT_EXTRA_REG(0x01bb, MSR_OFFCORE_RSP_1, 0xffff, RSP_1),
  138. INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x100b),
  139. EVENT_EXTRA_END
  140. };
  141. static struct event_constraint intel_v1_event_constraints[] __read_mostly =
  142. {
  143. EVENT_CONSTRAINT_END
  144. };
  145. static struct event_constraint intel_gen_event_constraints[] __read_mostly =
  146. {
  147. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  148. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  149. FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */
  150. EVENT_CONSTRAINT_END
  151. };
  152. static struct event_constraint intel_slm_event_constraints[] __read_mostly =
  153. {
  154. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  155. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  156. FIXED_EVENT_CONSTRAINT(0x0300, 2), /* pseudo CPU_CLK_UNHALTED.REF */
  157. EVENT_CONSTRAINT_END
  158. };
  159. static struct extra_reg intel_snb_extra_regs[] __read_mostly = {
  160. /* must define OFFCORE_RSP_X first, see intel_fixup_er() */
  161. INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0x3f807f8fffull, RSP_0),
  162. INTEL_UEVENT_EXTRA_REG(0x01bb, MSR_OFFCORE_RSP_1, 0x3f807f8fffull, RSP_1),
  163. INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x01cd),
  164. EVENT_EXTRA_END
  165. };
  166. static struct extra_reg intel_snbep_extra_regs[] __read_mostly = {
  167. /* must define OFFCORE_RSP_X first, see intel_fixup_er() */
  168. INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0x3fffff8fffull, RSP_0),
  169. INTEL_UEVENT_EXTRA_REG(0x01bb, MSR_OFFCORE_RSP_1, 0x3fffff8fffull, RSP_1),
  170. INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x01cd),
  171. EVENT_EXTRA_END
  172. };
  173. EVENT_ATTR_STR(mem-loads, mem_ld_nhm, "event=0x0b,umask=0x10,ldlat=3");
  174. EVENT_ATTR_STR(mem-loads, mem_ld_snb, "event=0xcd,umask=0x1,ldlat=3");
  175. EVENT_ATTR_STR(mem-stores, mem_st_snb, "event=0xcd,umask=0x2");
  176. struct attribute *nhm_events_attrs[] = {
  177. EVENT_PTR(mem_ld_nhm),
  178. NULL,
  179. };
  180. struct attribute *snb_events_attrs[] = {
  181. EVENT_PTR(mem_ld_snb),
  182. EVENT_PTR(mem_st_snb),
  183. NULL,
  184. };
  185. static struct event_constraint intel_hsw_event_constraints[] = {
  186. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  187. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  188. FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */
  189. INTEL_EVENT_CONSTRAINT(0x48, 0x4), /* L1D_PEND_MISS.* */
  190. INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */
  191. INTEL_EVENT_CONSTRAINT(0xcd, 0x8), /* MEM_TRANS_RETIRED.LOAD_LATENCY */
  192. /* CYCLE_ACTIVITY.CYCLES_L1D_PENDING */
  193. INTEL_UEVENT_CONSTRAINT(0x08a3, 0x4),
  194. /* CYCLE_ACTIVITY.STALLS_L1D_PENDING */
  195. INTEL_UEVENT_CONSTRAINT(0x0ca3, 0x4),
  196. /* CYCLE_ACTIVITY.CYCLES_NO_EXECUTE */
  197. INTEL_UEVENT_CONSTRAINT(0x04a3, 0xf),
  198. INTEL_EXCLEVT_CONSTRAINT(0xd0, 0xf), /* MEM_UOPS_RETIRED.* */
  199. INTEL_EXCLEVT_CONSTRAINT(0xd1, 0xf), /* MEM_LOAD_UOPS_RETIRED.* */
  200. INTEL_EXCLEVT_CONSTRAINT(0xd2, 0xf), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
  201. INTEL_EXCLEVT_CONSTRAINT(0xd3, 0xf), /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.* */
  202. EVENT_CONSTRAINT_END
  203. };
  204. struct event_constraint intel_bdw_event_constraints[] = {
  205. FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */
  206. FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */
  207. FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */
  208. INTEL_UEVENT_CONSTRAINT(0x148, 0x4), /* L1D_PEND_MISS.PENDING */
  209. INTEL_EVENT_CONSTRAINT(0xa3, 0x4), /* CYCLE_ACTIVITY.* */
  210. EVENT_CONSTRAINT_END
  211. };
  212. static u64 intel_pmu_event_map(int hw_event)
  213. {
  214. return intel_perfmon_event_map[hw_event];
  215. }
  216. #define SNB_DMND_DATA_RD (1ULL << 0)
  217. #define SNB_DMND_RFO (1ULL << 1)
  218. #define SNB_DMND_IFETCH (1ULL << 2)
  219. #define SNB_DMND_WB (1ULL << 3)
  220. #define SNB_PF_DATA_RD (1ULL << 4)
  221. #define SNB_PF_RFO (1ULL << 5)
  222. #define SNB_PF_IFETCH (1ULL << 6)
  223. #define SNB_LLC_DATA_RD (1ULL << 7)
  224. #define SNB_LLC_RFO (1ULL << 8)
  225. #define SNB_LLC_IFETCH (1ULL << 9)
  226. #define SNB_BUS_LOCKS (1ULL << 10)
  227. #define SNB_STRM_ST (1ULL << 11)
  228. #define SNB_OTHER (1ULL << 15)
  229. #define SNB_RESP_ANY (1ULL << 16)
  230. #define SNB_NO_SUPP (1ULL << 17)
  231. #define SNB_LLC_HITM (1ULL << 18)
  232. #define SNB_LLC_HITE (1ULL << 19)
  233. #define SNB_LLC_HITS (1ULL << 20)
  234. #define SNB_LLC_HITF (1ULL << 21)
  235. #define SNB_LOCAL (1ULL << 22)
  236. #define SNB_REMOTE (0xffULL << 23)
  237. #define SNB_SNP_NONE (1ULL << 31)
  238. #define SNB_SNP_NOT_NEEDED (1ULL << 32)
  239. #define SNB_SNP_MISS (1ULL << 33)
  240. #define SNB_NO_FWD (1ULL << 34)
  241. #define SNB_SNP_FWD (1ULL << 35)
  242. #define SNB_HITM (1ULL << 36)
  243. #define SNB_NON_DRAM (1ULL << 37)
  244. #define SNB_DMND_READ (SNB_DMND_DATA_RD|SNB_LLC_DATA_RD)
  245. #define SNB_DMND_WRITE (SNB_DMND_RFO|SNB_LLC_RFO)
  246. #define SNB_DMND_PREFETCH (SNB_PF_DATA_RD|SNB_PF_RFO)
  247. #define SNB_SNP_ANY (SNB_SNP_NONE|SNB_SNP_NOT_NEEDED| \
  248. SNB_SNP_MISS|SNB_NO_FWD|SNB_SNP_FWD| \
  249. SNB_HITM)
  250. #define SNB_DRAM_ANY (SNB_LOCAL|SNB_REMOTE|SNB_SNP_ANY)
  251. #define SNB_DRAM_REMOTE (SNB_REMOTE|SNB_SNP_ANY)
  252. #define SNB_L3_ACCESS SNB_RESP_ANY
  253. #define SNB_L3_MISS (SNB_DRAM_ANY|SNB_NON_DRAM)
  254. static __initconst const u64 snb_hw_cache_extra_regs
  255. [PERF_COUNT_HW_CACHE_MAX]
  256. [PERF_COUNT_HW_CACHE_OP_MAX]
  257. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  258. {
  259. [ C(LL ) ] = {
  260. [ C(OP_READ) ] = {
  261. [ C(RESULT_ACCESS) ] = SNB_DMND_READ|SNB_L3_ACCESS,
  262. [ C(RESULT_MISS) ] = SNB_DMND_READ|SNB_L3_MISS,
  263. },
  264. [ C(OP_WRITE) ] = {
  265. [ C(RESULT_ACCESS) ] = SNB_DMND_WRITE|SNB_L3_ACCESS,
  266. [ C(RESULT_MISS) ] = SNB_DMND_WRITE|SNB_L3_MISS,
  267. },
  268. [ C(OP_PREFETCH) ] = {
  269. [ C(RESULT_ACCESS) ] = SNB_DMND_PREFETCH|SNB_L3_ACCESS,
  270. [ C(RESULT_MISS) ] = SNB_DMND_PREFETCH|SNB_L3_MISS,
  271. },
  272. },
  273. [ C(NODE) ] = {
  274. [ C(OP_READ) ] = {
  275. [ C(RESULT_ACCESS) ] = SNB_DMND_READ|SNB_DRAM_ANY,
  276. [ C(RESULT_MISS) ] = SNB_DMND_READ|SNB_DRAM_REMOTE,
  277. },
  278. [ C(OP_WRITE) ] = {
  279. [ C(RESULT_ACCESS) ] = SNB_DMND_WRITE|SNB_DRAM_ANY,
  280. [ C(RESULT_MISS) ] = SNB_DMND_WRITE|SNB_DRAM_REMOTE,
  281. },
  282. [ C(OP_PREFETCH) ] = {
  283. [ C(RESULT_ACCESS) ] = SNB_DMND_PREFETCH|SNB_DRAM_ANY,
  284. [ C(RESULT_MISS) ] = SNB_DMND_PREFETCH|SNB_DRAM_REMOTE,
  285. },
  286. },
  287. };
  288. static __initconst const u64 snb_hw_cache_event_ids
  289. [PERF_COUNT_HW_CACHE_MAX]
  290. [PERF_COUNT_HW_CACHE_OP_MAX]
  291. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  292. {
  293. [ C(L1D) ] = {
  294. [ C(OP_READ) ] = {
  295. [ C(RESULT_ACCESS) ] = 0xf1d0, /* MEM_UOP_RETIRED.LOADS */
  296. [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPLACEMENT */
  297. },
  298. [ C(OP_WRITE) ] = {
  299. [ C(RESULT_ACCESS) ] = 0xf2d0, /* MEM_UOP_RETIRED.STORES */
  300. [ C(RESULT_MISS) ] = 0x0851, /* L1D.ALL_M_REPLACEMENT */
  301. },
  302. [ C(OP_PREFETCH) ] = {
  303. [ C(RESULT_ACCESS) ] = 0x0,
  304. [ C(RESULT_MISS) ] = 0x024e, /* HW_PRE_REQ.DL1_MISS */
  305. },
  306. },
  307. [ C(L1I ) ] = {
  308. [ C(OP_READ) ] = {
  309. [ C(RESULT_ACCESS) ] = 0x0,
  310. [ C(RESULT_MISS) ] = 0x0280, /* ICACHE.MISSES */
  311. },
  312. [ C(OP_WRITE) ] = {
  313. [ C(RESULT_ACCESS) ] = -1,
  314. [ C(RESULT_MISS) ] = -1,
  315. },
  316. [ C(OP_PREFETCH) ] = {
  317. [ C(RESULT_ACCESS) ] = 0x0,
  318. [ C(RESULT_MISS) ] = 0x0,
  319. },
  320. },
  321. [ C(LL ) ] = {
  322. [ C(OP_READ) ] = {
  323. /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */
  324. [ C(RESULT_ACCESS) ] = 0x01b7,
  325. /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */
  326. [ C(RESULT_MISS) ] = 0x01b7,
  327. },
  328. [ C(OP_WRITE) ] = {
  329. /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */
  330. [ C(RESULT_ACCESS) ] = 0x01b7,
  331. /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */
  332. [ C(RESULT_MISS) ] = 0x01b7,
  333. },
  334. [ C(OP_PREFETCH) ] = {
  335. /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */
  336. [ C(RESULT_ACCESS) ] = 0x01b7,
  337. /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */
  338. [ C(RESULT_MISS) ] = 0x01b7,
  339. },
  340. },
  341. [ C(DTLB) ] = {
  342. [ C(OP_READ) ] = {
  343. [ C(RESULT_ACCESS) ] = 0x81d0, /* MEM_UOP_RETIRED.ALL_LOADS */
  344. [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.CAUSES_A_WALK */
  345. },
  346. [ C(OP_WRITE) ] = {
  347. [ C(RESULT_ACCESS) ] = 0x82d0, /* MEM_UOP_RETIRED.ALL_STORES */
  348. [ C(RESULT_MISS) ] = 0x0149, /* DTLB_STORE_MISSES.MISS_CAUSES_A_WALK */
  349. },
  350. [ C(OP_PREFETCH) ] = {
  351. [ C(RESULT_ACCESS) ] = 0x0,
  352. [ C(RESULT_MISS) ] = 0x0,
  353. },
  354. },
  355. [ C(ITLB) ] = {
  356. [ C(OP_READ) ] = {
  357. [ C(RESULT_ACCESS) ] = 0x1085, /* ITLB_MISSES.STLB_HIT */
  358. [ C(RESULT_MISS) ] = 0x0185, /* ITLB_MISSES.CAUSES_A_WALK */
  359. },
  360. [ C(OP_WRITE) ] = {
  361. [ C(RESULT_ACCESS) ] = -1,
  362. [ C(RESULT_MISS) ] = -1,
  363. },
  364. [ C(OP_PREFETCH) ] = {
  365. [ C(RESULT_ACCESS) ] = -1,
  366. [ C(RESULT_MISS) ] = -1,
  367. },
  368. },
  369. [ C(BPU ) ] = {
  370. [ C(OP_READ) ] = {
  371. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */
  372. [ C(RESULT_MISS) ] = 0x00c5, /* BR_MISP_RETIRED.ALL_BRANCHES */
  373. },
  374. [ C(OP_WRITE) ] = {
  375. [ C(RESULT_ACCESS) ] = -1,
  376. [ C(RESULT_MISS) ] = -1,
  377. },
  378. [ C(OP_PREFETCH) ] = {
  379. [ C(RESULT_ACCESS) ] = -1,
  380. [ C(RESULT_MISS) ] = -1,
  381. },
  382. },
  383. [ C(NODE) ] = {
  384. [ C(OP_READ) ] = {
  385. [ C(RESULT_ACCESS) ] = 0x01b7,
  386. [ C(RESULT_MISS) ] = 0x01b7,
  387. },
  388. [ C(OP_WRITE) ] = {
  389. [ C(RESULT_ACCESS) ] = 0x01b7,
  390. [ C(RESULT_MISS) ] = 0x01b7,
  391. },
  392. [ C(OP_PREFETCH) ] = {
  393. [ C(RESULT_ACCESS) ] = 0x01b7,
  394. [ C(RESULT_MISS) ] = 0x01b7,
  395. },
  396. },
  397. };
  398. /*
  399. * Notes on the events:
  400. * - data reads do not include code reads (comparable to earlier tables)
  401. * - data counts include speculative execution (except L1 write, dtlb, bpu)
  402. * - remote node access includes remote memory, remote cache, remote mmio.
  403. * - prefetches are not included in the counts because they are not
  404. * reliably counted.
  405. */
  406. #define HSW_DEMAND_DATA_RD BIT_ULL(0)
  407. #define HSW_DEMAND_RFO BIT_ULL(1)
  408. #define HSW_ANY_RESPONSE BIT_ULL(16)
  409. #define HSW_SUPPLIER_NONE BIT_ULL(17)
  410. #define HSW_L3_MISS_LOCAL_DRAM BIT_ULL(22)
  411. #define HSW_L3_MISS_REMOTE_HOP0 BIT_ULL(27)
  412. #define HSW_L3_MISS_REMOTE_HOP1 BIT_ULL(28)
  413. #define HSW_L3_MISS_REMOTE_HOP2P BIT_ULL(29)
  414. #define HSW_L3_MISS (HSW_L3_MISS_LOCAL_DRAM| \
  415. HSW_L3_MISS_REMOTE_HOP0|HSW_L3_MISS_REMOTE_HOP1| \
  416. HSW_L3_MISS_REMOTE_HOP2P)
  417. #define HSW_SNOOP_NONE BIT_ULL(31)
  418. #define HSW_SNOOP_NOT_NEEDED BIT_ULL(32)
  419. #define HSW_SNOOP_MISS BIT_ULL(33)
  420. #define HSW_SNOOP_HIT_NO_FWD BIT_ULL(34)
  421. #define HSW_SNOOP_HIT_WITH_FWD BIT_ULL(35)
  422. #define HSW_SNOOP_HITM BIT_ULL(36)
  423. #define HSW_SNOOP_NON_DRAM BIT_ULL(37)
  424. #define HSW_ANY_SNOOP (HSW_SNOOP_NONE| \
  425. HSW_SNOOP_NOT_NEEDED|HSW_SNOOP_MISS| \
  426. HSW_SNOOP_HIT_NO_FWD|HSW_SNOOP_HIT_WITH_FWD| \
  427. HSW_SNOOP_HITM|HSW_SNOOP_NON_DRAM)
  428. #define HSW_SNOOP_DRAM (HSW_ANY_SNOOP & ~HSW_SNOOP_NON_DRAM)
  429. #define HSW_DEMAND_READ HSW_DEMAND_DATA_RD
  430. #define HSW_DEMAND_WRITE HSW_DEMAND_RFO
  431. #define HSW_L3_MISS_REMOTE (HSW_L3_MISS_REMOTE_HOP0|\
  432. HSW_L3_MISS_REMOTE_HOP1|HSW_L3_MISS_REMOTE_HOP2P)
  433. #define HSW_LLC_ACCESS HSW_ANY_RESPONSE
  434. #define BDW_L3_MISS_LOCAL BIT(26)
  435. #define BDW_L3_MISS (BDW_L3_MISS_LOCAL| \
  436. HSW_L3_MISS_REMOTE_HOP0|HSW_L3_MISS_REMOTE_HOP1| \
  437. HSW_L3_MISS_REMOTE_HOP2P)
  438. static __initconst const u64 hsw_hw_cache_event_ids
  439. [PERF_COUNT_HW_CACHE_MAX]
  440. [PERF_COUNT_HW_CACHE_OP_MAX]
  441. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  442. {
  443. [ C(L1D ) ] = {
  444. [ C(OP_READ) ] = {
  445. [ C(RESULT_ACCESS) ] = 0x81d0, /* MEM_UOPS_RETIRED.ALL_LOADS */
  446. [ C(RESULT_MISS) ] = 0x151, /* L1D.REPLACEMENT */
  447. },
  448. [ C(OP_WRITE) ] = {
  449. [ C(RESULT_ACCESS) ] = 0x82d0, /* MEM_UOPS_RETIRED.ALL_STORES */
  450. [ C(RESULT_MISS) ] = 0x0,
  451. },
  452. [ C(OP_PREFETCH) ] = {
  453. [ C(RESULT_ACCESS) ] = 0x0,
  454. [ C(RESULT_MISS) ] = 0x0,
  455. },
  456. },
  457. [ C(L1I ) ] = {
  458. [ C(OP_READ) ] = {
  459. [ C(RESULT_ACCESS) ] = 0x0,
  460. [ C(RESULT_MISS) ] = 0x280, /* ICACHE.MISSES */
  461. },
  462. [ C(OP_WRITE) ] = {
  463. [ C(RESULT_ACCESS) ] = -1,
  464. [ C(RESULT_MISS) ] = -1,
  465. },
  466. [ C(OP_PREFETCH) ] = {
  467. [ C(RESULT_ACCESS) ] = 0x0,
  468. [ C(RESULT_MISS) ] = 0x0,
  469. },
  470. },
  471. [ C(LL ) ] = {
  472. [ C(OP_READ) ] = {
  473. [ C(RESULT_ACCESS) ] = 0x1b7, /* OFFCORE_RESPONSE */
  474. [ C(RESULT_MISS) ] = 0x1b7, /* OFFCORE_RESPONSE */
  475. },
  476. [ C(OP_WRITE) ] = {
  477. [ C(RESULT_ACCESS) ] = 0x1b7, /* OFFCORE_RESPONSE */
  478. [ C(RESULT_MISS) ] = 0x1b7, /* OFFCORE_RESPONSE */
  479. },
  480. [ C(OP_PREFETCH) ] = {
  481. [ C(RESULT_ACCESS) ] = 0x0,
  482. [ C(RESULT_MISS) ] = 0x0,
  483. },
  484. },
  485. [ C(DTLB) ] = {
  486. [ C(OP_READ) ] = {
  487. [ C(RESULT_ACCESS) ] = 0x81d0, /* MEM_UOPS_RETIRED.ALL_LOADS */
  488. [ C(RESULT_MISS) ] = 0x108, /* DTLB_LOAD_MISSES.MISS_CAUSES_A_WALK */
  489. },
  490. [ C(OP_WRITE) ] = {
  491. [ C(RESULT_ACCESS) ] = 0x82d0, /* MEM_UOPS_RETIRED.ALL_STORES */
  492. [ C(RESULT_MISS) ] = 0x149, /* DTLB_STORE_MISSES.MISS_CAUSES_A_WALK */
  493. },
  494. [ C(OP_PREFETCH) ] = {
  495. [ C(RESULT_ACCESS) ] = 0x0,
  496. [ C(RESULT_MISS) ] = 0x0,
  497. },
  498. },
  499. [ C(ITLB) ] = {
  500. [ C(OP_READ) ] = {
  501. [ C(RESULT_ACCESS) ] = 0x6085, /* ITLB_MISSES.STLB_HIT */
  502. [ C(RESULT_MISS) ] = 0x185, /* ITLB_MISSES.MISS_CAUSES_A_WALK */
  503. },
  504. [ C(OP_WRITE) ] = {
  505. [ C(RESULT_ACCESS) ] = -1,
  506. [ C(RESULT_MISS) ] = -1,
  507. },
  508. [ C(OP_PREFETCH) ] = {
  509. [ C(RESULT_ACCESS) ] = -1,
  510. [ C(RESULT_MISS) ] = -1,
  511. },
  512. },
  513. [ C(BPU ) ] = {
  514. [ C(OP_READ) ] = {
  515. [ C(RESULT_ACCESS) ] = 0xc4, /* BR_INST_RETIRED.ALL_BRANCHES */
  516. [ C(RESULT_MISS) ] = 0xc5, /* BR_MISP_RETIRED.ALL_BRANCHES */
  517. },
  518. [ C(OP_WRITE) ] = {
  519. [ C(RESULT_ACCESS) ] = -1,
  520. [ C(RESULT_MISS) ] = -1,
  521. },
  522. [ C(OP_PREFETCH) ] = {
  523. [ C(RESULT_ACCESS) ] = -1,
  524. [ C(RESULT_MISS) ] = -1,
  525. },
  526. },
  527. [ C(NODE) ] = {
  528. [ C(OP_READ) ] = {
  529. [ C(RESULT_ACCESS) ] = 0x1b7, /* OFFCORE_RESPONSE */
  530. [ C(RESULT_MISS) ] = 0x1b7, /* OFFCORE_RESPONSE */
  531. },
  532. [ C(OP_WRITE) ] = {
  533. [ C(RESULT_ACCESS) ] = 0x1b7, /* OFFCORE_RESPONSE */
  534. [ C(RESULT_MISS) ] = 0x1b7, /* OFFCORE_RESPONSE */
  535. },
  536. [ C(OP_PREFETCH) ] = {
  537. [ C(RESULT_ACCESS) ] = 0x0,
  538. [ C(RESULT_MISS) ] = 0x0,
  539. },
  540. },
  541. };
  542. static __initconst const u64 hsw_hw_cache_extra_regs
  543. [PERF_COUNT_HW_CACHE_MAX]
  544. [PERF_COUNT_HW_CACHE_OP_MAX]
  545. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  546. {
  547. [ C(LL ) ] = {
  548. [ C(OP_READ) ] = {
  549. [ C(RESULT_ACCESS) ] = HSW_DEMAND_READ|
  550. HSW_LLC_ACCESS,
  551. [ C(RESULT_MISS) ] = HSW_DEMAND_READ|
  552. HSW_L3_MISS|HSW_ANY_SNOOP,
  553. },
  554. [ C(OP_WRITE) ] = {
  555. [ C(RESULT_ACCESS) ] = HSW_DEMAND_WRITE|
  556. HSW_LLC_ACCESS,
  557. [ C(RESULT_MISS) ] = HSW_DEMAND_WRITE|
  558. HSW_L3_MISS|HSW_ANY_SNOOP,
  559. },
  560. [ C(OP_PREFETCH) ] = {
  561. [ C(RESULT_ACCESS) ] = 0x0,
  562. [ C(RESULT_MISS) ] = 0x0,
  563. },
  564. },
  565. [ C(NODE) ] = {
  566. [ C(OP_READ) ] = {
  567. [ C(RESULT_ACCESS) ] = HSW_DEMAND_READ|
  568. HSW_L3_MISS_LOCAL_DRAM|
  569. HSW_SNOOP_DRAM,
  570. [ C(RESULT_MISS) ] = HSW_DEMAND_READ|
  571. HSW_L3_MISS_REMOTE|
  572. HSW_SNOOP_DRAM,
  573. },
  574. [ C(OP_WRITE) ] = {
  575. [ C(RESULT_ACCESS) ] = HSW_DEMAND_WRITE|
  576. HSW_L3_MISS_LOCAL_DRAM|
  577. HSW_SNOOP_DRAM,
  578. [ C(RESULT_MISS) ] = HSW_DEMAND_WRITE|
  579. HSW_L3_MISS_REMOTE|
  580. HSW_SNOOP_DRAM,
  581. },
  582. [ C(OP_PREFETCH) ] = {
  583. [ C(RESULT_ACCESS) ] = 0x0,
  584. [ C(RESULT_MISS) ] = 0x0,
  585. },
  586. },
  587. };
  588. static __initconst const u64 westmere_hw_cache_event_ids
  589. [PERF_COUNT_HW_CACHE_MAX]
  590. [PERF_COUNT_HW_CACHE_OP_MAX]
  591. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  592. {
  593. [ C(L1D) ] = {
  594. [ C(OP_READ) ] = {
  595. [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */
  596. [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPL */
  597. },
  598. [ C(OP_WRITE) ] = {
  599. [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */
  600. [ C(RESULT_MISS) ] = 0x0251, /* L1D.M_REPL */
  601. },
  602. [ C(OP_PREFETCH) ] = {
  603. [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */
  604. [ C(RESULT_MISS) ] = 0x024e, /* L1D_PREFETCH.MISS */
  605. },
  606. },
  607. [ C(L1I ) ] = {
  608. [ C(OP_READ) ] = {
  609. [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */
  610. [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */
  611. },
  612. [ C(OP_WRITE) ] = {
  613. [ C(RESULT_ACCESS) ] = -1,
  614. [ C(RESULT_MISS) ] = -1,
  615. },
  616. [ C(OP_PREFETCH) ] = {
  617. [ C(RESULT_ACCESS) ] = 0x0,
  618. [ C(RESULT_MISS) ] = 0x0,
  619. },
  620. },
  621. [ C(LL ) ] = {
  622. [ C(OP_READ) ] = {
  623. /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */
  624. [ C(RESULT_ACCESS) ] = 0x01b7,
  625. /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */
  626. [ C(RESULT_MISS) ] = 0x01b7,
  627. },
  628. /*
  629. * Use RFO, not WRITEBACK, because a write miss would typically occur
  630. * on RFO.
  631. */
  632. [ C(OP_WRITE) ] = {
  633. /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */
  634. [ C(RESULT_ACCESS) ] = 0x01b7,
  635. /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */
  636. [ C(RESULT_MISS) ] = 0x01b7,
  637. },
  638. [ C(OP_PREFETCH) ] = {
  639. /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */
  640. [ C(RESULT_ACCESS) ] = 0x01b7,
  641. /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */
  642. [ C(RESULT_MISS) ] = 0x01b7,
  643. },
  644. },
  645. [ C(DTLB) ] = {
  646. [ C(OP_READ) ] = {
  647. [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */
  648. [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.ANY */
  649. },
  650. [ C(OP_WRITE) ] = {
  651. [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */
  652. [ C(RESULT_MISS) ] = 0x010c, /* MEM_STORE_RETIRED.DTLB_MISS */
  653. },
  654. [ C(OP_PREFETCH) ] = {
  655. [ C(RESULT_ACCESS) ] = 0x0,
  656. [ C(RESULT_MISS) ] = 0x0,
  657. },
  658. },
  659. [ C(ITLB) ] = {
  660. [ C(OP_READ) ] = {
  661. [ C(RESULT_ACCESS) ] = 0x01c0, /* INST_RETIRED.ANY_P */
  662. [ C(RESULT_MISS) ] = 0x0185, /* ITLB_MISSES.ANY */
  663. },
  664. [ C(OP_WRITE) ] = {
  665. [ C(RESULT_ACCESS) ] = -1,
  666. [ C(RESULT_MISS) ] = -1,
  667. },
  668. [ C(OP_PREFETCH) ] = {
  669. [ C(RESULT_ACCESS) ] = -1,
  670. [ C(RESULT_MISS) ] = -1,
  671. },
  672. },
  673. [ C(BPU ) ] = {
  674. [ C(OP_READ) ] = {
  675. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */
  676. [ C(RESULT_MISS) ] = 0x03e8, /* BPU_CLEARS.ANY */
  677. },
  678. [ C(OP_WRITE) ] = {
  679. [ C(RESULT_ACCESS) ] = -1,
  680. [ C(RESULT_MISS) ] = -1,
  681. },
  682. [ C(OP_PREFETCH) ] = {
  683. [ C(RESULT_ACCESS) ] = -1,
  684. [ C(RESULT_MISS) ] = -1,
  685. },
  686. },
  687. [ C(NODE) ] = {
  688. [ C(OP_READ) ] = {
  689. [ C(RESULT_ACCESS) ] = 0x01b7,
  690. [ C(RESULT_MISS) ] = 0x01b7,
  691. },
  692. [ C(OP_WRITE) ] = {
  693. [ C(RESULT_ACCESS) ] = 0x01b7,
  694. [ C(RESULT_MISS) ] = 0x01b7,
  695. },
  696. [ C(OP_PREFETCH) ] = {
  697. [ C(RESULT_ACCESS) ] = 0x01b7,
  698. [ C(RESULT_MISS) ] = 0x01b7,
  699. },
  700. },
  701. };
  702. /*
  703. * Nehalem/Westmere MSR_OFFCORE_RESPONSE bits;
  704. * See IA32 SDM Vol 3B 30.6.1.3
  705. */
  706. #define NHM_DMND_DATA_RD (1 << 0)
  707. #define NHM_DMND_RFO (1 << 1)
  708. #define NHM_DMND_IFETCH (1 << 2)
  709. #define NHM_DMND_WB (1 << 3)
  710. #define NHM_PF_DATA_RD (1 << 4)
  711. #define NHM_PF_DATA_RFO (1 << 5)
  712. #define NHM_PF_IFETCH (1 << 6)
  713. #define NHM_OFFCORE_OTHER (1 << 7)
  714. #define NHM_UNCORE_HIT (1 << 8)
  715. #define NHM_OTHER_CORE_HIT_SNP (1 << 9)
  716. #define NHM_OTHER_CORE_HITM (1 << 10)
  717. /* reserved */
  718. #define NHM_REMOTE_CACHE_FWD (1 << 12)
  719. #define NHM_REMOTE_DRAM (1 << 13)
  720. #define NHM_LOCAL_DRAM (1 << 14)
  721. #define NHM_NON_DRAM (1 << 15)
  722. #define NHM_LOCAL (NHM_LOCAL_DRAM|NHM_REMOTE_CACHE_FWD)
  723. #define NHM_REMOTE (NHM_REMOTE_DRAM)
  724. #define NHM_DMND_READ (NHM_DMND_DATA_RD)
  725. #define NHM_DMND_WRITE (NHM_DMND_RFO|NHM_DMND_WB)
  726. #define NHM_DMND_PREFETCH (NHM_PF_DATA_RD|NHM_PF_DATA_RFO)
  727. #define NHM_L3_HIT (NHM_UNCORE_HIT|NHM_OTHER_CORE_HIT_SNP|NHM_OTHER_CORE_HITM)
  728. #define NHM_L3_MISS (NHM_NON_DRAM|NHM_LOCAL_DRAM|NHM_REMOTE_DRAM|NHM_REMOTE_CACHE_FWD)
  729. #define NHM_L3_ACCESS (NHM_L3_HIT|NHM_L3_MISS)
  730. static __initconst const u64 nehalem_hw_cache_extra_regs
  731. [PERF_COUNT_HW_CACHE_MAX]
  732. [PERF_COUNT_HW_CACHE_OP_MAX]
  733. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  734. {
  735. [ C(LL ) ] = {
  736. [ C(OP_READ) ] = {
  737. [ C(RESULT_ACCESS) ] = NHM_DMND_READ|NHM_L3_ACCESS,
  738. [ C(RESULT_MISS) ] = NHM_DMND_READ|NHM_L3_MISS,
  739. },
  740. [ C(OP_WRITE) ] = {
  741. [ C(RESULT_ACCESS) ] = NHM_DMND_WRITE|NHM_L3_ACCESS,
  742. [ C(RESULT_MISS) ] = NHM_DMND_WRITE|NHM_L3_MISS,
  743. },
  744. [ C(OP_PREFETCH) ] = {
  745. [ C(RESULT_ACCESS) ] = NHM_DMND_PREFETCH|NHM_L3_ACCESS,
  746. [ C(RESULT_MISS) ] = NHM_DMND_PREFETCH|NHM_L3_MISS,
  747. },
  748. },
  749. [ C(NODE) ] = {
  750. [ C(OP_READ) ] = {
  751. [ C(RESULT_ACCESS) ] = NHM_DMND_READ|NHM_LOCAL|NHM_REMOTE,
  752. [ C(RESULT_MISS) ] = NHM_DMND_READ|NHM_REMOTE,
  753. },
  754. [ C(OP_WRITE) ] = {
  755. [ C(RESULT_ACCESS) ] = NHM_DMND_WRITE|NHM_LOCAL|NHM_REMOTE,
  756. [ C(RESULT_MISS) ] = NHM_DMND_WRITE|NHM_REMOTE,
  757. },
  758. [ C(OP_PREFETCH) ] = {
  759. [ C(RESULT_ACCESS) ] = NHM_DMND_PREFETCH|NHM_LOCAL|NHM_REMOTE,
  760. [ C(RESULT_MISS) ] = NHM_DMND_PREFETCH|NHM_REMOTE,
  761. },
  762. },
  763. };
  764. static __initconst const u64 nehalem_hw_cache_event_ids
  765. [PERF_COUNT_HW_CACHE_MAX]
  766. [PERF_COUNT_HW_CACHE_OP_MAX]
  767. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  768. {
  769. [ C(L1D) ] = {
  770. [ C(OP_READ) ] = {
  771. [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */
  772. [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPL */
  773. },
  774. [ C(OP_WRITE) ] = {
  775. [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */
  776. [ C(RESULT_MISS) ] = 0x0251, /* L1D.M_REPL */
  777. },
  778. [ C(OP_PREFETCH) ] = {
  779. [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */
  780. [ C(RESULT_MISS) ] = 0x024e, /* L1D_PREFETCH.MISS */
  781. },
  782. },
  783. [ C(L1I ) ] = {
  784. [ C(OP_READ) ] = {
  785. [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */
  786. [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */
  787. },
  788. [ C(OP_WRITE) ] = {
  789. [ C(RESULT_ACCESS) ] = -1,
  790. [ C(RESULT_MISS) ] = -1,
  791. },
  792. [ C(OP_PREFETCH) ] = {
  793. [ C(RESULT_ACCESS) ] = 0x0,
  794. [ C(RESULT_MISS) ] = 0x0,
  795. },
  796. },
  797. [ C(LL ) ] = {
  798. [ C(OP_READ) ] = {
  799. /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */
  800. [ C(RESULT_ACCESS) ] = 0x01b7,
  801. /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */
  802. [ C(RESULT_MISS) ] = 0x01b7,
  803. },
  804. /*
  805. * Use RFO, not WRITEBACK, because a write miss would typically occur
  806. * on RFO.
  807. */
  808. [ C(OP_WRITE) ] = {
  809. /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */
  810. [ C(RESULT_ACCESS) ] = 0x01b7,
  811. /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */
  812. [ C(RESULT_MISS) ] = 0x01b7,
  813. },
  814. [ C(OP_PREFETCH) ] = {
  815. /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */
  816. [ C(RESULT_ACCESS) ] = 0x01b7,
  817. /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */
  818. [ C(RESULT_MISS) ] = 0x01b7,
  819. },
  820. },
  821. [ C(DTLB) ] = {
  822. [ C(OP_READ) ] = {
  823. [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI (alias) */
  824. [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.ANY */
  825. },
  826. [ C(OP_WRITE) ] = {
  827. [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI (alias) */
  828. [ C(RESULT_MISS) ] = 0x010c, /* MEM_STORE_RETIRED.DTLB_MISS */
  829. },
  830. [ C(OP_PREFETCH) ] = {
  831. [ C(RESULT_ACCESS) ] = 0x0,
  832. [ C(RESULT_MISS) ] = 0x0,
  833. },
  834. },
  835. [ C(ITLB) ] = {
  836. [ C(OP_READ) ] = {
  837. [ C(RESULT_ACCESS) ] = 0x01c0, /* INST_RETIRED.ANY_P */
  838. [ C(RESULT_MISS) ] = 0x20c8, /* ITLB_MISS_RETIRED */
  839. },
  840. [ C(OP_WRITE) ] = {
  841. [ C(RESULT_ACCESS) ] = -1,
  842. [ C(RESULT_MISS) ] = -1,
  843. },
  844. [ C(OP_PREFETCH) ] = {
  845. [ C(RESULT_ACCESS) ] = -1,
  846. [ C(RESULT_MISS) ] = -1,
  847. },
  848. },
  849. [ C(BPU ) ] = {
  850. [ C(OP_READ) ] = {
  851. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */
  852. [ C(RESULT_MISS) ] = 0x03e8, /* BPU_CLEARS.ANY */
  853. },
  854. [ C(OP_WRITE) ] = {
  855. [ C(RESULT_ACCESS) ] = -1,
  856. [ C(RESULT_MISS) ] = -1,
  857. },
  858. [ C(OP_PREFETCH) ] = {
  859. [ C(RESULT_ACCESS) ] = -1,
  860. [ C(RESULT_MISS) ] = -1,
  861. },
  862. },
  863. [ C(NODE) ] = {
  864. [ C(OP_READ) ] = {
  865. [ C(RESULT_ACCESS) ] = 0x01b7,
  866. [ C(RESULT_MISS) ] = 0x01b7,
  867. },
  868. [ C(OP_WRITE) ] = {
  869. [ C(RESULT_ACCESS) ] = 0x01b7,
  870. [ C(RESULT_MISS) ] = 0x01b7,
  871. },
  872. [ C(OP_PREFETCH) ] = {
  873. [ C(RESULT_ACCESS) ] = 0x01b7,
  874. [ C(RESULT_MISS) ] = 0x01b7,
  875. },
  876. },
  877. };
  878. static __initconst const u64 core2_hw_cache_event_ids
  879. [PERF_COUNT_HW_CACHE_MAX]
  880. [PERF_COUNT_HW_CACHE_OP_MAX]
  881. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  882. {
  883. [ C(L1D) ] = {
  884. [ C(OP_READ) ] = {
  885. [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI */
  886. [ C(RESULT_MISS) ] = 0x0140, /* L1D_CACHE_LD.I_STATE */
  887. },
  888. [ C(OP_WRITE) ] = {
  889. [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI */
  890. [ C(RESULT_MISS) ] = 0x0141, /* L1D_CACHE_ST.I_STATE */
  891. },
  892. [ C(OP_PREFETCH) ] = {
  893. [ C(RESULT_ACCESS) ] = 0x104e, /* L1D_PREFETCH.REQUESTS */
  894. [ C(RESULT_MISS) ] = 0,
  895. },
  896. },
  897. [ C(L1I ) ] = {
  898. [ C(OP_READ) ] = {
  899. [ C(RESULT_ACCESS) ] = 0x0080, /* L1I.READS */
  900. [ C(RESULT_MISS) ] = 0x0081, /* L1I.MISSES */
  901. },
  902. [ C(OP_WRITE) ] = {
  903. [ C(RESULT_ACCESS) ] = -1,
  904. [ C(RESULT_MISS) ] = -1,
  905. },
  906. [ C(OP_PREFETCH) ] = {
  907. [ C(RESULT_ACCESS) ] = 0,
  908. [ C(RESULT_MISS) ] = 0,
  909. },
  910. },
  911. [ C(LL ) ] = {
  912. [ C(OP_READ) ] = {
  913. [ C(RESULT_ACCESS) ] = 0x4f29, /* L2_LD.MESI */
  914. [ C(RESULT_MISS) ] = 0x4129, /* L2_LD.ISTATE */
  915. },
  916. [ C(OP_WRITE) ] = {
  917. [ C(RESULT_ACCESS) ] = 0x4f2A, /* L2_ST.MESI */
  918. [ C(RESULT_MISS) ] = 0x412A, /* L2_ST.ISTATE */
  919. },
  920. [ C(OP_PREFETCH) ] = {
  921. [ C(RESULT_ACCESS) ] = 0,
  922. [ C(RESULT_MISS) ] = 0,
  923. },
  924. },
  925. [ C(DTLB) ] = {
  926. [ C(OP_READ) ] = {
  927. [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI (alias) */
  928. [ C(RESULT_MISS) ] = 0x0208, /* DTLB_MISSES.MISS_LD */
  929. },
  930. [ C(OP_WRITE) ] = {
  931. [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI (alias) */
  932. [ C(RESULT_MISS) ] = 0x0808, /* DTLB_MISSES.MISS_ST */
  933. },
  934. [ C(OP_PREFETCH) ] = {
  935. [ C(RESULT_ACCESS) ] = 0,
  936. [ C(RESULT_MISS) ] = 0,
  937. },
  938. },
  939. [ C(ITLB) ] = {
  940. [ C(OP_READ) ] = {
  941. [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */
  942. [ C(RESULT_MISS) ] = 0x1282, /* ITLBMISSES */
  943. },
  944. [ C(OP_WRITE) ] = {
  945. [ C(RESULT_ACCESS) ] = -1,
  946. [ C(RESULT_MISS) ] = -1,
  947. },
  948. [ C(OP_PREFETCH) ] = {
  949. [ C(RESULT_ACCESS) ] = -1,
  950. [ C(RESULT_MISS) ] = -1,
  951. },
  952. },
  953. [ C(BPU ) ] = {
  954. [ C(OP_READ) ] = {
  955. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */
  956. [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */
  957. },
  958. [ C(OP_WRITE) ] = {
  959. [ C(RESULT_ACCESS) ] = -1,
  960. [ C(RESULT_MISS) ] = -1,
  961. },
  962. [ C(OP_PREFETCH) ] = {
  963. [ C(RESULT_ACCESS) ] = -1,
  964. [ C(RESULT_MISS) ] = -1,
  965. },
  966. },
  967. };
  968. static __initconst const u64 atom_hw_cache_event_ids
  969. [PERF_COUNT_HW_CACHE_MAX]
  970. [PERF_COUNT_HW_CACHE_OP_MAX]
  971. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  972. {
  973. [ C(L1D) ] = {
  974. [ C(OP_READ) ] = {
  975. [ C(RESULT_ACCESS) ] = 0x2140, /* L1D_CACHE.LD */
  976. [ C(RESULT_MISS) ] = 0,
  977. },
  978. [ C(OP_WRITE) ] = {
  979. [ C(RESULT_ACCESS) ] = 0x2240, /* L1D_CACHE.ST */
  980. [ C(RESULT_MISS) ] = 0,
  981. },
  982. [ C(OP_PREFETCH) ] = {
  983. [ C(RESULT_ACCESS) ] = 0x0,
  984. [ C(RESULT_MISS) ] = 0,
  985. },
  986. },
  987. [ C(L1I ) ] = {
  988. [ C(OP_READ) ] = {
  989. [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */
  990. [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */
  991. },
  992. [ C(OP_WRITE) ] = {
  993. [ C(RESULT_ACCESS) ] = -1,
  994. [ C(RESULT_MISS) ] = -1,
  995. },
  996. [ C(OP_PREFETCH) ] = {
  997. [ C(RESULT_ACCESS) ] = 0,
  998. [ C(RESULT_MISS) ] = 0,
  999. },
  1000. },
  1001. [ C(LL ) ] = {
  1002. [ C(OP_READ) ] = {
  1003. [ C(RESULT_ACCESS) ] = 0x4f29, /* L2_LD.MESI */
  1004. [ C(RESULT_MISS) ] = 0x4129, /* L2_LD.ISTATE */
  1005. },
  1006. [ C(OP_WRITE) ] = {
  1007. [ C(RESULT_ACCESS) ] = 0x4f2A, /* L2_ST.MESI */
  1008. [ C(RESULT_MISS) ] = 0x412A, /* L2_ST.ISTATE */
  1009. },
  1010. [ C(OP_PREFETCH) ] = {
  1011. [ C(RESULT_ACCESS) ] = 0,
  1012. [ C(RESULT_MISS) ] = 0,
  1013. },
  1014. },
  1015. [ C(DTLB) ] = {
  1016. [ C(OP_READ) ] = {
  1017. [ C(RESULT_ACCESS) ] = 0x2140, /* L1D_CACHE_LD.MESI (alias) */
  1018. [ C(RESULT_MISS) ] = 0x0508, /* DTLB_MISSES.MISS_LD */
  1019. },
  1020. [ C(OP_WRITE) ] = {
  1021. [ C(RESULT_ACCESS) ] = 0x2240, /* L1D_CACHE_ST.MESI (alias) */
  1022. [ C(RESULT_MISS) ] = 0x0608, /* DTLB_MISSES.MISS_ST */
  1023. },
  1024. [ C(OP_PREFETCH) ] = {
  1025. [ C(RESULT_ACCESS) ] = 0,
  1026. [ C(RESULT_MISS) ] = 0,
  1027. },
  1028. },
  1029. [ C(ITLB) ] = {
  1030. [ C(OP_READ) ] = {
  1031. [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */
  1032. [ C(RESULT_MISS) ] = 0x0282, /* ITLB.MISSES */
  1033. },
  1034. [ C(OP_WRITE) ] = {
  1035. [ C(RESULT_ACCESS) ] = -1,
  1036. [ C(RESULT_MISS) ] = -1,
  1037. },
  1038. [ C(OP_PREFETCH) ] = {
  1039. [ C(RESULT_ACCESS) ] = -1,
  1040. [ C(RESULT_MISS) ] = -1,
  1041. },
  1042. },
  1043. [ C(BPU ) ] = {
  1044. [ C(OP_READ) ] = {
  1045. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */
  1046. [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */
  1047. },
  1048. [ C(OP_WRITE) ] = {
  1049. [ C(RESULT_ACCESS) ] = -1,
  1050. [ C(RESULT_MISS) ] = -1,
  1051. },
  1052. [ C(OP_PREFETCH) ] = {
  1053. [ C(RESULT_ACCESS) ] = -1,
  1054. [ C(RESULT_MISS) ] = -1,
  1055. },
  1056. },
  1057. };
  1058. static struct extra_reg intel_slm_extra_regs[] __read_mostly =
  1059. {
  1060. /* must define OFFCORE_RSP_X first, see intel_fixup_er() */
  1061. INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0x768005ffffull, RSP_0),
  1062. INTEL_UEVENT_EXTRA_REG(0x02b7, MSR_OFFCORE_RSP_1, 0x768005ffffull, RSP_1),
  1063. EVENT_EXTRA_END
  1064. };
  1065. #define SLM_DMND_READ SNB_DMND_DATA_RD
  1066. #define SLM_DMND_WRITE SNB_DMND_RFO
  1067. #define SLM_DMND_PREFETCH (SNB_PF_DATA_RD|SNB_PF_RFO)
  1068. #define SLM_SNP_ANY (SNB_SNP_NONE|SNB_SNP_MISS|SNB_NO_FWD|SNB_HITM)
  1069. #define SLM_LLC_ACCESS SNB_RESP_ANY
  1070. #define SLM_LLC_MISS (SLM_SNP_ANY|SNB_NON_DRAM)
  1071. static __initconst const u64 slm_hw_cache_extra_regs
  1072. [PERF_COUNT_HW_CACHE_MAX]
  1073. [PERF_COUNT_HW_CACHE_OP_MAX]
  1074. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  1075. {
  1076. [ C(LL ) ] = {
  1077. [ C(OP_READ) ] = {
  1078. [ C(RESULT_ACCESS) ] = SLM_DMND_READ|SLM_LLC_ACCESS,
  1079. [ C(RESULT_MISS) ] = SLM_DMND_READ|SLM_LLC_MISS,
  1080. },
  1081. [ C(OP_WRITE) ] = {
  1082. [ C(RESULT_ACCESS) ] = SLM_DMND_WRITE|SLM_LLC_ACCESS,
  1083. [ C(RESULT_MISS) ] = SLM_DMND_WRITE|SLM_LLC_MISS,
  1084. },
  1085. [ C(OP_PREFETCH) ] = {
  1086. [ C(RESULT_ACCESS) ] = SLM_DMND_PREFETCH|SLM_LLC_ACCESS,
  1087. [ C(RESULT_MISS) ] = SLM_DMND_PREFETCH|SLM_LLC_MISS,
  1088. },
  1089. },
  1090. };
  1091. static __initconst const u64 slm_hw_cache_event_ids
  1092. [PERF_COUNT_HW_CACHE_MAX]
  1093. [PERF_COUNT_HW_CACHE_OP_MAX]
  1094. [PERF_COUNT_HW_CACHE_RESULT_MAX] =
  1095. {
  1096. [ C(L1D) ] = {
  1097. [ C(OP_READ) ] = {
  1098. [ C(RESULT_ACCESS) ] = 0,
  1099. [ C(RESULT_MISS) ] = 0x0104, /* LD_DCU_MISS */
  1100. },
  1101. [ C(OP_WRITE) ] = {
  1102. [ C(RESULT_ACCESS) ] = 0,
  1103. [ C(RESULT_MISS) ] = 0,
  1104. },
  1105. [ C(OP_PREFETCH) ] = {
  1106. [ C(RESULT_ACCESS) ] = 0,
  1107. [ C(RESULT_MISS) ] = 0,
  1108. },
  1109. },
  1110. [ C(L1I ) ] = {
  1111. [ C(OP_READ) ] = {
  1112. [ C(RESULT_ACCESS) ] = 0x0380, /* ICACHE.ACCESSES */
  1113. [ C(RESULT_MISS) ] = 0x0280, /* ICACGE.MISSES */
  1114. },
  1115. [ C(OP_WRITE) ] = {
  1116. [ C(RESULT_ACCESS) ] = -1,
  1117. [ C(RESULT_MISS) ] = -1,
  1118. },
  1119. [ C(OP_PREFETCH) ] = {
  1120. [ C(RESULT_ACCESS) ] = 0,
  1121. [ C(RESULT_MISS) ] = 0,
  1122. },
  1123. },
  1124. [ C(LL ) ] = {
  1125. [ C(OP_READ) ] = {
  1126. /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */
  1127. [ C(RESULT_ACCESS) ] = 0x01b7,
  1128. /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */
  1129. [ C(RESULT_MISS) ] = 0x01b7,
  1130. },
  1131. [ C(OP_WRITE) ] = {
  1132. /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */
  1133. [ C(RESULT_ACCESS) ] = 0x01b7,
  1134. /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */
  1135. [ C(RESULT_MISS) ] = 0x01b7,
  1136. },
  1137. [ C(OP_PREFETCH) ] = {
  1138. /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */
  1139. [ C(RESULT_ACCESS) ] = 0x01b7,
  1140. /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */
  1141. [ C(RESULT_MISS) ] = 0x01b7,
  1142. },
  1143. },
  1144. [ C(DTLB) ] = {
  1145. [ C(OP_READ) ] = {
  1146. [ C(RESULT_ACCESS) ] = 0,
  1147. [ C(RESULT_MISS) ] = 0x0804, /* LD_DTLB_MISS */
  1148. },
  1149. [ C(OP_WRITE) ] = {
  1150. [ C(RESULT_ACCESS) ] = 0,
  1151. [ C(RESULT_MISS) ] = 0,
  1152. },
  1153. [ C(OP_PREFETCH) ] = {
  1154. [ C(RESULT_ACCESS) ] = 0,
  1155. [ C(RESULT_MISS) ] = 0,
  1156. },
  1157. },
  1158. [ C(ITLB) ] = {
  1159. [ C(OP_READ) ] = {
  1160. [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */
  1161. [ C(RESULT_MISS) ] = 0x0282, /* ITLB.MISSES */
  1162. },
  1163. [ C(OP_WRITE) ] = {
  1164. [ C(RESULT_ACCESS) ] = -1,
  1165. [ C(RESULT_MISS) ] = -1,
  1166. },
  1167. [ C(OP_PREFETCH) ] = {
  1168. [ C(RESULT_ACCESS) ] = -1,
  1169. [ C(RESULT_MISS) ] = -1,
  1170. },
  1171. },
  1172. [ C(BPU ) ] = {
  1173. [ C(OP_READ) ] = {
  1174. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */
  1175. [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */
  1176. },
  1177. [ C(OP_WRITE) ] = {
  1178. [ C(RESULT_ACCESS) ] = -1,
  1179. [ C(RESULT_MISS) ] = -1,
  1180. },
  1181. [ C(OP_PREFETCH) ] = {
  1182. [ C(RESULT_ACCESS) ] = -1,
  1183. [ C(RESULT_MISS) ] = -1,
  1184. },
  1185. },
  1186. };
  1187. /*
  1188. * Use from PMIs where the LBRs are already disabled.
  1189. */
  1190. static void __intel_pmu_disable_all(void)
  1191. {
  1192. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1193. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0);
  1194. if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask))
  1195. intel_pmu_disable_bts();
  1196. else
  1197. intel_bts_disable_local();
  1198. intel_pmu_pebs_disable_all();
  1199. }
  1200. static void intel_pmu_disable_all(void)
  1201. {
  1202. __intel_pmu_disable_all();
  1203. intel_pmu_lbr_disable_all();
  1204. }
  1205. static void __intel_pmu_enable_all(int added, bool pmi)
  1206. {
  1207. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1208. intel_pmu_pebs_enable_all();
  1209. intel_pmu_lbr_enable_all(pmi);
  1210. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL,
  1211. x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask);
  1212. if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask)) {
  1213. struct perf_event *event =
  1214. cpuc->events[INTEL_PMC_IDX_FIXED_BTS];
  1215. if (WARN_ON_ONCE(!event))
  1216. return;
  1217. intel_pmu_enable_bts(event->hw.config);
  1218. } else
  1219. intel_bts_enable_local();
  1220. }
  1221. static void intel_pmu_enable_all(int added)
  1222. {
  1223. __intel_pmu_enable_all(added, false);
  1224. }
  1225. /*
  1226. * Workaround for:
  1227. * Intel Errata AAK100 (model 26)
  1228. * Intel Errata AAP53 (model 30)
  1229. * Intel Errata BD53 (model 44)
  1230. *
  1231. * The official story:
  1232. * These chips need to be 'reset' when adding counters by programming the
  1233. * magic three (non-counting) events 0x4300B5, 0x4300D2, and 0x4300B1 either
  1234. * in sequence on the same PMC or on different PMCs.
  1235. *
  1236. * In practise it appears some of these events do in fact count, and
  1237. * we need to programm all 4 events.
  1238. */
  1239. static void intel_pmu_nhm_workaround(void)
  1240. {
  1241. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1242. static const unsigned long nhm_magic[4] = {
  1243. 0x4300B5,
  1244. 0x4300D2,
  1245. 0x4300B1,
  1246. 0x4300B1
  1247. };
  1248. struct perf_event *event;
  1249. int i;
  1250. /*
  1251. * The Errata requires below steps:
  1252. * 1) Clear MSR_IA32_PEBS_ENABLE and MSR_CORE_PERF_GLOBAL_CTRL;
  1253. * 2) Configure 4 PERFEVTSELx with the magic events and clear
  1254. * the corresponding PMCx;
  1255. * 3) set bit0~bit3 of MSR_CORE_PERF_GLOBAL_CTRL;
  1256. * 4) Clear MSR_CORE_PERF_GLOBAL_CTRL;
  1257. * 5) Clear 4 pairs of ERFEVTSELx and PMCx;
  1258. */
  1259. /*
  1260. * The real steps we choose are a little different from above.
  1261. * A) To reduce MSR operations, we don't run step 1) as they
  1262. * are already cleared before this function is called;
  1263. * B) Call x86_perf_event_update to save PMCx before configuring
  1264. * PERFEVTSELx with magic number;
  1265. * C) With step 5), we do clear only when the PERFEVTSELx is
  1266. * not used currently.
  1267. * D) Call x86_perf_event_set_period to restore PMCx;
  1268. */
  1269. /* We always operate 4 pairs of PERF Counters */
  1270. for (i = 0; i < 4; i++) {
  1271. event = cpuc->events[i];
  1272. if (event)
  1273. x86_perf_event_update(event);
  1274. }
  1275. for (i = 0; i < 4; i++) {
  1276. wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, nhm_magic[i]);
  1277. wrmsrl(MSR_ARCH_PERFMON_PERFCTR0 + i, 0x0);
  1278. }
  1279. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0xf);
  1280. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x0);
  1281. for (i = 0; i < 4; i++) {
  1282. event = cpuc->events[i];
  1283. if (event) {
  1284. x86_perf_event_set_period(event);
  1285. __x86_pmu_enable_event(&event->hw,
  1286. ARCH_PERFMON_EVENTSEL_ENABLE);
  1287. } else
  1288. wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, 0x0);
  1289. }
  1290. }
  1291. static void intel_pmu_nhm_enable_all(int added)
  1292. {
  1293. if (added)
  1294. intel_pmu_nhm_workaround();
  1295. intel_pmu_enable_all(added);
  1296. }
  1297. static inline u64 intel_pmu_get_status(void)
  1298. {
  1299. u64 status;
  1300. rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status);
  1301. return status;
  1302. }
  1303. static inline void intel_pmu_ack_status(u64 ack)
  1304. {
  1305. wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack);
  1306. }
  1307. static void intel_pmu_disable_fixed(struct hw_perf_event *hwc)
  1308. {
  1309. int idx = hwc->idx - INTEL_PMC_IDX_FIXED;
  1310. u64 ctrl_val, mask;
  1311. mask = 0xfULL << (idx * 4);
  1312. rdmsrl(hwc->config_base, ctrl_val);
  1313. ctrl_val &= ~mask;
  1314. wrmsrl(hwc->config_base, ctrl_val);
  1315. }
  1316. static inline bool event_is_checkpointed(struct perf_event *event)
  1317. {
  1318. return (event->hw.config & HSW_IN_TX_CHECKPOINTED) != 0;
  1319. }
  1320. static void intel_pmu_disable_event(struct perf_event *event)
  1321. {
  1322. struct hw_perf_event *hwc = &event->hw;
  1323. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1324. if (unlikely(hwc->idx == INTEL_PMC_IDX_FIXED_BTS)) {
  1325. intel_pmu_disable_bts();
  1326. intel_pmu_drain_bts_buffer();
  1327. return;
  1328. }
  1329. cpuc->intel_ctrl_guest_mask &= ~(1ull << hwc->idx);
  1330. cpuc->intel_ctrl_host_mask &= ~(1ull << hwc->idx);
  1331. cpuc->intel_cp_status &= ~(1ull << hwc->idx);
  1332. /*
  1333. * must disable before any actual event
  1334. * because any event may be combined with LBR
  1335. */
  1336. if (needs_branch_stack(event))
  1337. intel_pmu_lbr_disable(event);
  1338. if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) {
  1339. intel_pmu_disable_fixed(hwc);
  1340. return;
  1341. }
  1342. x86_pmu_disable_event(event);
  1343. if (unlikely(event->attr.precise_ip))
  1344. intel_pmu_pebs_disable(event);
  1345. }
  1346. static void intel_pmu_enable_fixed(struct hw_perf_event *hwc)
  1347. {
  1348. int idx = hwc->idx - INTEL_PMC_IDX_FIXED;
  1349. u64 ctrl_val, bits, mask;
  1350. /*
  1351. * Enable IRQ generation (0x8),
  1352. * and enable ring-3 counting (0x2) and ring-0 counting (0x1)
  1353. * if requested:
  1354. */
  1355. bits = 0x8ULL;
  1356. if (hwc->config & ARCH_PERFMON_EVENTSEL_USR)
  1357. bits |= 0x2;
  1358. if (hwc->config & ARCH_PERFMON_EVENTSEL_OS)
  1359. bits |= 0x1;
  1360. /*
  1361. * ANY bit is supported in v3 and up
  1362. */
  1363. if (x86_pmu.version > 2 && hwc->config & ARCH_PERFMON_EVENTSEL_ANY)
  1364. bits |= 0x4;
  1365. bits <<= (idx * 4);
  1366. mask = 0xfULL << (idx * 4);
  1367. rdmsrl(hwc->config_base, ctrl_val);
  1368. ctrl_val &= ~mask;
  1369. ctrl_val |= bits;
  1370. wrmsrl(hwc->config_base, ctrl_val);
  1371. }
  1372. static void intel_pmu_enable_event(struct perf_event *event)
  1373. {
  1374. struct hw_perf_event *hwc = &event->hw;
  1375. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1376. if (unlikely(hwc->idx == INTEL_PMC_IDX_FIXED_BTS)) {
  1377. if (!__this_cpu_read(cpu_hw_events.enabled))
  1378. return;
  1379. intel_pmu_enable_bts(hwc->config);
  1380. return;
  1381. }
  1382. /*
  1383. * must enabled before any actual event
  1384. * because any event may be combined with LBR
  1385. */
  1386. if (needs_branch_stack(event))
  1387. intel_pmu_lbr_enable(event);
  1388. if (event->attr.exclude_host)
  1389. cpuc->intel_ctrl_guest_mask |= (1ull << hwc->idx);
  1390. if (event->attr.exclude_guest)
  1391. cpuc->intel_ctrl_host_mask |= (1ull << hwc->idx);
  1392. if (unlikely(event_is_checkpointed(event)))
  1393. cpuc->intel_cp_status |= (1ull << hwc->idx);
  1394. if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) {
  1395. intel_pmu_enable_fixed(hwc);
  1396. return;
  1397. }
  1398. if (unlikely(event->attr.precise_ip))
  1399. intel_pmu_pebs_enable(event);
  1400. __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE);
  1401. }
  1402. /*
  1403. * Save and restart an expired event. Called by NMI contexts,
  1404. * so it has to be careful about preempting normal event ops:
  1405. */
  1406. int intel_pmu_save_and_restart(struct perf_event *event)
  1407. {
  1408. x86_perf_event_update(event);
  1409. /*
  1410. * For a checkpointed counter always reset back to 0. This
  1411. * avoids a situation where the counter overflows, aborts the
  1412. * transaction and is then set back to shortly before the
  1413. * overflow, and overflows and aborts again.
  1414. */
  1415. if (unlikely(event_is_checkpointed(event))) {
  1416. /* No race with NMIs because the counter should not be armed */
  1417. wrmsrl(event->hw.event_base, 0);
  1418. local64_set(&event->hw.prev_count, 0);
  1419. }
  1420. return x86_perf_event_set_period(event);
  1421. }
  1422. static void intel_pmu_reset(void)
  1423. {
  1424. struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds);
  1425. unsigned long flags;
  1426. int idx;
  1427. if (!x86_pmu.num_counters)
  1428. return;
  1429. local_irq_save(flags);
  1430. pr_info("clearing PMU state on CPU#%d\n", smp_processor_id());
  1431. for (idx = 0; idx < x86_pmu.num_counters; idx++) {
  1432. wrmsrl_safe(x86_pmu_config_addr(idx), 0ull);
  1433. wrmsrl_safe(x86_pmu_event_addr(idx), 0ull);
  1434. }
  1435. for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++)
  1436. wrmsrl_safe(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull);
  1437. if (ds)
  1438. ds->bts_index = ds->bts_buffer_base;
  1439. /* Ack all overflows and disable fixed counters */
  1440. if (x86_pmu.version >= 2) {
  1441. intel_pmu_ack_status(intel_pmu_get_status());
  1442. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0);
  1443. }
  1444. /* Reset LBRs and LBR freezing */
  1445. if (x86_pmu.lbr_nr) {
  1446. update_debugctlmsr(get_debugctlmsr() &
  1447. ~(DEBUGCTLMSR_FREEZE_LBRS_ON_PMI|DEBUGCTLMSR_LBR));
  1448. }
  1449. local_irq_restore(flags);
  1450. }
  1451. /*
  1452. * This handler is triggered by the local APIC, so the APIC IRQ handling
  1453. * rules apply:
  1454. */
  1455. static int intel_pmu_handle_irq(struct pt_regs *regs)
  1456. {
  1457. struct perf_sample_data data;
  1458. struct cpu_hw_events *cpuc;
  1459. int bit, loops;
  1460. u64 status;
  1461. int handled;
  1462. cpuc = this_cpu_ptr(&cpu_hw_events);
  1463. /*
  1464. * No known reason to not always do late ACK,
  1465. * but just in case do it opt-in.
  1466. */
  1467. if (!x86_pmu.late_ack)
  1468. apic_write(APIC_LVTPC, APIC_DM_NMI);
  1469. __intel_pmu_disable_all();
  1470. handled = intel_pmu_drain_bts_buffer();
  1471. handled += intel_bts_interrupt();
  1472. status = intel_pmu_get_status();
  1473. if (!status)
  1474. goto done;
  1475. loops = 0;
  1476. again:
  1477. intel_pmu_ack_status(status);
  1478. if (++loops > 100) {
  1479. static bool warned = false;
  1480. if (!warned) {
  1481. WARN(1, "perfevents: irq loop stuck!\n");
  1482. perf_event_print_debug();
  1483. warned = true;
  1484. }
  1485. intel_pmu_reset();
  1486. goto done;
  1487. }
  1488. inc_irq_stat(apic_perf_irqs);
  1489. intel_pmu_lbr_read();
  1490. /*
  1491. * CondChgd bit 63 doesn't mean any overflow status. Ignore
  1492. * and clear the bit.
  1493. */
  1494. if (__test_and_clear_bit(63, (unsigned long *)&status)) {
  1495. if (!status)
  1496. goto done;
  1497. }
  1498. /*
  1499. * PEBS overflow sets bit 62 in the global status register
  1500. */
  1501. if (__test_and_clear_bit(62, (unsigned long *)&status)) {
  1502. handled++;
  1503. x86_pmu.drain_pebs(regs);
  1504. }
  1505. /*
  1506. * Intel PT
  1507. */
  1508. if (__test_and_clear_bit(55, (unsigned long *)&status)) {
  1509. handled++;
  1510. intel_pt_interrupt();
  1511. }
  1512. /*
  1513. * Checkpointed counters can lead to 'spurious' PMIs because the
  1514. * rollback caused by the PMI will have cleared the overflow status
  1515. * bit. Therefore always force probe these counters.
  1516. */
  1517. status |= cpuc->intel_cp_status;
  1518. for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) {
  1519. struct perf_event *event = cpuc->events[bit];
  1520. handled++;
  1521. if (!test_bit(bit, cpuc->active_mask))
  1522. continue;
  1523. if (!intel_pmu_save_and_restart(event))
  1524. continue;
  1525. perf_sample_data_init(&data, 0, event->hw.last_period);
  1526. if (has_branch_stack(event))
  1527. data.br_stack = &cpuc->lbr_stack;
  1528. if (perf_event_overflow(event, &data, regs))
  1529. x86_pmu_stop(event, 0);
  1530. }
  1531. /*
  1532. * Repeat if there is more work to be done:
  1533. */
  1534. status = intel_pmu_get_status();
  1535. if (status)
  1536. goto again;
  1537. done:
  1538. __intel_pmu_enable_all(0, true);
  1539. /*
  1540. * Only unmask the NMI after the overflow counters
  1541. * have been reset. This avoids spurious NMIs on
  1542. * Haswell CPUs.
  1543. */
  1544. if (x86_pmu.late_ack)
  1545. apic_write(APIC_LVTPC, APIC_DM_NMI);
  1546. return handled;
  1547. }
  1548. static struct event_constraint *
  1549. intel_bts_constraints(struct perf_event *event)
  1550. {
  1551. struct hw_perf_event *hwc = &event->hw;
  1552. unsigned int hw_event, bts_event;
  1553. if (event->attr.freq)
  1554. return NULL;
  1555. hw_event = hwc->config & INTEL_ARCH_EVENT_MASK;
  1556. bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS);
  1557. if (unlikely(hw_event == bts_event && hwc->sample_period == 1))
  1558. return &bts_constraint;
  1559. return NULL;
  1560. }
  1561. static int intel_alt_er(int idx)
  1562. {
  1563. if (!(x86_pmu.flags & PMU_FL_HAS_RSP_1))
  1564. return idx;
  1565. if (idx == EXTRA_REG_RSP_0)
  1566. return EXTRA_REG_RSP_1;
  1567. if (idx == EXTRA_REG_RSP_1)
  1568. return EXTRA_REG_RSP_0;
  1569. return idx;
  1570. }
  1571. static void intel_fixup_er(struct perf_event *event, int idx)
  1572. {
  1573. event->hw.extra_reg.idx = idx;
  1574. if (idx == EXTRA_REG_RSP_0) {
  1575. event->hw.config &= ~INTEL_ARCH_EVENT_MASK;
  1576. event->hw.config |= x86_pmu.extra_regs[EXTRA_REG_RSP_0].event;
  1577. event->hw.extra_reg.reg = MSR_OFFCORE_RSP_0;
  1578. } else if (idx == EXTRA_REG_RSP_1) {
  1579. event->hw.config &= ~INTEL_ARCH_EVENT_MASK;
  1580. event->hw.config |= x86_pmu.extra_regs[EXTRA_REG_RSP_1].event;
  1581. event->hw.extra_reg.reg = MSR_OFFCORE_RSP_1;
  1582. }
  1583. }
  1584. /*
  1585. * manage allocation of shared extra msr for certain events
  1586. *
  1587. * sharing can be:
  1588. * per-cpu: to be shared between the various events on a single PMU
  1589. * per-core: per-cpu + shared by HT threads
  1590. */
  1591. static struct event_constraint *
  1592. __intel_shared_reg_get_constraints(struct cpu_hw_events *cpuc,
  1593. struct perf_event *event,
  1594. struct hw_perf_event_extra *reg)
  1595. {
  1596. struct event_constraint *c = &emptyconstraint;
  1597. struct er_account *era;
  1598. unsigned long flags;
  1599. int idx = reg->idx;
  1600. /*
  1601. * reg->alloc can be set due to existing state, so for fake cpuc we
  1602. * need to ignore this, otherwise we might fail to allocate proper fake
  1603. * state for this extra reg constraint. Also see the comment below.
  1604. */
  1605. if (reg->alloc && !cpuc->is_fake)
  1606. return NULL; /* call x86_get_event_constraint() */
  1607. again:
  1608. era = &cpuc->shared_regs->regs[idx];
  1609. /*
  1610. * we use spin_lock_irqsave() to avoid lockdep issues when
  1611. * passing a fake cpuc
  1612. */
  1613. raw_spin_lock_irqsave(&era->lock, flags);
  1614. if (!atomic_read(&era->ref) || era->config == reg->config) {
  1615. /*
  1616. * If its a fake cpuc -- as per validate_{group,event}() we
  1617. * shouldn't touch event state and we can avoid doing so
  1618. * since both will only call get_event_constraints() once
  1619. * on each event, this avoids the need for reg->alloc.
  1620. *
  1621. * Not doing the ER fixup will only result in era->reg being
  1622. * wrong, but since we won't actually try and program hardware
  1623. * this isn't a problem either.
  1624. */
  1625. if (!cpuc->is_fake) {
  1626. if (idx != reg->idx)
  1627. intel_fixup_er(event, idx);
  1628. /*
  1629. * x86_schedule_events() can call get_event_constraints()
  1630. * multiple times on events in the case of incremental
  1631. * scheduling(). reg->alloc ensures we only do the ER
  1632. * allocation once.
  1633. */
  1634. reg->alloc = 1;
  1635. }
  1636. /* lock in msr value */
  1637. era->config = reg->config;
  1638. era->reg = reg->reg;
  1639. /* one more user */
  1640. atomic_inc(&era->ref);
  1641. /*
  1642. * need to call x86_get_event_constraint()
  1643. * to check if associated event has constraints
  1644. */
  1645. c = NULL;
  1646. } else {
  1647. idx = intel_alt_er(idx);
  1648. if (idx != reg->idx) {
  1649. raw_spin_unlock_irqrestore(&era->lock, flags);
  1650. goto again;
  1651. }
  1652. }
  1653. raw_spin_unlock_irqrestore(&era->lock, flags);
  1654. return c;
  1655. }
  1656. static void
  1657. __intel_shared_reg_put_constraints(struct cpu_hw_events *cpuc,
  1658. struct hw_perf_event_extra *reg)
  1659. {
  1660. struct er_account *era;
  1661. /*
  1662. * Only put constraint if extra reg was actually allocated. Also takes
  1663. * care of event which do not use an extra shared reg.
  1664. *
  1665. * Also, if this is a fake cpuc we shouldn't touch any event state
  1666. * (reg->alloc) and we don't care about leaving inconsistent cpuc state
  1667. * either since it'll be thrown out.
  1668. */
  1669. if (!reg->alloc || cpuc->is_fake)
  1670. return;
  1671. era = &cpuc->shared_regs->regs[reg->idx];
  1672. /* one fewer user */
  1673. atomic_dec(&era->ref);
  1674. /* allocate again next time */
  1675. reg->alloc = 0;
  1676. }
  1677. static struct event_constraint *
  1678. intel_shared_regs_constraints(struct cpu_hw_events *cpuc,
  1679. struct perf_event *event)
  1680. {
  1681. struct event_constraint *c = NULL, *d;
  1682. struct hw_perf_event_extra *xreg, *breg;
  1683. xreg = &event->hw.extra_reg;
  1684. if (xreg->idx != EXTRA_REG_NONE) {
  1685. c = __intel_shared_reg_get_constraints(cpuc, event, xreg);
  1686. if (c == &emptyconstraint)
  1687. return c;
  1688. }
  1689. breg = &event->hw.branch_reg;
  1690. if (breg->idx != EXTRA_REG_NONE) {
  1691. d = __intel_shared_reg_get_constraints(cpuc, event, breg);
  1692. if (d == &emptyconstraint) {
  1693. __intel_shared_reg_put_constraints(cpuc, xreg);
  1694. c = d;
  1695. }
  1696. }
  1697. return c;
  1698. }
  1699. struct event_constraint *
  1700. x86_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
  1701. struct perf_event *event)
  1702. {
  1703. struct event_constraint *c;
  1704. if (x86_pmu.event_constraints) {
  1705. for_each_event_constraint(c, x86_pmu.event_constraints) {
  1706. if ((event->hw.config & c->cmask) == c->code) {
  1707. event->hw.flags |= c->flags;
  1708. return c;
  1709. }
  1710. }
  1711. }
  1712. return &unconstrained;
  1713. }
  1714. static struct event_constraint *
  1715. __intel_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
  1716. struct perf_event *event)
  1717. {
  1718. struct event_constraint *c;
  1719. c = intel_bts_constraints(event);
  1720. if (c)
  1721. return c;
  1722. c = intel_shared_regs_constraints(cpuc, event);
  1723. if (c)
  1724. return c;
  1725. c = intel_pebs_constraints(event);
  1726. if (c)
  1727. return c;
  1728. return x86_get_event_constraints(cpuc, idx, event);
  1729. }
  1730. static void
  1731. intel_start_scheduling(struct cpu_hw_events *cpuc)
  1732. {
  1733. struct intel_excl_cntrs *excl_cntrs = cpuc->excl_cntrs;
  1734. struct intel_excl_states *xl, *xlo;
  1735. int tid = cpuc->excl_thread_id;
  1736. int o_tid = 1 - tid; /* sibling thread */
  1737. /*
  1738. * nothing needed if in group validation mode
  1739. */
  1740. if (cpuc->is_fake || !is_ht_workaround_enabled())
  1741. return;
  1742. /*
  1743. * no exclusion needed
  1744. */
  1745. if (!excl_cntrs)
  1746. return;
  1747. xlo = &excl_cntrs->states[o_tid];
  1748. xl = &excl_cntrs->states[tid];
  1749. xl->sched_started = true;
  1750. xl->num_alloc_cntrs = 0;
  1751. /*
  1752. * lock shared state until we are done scheduling
  1753. * in stop_event_scheduling()
  1754. * makes scheduling appear as a transaction
  1755. */
  1756. WARN_ON_ONCE(!irqs_disabled());
  1757. raw_spin_lock(&excl_cntrs->lock);
  1758. /*
  1759. * save initial state of sibling thread
  1760. */
  1761. memcpy(xlo->init_state, xlo->state, sizeof(xlo->init_state));
  1762. }
  1763. static void
  1764. intel_stop_scheduling(struct cpu_hw_events *cpuc)
  1765. {
  1766. struct intel_excl_cntrs *excl_cntrs = cpuc->excl_cntrs;
  1767. struct intel_excl_states *xl, *xlo;
  1768. int tid = cpuc->excl_thread_id;
  1769. int o_tid = 1 - tid; /* sibling thread */
  1770. /*
  1771. * nothing needed if in group validation mode
  1772. */
  1773. if (cpuc->is_fake || !is_ht_workaround_enabled())
  1774. return;
  1775. /*
  1776. * no exclusion needed
  1777. */
  1778. if (!excl_cntrs)
  1779. return;
  1780. xlo = &excl_cntrs->states[o_tid];
  1781. xl = &excl_cntrs->states[tid];
  1782. /*
  1783. * make new sibling thread state visible
  1784. */
  1785. memcpy(xlo->state, xlo->init_state, sizeof(xlo->state));
  1786. xl->sched_started = false;
  1787. /*
  1788. * release shared state lock (acquired in intel_start_scheduling())
  1789. */
  1790. raw_spin_unlock(&excl_cntrs->lock);
  1791. }
  1792. static struct event_constraint *
  1793. intel_get_excl_constraints(struct cpu_hw_events *cpuc, struct perf_event *event,
  1794. int idx, struct event_constraint *c)
  1795. {
  1796. struct event_constraint *cx;
  1797. struct intel_excl_cntrs *excl_cntrs = cpuc->excl_cntrs;
  1798. struct intel_excl_states *xl, *xlo;
  1799. int is_excl, i;
  1800. int tid = cpuc->excl_thread_id;
  1801. int o_tid = 1 - tid; /* alternate */
  1802. /*
  1803. * validating a group does not require
  1804. * enforcing cross-thread exclusion
  1805. */
  1806. if (cpuc->is_fake || !is_ht_workaround_enabled())
  1807. return c;
  1808. /*
  1809. * no exclusion needed
  1810. */
  1811. if (!excl_cntrs)
  1812. return c;
  1813. /*
  1814. * event requires exclusive counter access
  1815. * across HT threads
  1816. */
  1817. is_excl = c->flags & PERF_X86_EVENT_EXCL;
  1818. /*
  1819. * xl = state of current HT
  1820. * xlo = state of sibling HT
  1821. */
  1822. xl = &excl_cntrs->states[tid];
  1823. xlo = &excl_cntrs->states[o_tid];
  1824. /*
  1825. * do not allow scheduling of more than max_alloc_cntrs
  1826. * which is set to half the available generic counters.
  1827. * this helps avoid counter starvation of sibling thread
  1828. * by ensuring at most half the counters cannot be in
  1829. * exclusive mode. There is not designated counters for the
  1830. * limits. Any N/2 counters can be used. This helps with
  1831. * events with specifix counter constraints
  1832. */
  1833. if (xl->num_alloc_cntrs++ == xl->max_alloc_cntrs)
  1834. return &emptyconstraint;
  1835. cx = c;
  1836. /*
  1837. * because we modify the constraint, we need
  1838. * to make a copy. Static constraints come
  1839. * from static const tables.
  1840. *
  1841. * only needed when constraint has not yet
  1842. * been cloned (marked dynamic)
  1843. */
  1844. if (!(c->flags & PERF_X86_EVENT_DYNAMIC)) {
  1845. /* sanity check */
  1846. if (idx < 0)
  1847. return &emptyconstraint;
  1848. /*
  1849. * grab pre-allocated constraint entry
  1850. */
  1851. cx = &cpuc->constraint_list[idx];
  1852. /*
  1853. * initialize dynamic constraint
  1854. * with static constraint
  1855. */
  1856. memcpy(cx, c, sizeof(*cx));
  1857. /*
  1858. * mark constraint as dynamic, so we
  1859. * can free it later on
  1860. */
  1861. cx->flags |= PERF_X86_EVENT_DYNAMIC;
  1862. }
  1863. /*
  1864. * From here on, the constraint is dynamic.
  1865. * Either it was just allocated above, or it
  1866. * was allocated during a earlier invocation
  1867. * of this function
  1868. */
  1869. /*
  1870. * Modify static constraint with current dynamic
  1871. * state of thread
  1872. *
  1873. * EXCLUSIVE: sibling counter measuring exclusive event
  1874. * SHARED : sibling counter measuring non-exclusive event
  1875. * UNUSED : sibling counter unused
  1876. */
  1877. for_each_set_bit(i, cx->idxmsk, X86_PMC_IDX_MAX) {
  1878. /*
  1879. * exclusive event in sibling counter
  1880. * our corresponding counter cannot be used
  1881. * regardless of our event
  1882. */
  1883. if (xl->state[i] == INTEL_EXCL_EXCLUSIVE)
  1884. __clear_bit(i, cx->idxmsk);
  1885. /*
  1886. * if measuring an exclusive event, sibling
  1887. * measuring non-exclusive, then counter cannot
  1888. * be used
  1889. */
  1890. if (is_excl && xl->state[i] == INTEL_EXCL_SHARED)
  1891. __clear_bit(i, cx->idxmsk);
  1892. }
  1893. /*
  1894. * recompute actual bit weight for scheduling algorithm
  1895. */
  1896. cx->weight = hweight64(cx->idxmsk64);
  1897. /*
  1898. * if we return an empty mask, then switch
  1899. * back to static empty constraint to avoid
  1900. * the cost of freeing later on
  1901. */
  1902. if (cx->weight == 0)
  1903. cx = &emptyconstraint;
  1904. return cx;
  1905. }
  1906. static struct event_constraint *
  1907. intel_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
  1908. struct perf_event *event)
  1909. {
  1910. struct event_constraint *c1 = event->hw.constraint;
  1911. struct event_constraint *c2;
  1912. /*
  1913. * first time only
  1914. * - static constraint: no change across incremental scheduling calls
  1915. * - dynamic constraint: handled by intel_get_excl_constraints()
  1916. */
  1917. c2 = __intel_get_event_constraints(cpuc, idx, event);
  1918. if (c1 && (c1->flags & PERF_X86_EVENT_DYNAMIC)) {
  1919. bitmap_copy(c1->idxmsk, c2->idxmsk, X86_PMC_IDX_MAX);
  1920. c1->weight = c2->weight;
  1921. c2 = c1;
  1922. }
  1923. if (cpuc->excl_cntrs)
  1924. return intel_get_excl_constraints(cpuc, event, idx, c2);
  1925. return c2;
  1926. }
  1927. static void intel_put_excl_constraints(struct cpu_hw_events *cpuc,
  1928. struct perf_event *event)
  1929. {
  1930. struct hw_perf_event *hwc = &event->hw;
  1931. struct intel_excl_cntrs *excl_cntrs = cpuc->excl_cntrs;
  1932. struct intel_excl_states *xlo, *xl;
  1933. unsigned long flags = 0; /* keep compiler happy */
  1934. int tid = cpuc->excl_thread_id;
  1935. int o_tid = 1 - tid;
  1936. /*
  1937. * nothing needed if in group validation mode
  1938. */
  1939. if (cpuc->is_fake)
  1940. return;
  1941. WARN_ON_ONCE(!excl_cntrs);
  1942. if (!excl_cntrs)
  1943. return;
  1944. xl = &excl_cntrs->states[tid];
  1945. xlo = &excl_cntrs->states[o_tid];
  1946. /*
  1947. * put_constraint may be called from x86_schedule_events()
  1948. * which already has the lock held so here make locking
  1949. * conditional
  1950. */
  1951. if (!xl->sched_started)
  1952. raw_spin_lock_irqsave(&excl_cntrs->lock, flags);
  1953. /*
  1954. * if event was actually assigned, then mark the
  1955. * counter state as unused now
  1956. */
  1957. if (hwc->idx >= 0)
  1958. xlo->state[hwc->idx] = INTEL_EXCL_UNUSED;
  1959. if (!xl->sched_started)
  1960. raw_spin_unlock_irqrestore(&excl_cntrs->lock, flags);
  1961. }
  1962. static void
  1963. intel_put_shared_regs_event_constraints(struct cpu_hw_events *cpuc,
  1964. struct perf_event *event)
  1965. {
  1966. struct hw_perf_event_extra *reg;
  1967. reg = &event->hw.extra_reg;
  1968. if (reg->idx != EXTRA_REG_NONE)
  1969. __intel_shared_reg_put_constraints(cpuc, reg);
  1970. reg = &event->hw.branch_reg;
  1971. if (reg->idx != EXTRA_REG_NONE)
  1972. __intel_shared_reg_put_constraints(cpuc, reg);
  1973. }
  1974. static void intel_put_event_constraints(struct cpu_hw_events *cpuc,
  1975. struct perf_event *event)
  1976. {
  1977. struct event_constraint *c = event->hw.constraint;
  1978. intel_put_shared_regs_event_constraints(cpuc, event);
  1979. /*
  1980. * is PMU has exclusive counter restrictions, then
  1981. * all events are subject to and must call the
  1982. * put_excl_constraints() routine
  1983. */
  1984. if (c && cpuc->excl_cntrs)
  1985. intel_put_excl_constraints(cpuc, event);
  1986. /* cleanup dynamic constraint */
  1987. if (c && (c->flags & PERF_X86_EVENT_DYNAMIC))
  1988. event->hw.constraint = NULL;
  1989. }
  1990. static void intel_commit_scheduling(struct cpu_hw_events *cpuc,
  1991. struct perf_event *event, int cntr)
  1992. {
  1993. struct intel_excl_cntrs *excl_cntrs = cpuc->excl_cntrs;
  1994. struct event_constraint *c = event->hw.constraint;
  1995. struct intel_excl_states *xlo, *xl;
  1996. int tid = cpuc->excl_thread_id;
  1997. int o_tid = 1 - tid;
  1998. int is_excl;
  1999. if (cpuc->is_fake || !c)
  2000. return;
  2001. is_excl = c->flags & PERF_X86_EVENT_EXCL;
  2002. if (!(c->flags & PERF_X86_EVENT_DYNAMIC))
  2003. return;
  2004. WARN_ON_ONCE(!excl_cntrs);
  2005. if (!excl_cntrs)
  2006. return;
  2007. xl = &excl_cntrs->states[tid];
  2008. xlo = &excl_cntrs->states[o_tid];
  2009. WARN_ON_ONCE(!raw_spin_is_locked(&excl_cntrs->lock));
  2010. if (cntr >= 0) {
  2011. if (is_excl)
  2012. xlo->init_state[cntr] = INTEL_EXCL_EXCLUSIVE;
  2013. else
  2014. xlo->init_state[cntr] = INTEL_EXCL_SHARED;
  2015. }
  2016. }
  2017. static void intel_pebs_aliases_core2(struct perf_event *event)
  2018. {
  2019. if ((event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) {
  2020. /*
  2021. * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P
  2022. * (0x003c) so that we can use it with PEBS.
  2023. *
  2024. * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't
  2025. * PEBS capable. However we can use INST_RETIRED.ANY_P
  2026. * (0x00c0), which is a PEBS capable event, to get the same
  2027. * count.
  2028. *
  2029. * INST_RETIRED.ANY_P counts the number of cycles that retires
  2030. * CNTMASK instructions. By setting CNTMASK to a value (16)
  2031. * larger than the maximum number of instructions that can be
  2032. * retired per cycle (4) and then inverting the condition, we
  2033. * count all cycles that retire 16 or less instructions, which
  2034. * is every cycle.
  2035. *
  2036. * Thereby we gain a PEBS capable cycle counter.
  2037. */
  2038. u64 alt_config = X86_CONFIG(.event=0xc0, .inv=1, .cmask=16);
  2039. alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK);
  2040. event->hw.config = alt_config;
  2041. }
  2042. }
  2043. static void intel_pebs_aliases_snb(struct perf_event *event)
  2044. {
  2045. if ((event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) {
  2046. /*
  2047. * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P
  2048. * (0x003c) so that we can use it with PEBS.
  2049. *
  2050. * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't
  2051. * PEBS capable. However we can use UOPS_RETIRED.ALL
  2052. * (0x01c2), which is a PEBS capable event, to get the same
  2053. * count.
  2054. *
  2055. * UOPS_RETIRED.ALL counts the number of cycles that retires
  2056. * CNTMASK micro-ops. By setting CNTMASK to a value (16)
  2057. * larger than the maximum number of micro-ops that can be
  2058. * retired per cycle (4) and then inverting the condition, we
  2059. * count all cycles that retire 16 or less micro-ops, which
  2060. * is every cycle.
  2061. *
  2062. * Thereby we gain a PEBS capable cycle counter.
  2063. */
  2064. u64 alt_config = X86_CONFIG(.event=0xc2, .umask=0x01, .inv=1, .cmask=16);
  2065. alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK);
  2066. event->hw.config = alt_config;
  2067. }
  2068. }
  2069. static int intel_pmu_hw_config(struct perf_event *event)
  2070. {
  2071. int ret = x86_pmu_hw_config(event);
  2072. if (ret)
  2073. return ret;
  2074. if (event->attr.precise_ip && x86_pmu.pebs_aliases)
  2075. x86_pmu.pebs_aliases(event);
  2076. if (needs_branch_stack(event)) {
  2077. ret = intel_pmu_setup_lbr_filter(event);
  2078. if (ret)
  2079. return ret;
  2080. /*
  2081. * BTS is set up earlier in this path, so don't account twice
  2082. */
  2083. if (!intel_pmu_has_bts(event)) {
  2084. /* disallow lbr if conflicting events are present */
  2085. if (x86_add_exclusive(x86_lbr_exclusive_lbr))
  2086. return -EBUSY;
  2087. event->destroy = hw_perf_lbr_event_destroy;
  2088. }
  2089. }
  2090. if (event->attr.type != PERF_TYPE_RAW)
  2091. return 0;
  2092. if (!(event->attr.config & ARCH_PERFMON_EVENTSEL_ANY))
  2093. return 0;
  2094. if (x86_pmu.version < 3)
  2095. return -EINVAL;
  2096. if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
  2097. return -EACCES;
  2098. event->hw.config |= ARCH_PERFMON_EVENTSEL_ANY;
  2099. return 0;
  2100. }
  2101. struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr)
  2102. {
  2103. if (x86_pmu.guest_get_msrs)
  2104. return x86_pmu.guest_get_msrs(nr);
  2105. *nr = 0;
  2106. return NULL;
  2107. }
  2108. EXPORT_SYMBOL_GPL(perf_guest_get_msrs);
  2109. static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr)
  2110. {
  2111. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  2112. struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs;
  2113. arr[0].msr = MSR_CORE_PERF_GLOBAL_CTRL;
  2114. arr[0].host = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask;
  2115. arr[0].guest = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_host_mask;
  2116. /*
  2117. * If PMU counter has PEBS enabled it is not enough to disable counter
  2118. * on a guest entry since PEBS memory write can overshoot guest entry
  2119. * and corrupt guest memory. Disabling PEBS solves the problem.
  2120. */
  2121. arr[1].msr = MSR_IA32_PEBS_ENABLE;
  2122. arr[1].host = cpuc->pebs_enabled;
  2123. arr[1].guest = 0;
  2124. *nr = 2;
  2125. return arr;
  2126. }
  2127. static struct perf_guest_switch_msr *core_guest_get_msrs(int *nr)
  2128. {
  2129. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  2130. struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs;
  2131. int idx;
  2132. for (idx = 0; idx < x86_pmu.num_counters; idx++) {
  2133. struct perf_event *event = cpuc->events[idx];
  2134. arr[idx].msr = x86_pmu_config_addr(idx);
  2135. arr[idx].host = arr[idx].guest = 0;
  2136. if (!test_bit(idx, cpuc->active_mask))
  2137. continue;
  2138. arr[idx].host = arr[idx].guest =
  2139. event->hw.config | ARCH_PERFMON_EVENTSEL_ENABLE;
  2140. if (event->attr.exclude_host)
  2141. arr[idx].host &= ~ARCH_PERFMON_EVENTSEL_ENABLE;
  2142. else if (event->attr.exclude_guest)
  2143. arr[idx].guest &= ~ARCH_PERFMON_EVENTSEL_ENABLE;
  2144. }
  2145. *nr = x86_pmu.num_counters;
  2146. return arr;
  2147. }
  2148. static void core_pmu_enable_event(struct perf_event *event)
  2149. {
  2150. if (!event->attr.exclude_host)
  2151. x86_pmu_enable_event(event);
  2152. }
  2153. static void core_pmu_enable_all(int added)
  2154. {
  2155. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  2156. int idx;
  2157. for (idx = 0; idx < x86_pmu.num_counters; idx++) {
  2158. struct hw_perf_event *hwc = &cpuc->events[idx]->hw;
  2159. if (!test_bit(idx, cpuc->active_mask) ||
  2160. cpuc->events[idx]->attr.exclude_host)
  2161. continue;
  2162. __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE);
  2163. }
  2164. }
  2165. static int hsw_hw_config(struct perf_event *event)
  2166. {
  2167. int ret = intel_pmu_hw_config(event);
  2168. if (ret)
  2169. return ret;
  2170. if (!boot_cpu_has(X86_FEATURE_RTM) && !boot_cpu_has(X86_FEATURE_HLE))
  2171. return 0;
  2172. event->hw.config |= event->attr.config & (HSW_IN_TX|HSW_IN_TX_CHECKPOINTED);
  2173. /*
  2174. * IN_TX/IN_TX-CP filters are not supported by the Haswell PMU with
  2175. * PEBS or in ANY thread mode. Since the results are non-sensical forbid
  2176. * this combination.
  2177. */
  2178. if ((event->hw.config & (HSW_IN_TX|HSW_IN_TX_CHECKPOINTED)) &&
  2179. ((event->hw.config & ARCH_PERFMON_EVENTSEL_ANY) ||
  2180. event->attr.precise_ip > 0))
  2181. return -EOPNOTSUPP;
  2182. if (event_is_checkpointed(event)) {
  2183. /*
  2184. * Sampling of checkpointed events can cause situations where
  2185. * the CPU constantly aborts because of a overflow, which is
  2186. * then checkpointed back and ignored. Forbid checkpointing
  2187. * for sampling.
  2188. *
  2189. * But still allow a long sampling period, so that perf stat
  2190. * from KVM works.
  2191. */
  2192. if (event->attr.sample_period > 0 &&
  2193. event->attr.sample_period < 0x7fffffff)
  2194. return -EOPNOTSUPP;
  2195. }
  2196. return 0;
  2197. }
  2198. static struct event_constraint counter2_constraint =
  2199. EVENT_CONSTRAINT(0, 0x4, 0);
  2200. static struct event_constraint *
  2201. hsw_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
  2202. struct perf_event *event)
  2203. {
  2204. struct event_constraint *c;
  2205. c = intel_get_event_constraints(cpuc, idx, event);
  2206. /* Handle special quirk on in_tx_checkpointed only in counter 2 */
  2207. if (event->hw.config & HSW_IN_TX_CHECKPOINTED) {
  2208. if (c->idxmsk64 & (1U << 2))
  2209. return &counter2_constraint;
  2210. return &emptyconstraint;
  2211. }
  2212. return c;
  2213. }
  2214. /*
  2215. * Broadwell:
  2216. *
  2217. * The INST_RETIRED.ALL period always needs to have lowest 6 bits cleared
  2218. * (BDM55) and it must not use a period smaller than 100 (BDM11). We combine
  2219. * the two to enforce a minimum period of 128 (the smallest value that has bits
  2220. * 0-5 cleared and >= 100).
  2221. *
  2222. * Because of how the code in x86_perf_event_set_period() works, the truncation
  2223. * of the lower 6 bits is 'harmless' as we'll occasionally add a longer period
  2224. * to make up for the 'lost' events due to carrying the 'error' in period_left.
  2225. *
  2226. * Therefore the effective (average) period matches the requested period,
  2227. * despite coarser hardware granularity.
  2228. */
  2229. static unsigned bdw_limit_period(struct perf_event *event, unsigned left)
  2230. {
  2231. if ((event->hw.config & INTEL_ARCH_EVENT_MASK) ==
  2232. X86_CONFIG(.event=0xc0, .umask=0x01)) {
  2233. if (left < 128)
  2234. left = 128;
  2235. left &= ~0x3fu;
  2236. }
  2237. return left;
  2238. }
  2239. PMU_FORMAT_ATTR(event, "config:0-7" );
  2240. PMU_FORMAT_ATTR(umask, "config:8-15" );
  2241. PMU_FORMAT_ATTR(edge, "config:18" );
  2242. PMU_FORMAT_ATTR(pc, "config:19" );
  2243. PMU_FORMAT_ATTR(any, "config:21" ); /* v3 + */
  2244. PMU_FORMAT_ATTR(inv, "config:23" );
  2245. PMU_FORMAT_ATTR(cmask, "config:24-31" );
  2246. PMU_FORMAT_ATTR(in_tx, "config:32");
  2247. PMU_FORMAT_ATTR(in_tx_cp, "config:33");
  2248. static struct attribute *intel_arch_formats_attr[] = {
  2249. &format_attr_event.attr,
  2250. &format_attr_umask.attr,
  2251. &format_attr_edge.attr,
  2252. &format_attr_pc.attr,
  2253. &format_attr_inv.attr,
  2254. &format_attr_cmask.attr,
  2255. NULL,
  2256. };
  2257. ssize_t intel_event_sysfs_show(char *page, u64 config)
  2258. {
  2259. u64 event = (config & ARCH_PERFMON_EVENTSEL_EVENT);
  2260. return x86_event_sysfs_show(page, config, event);
  2261. }
  2262. static __initconst const struct x86_pmu core_pmu = {
  2263. .name = "core",
  2264. .handle_irq = x86_pmu_handle_irq,
  2265. .disable_all = x86_pmu_disable_all,
  2266. .enable_all = core_pmu_enable_all,
  2267. .enable = core_pmu_enable_event,
  2268. .disable = x86_pmu_disable_event,
  2269. .hw_config = x86_pmu_hw_config,
  2270. .schedule_events = x86_schedule_events,
  2271. .eventsel = MSR_ARCH_PERFMON_EVENTSEL0,
  2272. .perfctr = MSR_ARCH_PERFMON_PERFCTR0,
  2273. .event_map = intel_pmu_event_map,
  2274. .max_events = ARRAY_SIZE(intel_perfmon_event_map),
  2275. .apic = 1,
  2276. /*
  2277. * Intel PMCs cannot be accessed sanely above 32 bit width,
  2278. * so we install an artificial 1<<31 period regardless of
  2279. * the generic event period:
  2280. */
  2281. .max_period = (1ULL << 31) - 1,
  2282. .get_event_constraints = intel_get_event_constraints,
  2283. .put_event_constraints = intel_put_event_constraints,
  2284. .event_constraints = intel_core_event_constraints,
  2285. .guest_get_msrs = core_guest_get_msrs,
  2286. .format_attrs = intel_arch_formats_attr,
  2287. .events_sysfs_show = intel_event_sysfs_show,
  2288. };
  2289. struct intel_shared_regs *allocate_shared_regs(int cpu)
  2290. {
  2291. struct intel_shared_regs *regs;
  2292. int i;
  2293. regs = kzalloc_node(sizeof(struct intel_shared_regs),
  2294. GFP_KERNEL, cpu_to_node(cpu));
  2295. if (regs) {
  2296. /*
  2297. * initialize the locks to keep lockdep happy
  2298. */
  2299. for (i = 0; i < EXTRA_REG_MAX; i++)
  2300. raw_spin_lock_init(&regs->regs[i].lock);
  2301. regs->core_id = -1;
  2302. }
  2303. return regs;
  2304. }
  2305. static struct intel_excl_cntrs *allocate_excl_cntrs(int cpu)
  2306. {
  2307. struct intel_excl_cntrs *c;
  2308. int i;
  2309. c = kzalloc_node(sizeof(struct intel_excl_cntrs),
  2310. GFP_KERNEL, cpu_to_node(cpu));
  2311. if (c) {
  2312. raw_spin_lock_init(&c->lock);
  2313. for (i = 0; i < X86_PMC_IDX_MAX; i++) {
  2314. c->states[0].state[i] = INTEL_EXCL_UNUSED;
  2315. c->states[0].init_state[i] = INTEL_EXCL_UNUSED;
  2316. c->states[1].state[i] = INTEL_EXCL_UNUSED;
  2317. c->states[1].init_state[i] = INTEL_EXCL_UNUSED;
  2318. }
  2319. c->core_id = -1;
  2320. }
  2321. return c;
  2322. }
  2323. static int intel_pmu_cpu_prepare(int cpu)
  2324. {
  2325. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  2326. if (x86_pmu.extra_regs || x86_pmu.lbr_sel_map) {
  2327. cpuc->shared_regs = allocate_shared_regs(cpu);
  2328. if (!cpuc->shared_regs)
  2329. return NOTIFY_BAD;
  2330. }
  2331. if (x86_pmu.flags & PMU_FL_EXCL_CNTRS) {
  2332. size_t sz = X86_PMC_IDX_MAX * sizeof(struct event_constraint);
  2333. cpuc->constraint_list = kzalloc(sz, GFP_KERNEL);
  2334. if (!cpuc->constraint_list)
  2335. return NOTIFY_BAD;
  2336. cpuc->excl_cntrs = allocate_excl_cntrs(cpu);
  2337. if (!cpuc->excl_cntrs) {
  2338. kfree(cpuc->constraint_list);
  2339. kfree(cpuc->shared_regs);
  2340. return NOTIFY_BAD;
  2341. }
  2342. cpuc->excl_thread_id = 0;
  2343. }
  2344. return NOTIFY_OK;
  2345. }
  2346. static void intel_pmu_cpu_starting(int cpu)
  2347. {
  2348. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  2349. int core_id = topology_core_id(cpu);
  2350. int i;
  2351. init_debug_store_on_cpu(cpu);
  2352. /*
  2353. * Deal with CPUs that don't clear their LBRs on power-up.
  2354. */
  2355. intel_pmu_lbr_reset();
  2356. cpuc->lbr_sel = NULL;
  2357. if (!cpuc->shared_regs)
  2358. return;
  2359. if (!(x86_pmu.flags & PMU_FL_NO_HT_SHARING)) {
  2360. void **onln = &cpuc->kfree_on_online[X86_PERF_KFREE_SHARED];
  2361. for_each_cpu(i, topology_thread_cpumask(cpu)) {
  2362. struct intel_shared_regs *pc;
  2363. pc = per_cpu(cpu_hw_events, i).shared_regs;
  2364. if (pc && pc->core_id == core_id) {
  2365. *onln = cpuc->shared_regs;
  2366. cpuc->shared_regs = pc;
  2367. break;
  2368. }
  2369. }
  2370. cpuc->shared_regs->core_id = core_id;
  2371. cpuc->shared_regs->refcnt++;
  2372. }
  2373. if (x86_pmu.lbr_sel_map)
  2374. cpuc->lbr_sel = &cpuc->shared_regs->regs[EXTRA_REG_LBR];
  2375. if (x86_pmu.flags & PMU_FL_EXCL_CNTRS) {
  2376. int h = x86_pmu.num_counters >> 1;
  2377. for_each_cpu(i, topology_thread_cpumask(cpu)) {
  2378. struct intel_excl_cntrs *c;
  2379. c = per_cpu(cpu_hw_events, i).excl_cntrs;
  2380. if (c && c->core_id == core_id) {
  2381. cpuc->kfree_on_online[1] = cpuc->excl_cntrs;
  2382. cpuc->excl_cntrs = c;
  2383. cpuc->excl_thread_id = 1;
  2384. break;
  2385. }
  2386. }
  2387. cpuc->excl_cntrs->core_id = core_id;
  2388. cpuc->excl_cntrs->refcnt++;
  2389. /*
  2390. * set hard limit to half the number of generic counters
  2391. */
  2392. cpuc->excl_cntrs->states[0].max_alloc_cntrs = h;
  2393. cpuc->excl_cntrs->states[1].max_alloc_cntrs = h;
  2394. }
  2395. }
  2396. static void free_excl_cntrs(int cpu)
  2397. {
  2398. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  2399. struct intel_excl_cntrs *c;
  2400. c = cpuc->excl_cntrs;
  2401. if (c) {
  2402. if (c->core_id == -1 || --c->refcnt == 0)
  2403. kfree(c);
  2404. cpuc->excl_cntrs = NULL;
  2405. kfree(cpuc->constraint_list);
  2406. cpuc->constraint_list = NULL;
  2407. }
  2408. }
  2409. static void intel_pmu_cpu_dying(int cpu)
  2410. {
  2411. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  2412. struct intel_shared_regs *pc;
  2413. pc = cpuc->shared_regs;
  2414. if (pc) {
  2415. if (pc->core_id == -1 || --pc->refcnt == 0)
  2416. kfree(pc);
  2417. cpuc->shared_regs = NULL;
  2418. }
  2419. free_excl_cntrs(cpu);
  2420. fini_debug_store_on_cpu(cpu);
  2421. }
  2422. PMU_FORMAT_ATTR(offcore_rsp, "config1:0-63");
  2423. PMU_FORMAT_ATTR(ldlat, "config1:0-15");
  2424. static struct attribute *intel_arch3_formats_attr[] = {
  2425. &format_attr_event.attr,
  2426. &format_attr_umask.attr,
  2427. &format_attr_edge.attr,
  2428. &format_attr_pc.attr,
  2429. &format_attr_any.attr,
  2430. &format_attr_inv.attr,
  2431. &format_attr_cmask.attr,
  2432. &format_attr_in_tx.attr,
  2433. &format_attr_in_tx_cp.attr,
  2434. &format_attr_offcore_rsp.attr, /* XXX do NHM/WSM + SNB breakout */
  2435. &format_attr_ldlat.attr, /* PEBS load latency */
  2436. NULL,
  2437. };
  2438. static __initconst const struct x86_pmu intel_pmu = {
  2439. .name = "Intel",
  2440. .handle_irq = intel_pmu_handle_irq,
  2441. .disable_all = intel_pmu_disable_all,
  2442. .enable_all = intel_pmu_enable_all,
  2443. .enable = intel_pmu_enable_event,
  2444. .disable = intel_pmu_disable_event,
  2445. .hw_config = intel_pmu_hw_config,
  2446. .schedule_events = x86_schedule_events,
  2447. .eventsel = MSR_ARCH_PERFMON_EVENTSEL0,
  2448. .perfctr = MSR_ARCH_PERFMON_PERFCTR0,
  2449. .event_map = intel_pmu_event_map,
  2450. .max_events = ARRAY_SIZE(intel_perfmon_event_map),
  2451. .apic = 1,
  2452. /*
  2453. * Intel PMCs cannot be accessed sanely above 32 bit width,
  2454. * so we install an artificial 1<<31 period regardless of
  2455. * the generic event period:
  2456. */
  2457. .max_period = (1ULL << 31) - 1,
  2458. .get_event_constraints = intel_get_event_constraints,
  2459. .put_event_constraints = intel_put_event_constraints,
  2460. .pebs_aliases = intel_pebs_aliases_core2,
  2461. .format_attrs = intel_arch3_formats_attr,
  2462. .events_sysfs_show = intel_event_sysfs_show,
  2463. .cpu_prepare = intel_pmu_cpu_prepare,
  2464. .cpu_starting = intel_pmu_cpu_starting,
  2465. .cpu_dying = intel_pmu_cpu_dying,
  2466. .guest_get_msrs = intel_guest_get_msrs,
  2467. .sched_task = intel_pmu_lbr_sched_task,
  2468. };
  2469. static __init void intel_clovertown_quirk(void)
  2470. {
  2471. /*
  2472. * PEBS is unreliable due to:
  2473. *
  2474. * AJ67 - PEBS may experience CPL leaks
  2475. * AJ68 - PEBS PMI may be delayed by one event
  2476. * AJ69 - GLOBAL_STATUS[62] will only be set when DEBUGCTL[12]
  2477. * AJ106 - FREEZE_LBRS_ON_PMI doesn't work in combination with PEBS
  2478. *
  2479. * AJ67 could be worked around by restricting the OS/USR flags.
  2480. * AJ69 could be worked around by setting PMU_FREEZE_ON_PMI.
  2481. *
  2482. * AJ106 could possibly be worked around by not allowing LBR
  2483. * usage from PEBS, including the fixup.
  2484. * AJ68 could possibly be worked around by always programming
  2485. * a pebs_event_reset[0] value and coping with the lost events.
  2486. *
  2487. * But taken together it might just make sense to not enable PEBS on
  2488. * these chips.
  2489. */
  2490. pr_warn("PEBS disabled due to CPU errata\n");
  2491. x86_pmu.pebs = 0;
  2492. x86_pmu.pebs_constraints = NULL;
  2493. }
  2494. static int intel_snb_pebs_broken(int cpu)
  2495. {
  2496. u32 rev = UINT_MAX; /* default to broken for unknown models */
  2497. switch (cpu_data(cpu).x86_model) {
  2498. case 42: /* SNB */
  2499. rev = 0x28;
  2500. break;
  2501. case 45: /* SNB-EP */
  2502. switch (cpu_data(cpu).x86_mask) {
  2503. case 6: rev = 0x618; break;
  2504. case 7: rev = 0x70c; break;
  2505. }
  2506. }
  2507. return (cpu_data(cpu).microcode < rev);
  2508. }
  2509. static void intel_snb_check_microcode(void)
  2510. {
  2511. int pebs_broken = 0;
  2512. int cpu;
  2513. get_online_cpus();
  2514. for_each_online_cpu(cpu) {
  2515. if ((pebs_broken = intel_snb_pebs_broken(cpu)))
  2516. break;
  2517. }
  2518. put_online_cpus();
  2519. if (pebs_broken == x86_pmu.pebs_broken)
  2520. return;
  2521. /*
  2522. * Serialized by the microcode lock..
  2523. */
  2524. if (x86_pmu.pebs_broken) {
  2525. pr_info("PEBS enabled due to microcode update\n");
  2526. x86_pmu.pebs_broken = 0;
  2527. } else {
  2528. pr_info("PEBS disabled due to CPU errata, please upgrade microcode\n");
  2529. x86_pmu.pebs_broken = 1;
  2530. }
  2531. }
  2532. /*
  2533. * Under certain circumstances, access certain MSR may cause #GP.
  2534. * The function tests if the input MSR can be safely accessed.
  2535. */
  2536. static bool check_msr(unsigned long msr, u64 mask)
  2537. {
  2538. u64 val_old, val_new, val_tmp;
  2539. /*
  2540. * Read the current value, change it and read it back to see if it
  2541. * matches, this is needed to detect certain hardware emulators
  2542. * (qemu/kvm) that don't trap on the MSR access and always return 0s.
  2543. */
  2544. if (rdmsrl_safe(msr, &val_old))
  2545. return false;
  2546. /*
  2547. * Only change the bits which can be updated by wrmsrl.
  2548. */
  2549. val_tmp = val_old ^ mask;
  2550. if (wrmsrl_safe(msr, val_tmp) ||
  2551. rdmsrl_safe(msr, &val_new))
  2552. return false;
  2553. if (val_new != val_tmp)
  2554. return false;
  2555. /* Here it's sure that the MSR can be safely accessed.
  2556. * Restore the old value and return.
  2557. */
  2558. wrmsrl(msr, val_old);
  2559. return true;
  2560. }
  2561. static __init void intel_sandybridge_quirk(void)
  2562. {
  2563. x86_pmu.check_microcode = intel_snb_check_microcode;
  2564. intel_snb_check_microcode();
  2565. }
  2566. static const struct { int id; char *name; } intel_arch_events_map[] __initconst = {
  2567. { PERF_COUNT_HW_CPU_CYCLES, "cpu cycles" },
  2568. { PERF_COUNT_HW_INSTRUCTIONS, "instructions" },
  2569. { PERF_COUNT_HW_BUS_CYCLES, "bus cycles" },
  2570. { PERF_COUNT_HW_CACHE_REFERENCES, "cache references" },
  2571. { PERF_COUNT_HW_CACHE_MISSES, "cache misses" },
  2572. { PERF_COUNT_HW_BRANCH_INSTRUCTIONS, "branch instructions" },
  2573. { PERF_COUNT_HW_BRANCH_MISSES, "branch misses" },
  2574. };
  2575. static __init void intel_arch_events_quirk(void)
  2576. {
  2577. int bit;
  2578. /* disable event that reported as not presend by cpuid */
  2579. for_each_set_bit(bit, x86_pmu.events_mask, ARRAY_SIZE(intel_arch_events_map)) {
  2580. intel_perfmon_event_map[intel_arch_events_map[bit].id] = 0;
  2581. pr_warn("CPUID marked event: \'%s\' unavailable\n",
  2582. intel_arch_events_map[bit].name);
  2583. }
  2584. }
  2585. static __init void intel_nehalem_quirk(void)
  2586. {
  2587. union cpuid10_ebx ebx;
  2588. ebx.full = x86_pmu.events_maskl;
  2589. if (ebx.split.no_branch_misses_retired) {
  2590. /*
  2591. * Erratum AAJ80 detected, we work it around by using
  2592. * the BR_MISP_EXEC.ANY event. This will over-count
  2593. * branch-misses, but it's still much better than the
  2594. * architectural event which is often completely bogus:
  2595. */
  2596. intel_perfmon_event_map[PERF_COUNT_HW_BRANCH_MISSES] = 0x7f89;
  2597. ebx.split.no_branch_misses_retired = 0;
  2598. x86_pmu.events_maskl = ebx.full;
  2599. pr_info("CPU erratum AAJ80 worked around\n");
  2600. }
  2601. }
  2602. /*
  2603. * enable software workaround for errata:
  2604. * SNB: BJ122
  2605. * IVB: BV98
  2606. * HSW: HSD29
  2607. *
  2608. * Only needed when HT is enabled. However detecting
  2609. * if HT is enabled is difficult (model specific). So instead,
  2610. * we enable the workaround in the early boot, and verify if
  2611. * it is needed in a later initcall phase once we have valid
  2612. * topology information to check if HT is actually enabled
  2613. */
  2614. static __init void intel_ht_bug(void)
  2615. {
  2616. x86_pmu.flags |= PMU_FL_EXCL_CNTRS | PMU_FL_EXCL_ENABLED;
  2617. x86_pmu.commit_scheduling = intel_commit_scheduling;
  2618. x86_pmu.start_scheduling = intel_start_scheduling;
  2619. x86_pmu.stop_scheduling = intel_stop_scheduling;
  2620. }
  2621. EVENT_ATTR_STR(mem-loads, mem_ld_hsw, "event=0xcd,umask=0x1,ldlat=3");
  2622. EVENT_ATTR_STR(mem-stores, mem_st_hsw, "event=0xd0,umask=0x82")
  2623. /* Haswell special events */
  2624. EVENT_ATTR_STR(tx-start, tx_start, "event=0xc9,umask=0x1");
  2625. EVENT_ATTR_STR(tx-commit, tx_commit, "event=0xc9,umask=0x2");
  2626. EVENT_ATTR_STR(tx-abort, tx_abort, "event=0xc9,umask=0x4");
  2627. EVENT_ATTR_STR(tx-capacity, tx_capacity, "event=0x54,umask=0x2");
  2628. EVENT_ATTR_STR(tx-conflict, tx_conflict, "event=0x54,umask=0x1");
  2629. EVENT_ATTR_STR(el-start, el_start, "event=0xc8,umask=0x1");
  2630. EVENT_ATTR_STR(el-commit, el_commit, "event=0xc8,umask=0x2");
  2631. EVENT_ATTR_STR(el-abort, el_abort, "event=0xc8,umask=0x4");
  2632. EVENT_ATTR_STR(el-capacity, el_capacity, "event=0x54,umask=0x2");
  2633. EVENT_ATTR_STR(el-conflict, el_conflict, "event=0x54,umask=0x1");
  2634. EVENT_ATTR_STR(cycles-t, cycles_t, "event=0x3c,in_tx=1");
  2635. EVENT_ATTR_STR(cycles-ct, cycles_ct, "event=0x3c,in_tx=1,in_tx_cp=1");
  2636. static struct attribute *hsw_events_attrs[] = {
  2637. EVENT_PTR(tx_start),
  2638. EVENT_PTR(tx_commit),
  2639. EVENT_PTR(tx_abort),
  2640. EVENT_PTR(tx_capacity),
  2641. EVENT_PTR(tx_conflict),
  2642. EVENT_PTR(el_start),
  2643. EVENT_PTR(el_commit),
  2644. EVENT_PTR(el_abort),
  2645. EVENT_PTR(el_capacity),
  2646. EVENT_PTR(el_conflict),
  2647. EVENT_PTR(cycles_t),
  2648. EVENT_PTR(cycles_ct),
  2649. EVENT_PTR(mem_ld_hsw),
  2650. EVENT_PTR(mem_st_hsw),
  2651. NULL
  2652. };
  2653. __init int intel_pmu_init(void)
  2654. {
  2655. union cpuid10_edx edx;
  2656. union cpuid10_eax eax;
  2657. union cpuid10_ebx ebx;
  2658. struct event_constraint *c;
  2659. unsigned int unused;
  2660. struct extra_reg *er;
  2661. int version, i;
  2662. if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) {
  2663. switch (boot_cpu_data.x86) {
  2664. case 0x6:
  2665. return p6_pmu_init();
  2666. case 0xb:
  2667. return knc_pmu_init();
  2668. case 0xf:
  2669. return p4_pmu_init();
  2670. }
  2671. return -ENODEV;
  2672. }
  2673. /*
  2674. * Check whether the Architectural PerfMon supports
  2675. * Branch Misses Retired hw_event or not.
  2676. */
  2677. cpuid(10, &eax.full, &ebx.full, &unused, &edx.full);
  2678. if (eax.split.mask_length < ARCH_PERFMON_EVENTS_COUNT)
  2679. return -ENODEV;
  2680. version = eax.split.version_id;
  2681. if (version < 2)
  2682. x86_pmu = core_pmu;
  2683. else
  2684. x86_pmu = intel_pmu;
  2685. x86_pmu.version = version;
  2686. x86_pmu.num_counters = eax.split.num_counters;
  2687. x86_pmu.cntval_bits = eax.split.bit_width;
  2688. x86_pmu.cntval_mask = (1ULL << eax.split.bit_width) - 1;
  2689. x86_pmu.events_maskl = ebx.full;
  2690. x86_pmu.events_mask_len = eax.split.mask_length;
  2691. x86_pmu.max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, x86_pmu.num_counters);
  2692. /*
  2693. * Quirk: v2 perfmon does not report fixed-purpose events, so
  2694. * assume at least 3 events:
  2695. */
  2696. if (version > 1)
  2697. x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
  2698. if (boot_cpu_has(X86_FEATURE_PDCM)) {
  2699. u64 capabilities;
  2700. rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
  2701. x86_pmu.intel_cap.capabilities = capabilities;
  2702. }
  2703. intel_ds_init();
  2704. x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last */
  2705. /*
  2706. * Install the hw-cache-events table:
  2707. */
  2708. switch (boot_cpu_data.x86_model) {
  2709. case 14: /* 65nm Core "Yonah" */
  2710. pr_cont("Core events, ");
  2711. break;
  2712. case 15: /* 65nm Core2 "Merom" */
  2713. x86_add_quirk(intel_clovertown_quirk);
  2714. case 22: /* 65nm Core2 "Merom-L" */
  2715. case 23: /* 45nm Core2 "Penryn" */
  2716. case 29: /* 45nm Core2 "Dunnington (MP) */
  2717. memcpy(hw_cache_event_ids, core2_hw_cache_event_ids,
  2718. sizeof(hw_cache_event_ids));
  2719. intel_pmu_lbr_init_core();
  2720. x86_pmu.event_constraints = intel_core2_event_constraints;
  2721. x86_pmu.pebs_constraints = intel_core2_pebs_event_constraints;
  2722. pr_cont("Core2 events, ");
  2723. break;
  2724. case 30: /* 45nm Nehalem */
  2725. case 26: /* 45nm Nehalem-EP */
  2726. case 46: /* 45nm Nehalem-EX */
  2727. memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids,
  2728. sizeof(hw_cache_event_ids));
  2729. memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs,
  2730. sizeof(hw_cache_extra_regs));
  2731. intel_pmu_lbr_init_nhm();
  2732. x86_pmu.event_constraints = intel_nehalem_event_constraints;
  2733. x86_pmu.pebs_constraints = intel_nehalem_pebs_event_constraints;
  2734. x86_pmu.enable_all = intel_pmu_nhm_enable_all;
  2735. x86_pmu.extra_regs = intel_nehalem_extra_regs;
  2736. x86_pmu.cpu_events = nhm_events_attrs;
  2737. /* UOPS_ISSUED.STALLED_CYCLES */
  2738. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
  2739. X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1);
  2740. /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */
  2741. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] =
  2742. X86_CONFIG(.event=0xb1, .umask=0x3f, .inv=1, .cmask=1);
  2743. x86_add_quirk(intel_nehalem_quirk);
  2744. pr_cont("Nehalem events, ");
  2745. break;
  2746. case 28: /* 45nm Atom "Pineview" */
  2747. case 38: /* 45nm Atom "Lincroft" */
  2748. case 39: /* 32nm Atom "Penwell" */
  2749. case 53: /* 32nm Atom "Cloverview" */
  2750. case 54: /* 32nm Atom "Cedarview" */
  2751. memcpy(hw_cache_event_ids, atom_hw_cache_event_ids,
  2752. sizeof(hw_cache_event_ids));
  2753. intel_pmu_lbr_init_atom();
  2754. x86_pmu.event_constraints = intel_gen_event_constraints;
  2755. x86_pmu.pebs_constraints = intel_atom_pebs_event_constraints;
  2756. pr_cont("Atom events, ");
  2757. break;
  2758. case 55: /* 22nm Atom "Silvermont" */
  2759. case 76: /* 14nm Atom "Airmont" */
  2760. case 77: /* 22nm Atom "Silvermont Avoton/Rangely" */
  2761. memcpy(hw_cache_event_ids, slm_hw_cache_event_ids,
  2762. sizeof(hw_cache_event_ids));
  2763. memcpy(hw_cache_extra_regs, slm_hw_cache_extra_regs,
  2764. sizeof(hw_cache_extra_regs));
  2765. intel_pmu_lbr_init_atom();
  2766. x86_pmu.event_constraints = intel_slm_event_constraints;
  2767. x86_pmu.pebs_constraints = intel_slm_pebs_event_constraints;
  2768. x86_pmu.extra_regs = intel_slm_extra_regs;
  2769. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2770. pr_cont("Silvermont events, ");
  2771. break;
  2772. case 37: /* 32nm Westmere */
  2773. case 44: /* 32nm Westmere-EP */
  2774. case 47: /* 32nm Westmere-EX */
  2775. memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids,
  2776. sizeof(hw_cache_event_ids));
  2777. memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs,
  2778. sizeof(hw_cache_extra_regs));
  2779. intel_pmu_lbr_init_nhm();
  2780. x86_pmu.event_constraints = intel_westmere_event_constraints;
  2781. x86_pmu.enable_all = intel_pmu_nhm_enable_all;
  2782. x86_pmu.pebs_constraints = intel_westmere_pebs_event_constraints;
  2783. x86_pmu.extra_regs = intel_westmere_extra_regs;
  2784. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2785. x86_pmu.cpu_events = nhm_events_attrs;
  2786. /* UOPS_ISSUED.STALLED_CYCLES */
  2787. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
  2788. X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1);
  2789. /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */
  2790. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] =
  2791. X86_CONFIG(.event=0xb1, .umask=0x3f, .inv=1, .cmask=1);
  2792. pr_cont("Westmere events, ");
  2793. break;
  2794. case 42: /* 32nm SandyBridge */
  2795. case 45: /* 32nm SandyBridge-E/EN/EP */
  2796. x86_add_quirk(intel_sandybridge_quirk);
  2797. x86_add_quirk(intel_ht_bug);
  2798. memcpy(hw_cache_event_ids, snb_hw_cache_event_ids,
  2799. sizeof(hw_cache_event_ids));
  2800. memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs,
  2801. sizeof(hw_cache_extra_regs));
  2802. intel_pmu_lbr_init_snb();
  2803. x86_pmu.event_constraints = intel_snb_event_constraints;
  2804. x86_pmu.pebs_constraints = intel_snb_pebs_event_constraints;
  2805. x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
  2806. if (boot_cpu_data.x86_model == 45)
  2807. x86_pmu.extra_regs = intel_snbep_extra_regs;
  2808. else
  2809. x86_pmu.extra_regs = intel_snb_extra_regs;
  2810. /* all extra regs are per-cpu when HT is on */
  2811. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2812. x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
  2813. x86_pmu.cpu_events = snb_events_attrs;
  2814. /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
  2815. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
  2816. X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1);
  2817. /* UOPS_DISPATCHED.THREAD,c=1,i=1 to count stall cycles*/
  2818. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] =
  2819. X86_CONFIG(.event=0xb1, .umask=0x01, .inv=1, .cmask=1);
  2820. pr_cont("SandyBridge events, ");
  2821. break;
  2822. case 58: /* 22nm IvyBridge */
  2823. case 62: /* 22nm IvyBridge-EP/EX */
  2824. x86_add_quirk(intel_ht_bug);
  2825. memcpy(hw_cache_event_ids, snb_hw_cache_event_ids,
  2826. sizeof(hw_cache_event_ids));
  2827. /* dTLB-load-misses on IVB is different than SNB */
  2828. hw_cache_event_ids[C(DTLB)][C(OP_READ)][C(RESULT_MISS)] = 0x8108; /* DTLB_LOAD_MISSES.DEMAND_LD_MISS_CAUSES_A_WALK */
  2829. memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs,
  2830. sizeof(hw_cache_extra_regs));
  2831. intel_pmu_lbr_init_snb();
  2832. x86_pmu.event_constraints = intel_ivb_event_constraints;
  2833. x86_pmu.pebs_constraints = intel_ivb_pebs_event_constraints;
  2834. x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
  2835. if (boot_cpu_data.x86_model == 62)
  2836. x86_pmu.extra_regs = intel_snbep_extra_regs;
  2837. else
  2838. x86_pmu.extra_regs = intel_snb_extra_regs;
  2839. /* all extra regs are per-cpu when HT is on */
  2840. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2841. x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
  2842. x86_pmu.cpu_events = snb_events_attrs;
  2843. /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
  2844. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
  2845. X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1);
  2846. pr_cont("IvyBridge events, ");
  2847. break;
  2848. case 60: /* 22nm Haswell Core */
  2849. case 63: /* 22nm Haswell Server */
  2850. case 69: /* 22nm Haswell ULT */
  2851. case 70: /* 22nm Haswell + GT3e (Intel Iris Pro graphics) */
  2852. x86_add_quirk(intel_ht_bug);
  2853. x86_pmu.late_ack = true;
  2854. memcpy(hw_cache_event_ids, hsw_hw_cache_event_ids, sizeof(hw_cache_event_ids));
  2855. memcpy(hw_cache_extra_regs, hsw_hw_cache_extra_regs, sizeof(hw_cache_extra_regs));
  2856. intel_pmu_lbr_init_hsw();
  2857. x86_pmu.event_constraints = intel_hsw_event_constraints;
  2858. x86_pmu.pebs_constraints = intel_hsw_pebs_event_constraints;
  2859. x86_pmu.extra_regs = intel_snbep_extra_regs;
  2860. x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
  2861. /* all extra regs are per-cpu when HT is on */
  2862. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2863. x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
  2864. x86_pmu.hw_config = hsw_hw_config;
  2865. x86_pmu.get_event_constraints = hsw_get_event_constraints;
  2866. x86_pmu.cpu_events = hsw_events_attrs;
  2867. x86_pmu.lbr_double_abort = true;
  2868. pr_cont("Haswell events, ");
  2869. break;
  2870. case 61: /* 14nm Broadwell Core-M */
  2871. case 86: /* 14nm Broadwell Xeon D */
  2872. x86_pmu.late_ack = true;
  2873. memcpy(hw_cache_event_ids, hsw_hw_cache_event_ids, sizeof(hw_cache_event_ids));
  2874. memcpy(hw_cache_extra_regs, hsw_hw_cache_extra_regs, sizeof(hw_cache_extra_regs));
  2875. /* L3_MISS_LOCAL_DRAM is BIT(26) in Broadwell */
  2876. hw_cache_extra_regs[C(LL)][C(OP_READ)][C(RESULT_MISS)] = HSW_DEMAND_READ |
  2877. BDW_L3_MISS|HSW_SNOOP_DRAM;
  2878. hw_cache_extra_regs[C(LL)][C(OP_WRITE)][C(RESULT_MISS)] = HSW_DEMAND_WRITE|BDW_L3_MISS|
  2879. HSW_SNOOP_DRAM;
  2880. hw_cache_extra_regs[C(NODE)][C(OP_READ)][C(RESULT_ACCESS)] = HSW_DEMAND_READ|
  2881. BDW_L3_MISS_LOCAL|HSW_SNOOP_DRAM;
  2882. hw_cache_extra_regs[C(NODE)][C(OP_WRITE)][C(RESULT_ACCESS)] = HSW_DEMAND_WRITE|
  2883. BDW_L3_MISS_LOCAL|HSW_SNOOP_DRAM;
  2884. intel_pmu_lbr_init_hsw();
  2885. x86_pmu.event_constraints = intel_bdw_event_constraints;
  2886. x86_pmu.pebs_constraints = intel_hsw_pebs_event_constraints;
  2887. x86_pmu.extra_regs = intel_snbep_extra_regs;
  2888. x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
  2889. /* all extra regs are per-cpu when HT is on */
  2890. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2891. x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
  2892. x86_pmu.hw_config = hsw_hw_config;
  2893. x86_pmu.get_event_constraints = hsw_get_event_constraints;
  2894. x86_pmu.cpu_events = hsw_events_attrs;
  2895. x86_pmu.limit_period = bdw_limit_period;
  2896. pr_cont("Broadwell events, ");
  2897. break;
  2898. default:
  2899. switch (x86_pmu.version) {
  2900. case 1:
  2901. x86_pmu.event_constraints = intel_v1_event_constraints;
  2902. pr_cont("generic architected perfmon v1, ");
  2903. break;
  2904. default:
  2905. /*
  2906. * default constraints for v2 and up
  2907. */
  2908. x86_pmu.event_constraints = intel_gen_event_constraints;
  2909. pr_cont("generic architected perfmon, ");
  2910. break;
  2911. }
  2912. }
  2913. if (x86_pmu.num_counters > INTEL_PMC_MAX_GENERIC) {
  2914. WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!",
  2915. x86_pmu.num_counters, INTEL_PMC_MAX_GENERIC);
  2916. x86_pmu.num_counters = INTEL_PMC_MAX_GENERIC;
  2917. }
  2918. x86_pmu.intel_ctrl = (1 << x86_pmu.num_counters) - 1;
  2919. if (x86_pmu.num_counters_fixed > INTEL_PMC_MAX_FIXED) {
  2920. WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!",
  2921. x86_pmu.num_counters_fixed, INTEL_PMC_MAX_FIXED);
  2922. x86_pmu.num_counters_fixed = INTEL_PMC_MAX_FIXED;
  2923. }
  2924. x86_pmu.intel_ctrl |=
  2925. ((1LL << x86_pmu.num_counters_fixed)-1) << INTEL_PMC_IDX_FIXED;
  2926. if (x86_pmu.event_constraints) {
  2927. /*
  2928. * event on fixed counter2 (REF_CYCLES) only works on this
  2929. * counter, so do not extend mask to generic counters
  2930. */
  2931. for_each_event_constraint(c, x86_pmu.event_constraints) {
  2932. if (c->cmask != FIXED_EVENT_FLAGS
  2933. || c->idxmsk64 == INTEL_PMC_MSK_FIXED_REF_CYCLES) {
  2934. continue;
  2935. }
  2936. c->idxmsk64 |= (1ULL << x86_pmu.num_counters) - 1;
  2937. c->weight += x86_pmu.num_counters;
  2938. }
  2939. }
  2940. /*
  2941. * Access LBR MSR may cause #GP under certain circumstances.
  2942. * E.g. KVM doesn't support LBR MSR
  2943. * Check all LBT MSR here.
  2944. * Disable LBR access if any LBR MSRs can not be accessed.
  2945. */
  2946. if (x86_pmu.lbr_nr && !check_msr(x86_pmu.lbr_tos, 0x3UL))
  2947. x86_pmu.lbr_nr = 0;
  2948. for (i = 0; i < x86_pmu.lbr_nr; i++) {
  2949. if (!(check_msr(x86_pmu.lbr_from + i, 0xffffUL) &&
  2950. check_msr(x86_pmu.lbr_to + i, 0xffffUL)))
  2951. x86_pmu.lbr_nr = 0;
  2952. }
  2953. /*
  2954. * Access extra MSR may cause #GP under certain circumstances.
  2955. * E.g. KVM doesn't support offcore event
  2956. * Check all extra_regs here.
  2957. */
  2958. if (x86_pmu.extra_regs) {
  2959. for (er = x86_pmu.extra_regs; er->msr; er++) {
  2960. er->extra_msr_access = check_msr(er->msr, 0x1ffUL);
  2961. /* Disable LBR select mapping */
  2962. if ((er->idx == EXTRA_REG_LBR) && !er->extra_msr_access)
  2963. x86_pmu.lbr_sel_map = NULL;
  2964. }
  2965. }
  2966. /* Support full width counters using alternative MSR range */
  2967. if (x86_pmu.intel_cap.full_width_write) {
  2968. x86_pmu.max_period = x86_pmu.cntval_mask;
  2969. x86_pmu.perfctr = MSR_IA32_PMC0;
  2970. pr_cont("full-width counters, ");
  2971. }
  2972. return 0;
  2973. }
  2974. /*
  2975. * HT bug: phase 2 init
  2976. * Called once we have valid topology information to check
  2977. * whether or not HT is enabled
  2978. * If HT is off, then we disable the workaround
  2979. */
  2980. static __init int fixup_ht_bug(void)
  2981. {
  2982. int cpu = smp_processor_id();
  2983. int w, c;
  2984. /*
  2985. * problem not present on this CPU model, nothing to do
  2986. */
  2987. if (!(x86_pmu.flags & PMU_FL_EXCL_ENABLED))
  2988. return 0;
  2989. w = cpumask_weight(topology_thread_cpumask(cpu));
  2990. if (w > 1) {
  2991. pr_info("PMU erratum BJ122, BV98, HSD29 worked around, HT is on\n");
  2992. return 0;
  2993. }
  2994. watchdog_nmi_disable_all();
  2995. x86_pmu.flags &= ~(PMU_FL_EXCL_CNTRS | PMU_FL_EXCL_ENABLED);
  2996. x86_pmu.commit_scheduling = NULL;
  2997. x86_pmu.start_scheduling = NULL;
  2998. x86_pmu.stop_scheduling = NULL;
  2999. watchdog_nmi_enable_all();
  3000. get_online_cpus();
  3001. for_each_online_cpu(c) {
  3002. free_excl_cntrs(c);
  3003. }
  3004. put_online_cpus();
  3005. pr_info("PMU erratum BJ122, BV98, HSD29 workaround disabled, HT off\n");
  3006. return 0;
  3007. }
  3008. subsys_initcall(fixup_ht_bug)