perf_event_intel.c 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415
  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) ] = 0,
  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. [ C(RESULT_MISS) ] = 0,
  1129. },
  1130. [ C(OP_WRITE) ] = {
  1131. /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */
  1132. [ C(RESULT_ACCESS) ] = 0x01b7,
  1133. /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */
  1134. [ C(RESULT_MISS) ] = 0x01b7,
  1135. },
  1136. [ C(OP_PREFETCH) ] = {
  1137. /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */
  1138. [ C(RESULT_ACCESS) ] = 0x01b7,
  1139. /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */
  1140. [ C(RESULT_MISS) ] = 0x01b7,
  1141. },
  1142. },
  1143. [ C(DTLB) ] = {
  1144. [ C(OP_READ) ] = {
  1145. [ C(RESULT_ACCESS) ] = 0,
  1146. [ C(RESULT_MISS) ] = 0x0804, /* LD_DTLB_MISS */
  1147. },
  1148. [ C(OP_WRITE) ] = {
  1149. [ C(RESULT_ACCESS) ] = 0,
  1150. [ C(RESULT_MISS) ] = 0,
  1151. },
  1152. [ C(OP_PREFETCH) ] = {
  1153. [ C(RESULT_ACCESS) ] = 0,
  1154. [ C(RESULT_MISS) ] = 0,
  1155. },
  1156. },
  1157. [ C(ITLB) ] = {
  1158. [ C(OP_READ) ] = {
  1159. [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */
  1160. [ C(RESULT_MISS) ] = 0x40205, /* PAGE_WALKS.I_SIDE_WALKS */
  1161. },
  1162. [ C(OP_WRITE) ] = {
  1163. [ C(RESULT_ACCESS) ] = -1,
  1164. [ C(RESULT_MISS) ] = -1,
  1165. },
  1166. [ C(OP_PREFETCH) ] = {
  1167. [ C(RESULT_ACCESS) ] = -1,
  1168. [ C(RESULT_MISS) ] = -1,
  1169. },
  1170. },
  1171. [ C(BPU ) ] = {
  1172. [ C(OP_READ) ] = {
  1173. [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */
  1174. [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */
  1175. },
  1176. [ C(OP_WRITE) ] = {
  1177. [ C(RESULT_ACCESS) ] = -1,
  1178. [ C(RESULT_MISS) ] = -1,
  1179. },
  1180. [ C(OP_PREFETCH) ] = {
  1181. [ C(RESULT_ACCESS) ] = -1,
  1182. [ C(RESULT_MISS) ] = -1,
  1183. },
  1184. },
  1185. };
  1186. /*
  1187. * Use from PMIs where the LBRs are already disabled.
  1188. */
  1189. static void __intel_pmu_disable_all(void)
  1190. {
  1191. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1192. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0);
  1193. if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask))
  1194. intel_pmu_disable_bts();
  1195. else
  1196. intel_bts_disable_local();
  1197. intel_pmu_pebs_disable_all();
  1198. }
  1199. static void intel_pmu_disable_all(void)
  1200. {
  1201. __intel_pmu_disable_all();
  1202. intel_pmu_lbr_disable_all();
  1203. }
  1204. static void __intel_pmu_enable_all(int added, bool pmi)
  1205. {
  1206. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1207. intel_pmu_pebs_enable_all();
  1208. intel_pmu_lbr_enable_all(pmi);
  1209. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL,
  1210. x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask);
  1211. if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask)) {
  1212. struct perf_event *event =
  1213. cpuc->events[INTEL_PMC_IDX_FIXED_BTS];
  1214. if (WARN_ON_ONCE(!event))
  1215. return;
  1216. intel_pmu_enable_bts(event->hw.config);
  1217. } else
  1218. intel_bts_enable_local();
  1219. }
  1220. static void intel_pmu_enable_all(int added)
  1221. {
  1222. __intel_pmu_enable_all(added, false);
  1223. }
  1224. /*
  1225. * Workaround for:
  1226. * Intel Errata AAK100 (model 26)
  1227. * Intel Errata AAP53 (model 30)
  1228. * Intel Errata BD53 (model 44)
  1229. *
  1230. * The official story:
  1231. * These chips need to be 'reset' when adding counters by programming the
  1232. * magic three (non-counting) events 0x4300B5, 0x4300D2, and 0x4300B1 either
  1233. * in sequence on the same PMC or on different PMCs.
  1234. *
  1235. * In practise it appears some of these events do in fact count, and
  1236. * we need to programm all 4 events.
  1237. */
  1238. static void intel_pmu_nhm_workaround(void)
  1239. {
  1240. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1241. static const unsigned long nhm_magic[4] = {
  1242. 0x4300B5,
  1243. 0x4300D2,
  1244. 0x4300B1,
  1245. 0x4300B1
  1246. };
  1247. struct perf_event *event;
  1248. int i;
  1249. /*
  1250. * The Errata requires below steps:
  1251. * 1) Clear MSR_IA32_PEBS_ENABLE and MSR_CORE_PERF_GLOBAL_CTRL;
  1252. * 2) Configure 4 PERFEVTSELx with the magic events and clear
  1253. * the corresponding PMCx;
  1254. * 3) set bit0~bit3 of MSR_CORE_PERF_GLOBAL_CTRL;
  1255. * 4) Clear MSR_CORE_PERF_GLOBAL_CTRL;
  1256. * 5) Clear 4 pairs of ERFEVTSELx and PMCx;
  1257. */
  1258. /*
  1259. * The real steps we choose are a little different from above.
  1260. * A) To reduce MSR operations, we don't run step 1) as they
  1261. * are already cleared before this function is called;
  1262. * B) Call x86_perf_event_update to save PMCx before configuring
  1263. * PERFEVTSELx with magic number;
  1264. * C) With step 5), we do clear only when the PERFEVTSELx is
  1265. * not used currently.
  1266. * D) Call x86_perf_event_set_period to restore PMCx;
  1267. */
  1268. /* We always operate 4 pairs of PERF Counters */
  1269. for (i = 0; i < 4; i++) {
  1270. event = cpuc->events[i];
  1271. if (event)
  1272. x86_perf_event_update(event);
  1273. }
  1274. for (i = 0; i < 4; i++) {
  1275. wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, nhm_magic[i]);
  1276. wrmsrl(MSR_ARCH_PERFMON_PERFCTR0 + i, 0x0);
  1277. }
  1278. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0xf);
  1279. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x0);
  1280. for (i = 0; i < 4; i++) {
  1281. event = cpuc->events[i];
  1282. if (event) {
  1283. x86_perf_event_set_period(event);
  1284. __x86_pmu_enable_event(&event->hw,
  1285. ARCH_PERFMON_EVENTSEL_ENABLE);
  1286. } else
  1287. wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, 0x0);
  1288. }
  1289. }
  1290. static void intel_pmu_nhm_enable_all(int added)
  1291. {
  1292. if (added)
  1293. intel_pmu_nhm_workaround();
  1294. intel_pmu_enable_all(added);
  1295. }
  1296. static inline u64 intel_pmu_get_status(void)
  1297. {
  1298. u64 status;
  1299. rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status);
  1300. return status;
  1301. }
  1302. static inline void intel_pmu_ack_status(u64 ack)
  1303. {
  1304. wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack);
  1305. }
  1306. static void intel_pmu_disable_fixed(struct hw_perf_event *hwc)
  1307. {
  1308. int idx = hwc->idx - INTEL_PMC_IDX_FIXED;
  1309. u64 ctrl_val, mask;
  1310. mask = 0xfULL << (idx * 4);
  1311. rdmsrl(hwc->config_base, ctrl_val);
  1312. ctrl_val &= ~mask;
  1313. wrmsrl(hwc->config_base, ctrl_val);
  1314. }
  1315. static inline bool event_is_checkpointed(struct perf_event *event)
  1316. {
  1317. return (event->hw.config & HSW_IN_TX_CHECKPOINTED) != 0;
  1318. }
  1319. static void intel_pmu_disable_event(struct perf_event *event)
  1320. {
  1321. struct hw_perf_event *hwc = &event->hw;
  1322. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1323. if (unlikely(hwc->idx == INTEL_PMC_IDX_FIXED_BTS)) {
  1324. intel_pmu_disable_bts();
  1325. intel_pmu_drain_bts_buffer();
  1326. return;
  1327. }
  1328. cpuc->intel_ctrl_guest_mask &= ~(1ull << hwc->idx);
  1329. cpuc->intel_ctrl_host_mask &= ~(1ull << hwc->idx);
  1330. cpuc->intel_cp_status &= ~(1ull << hwc->idx);
  1331. /*
  1332. * must disable before any actual event
  1333. * because any event may be combined with LBR
  1334. */
  1335. if (needs_branch_stack(event))
  1336. intel_pmu_lbr_disable(event);
  1337. if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) {
  1338. intel_pmu_disable_fixed(hwc);
  1339. return;
  1340. }
  1341. x86_pmu_disable_event(event);
  1342. if (unlikely(event->attr.precise_ip))
  1343. intel_pmu_pebs_disable(event);
  1344. }
  1345. static void intel_pmu_enable_fixed(struct hw_perf_event *hwc)
  1346. {
  1347. int idx = hwc->idx - INTEL_PMC_IDX_FIXED;
  1348. u64 ctrl_val, bits, mask;
  1349. /*
  1350. * Enable IRQ generation (0x8),
  1351. * and enable ring-3 counting (0x2) and ring-0 counting (0x1)
  1352. * if requested:
  1353. */
  1354. bits = 0x8ULL;
  1355. if (hwc->config & ARCH_PERFMON_EVENTSEL_USR)
  1356. bits |= 0x2;
  1357. if (hwc->config & ARCH_PERFMON_EVENTSEL_OS)
  1358. bits |= 0x1;
  1359. /*
  1360. * ANY bit is supported in v3 and up
  1361. */
  1362. if (x86_pmu.version > 2 && hwc->config & ARCH_PERFMON_EVENTSEL_ANY)
  1363. bits |= 0x4;
  1364. bits <<= (idx * 4);
  1365. mask = 0xfULL << (idx * 4);
  1366. rdmsrl(hwc->config_base, ctrl_val);
  1367. ctrl_val &= ~mask;
  1368. ctrl_val |= bits;
  1369. wrmsrl(hwc->config_base, ctrl_val);
  1370. }
  1371. static void intel_pmu_enable_event(struct perf_event *event)
  1372. {
  1373. struct hw_perf_event *hwc = &event->hw;
  1374. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1375. if (unlikely(hwc->idx == INTEL_PMC_IDX_FIXED_BTS)) {
  1376. if (!__this_cpu_read(cpu_hw_events.enabled))
  1377. return;
  1378. intel_pmu_enable_bts(hwc->config);
  1379. return;
  1380. }
  1381. /*
  1382. * must enabled before any actual event
  1383. * because any event may be combined with LBR
  1384. */
  1385. if (needs_branch_stack(event))
  1386. intel_pmu_lbr_enable(event);
  1387. if (event->attr.exclude_host)
  1388. cpuc->intel_ctrl_guest_mask |= (1ull << hwc->idx);
  1389. if (event->attr.exclude_guest)
  1390. cpuc->intel_ctrl_host_mask |= (1ull << hwc->idx);
  1391. if (unlikely(event_is_checkpointed(event)))
  1392. cpuc->intel_cp_status |= (1ull << hwc->idx);
  1393. if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) {
  1394. intel_pmu_enable_fixed(hwc);
  1395. return;
  1396. }
  1397. if (unlikely(event->attr.precise_ip))
  1398. intel_pmu_pebs_enable(event);
  1399. __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE);
  1400. }
  1401. /*
  1402. * Save and restart an expired event. Called by NMI contexts,
  1403. * so it has to be careful about preempting normal event ops:
  1404. */
  1405. int intel_pmu_save_and_restart(struct perf_event *event)
  1406. {
  1407. x86_perf_event_update(event);
  1408. /*
  1409. * For a checkpointed counter always reset back to 0. This
  1410. * avoids a situation where the counter overflows, aborts the
  1411. * transaction and is then set back to shortly before the
  1412. * overflow, and overflows and aborts again.
  1413. */
  1414. if (unlikely(event_is_checkpointed(event))) {
  1415. /* No race with NMIs because the counter should not be armed */
  1416. wrmsrl(event->hw.event_base, 0);
  1417. local64_set(&event->hw.prev_count, 0);
  1418. }
  1419. return x86_perf_event_set_period(event);
  1420. }
  1421. static void intel_pmu_reset(void)
  1422. {
  1423. struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds);
  1424. unsigned long flags;
  1425. int idx;
  1426. if (!x86_pmu.num_counters)
  1427. return;
  1428. local_irq_save(flags);
  1429. pr_info("clearing PMU state on CPU#%d\n", smp_processor_id());
  1430. for (idx = 0; idx < x86_pmu.num_counters; idx++) {
  1431. wrmsrl_safe(x86_pmu_config_addr(idx), 0ull);
  1432. wrmsrl_safe(x86_pmu_event_addr(idx), 0ull);
  1433. }
  1434. for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++)
  1435. wrmsrl_safe(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull);
  1436. if (ds)
  1437. ds->bts_index = ds->bts_buffer_base;
  1438. /* Ack all overflows and disable fixed counters */
  1439. if (x86_pmu.version >= 2) {
  1440. intel_pmu_ack_status(intel_pmu_get_status());
  1441. wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0);
  1442. }
  1443. /* Reset LBRs and LBR freezing */
  1444. if (x86_pmu.lbr_nr) {
  1445. update_debugctlmsr(get_debugctlmsr() &
  1446. ~(DEBUGCTLMSR_FREEZE_LBRS_ON_PMI|DEBUGCTLMSR_LBR));
  1447. }
  1448. local_irq_restore(flags);
  1449. }
  1450. /*
  1451. * This handler is triggered by the local APIC, so the APIC IRQ handling
  1452. * rules apply:
  1453. */
  1454. static int intel_pmu_handle_irq(struct pt_regs *regs)
  1455. {
  1456. struct perf_sample_data data;
  1457. struct cpu_hw_events *cpuc;
  1458. int bit, loops;
  1459. u64 status;
  1460. int handled;
  1461. cpuc = this_cpu_ptr(&cpu_hw_events);
  1462. /*
  1463. * No known reason to not always do late ACK,
  1464. * but just in case do it opt-in.
  1465. */
  1466. if (!x86_pmu.late_ack)
  1467. apic_write(APIC_LVTPC, APIC_DM_NMI);
  1468. __intel_pmu_disable_all();
  1469. handled = intel_pmu_drain_bts_buffer();
  1470. handled += intel_bts_interrupt();
  1471. status = intel_pmu_get_status();
  1472. if (!status)
  1473. goto done;
  1474. loops = 0;
  1475. again:
  1476. intel_pmu_ack_status(status);
  1477. if (++loops > 100) {
  1478. static bool warned = false;
  1479. if (!warned) {
  1480. WARN(1, "perfevents: irq loop stuck!\n");
  1481. perf_event_print_debug();
  1482. warned = true;
  1483. }
  1484. intel_pmu_reset();
  1485. goto done;
  1486. }
  1487. inc_irq_stat(apic_perf_irqs);
  1488. intel_pmu_lbr_read();
  1489. /*
  1490. * CondChgd bit 63 doesn't mean any overflow status. Ignore
  1491. * and clear the bit.
  1492. */
  1493. if (__test_and_clear_bit(63, (unsigned long *)&status)) {
  1494. if (!status)
  1495. goto done;
  1496. }
  1497. /*
  1498. * PEBS overflow sets bit 62 in the global status register
  1499. */
  1500. if (__test_and_clear_bit(62, (unsigned long *)&status)) {
  1501. handled++;
  1502. x86_pmu.drain_pebs(regs);
  1503. }
  1504. /*
  1505. * Intel PT
  1506. */
  1507. if (__test_and_clear_bit(55, (unsigned long *)&status)) {
  1508. handled++;
  1509. intel_pt_interrupt();
  1510. }
  1511. /*
  1512. * Checkpointed counters can lead to 'spurious' PMIs because the
  1513. * rollback caused by the PMI will have cleared the overflow status
  1514. * bit. Therefore always force probe these counters.
  1515. */
  1516. status |= cpuc->intel_cp_status;
  1517. for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) {
  1518. struct perf_event *event = cpuc->events[bit];
  1519. handled++;
  1520. if (!test_bit(bit, cpuc->active_mask))
  1521. continue;
  1522. if (!intel_pmu_save_and_restart(event))
  1523. continue;
  1524. perf_sample_data_init(&data, 0, event->hw.last_period);
  1525. if (has_branch_stack(event))
  1526. data.br_stack = &cpuc->lbr_stack;
  1527. if (perf_event_overflow(event, &data, regs))
  1528. x86_pmu_stop(event, 0);
  1529. }
  1530. /*
  1531. * Repeat if there is more work to be done:
  1532. */
  1533. status = intel_pmu_get_status();
  1534. if (status)
  1535. goto again;
  1536. done:
  1537. __intel_pmu_enable_all(0, true);
  1538. /*
  1539. * Only unmask the NMI after the overflow counters
  1540. * have been reset. This avoids spurious NMIs on
  1541. * Haswell CPUs.
  1542. */
  1543. if (x86_pmu.late_ack)
  1544. apic_write(APIC_LVTPC, APIC_DM_NMI);
  1545. return handled;
  1546. }
  1547. static struct event_constraint *
  1548. intel_bts_constraints(struct perf_event *event)
  1549. {
  1550. struct hw_perf_event *hwc = &event->hw;
  1551. unsigned int hw_event, bts_event;
  1552. if (event->attr.freq)
  1553. return NULL;
  1554. hw_event = hwc->config & INTEL_ARCH_EVENT_MASK;
  1555. bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS);
  1556. if (unlikely(hw_event == bts_event && hwc->sample_period == 1))
  1557. return &bts_constraint;
  1558. return NULL;
  1559. }
  1560. static int intel_alt_er(int idx)
  1561. {
  1562. if (!(x86_pmu.flags & PMU_FL_HAS_RSP_1))
  1563. return idx;
  1564. if (idx == EXTRA_REG_RSP_0)
  1565. return EXTRA_REG_RSP_1;
  1566. if (idx == EXTRA_REG_RSP_1)
  1567. return EXTRA_REG_RSP_0;
  1568. return idx;
  1569. }
  1570. static void intel_fixup_er(struct perf_event *event, int idx)
  1571. {
  1572. event->hw.extra_reg.idx = idx;
  1573. if (idx == EXTRA_REG_RSP_0) {
  1574. event->hw.config &= ~INTEL_ARCH_EVENT_MASK;
  1575. event->hw.config |= x86_pmu.extra_regs[EXTRA_REG_RSP_0].event;
  1576. event->hw.extra_reg.reg = MSR_OFFCORE_RSP_0;
  1577. } else if (idx == EXTRA_REG_RSP_1) {
  1578. event->hw.config &= ~INTEL_ARCH_EVENT_MASK;
  1579. event->hw.config |= x86_pmu.extra_regs[EXTRA_REG_RSP_1].event;
  1580. event->hw.extra_reg.reg = MSR_OFFCORE_RSP_1;
  1581. }
  1582. }
  1583. /*
  1584. * manage allocation of shared extra msr for certain events
  1585. *
  1586. * sharing can be:
  1587. * per-cpu: to be shared between the various events on a single PMU
  1588. * per-core: per-cpu + shared by HT threads
  1589. */
  1590. static struct event_constraint *
  1591. __intel_shared_reg_get_constraints(struct cpu_hw_events *cpuc,
  1592. struct perf_event *event,
  1593. struct hw_perf_event_extra *reg)
  1594. {
  1595. struct event_constraint *c = &emptyconstraint;
  1596. struct er_account *era;
  1597. unsigned long flags;
  1598. int idx = reg->idx;
  1599. /*
  1600. * reg->alloc can be set due to existing state, so for fake cpuc we
  1601. * need to ignore this, otherwise we might fail to allocate proper fake
  1602. * state for this extra reg constraint. Also see the comment below.
  1603. */
  1604. if (reg->alloc && !cpuc->is_fake)
  1605. return NULL; /* call x86_get_event_constraint() */
  1606. again:
  1607. era = &cpuc->shared_regs->regs[idx];
  1608. /*
  1609. * we use spin_lock_irqsave() to avoid lockdep issues when
  1610. * passing a fake cpuc
  1611. */
  1612. raw_spin_lock_irqsave(&era->lock, flags);
  1613. if (!atomic_read(&era->ref) || era->config == reg->config) {
  1614. /*
  1615. * If its a fake cpuc -- as per validate_{group,event}() we
  1616. * shouldn't touch event state and we can avoid doing so
  1617. * since both will only call get_event_constraints() once
  1618. * on each event, this avoids the need for reg->alloc.
  1619. *
  1620. * Not doing the ER fixup will only result in era->reg being
  1621. * wrong, but since we won't actually try and program hardware
  1622. * this isn't a problem either.
  1623. */
  1624. if (!cpuc->is_fake) {
  1625. if (idx != reg->idx)
  1626. intel_fixup_er(event, idx);
  1627. /*
  1628. * x86_schedule_events() can call get_event_constraints()
  1629. * multiple times on events in the case of incremental
  1630. * scheduling(). reg->alloc ensures we only do the ER
  1631. * allocation once.
  1632. */
  1633. reg->alloc = 1;
  1634. }
  1635. /* lock in msr value */
  1636. era->config = reg->config;
  1637. era->reg = reg->reg;
  1638. /* one more user */
  1639. atomic_inc(&era->ref);
  1640. /*
  1641. * need to call x86_get_event_constraint()
  1642. * to check if associated event has constraints
  1643. */
  1644. c = NULL;
  1645. } else {
  1646. idx = intel_alt_er(idx);
  1647. if (idx != reg->idx) {
  1648. raw_spin_unlock_irqrestore(&era->lock, flags);
  1649. goto again;
  1650. }
  1651. }
  1652. raw_spin_unlock_irqrestore(&era->lock, flags);
  1653. return c;
  1654. }
  1655. static void
  1656. __intel_shared_reg_put_constraints(struct cpu_hw_events *cpuc,
  1657. struct hw_perf_event_extra *reg)
  1658. {
  1659. struct er_account *era;
  1660. /*
  1661. * Only put constraint if extra reg was actually allocated. Also takes
  1662. * care of event which do not use an extra shared reg.
  1663. *
  1664. * Also, if this is a fake cpuc we shouldn't touch any event state
  1665. * (reg->alloc) and we don't care about leaving inconsistent cpuc state
  1666. * either since it'll be thrown out.
  1667. */
  1668. if (!reg->alloc || cpuc->is_fake)
  1669. return;
  1670. era = &cpuc->shared_regs->regs[reg->idx];
  1671. /* one fewer user */
  1672. atomic_dec(&era->ref);
  1673. /* allocate again next time */
  1674. reg->alloc = 0;
  1675. }
  1676. static struct event_constraint *
  1677. intel_shared_regs_constraints(struct cpu_hw_events *cpuc,
  1678. struct perf_event *event)
  1679. {
  1680. struct event_constraint *c = NULL, *d;
  1681. struct hw_perf_event_extra *xreg, *breg;
  1682. xreg = &event->hw.extra_reg;
  1683. if (xreg->idx != EXTRA_REG_NONE) {
  1684. c = __intel_shared_reg_get_constraints(cpuc, event, xreg);
  1685. if (c == &emptyconstraint)
  1686. return c;
  1687. }
  1688. breg = &event->hw.branch_reg;
  1689. if (breg->idx != EXTRA_REG_NONE) {
  1690. d = __intel_shared_reg_get_constraints(cpuc, event, breg);
  1691. if (d == &emptyconstraint) {
  1692. __intel_shared_reg_put_constraints(cpuc, xreg);
  1693. c = d;
  1694. }
  1695. }
  1696. return c;
  1697. }
  1698. struct event_constraint *
  1699. x86_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
  1700. struct perf_event *event)
  1701. {
  1702. struct event_constraint *c;
  1703. if (x86_pmu.event_constraints) {
  1704. for_each_event_constraint(c, x86_pmu.event_constraints) {
  1705. if ((event->hw.config & c->cmask) == c->code) {
  1706. event->hw.flags |= c->flags;
  1707. return c;
  1708. }
  1709. }
  1710. }
  1711. return &unconstrained;
  1712. }
  1713. static struct event_constraint *
  1714. __intel_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
  1715. struct perf_event *event)
  1716. {
  1717. struct event_constraint *c;
  1718. c = intel_bts_constraints(event);
  1719. if (c)
  1720. return c;
  1721. c = intel_shared_regs_constraints(cpuc, event);
  1722. if (c)
  1723. return c;
  1724. c = intel_pebs_constraints(event);
  1725. if (c)
  1726. return c;
  1727. return x86_get_event_constraints(cpuc, idx, event);
  1728. }
  1729. static void
  1730. intel_start_scheduling(struct cpu_hw_events *cpuc)
  1731. {
  1732. struct intel_excl_cntrs *excl_cntrs = cpuc->excl_cntrs;
  1733. struct intel_excl_states *xl, *xlo;
  1734. int tid = cpuc->excl_thread_id;
  1735. int o_tid = 1 - tid; /* sibling thread */
  1736. /*
  1737. * nothing needed if in group validation mode
  1738. */
  1739. if (cpuc->is_fake || !is_ht_workaround_enabled())
  1740. return;
  1741. /*
  1742. * no exclusion needed
  1743. */
  1744. if (!excl_cntrs)
  1745. return;
  1746. xlo = &excl_cntrs->states[o_tid];
  1747. xl = &excl_cntrs->states[tid];
  1748. xl->sched_started = true;
  1749. /*
  1750. * lock shared state until we are done scheduling
  1751. * in stop_event_scheduling()
  1752. * makes scheduling appear as a transaction
  1753. */
  1754. WARN_ON_ONCE(!irqs_disabled());
  1755. raw_spin_lock(&excl_cntrs->lock);
  1756. /*
  1757. * save initial state of sibling thread
  1758. */
  1759. memcpy(xlo->init_state, xlo->state, sizeof(xlo->init_state));
  1760. }
  1761. static void
  1762. intel_stop_scheduling(struct cpu_hw_events *cpuc)
  1763. {
  1764. struct intel_excl_cntrs *excl_cntrs = cpuc->excl_cntrs;
  1765. struct intel_excl_states *xl, *xlo;
  1766. int tid = cpuc->excl_thread_id;
  1767. int o_tid = 1 - tid; /* sibling thread */
  1768. /*
  1769. * nothing needed if in group validation mode
  1770. */
  1771. if (cpuc->is_fake || !is_ht_workaround_enabled())
  1772. return;
  1773. /*
  1774. * no exclusion needed
  1775. */
  1776. if (!excl_cntrs)
  1777. return;
  1778. xlo = &excl_cntrs->states[o_tid];
  1779. xl = &excl_cntrs->states[tid];
  1780. /*
  1781. * make new sibling thread state visible
  1782. */
  1783. memcpy(xlo->state, xlo->init_state, sizeof(xlo->state));
  1784. xl->sched_started = false;
  1785. /*
  1786. * release shared state lock (acquired in intel_start_scheduling())
  1787. */
  1788. raw_spin_unlock(&excl_cntrs->lock);
  1789. }
  1790. static struct event_constraint *
  1791. intel_get_excl_constraints(struct cpu_hw_events *cpuc, struct perf_event *event,
  1792. int idx, struct event_constraint *c)
  1793. {
  1794. struct event_constraint *cx;
  1795. struct intel_excl_cntrs *excl_cntrs = cpuc->excl_cntrs;
  1796. struct intel_excl_states *xl, *xlo;
  1797. int is_excl, i;
  1798. int tid = cpuc->excl_thread_id;
  1799. int o_tid = 1 - tid; /* alternate */
  1800. /*
  1801. * validating a group does not require
  1802. * enforcing cross-thread exclusion
  1803. */
  1804. if (cpuc->is_fake || !is_ht_workaround_enabled())
  1805. return c;
  1806. /*
  1807. * no exclusion needed
  1808. */
  1809. if (!excl_cntrs)
  1810. return c;
  1811. /*
  1812. * event requires exclusive counter access
  1813. * across HT threads
  1814. */
  1815. is_excl = c->flags & PERF_X86_EVENT_EXCL;
  1816. if (is_excl && !(event->hw.flags & PERF_X86_EVENT_EXCL_ACCT)) {
  1817. event->hw.flags |= PERF_X86_EVENT_EXCL_ACCT;
  1818. if (!cpuc->n_excl++)
  1819. WRITE_ONCE(excl_cntrs->has_exclusive[tid], 1);
  1820. }
  1821. /*
  1822. * xl = state of current HT
  1823. * xlo = state of sibling HT
  1824. */
  1825. xl = &excl_cntrs->states[tid];
  1826. xlo = &excl_cntrs->states[o_tid];
  1827. cx = c;
  1828. /*
  1829. * because we modify the constraint, we need
  1830. * to make a copy. Static constraints come
  1831. * from static const tables.
  1832. *
  1833. * only needed when constraint has not yet
  1834. * been cloned (marked dynamic)
  1835. */
  1836. if (!(c->flags & PERF_X86_EVENT_DYNAMIC)) {
  1837. /* sanity check */
  1838. if (idx < 0)
  1839. return &emptyconstraint;
  1840. /*
  1841. * grab pre-allocated constraint entry
  1842. */
  1843. cx = &cpuc->constraint_list[idx];
  1844. /*
  1845. * initialize dynamic constraint
  1846. * with static constraint
  1847. */
  1848. memcpy(cx, c, sizeof(*cx));
  1849. /*
  1850. * mark constraint as dynamic, so we
  1851. * can free it later on
  1852. */
  1853. cx->flags |= PERF_X86_EVENT_DYNAMIC;
  1854. }
  1855. /*
  1856. * From here on, the constraint is dynamic.
  1857. * Either it was just allocated above, or it
  1858. * was allocated during a earlier invocation
  1859. * of this function
  1860. */
  1861. /*
  1862. * Modify static constraint with current dynamic
  1863. * state of thread
  1864. *
  1865. * EXCLUSIVE: sibling counter measuring exclusive event
  1866. * SHARED : sibling counter measuring non-exclusive event
  1867. * UNUSED : sibling counter unused
  1868. */
  1869. for_each_set_bit(i, cx->idxmsk, X86_PMC_IDX_MAX) {
  1870. /*
  1871. * exclusive event in sibling counter
  1872. * our corresponding counter cannot be used
  1873. * regardless of our event
  1874. */
  1875. if (xl->state[i] == INTEL_EXCL_EXCLUSIVE)
  1876. __clear_bit(i, cx->idxmsk);
  1877. /*
  1878. * if measuring an exclusive event, sibling
  1879. * measuring non-exclusive, then counter cannot
  1880. * be used
  1881. */
  1882. if (is_excl && xl->state[i] == INTEL_EXCL_SHARED)
  1883. __clear_bit(i, cx->idxmsk);
  1884. }
  1885. /*
  1886. * recompute actual bit weight for scheduling algorithm
  1887. */
  1888. cx->weight = hweight64(cx->idxmsk64);
  1889. /*
  1890. * if we return an empty mask, then switch
  1891. * back to static empty constraint to avoid
  1892. * the cost of freeing later on
  1893. */
  1894. if (cx->weight == 0)
  1895. cx = &emptyconstraint;
  1896. return cx;
  1897. }
  1898. static struct event_constraint *
  1899. intel_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
  1900. struct perf_event *event)
  1901. {
  1902. struct event_constraint *c1 = cpuc->event_constraint[idx];
  1903. struct event_constraint *c2;
  1904. /*
  1905. * first time only
  1906. * - static constraint: no change across incremental scheduling calls
  1907. * - dynamic constraint: handled by intel_get_excl_constraints()
  1908. */
  1909. c2 = __intel_get_event_constraints(cpuc, idx, event);
  1910. if (c1 && (c1->flags & PERF_X86_EVENT_DYNAMIC)) {
  1911. bitmap_copy(c1->idxmsk, c2->idxmsk, X86_PMC_IDX_MAX);
  1912. c1->weight = c2->weight;
  1913. c2 = c1;
  1914. }
  1915. if (cpuc->excl_cntrs)
  1916. return intel_get_excl_constraints(cpuc, event, idx, c2);
  1917. return c2;
  1918. }
  1919. static void intel_put_excl_constraints(struct cpu_hw_events *cpuc,
  1920. struct perf_event *event)
  1921. {
  1922. struct hw_perf_event *hwc = &event->hw;
  1923. struct intel_excl_cntrs *excl_cntrs = cpuc->excl_cntrs;
  1924. struct intel_excl_states *xlo, *xl;
  1925. unsigned long flags = 0; /* keep compiler happy */
  1926. int tid = cpuc->excl_thread_id;
  1927. int o_tid = 1 - tid;
  1928. /*
  1929. * nothing needed if in group validation mode
  1930. */
  1931. if (cpuc->is_fake)
  1932. return;
  1933. WARN_ON_ONCE(!excl_cntrs);
  1934. if (!excl_cntrs)
  1935. return;
  1936. xl = &excl_cntrs->states[tid];
  1937. xlo = &excl_cntrs->states[o_tid];
  1938. if (hwc->flags & PERF_X86_EVENT_EXCL_ACCT) {
  1939. hwc->flags &= ~PERF_X86_EVENT_EXCL_ACCT;
  1940. if (!--cpuc->n_excl)
  1941. WRITE_ONCE(excl_cntrs->has_exclusive[tid], 0);
  1942. }
  1943. /*
  1944. * put_constraint may be called from x86_schedule_events()
  1945. * which already has the lock held so here make locking
  1946. * conditional
  1947. */
  1948. if (!xl->sched_started)
  1949. raw_spin_lock_irqsave(&excl_cntrs->lock, flags);
  1950. /*
  1951. * if event was actually assigned, then mark the
  1952. * counter state as unused now
  1953. */
  1954. if (hwc->idx >= 0)
  1955. xlo->state[hwc->idx] = INTEL_EXCL_UNUSED;
  1956. if (!xl->sched_started)
  1957. raw_spin_unlock_irqrestore(&excl_cntrs->lock, flags);
  1958. }
  1959. static void
  1960. intel_put_shared_regs_event_constraints(struct cpu_hw_events *cpuc,
  1961. struct perf_event *event)
  1962. {
  1963. struct hw_perf_event_extra *reg;
  1964. reg = &event->hw.extra_reg;
  1965. if (reg->idx != EXTRA_REG_NONE)
  1966. __intel_shared_reg_put_constraints(cpuc, reg);
  1967. reg = &event->hw.branch_reg;
  1968. if (reg->idx != EXTRA_REG_NONE)
  1969. __intel_shared_reg_put_constraints(cpuc, reg);
  1970. }
  1971. static void intel_put_event_constraints(struct cpu_hw_events *cpuc,
  1972. struct perf_event *event)
  1973. {
  1974. intel_put_shared_regs_event_constraints(cpuc, event);
  1975. /*
  1976. * is PMU has exclusive counter restrictions, then
  1977. * all events are subject to and must call the
  1978. * put_excl_constraints() routine
  1979. */
  1980. if (cpuc->excl_cntrs)
  1981. intel_put_excl_constraints(cpuc, event);
  1982. }
  1983. static void intel_commit_scheduling(struct cpu_hw_events *cpuc, int idx, int cntr)
  1984. {
  1985. struct intel_excl_cntrs *excl_cntrs = cpuc->excl_cntrs;
  1986. struct event_constraint *c = cpuc->event_constraint[idx];
  1987. struct intel_excl_states *xlo, *xl;
  1988. int tid = cpuc->excl_thread_id;
  1989. int o_tid = 1 - tid;
  1990. int is_excl;
  1991. if (cpuc->is_fake || !c)
  1992. return;
  1993. is_excl = c->flags & PERF_X86_EVENT_EXCL;
  1994. if (!(c->flags & PERF_X86_EVENT_DYNAMIC))
  1995. return;
  1996. WARN_ON_ONCE(!excl_cntrs);
  1997. if (!excl_cntrs)
  1998. return;
  1999. xl = &excl_cntrs->states[tid];
  2000. xlo = &excl_cntrs->states[o_tid];
  2001. WARN_ON_ONCE(!raw_spin_is_locked(&excl_cntrs->lock));
  2002. if (cntr >= 0) {
  2003. if (is_excl)
  2004. xlo->init_state[cntr] = INTEL_EXCL_EXCLUSIVE;
  2005. else
  2006. xlo->init_state[cntr] = INTEL_EXCL_SHARED;
  2007. }
  2008. }
  2009. static void intel_pebs_aliases_core2(struct perf_event *event)
  2010. {
  2011. if ((event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) {
  2012. /*
  2013. * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P
  2014. * (0x003c) so that we can use it with PEBS.
  2015. *
  2016. * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't
  2017. * PEBS capable. However we can use INST_RETIRED.ANY_P
  2018. * (0x00c0), which is a PEBS capable event, to get the same
  2019. * count.
  2020. *
  2021. * INST_RETIRED.ANY_P counts the number of cycles that retires
  2022. * CNTMASK instructions. By setting CNTMASK to a value (16)
  2023. * larger than the maximum number of instructions that can be
  2024. * retired per cycle (4) and then inverting the condition, we
  2025. * count all cycles that retire 16 or less instructions, which
  2026. * is every cycle.
  2027. *
  2028. * Thereby we gain a PEBS capable cycle counter.
  2029. */
  2030. u64 alt_config = X86_CONFIG(.event=0xc0, .inv=1, .cmask=16);
  2031. alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK);
  2032. event->hw.config = alt_config;
  2033. }
  2034. }
  2035. static void intel_pebs_aliases_snb(struct perf_event *event)
  2036. {
  2037. if ((event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) {
  2038. /*
  2039. * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P
  2040. * (0x003c) so that we can use it with PEBS.
  2041. *
  2042. * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't
  2043. * PEBS capable. However we can use UOPS_RETIRED.ALL
  2044. * (0x01c2), which is a PEBS capable event, to get the same
  2045. * count.
  2046. *
  2047. * UOPS_RETIRED.ALL counts the number of cycles that retires
  2048. * CNTMASK micro-ops. By setting CNTMASK to a value (16)
  2049. * larger than the maximum number of micro-ops that can be
  2050. * retired per cycle (4) and then inverting the condition, we
  2051. * count all cycles that retire 16 or less micro-ops, which
  2052. * is every cycle.
  2053. *
  2054. * Thereby we gain a PEBS capable cycle counter.
  2055. */
  2056. u64 alt_config = X86_CONFIG(.event=0xc2, .umask=0x01, .inv=1, .cmask=16);
  2057. alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK);
  2058. event->hw.config = alt_config;
  2059. }
  2060. }
  2061. static int intel_pmu_hw_config(struct perf_event *event)
  2062. {
  2063. int ret = x86_pmu_hw_config(event);
  2064. if (ret)
  2065. return ret;
  2066. if (event->attr.precise_ip && x86_pmu.pebs_aliases)
  2067. x86_pmu.pebs_aliases(event);
  2068. if (needs_branch_stack(event)) {
  2069. ret = intel_pmu_setup_lbr_filter(event);
  2070. if (ret)
  2071. return ret;
  2072. /*
  2073. * BTS is set up earlier in this path, so don't account twice
  2074. */
  2075. if (!intel_pmu_has_bts(event)) {
  2076. /* disallow lbr if conflicting events are present */
  2077. if (x86_add_exclusive(x86_lbr_exclusive_lbr))
  2078. return -EBUSY;
  2079. event->destroy = hw_perf_lbr_event_destroy;
  2080. }
  2081. }
  2082. if (event->attr.type != PERF_TYPE_RAW)
  2083. return 0;
  2084. if (!(event->attr.config & ARCH_PERFMON_EVENTSEL_ANY))
  2085. return 0;
  2086. if (x86_pmu.version < 3)
  2087. return -EINVAL;
  2088. if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
  2089. return -EACCES;
  2090. event->hw.config |= ARCH_PERFMON_EVENTSEL_ANY;
  2091. return 0;
  2092. }
  2093. struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr)
  2094. {
  2095. if (x86_pmu.guest_get_msrs)
  2096. return x86_pmu.guest_get_msrs(nr);
  2097. *nr = 0;
  2098. return NULL;
  2099. }
  2100. EXPORT_SYMBOL_GPL(perf_guest_get_msrs);
  2101. static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr)
  2102. {
  2103. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  2104. struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs;
  2105. arr[0].msr = MSR_CORE_PERF_GLOBAL_CTRL;
  2106. arr[0].host = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask;
  2107. arr[0].guest = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_host_mask;
  2108. /*
  2109. * If PMU counter has PEBS enabled it is not enough to disable counter
  2110. * on a guest entry since PEBS memory write can overshoot guest entry
  2111. * and corrupt guest memory. Disabling PEBS solves the problem.
  2112. */
  2113. arr[1].msr = MSR_IA32_PEBS_ENABLE;
  2114. arr[1].host = cpuc->pebs_enabled;
  2115. arr[1].guest = 0;
  2116. *nr = 2;
  2117. return arr;
  2118. }
  2119. static struct perf_guest_switch_msr *core_guest_get_msrs(int *nr)
  2120. {
  2121. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  2122. struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs;
  2123. int idx;
  2124. for (idx = 0; idx < x86_pmu.num_counters; idx++) {
  2125. struct perf_event *event = cpuc->events[idx];
  2126. arr[idx].msr = x86_pmu_config_addr(idx);
  2127. arr[idx].host = arr[idx].guest = 0;
  2128. if (!test_bit(idx, cpuc->active_mask))
  2129. continue;
  2130. arr[idx].host = arr[idx].guest =
  2131. event->hw.config | ARCH_PERFMON_EVENTSEL_ENABLE;
  2132. if (event->attr.exclude_host)
  2133. arr[idx].host &= ~ARCH_PERFMON_EVENTSEL_ENABLE;
  2134. else if (event->attr.exclude_guest)
  2135. arr[idx].guest &= ~ARCH_PERFMON_EVENTSEL_ENABLE;
  2136. }
  2137. *nr = x86_pmu.num_counters;
  2138. return arr;
  2139. }
  2140. static void core_pmu_enable_event(struct perf_event *event)
  2141. {
  2142. if (!event->attr.exclude_host)
  2143. x86_pmu_enable_event(event);
  2144. }
  2145. static void core_pmu_enable_all(int added)
  2146. {
  2147. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  2148. int idx;
  2149. for (idx = 0; idx < x86_pmu.num_counters; idx++) {
  2150. struct hw_perf_event *hwc = &cpuc->events[idx]->hw;
  2151. if (!test_bit(idx, cpuc->active_mask) ||
  2152. cpuc->events[idx]->attr.exclude_host)
  2153. continue;
  2154. __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE);
  2155. }
  2156. }
  2157. static int hsw_hw_config(struct perf_event *event)
  2158. {
  2159. int ret = intel_pmu_hw_config(event);
  2160. if (ret)
  2161. return ret;
  2162. if (!boot_cpu_has(X86_FEATURE_RTM) && !boot_cpu_has(X86_FEATURE_HLE))
  2163. return 0;
  2164. event->hw.config |= event->attr.config & (HSW_IN_TX|HSW_IN_TX_CHECKPOINTED);
  2165. /*
  2166. * IN_TX/IN_TX-CP filters are not supported by the Haswell PMU with
  2167. * PEBS or in ANY thread mode. Since the results are non-sensical forbid
  2168. * this combination.
  2169. */
  2170. if ((event->hw.config & (HSW_IN_TX|HSW_IN_TX_CHECKPOINTED)) &&
  2171. ((event->hw.config & ARCH_PERFMON_EVENTSEL_ANY) ||
  2172. event->attr.precise_ip > 0))
  2173. return -EOPNOTSUPP;
  2174. if (event_is_checkpointed(event)) {
  2175. /*
  2176. * Sampling of checkpointed events can cause situations where
  2177. * the CPU constantly aborts because of a overflow, which is
  2178. * then checkpointed back and ignored. Forbid checkpointing
  2179. * for sampling.
  2180. *
  2181. * But still allow a long sampling period, so that perf stat
  2182. * from KVM works.
  2183. */
  2184. if (event->attr.sample_period > 0 &&
  2185. event->attr.sample_period < 0x7fffffff)
  2186. return -EOPNOTSUPP;
  2187. }
  2188. return 0;
  2189. }
  2190. static struct event_constraint counter2_constraint =
  2191. EVENT_CONSTRAINT(0, 0x4, 0);
  2192. static struct event_constraint *
  2193. hsw_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
  2194. struct perf_event *event)
  2195. {
  2196. struct event_constraint *c;
  2197. c = intel_get_event_constraints(cpuc, idx, event);
  2198. /* Handle special quirk on in_tx_checkpointed only in counter 2 */
  2199. if (event->hw.config & HSW_IN_TX_CHECKPOINTED) {
  2200. if (c->idxmsk64 & (1U << 2))
  2201. return &counter2_constraint;
  2202. return &emptyconstraint;
  2203. }
  2204. return c;
  2205. }
  2206. /*
  2207. * Broadwell:
  2208. *
  2209. * The INST_RETIRED.ALL period always needs to have lowest 6 bits cleared
  2210. * (BDM55) and it must not use a period smaller than 100 (BDM11). We combine
  2211. * the two to enforce a minimum period of 128 (the smallest value that has bits
  2212. * 0-5 cleared and >= 100).
  2213. *
  2214. * Because of how the code in x86_perf_event_set_period() works, the truncation
  2215. * of the lower 6 bits is 'harmless' as we'll occasionally add a longer period
  2216. * to make up for the 'lost' events due to carrying the 'error' in period_left.
  2217. *
  2218. * Therefore the effective (average) period matches the requested period,
  2219. * despite coarser hardware granularity.
  2220. */
  2221. static unsigned bdw_limit_period(struct perf_event *event, unsigned left)
  2222. {
  2223. if ((event->hw.config & INTEL_ARCH_EVENT_MASK) ==
  2224. X86_CONFIG(.event=0xc0, .umask=0x01)) {
  2225. if (left < 128)
  2226. left = 128;
  2227. left &= ~0x3fu;
  2228. }
  2229. return left;
  2230. }
  2231. PMU_FORMAT_ATTR(event, "config:0-7" );
  2232. PMU_FORMAT_ATTR(umask, "config:8-15" );
  2233. PMU_FORMAT_ATTR(edge, "config:18" );
  2234. PMU_FORMAT_ATTR(pc, "config:19" );
  2235. PMU_FORMAT_ATTR(any, "config:21" ); /* v3 + */
  2236. PMU_FORMAT_ATTR(inv, "config:23" );
  2237. PMU_FORMAT_ATTR(cmask, "config:24-31" );
  2238. PMU_FORMAT_ATTR(in_tx, "config:32");
  2239. PMU_FORMAT_ATTR(in_tx_cp, "config:33");
  2240. static struct attribute *intel_arch_formats_attr[] = {
  2241. &format_attr_event.attr,
  2242. &format_attr_umask.attr,
  2243. &format_attr_edge.attr,
  2244. &format_attr_pc.attr,
  2245. &format_attr_inv.attr,
  2246. &format_attr_cmask.attr,
  2247. NULL,
  2248. };
  2249. ssize_t intel_event_sysfs_show(char *page, u64 config)
  2250. {
  2251. u64 event = (config & ARCH_PERFMON_EVENTSEL_EVENT);
  2252. return x86_event_sysfs_show(page, config, event);
  2253. }
  2254. struct intel_shared_regs *allocate_shared_regs(int cpu)
  2255. {
  2256. struct intel_shared_regs *regs;
  2257. int i;
  2258. regs = kzalloc_node(sizeof(struct intel_shared_regs),
  2259. GFP_KERNEL, cpu_to_node(cpu));
  2260. if (regs) {
  2261. /*
  2262. * initialize the locks to keep lockdep happy
  2263. */
  2264. for (i = 0; i < EXTRA_REG_MAX; i++)
  2265. raw_spin_lock_init(&regs->regs[i].lock);
  2266. regs->core_id = -1;
  2267. }
  2268. return regs;
  2269. }
  2270. static struct intel_excl_cntrs *allocate_excl_cntrs(int cpu)
  2271. {
  2272. struct intel_excl_cntrs *c;
  2273. int i;
  2274. c = kzalloc_node(sizeof(struct intel_excl_cntrs),
  2275. GFP_KERNEL, cpu_to_node(cpu));
  2276. if (c) {
  2277. raw_spin_lock_init(&c->lock);
  2278. for (i = 0; i < X86_PMC_IDX_MAX; i++) {
  2279. c->states[0].state[i] = INTEL_EXCL_UNUSED;
  2280. c->states[0].init_state[i] = INTEL_EXCL_UNUSED;
  2281. c->states[1].state[i] = INTEL_EXCL_UNUSED;
  2282. c->states[1].init_state[i] = INTEL_EXCL_UNUSED;
  2283. }
  2284. c->core_id = -1;
  2285. }
  2286. return c;
  2287. }
  2288. static int intel_pmu_cpu_prepare(int cpu)
  2289. {
  2290. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  2291. if (x86_pmu.extra_regs || x86_pmu.lbr_sel_map) {
  2292. cpuc->shared_regs = allocate_shared_regs(cpu);
  2293. if (!cpuc->shared_regs)
  2294. return NOTIFY_BAD;
  2295. }
  2296. if (x86_pmu.flags & PMU_FL_EXCL_CNTRS) {
  2297. size_t sz = X86_PMC_IDX_MAX * sizeof(struct event_constraint);
  2298. cpuc->constraint_list = kzalloc(sz, GFP_KERNEL);
  2299. if (!cpuc->constraint_list)
  2300. return NOTIFY_BAD;
  2301. cpuc->excl_cntrs = allocate_excl_cntrs(cpu);
  2302. if (!cpuc->excl_cntrs) {
  2303. kfree(cpuc->constraint_list);
  2304. kfree(cpuc->shared_regs);
  2305. return NOTIFY_BAD;
  2306. }
  2307. cpuc->excl_thread_id = 0;
  2308. }
  2309. return NOTIFY_OK;
  2310. }
  2311. static void intel_pmu_cpu_starting(int cpu)
  2312. {
  2313. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  2314. int core_id = topology_core_id(cpu);
  2315. int i;
  2316. init_debug_store_on_cpu(cpu);
  2317. /*
  2318. * Deal with CPUs that don't clear their LBRs on power-up.
  2319. */
  2320. intel_pmu_lbr_reset();
  2321. cpuc->lbr_sel = NULL;
  2322. if (!cpuc->shared_regs)
  2323. return;
  2324. if (!(x86_pmu.flags & PMU_FL_NO_HT_SHARING)) {
  2325. void **onln = &cpuc->kfree_on_online[X86_PERF_KFREE_SHARED];
  2326. for_each_cpu(i, topology_thread_cpumask(cpu)) {
  2327. struct intel_shared_regs *pc;
  2328. pc = per_cpu(cpu_hw_events, i).shared_regs;
  2329. if (pc && pc->core_id == core_id) {
  2330. *onln = cpuc->shared_regs;
  2331. cpuc->shared_regs = pc;
  2332. break;
  2333. }
  2334. }
  2335. cpuc->shared_regs->core_id = core_id;
  2336. cpuc->shared_regs->refcnt++;
  2337. }
  2338. if (x86_pmu.lbr_sel_map)
  2339. cpuc->lbr_sel = &cpuc->shared_regs->regs[EXTRA_REG_LBR];
  2340. if (x86_pmu.flags & PMU_FL_EXCL_CNTRS) {
  2341. for_each_cpu(i, topology_thread_cpumask(cpu)) {
  2342. struct intel_excl_cntrs *c;
  2343. c = per_cpu(cpu_hw_events, i).excl_cntrs;
  2344. if (c && c->core_id == core_id) {
  2345. cpuc->kfree_on_online[1] = cpuc->excl_cntrs;
  2346. cpuc->excl_cntrs = c;
  2347. cpuc->excl_thread_id = 1;
  2348. break;
  2349. }
  2350. }
  2351. cpuc->excl_cntrs->core_id = core_id;
  2352. cpuc->excl_cntrs->refcnt++;
  2353. }
  2354. }
  2355. static void free_excl_cntrs(int cpu)
  2356. {
  2357. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  2358. struct intel_excl_cntrs *c;
  2359. c = cpuc->excl_cntrs;
  2360. if (c) {
  2361. if (c->core_id == -1 || --c->refcnt == 0)
  2362. kfree(c);
  2363. cpuc->excl_cntrs = NULL;
  2364. kfree(cpuc->constraint_list);
  2365. cpuc->constraint_list = NULL;
  2366. }
  2367. }
  2368. static void intel_pmu_cpu_dying(int cpu)
  2369. {
  2370. struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
  2371. struct intel_shared_regs *pc;
  2372. pc = cpuc->shared_regs;
  2373. if (pc) {
  2374. if (pc->core_id == -1 || --pc->refcnt == 0)
  2375. kfree(pc);
  2376. cpuc->shared_regs = NULL;
  2377. }
  2378. free_excl_cntrs(cpu);
  2379. fini_debug_store_on_cpu(cpu);
  2380. }
  2381. PMU_FORMAT_ATTR(offcore_rsp, "config1:0-63");
  2382. PMU_FORMAT_ATTR(ldlat, "config1:0-15");
  2383. static struct attribute *intel_arch3_formats_attr[] = {
  2384. &format_attr_event.attr,
  2385. &format_attr_umask.attr,
  2386. &format_attr_edge.attr,
  2387. &format_attr_pc.attr,
  2388. &format_attr_any.attr,
  2389. &format_attr_inv.attr,
  2390. &format_attr_cmask.attr,
  2391. &format_attr_in_tx.attr,
  2392. &format_attr_in_tx_cp.attr,
  2393. &format_attr_offcore_rsp.attr, /* XXX do NHM/WSM + SNB breakout */
  2394. &format_attr_ldlat.attr, /* PEBS load latency */
  2395. NULL,
  2396. };
  2397. static __initconst const struct x86_pmu core_pmu = {
  2398. .name = "core",
  2399. .handle_irq = x86_pmu_handle_irq,
  2400. .disable_all = x86_pmu_disable_all,
  2401. .enable_all = core_pmu_enable_all,
  2402. .enable = core_pmu_enable_event,
  2403. .disable = x86_pmu_disable_event,
  2404. .hw_config = x86_pmu_hw_config,
  2405. .schedule_events = x86_schedule_events,
  2406. .eventsel = MSR_ARCH_PERFMON_EVENTSEL0,
  2407. .perfctr = MSR_ARCH_PERFMON_PERFCTR0,
  2408. .event_map = intel_pmu_event_map,
  2409. .max_events = ARRAY_SIZE(intel_perfmon_event_map),
  2410. .apic = 1,
  2411. /*
  2412. * Intel PMCs cannot be accessed sanely above 32-bit width,
  2413. * so we install an artificial 1<<31 period regardless of
  2414. * the generic event period:
  2415. */
  2416. .max_period = (1ULL<<31) - 1,
  2417. .get_event_constraints = intel_get_event_constraints,
  2418. .put_event_constraints = intel_put_event_constraints,
  2419. .event_constraints = intel_core_event_constraints,
  2420. .guest_get_msrs = core_guest_get_msrs,
  2421. .format_attrs = intel_arch_formats_attr,
  2422. .events_sysfs_show = intel_event_sysfs_show,
  2423. /*
  2424. * Virtual (or funny metal) CPU can define x86_pmu.extra_regs
  2425. * together with PMU version 1 and thus be using core_pmu with
  2426. * shared_regs. We need following callbacks here to allocate
  2427. * it properly.
  2428. */
  2429. .cpu_prepare = intel_pmu_cpu_prepare,
  2430. .cpu_starting = intel_pmu_cpu_starting,
  2431. .cpu_dying = intel_pmu_cpu_dying,
  2432. };
  2433. static __initconst const struct x86_pmu intel_pmu = {
  2434. .name = "Intel",
  2435. .handle_irq = intel_pmu_handle_irq,
  2436. .disable_all = intel_pmu_disable_all,
  2437. .enable_all = intel_pmu_enable_all,
  2438. .enable = intel_pmu_enable_event,
  2439. .disable = intel_pmu_disable_event,
  2440. .hw_config = intel_pmu_hw_config,
  2441. .schedule_events = x86_schedule_events,
  2442. .eventsel = MSR_ARCH_PERFMON_EVENTSEL0,
  2443. .perfctr = MSR_ARCH_PERFMON_PERFCTR0,
  2444. .event_map = intel_pmu_event_map,
  2445. .max_events = ARRAY_SIZE(intel_perfmon_event_map),
  2446. .apic = 1,
  2447. /*
  2448. * Intel PMCs cannot be accessed sanely above 32 bit width,
  2449. * so we install an artificial 1<<31 period regardless of
  2450. * the generic event period:
  2451. */
  2452. .max_period = (1ULL << 31) - 1,
  2453. .get_event_constraints = intel_get_event_constraints,
  2454. .put_event_constraints = intel_put_event_constraints,
  2455. .pebs_aliases = intel_pebs_aliases_core2,
  2456. .format_attrs = intel_arch3_formats_attr,
  2457. .events_sysfs_show = intel_event_sysfs_show,
  2458. .cpu_prepare = intel_pmu_cpu_prepare,
  2459. .cpu_starting = intel_pmu_cpu_starting,
  2460. .cpu_dying = intel_pmu_cpu_dying,
  2461. .guest_get_msrs = intel_guest_get_msrs,
  2462. .sched_task = intel_pmu_lbr_sched_task,
  2463. };
  2464. static __init void intel_clovertown_quirk(void)
  2465. {
  2466. /*
  2467. * PEBS is unreliable due to:
  2468. *
  2469. * AJ67 - PEBS may experience CPL leaks
  2470. * AJ68 - PEBS PMI may be delayed by one event
  2471. * AJ69 - GLOBAL_STATUS[62] will only be set when DEBUGCTL[12]
  2472. * AJ106 - FREEZE_LBRS_ON_PMI doesn't work in combination with PEBS
  2473. *
  2474. * AJ67 could be worked around by restricting the OS/USR flags.
  2475. * AJ69 could be worked around by setting PMU_FREEZE_ON_PMI.
  2476. *
  2477. * AJ106 could possibly be worked around by not allowing LBR
  2478. * usage from PEBS, including the fixup.
  2479. * AJ68 could possibly be worked around by always programming
  2480. * a pebs_event_reset[0] value and coping with the lost events.
  2481. *
  2482. * But taken together it might just make sense to not enable PEBS on
  2483. * these chips.
  2484. */
  2485. pr_warn("PEBS disabled due to CPU errata\n");
  2486. x86_pmu.pebs = 0;
  2487. x86_pmu.pebs_constraints = NULL;
  2488. }
  2489. static int intel_snb_pebs_broken(int cpu)
  2490. {
  2491. u32 rev = UINT_MAX; /* default to broken for unknown models */
  2492. switch (cpu_data(cpu).x86_model) {
  2493. case 42: /* SNB */
  2494. rev = 0x28;
  2495. break;
  2496. case 45: /* SNB-EP */
  2497. switch (cpu_data(cpu).x86_mask) {
  2498. case 6: rev = 0x618; break;
  2499. case 7: rev = 0x70c; break;
  2500. }
  2501. }
  2502. return (cpu_data(cpu).microcode < rev);
  2503. }
  2504. static void intel_snb_check_microcode(void)
  2505. {
  2506. int pebs_broken = 0;
  2507. int cpu;
  2508. get_online_cpus();
  2509. for_each_online_cpu(cpu) {
  2510. if ((pebs_broken = intel_snb_pebs_broken(cpu)))
  2511. break;
  2512. }
  2513. put_online_cpus();
  2514. if (pebs_broken == x86_pmu.pebs_broken)
  2515. return;
  2516. /*
  2517. * Serialized by the microcode lock..
  2518. */
  2519. if (x86_pmu.pebs_broken) {
  2520. pr_info("PEBS enabled due to microcode update\n");
  2521. x86_pmu.pebs_broken = 0;
  2522. } else {
  2523. pr_info("PEBS disabled due to CPU errata, please upgrade microcode\n");
  2524. x86_pmu.pebs_broken = 1;
  2525. }
  2526. }
  2527. /*
  2528. * Under certain circumstances, access certain MSR may cause #GP.
  2529. * The function tests if the input MSR can be safely accessed.
  2530. */
  2531. static bool check_msr(unsigned long msr, u64 mask)
  2532. {
  2533. u64 val_old, val_new, val_tmp;
  2534. /*
  2535. * Read the current value, change it and read it back to see if it
  2536. * matches, this is needed to detect certain hardware emulators
  2537. * (qemu/kvm) that don't trap on the MSR access and always return 0s.
  2538. */
  2539. if (rdmsrl_safe(msr, &val_old))
  2540. return false;
  2541. /*
  2542. * Only change the bits which can be updated by wrmsrl.
  2543. */
  2544. val_tmp = val_old ^ mask;
  2545. if (wrmsrl_safe(msr, val_tmp) ||
  2546. rdmsrl_safe(msr, &val_new))
  2547. return false;
  2548. if (val_new != val_tmp)
  2549. return false;
  2550. /* Here it's sure that the MSR can be safely accessed.
  2551. * Restore the old value and return.
  2552. */
  2553. wrmsrl(msr, val_old);
  2554. return true;
  2555. }
  2556. static __init void intel_sandybridge_quirk(void)
  2557. {
  2558. x86_pmu.check_microcode = intel_snb_check_microcode;
  2559. intel_snb_check_microcode();
  2560. }
  2561. static const struct { int id; char *name; } intel_arch_events_map[] __initconst = {
  2562. { PERF_COUNT_HW_CPU_CYCLES, "cpu cycles" },
  2563. { PERF_COUNT_HW_INSTRUCTIONS, "instructions" },
  2564. { PERF_COUNT_HW_BUS_CYCLES, "bus cycles" },
  2565. { PERF_COUNT_HW_CACHE_REFERENCES, "cache references" },
  2566. { PERF_COUNT_HW_CACHE_MISSES, "cache misses" },
  2567. { PERF_COUNT_HW_BRANCH_INSTRUCTIONS, "branch instructions" },
  2568. { PERF_COUNT_HW_BRANCH_MISSES, "branch misses" },
  2569. };
  2570. static __init void intel_arch_events_quirk(void)
  2571. {
  2572. int bit;
  2573. /* disable event that reported as not presend by cpuid */
  2574. for_each_set_bit(bit, x86_pmu.events_mask, ARRAY_SIZE(intel_arch_events_map)) {
  2575. intel_perfmon_event_map[intel_arch_events_map[bit].id] = 0;
  2576. pr_warn("CPUID marked event: \'%s\' unavailable\n",
  2577. intel_arch_events_map[bit].name);
  2578. }
  2579. }
  2580. static __init void intel_nehalem_quirk(void)
  2581. {
  2582. union cpuid10_ebx ebx;
  2583. ebx.full = x86_pmu.events_maskl;
  2584. if (ebx.split.no_branch_misses_retired) {
  2585. /*
  2586. * Erratum AAJ80 detected, we work it around by using
  2587. * the BR_MISP_EXEC.ANY event. This will over-count
  2588. * branch-misses, but it's still much better than the
  2589. * architectural event which is often completely bogus:
  2590. */
  2591. intel_perfmon_event_map[PERF_COUNT_HW_BRANCH_MISSES] = 0x7f89;
  2592. ebx.split.no_branch_misses_retired = 0;
  2593. x86_pmu.events_maskl = ebx.full;
  2594. pr_info("CPU erratum AAJ80 worked around\n");
  2595. }
  2596. }
  2597. /*
  2598. * enable software workaround for errata:
  2599. * SNB: BJ122
  2600. * IVB: BV98
  2601. * HSW: HSD29
  2602. *
  2603. * Only needed when HT is enabled. However detecting
  2604. * if HT is enabled is difficult (model specific). So instead,
  2605. * we enable the workaround in the early boot, and verify if
  2606. * it is needed in a later initcall phase once we have valid
  2607. * topology information to check if HT is actually enabled
  2608. */
  2609. static __init void intel_ht_bug(void)
  2610. {
  2611. x86_pmu.flags |= PMU_FL_EXCL_CNTRS | PMU_FL_EXCL_ENABLED;
  2612. x86_pmu.commit_scheduling = intel_commit_scheduling;
  2613. x86_pmu.start_scheduling = intel_start_scheduling;
  2614. x86_pmu.stop_scheduling = intel_stop_scheduling;
  2615. }
  2616. EVENT_ATTR_STR(mem-loads, mem_ld_hsw, "event=0xcd,umask=0x1,ldlat=3");
  2617. EVENT_ATTR_STR(mem-stores, mem_st_hsw, "event=0xd0,umask=0x82")
  2618. /* Haswell special events */
  2619. EVENT_ATTR_STR(tx-start, tx_start, "event=0xc9,umask=0x1");
  2620. EVENT_ATTR_STR(tx-commit, tx_commit, "event=0xc9,umask=0x2");
  2621. EVENT_ATTR_STR(tx-abort, tx_abort, "event=0xc9,umask=0x4");
  2622. EVENT_ATTR_STR(tx-capacity, tx_capacity, "event=0x54,umask=0x2");
  2623. EVENT_ATTR_STR(tx-conflict, tx_conflict, "event=0x54,umask=0x1");
  2624. EVENT_ATTR_STR(el-start, el_start, "event=0xc8,umask=0x1");
  2625. EVENT_ATTR_STR(el-commit, el_commit, "event=0xc8,umask=0x2");
  2626. EVENT_ATTR_STR(el-abort, el_abort, "event=0xc8,umask=0x4");
  2627. EVENT_ATTR_STR(el-capacity, el_capacity, "event=0x54,umask=0x2");
  2628. EVENT_ATTR_STR(el-conflict, el_conflict, "event=0x54,umask=0x1");
  2629. EVENT_ATTR_STR(cycles-t, cycles_t, "event=0x3c,in_tx=1");
  2630. EVENT_ATTR_STR(cycles-ct, cycles_ct, "event=0x3c,in_tx=1,in_tx_cp=1");
  2631. static struct attribute *hsw_events_attrs[] = {
  2632. EVENT_PTR(tx_start),
  2633. EVENT_PTR(tx_commit),
  2634. EVENT_PTR(tx_abort),
  2635. EVENT_PTR(tx_capacity),
  2636. EVENT_PTR(tx_conflict),
  2637. EVENT_PTR(el_start),
  2638. EVENT_PTR(el_commit),
  2639. EVENT_PTR(el_abort),
  2640. EVENT_PTR(el_capacity),
  2641. EVENT_PTR(el_conflict),
  2642. EVENT_PTR(cycles_t),
  2643. EVENT_PTR(cycles_ct),
  2644. EVENT_PTR(mem_ld_hsw),
  2645. EVENT_PTR(mem_st_hsw),
  2646. NULL
  2647. };
  2648. __init int intel_pmu_init(void)
  2649. {
  2650. union cpuid10_edx edx;
  2651. union cpuid10_eax eax;
  2652. union cpuid10_ebx ebx;
  2653. struct event_constraint *c;
  2654. unsigned int unused;
  2655. struct extra_reg *er;
  2656. int version, i;
  2657. if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) {
  2658. switch (boot_cpu_data.x86) {
  2659. case 0x6:
  2660. return p6_pmu_init();
  2661. case 0xb:
  2662. return knc_pmu_init();
  2663. case 0xf:
  2664. return p4_pmu_init();
  2665. }
  2666. return -ENODEV;
  2667. }
  2668. /*
  2669. * Check whether the Architectural PerfMon supports
  2670. * Branch Misses Retired hw_event or not.
  2671. */
  2672. cpuid(10, &eax.full, &ebx.full, &unused, &edx.full);
  2673. if (eax.split.mask_length < ARCH_PERFMON_EVENTS_COUNT)
  2674. return -ENODEV;
  2675. version = eax.split.version_id;
  2676. if (version < 2)
  2677. x86_pmu = core_pmu;
  2678. else
  2679. x86_pmu = intel_pmu;
  2680. x86_pmu.version = version;
  2681. x86_pmu.num_counters = eax.split.num_counters;
  2682. x86_pmu.cntval_bits = eax.split.bit_width;
  2683. x86_pmu.cntval_mask = (1ULL << eax.split.bit_width) - 1;
  2684. x86_pmu.events_maskl = ebx.full;
  2685. x86_pmu.events_mask_len = eax.split.mask_length;
  2686. x86_pmu.max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, x86_pmu.num_counters);
  2687. /*
  2688. * Quirk: v2 perfmon does not report fixed-purpose events, so
  2689. * assume at least 3 events:
  2690. */
  2691. if (version > 1)
  2692. x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
  2693. if (boot_cpu_has(X86_FEATURE_PDCM)) {
  2694. u64 capabilities;
  2695. rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
  2696. x86_pmu.intel_cap.capabilities = capabilities;
  2697. }
  2698. intel_ds_init();
  2699. x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last */
  2700. /*
  2701. * Install the hw-cache-events table:
  2702. */
  2703. switch (boot_cpu_data.x86_model) {
  2704. case 14: /* 65nm Core "Yonah" */
  2705. pr_cont("Core events, ");
  2706. break;
  2707. case 15: /* 65nm Core2 "Merom" */
  2708. x86_add_quirk(intel_clovertown_quirk);
  2709. case 22: /* 65nm Core2 "Merom-L" */
  2710. case 23: /* 45nm Core2 "Penryn" */
  2711. case 29: /* 45nm Core2 "Dunnington (MP) */
  2712. memcpy(hw_cache_event_ids, core2_hw_cache_event_ids,
  2713. sizeof(hw_cache_event_ids));
  2714. intel_pmu_lbr_init_core();
  2715. x86_pmu.event_constraints = intel_core2_event_constraints;
  2716. x86_pmu.pebs_constraints = intel_core2_pebs_event_constraints;
  2717. pr_cont("Core2 events, ");
  2718. break;
  2719. case 30: /* 45nm Nehalem */
  2720. case 26: /* 45nm Nehalem-EP */
  2721. case 46: /* 45nm Nehalem-EX */
  2722. memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids,
  2723. sizeof(hw_cache_event_ids));
  2724. memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs,
  2725. sizeof(hw_cache_extra_regs));
  2726. intel_pmu_lbr_init_nhm();
  2727. x86_pmu.event_constraints = intel_nehalem_event_constraints;
  2728. x86_pmu.pebs_constraints = intel_nehalem_pebs_event_constraints;
  2729. x86_pmu.enable_all = intel_pmu_nhm_enable_all;
  2730. x86_pmu.extra_regs = intel_nehalem_extra_regs;
  2731. x86_pmu.cpu_events = nhm_events_attrs;
  2732. /* UOPS_ISSUED.STALLED_CYCLES */
  2733. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
  2734. X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1);
  2735. /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */
  2736. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] =
  2737. X86_CONFIG(.event=0xb1, .umask=0x3f, .inv=1, .cmask=1);
  2738. x86_add_quirk(intel_nehalem_quirk);
  2739. pr_cont("Nehalem events, ");
  2740. break;
  2741. case 28: /* 45nm Atom "Pineview" */
  2742. case 38: /* 45nm Atom "Lincroft" */
  2743. case 39: /* 32nm Atom "Penwell" */
  2744. case 53: /* 32nm Atom "Cloverview" */
  2745. case 54: /* 32nm Atom "Cedarview" */
  2746. memcpy(hw_cache_event_ids, atom_hw_cache_event_ids,
  2747. sizeof(hw_cache_event_ids));
  2748. intel_pmu_lbr_init_atom();
  2749. x86_pmu.event_constraints = intel_gen_event_constraints;
  2750. x86_pmu.pebs_constraints = intel_atom_pebs_event_constraints;
  2751. pr_cont("Atom events, ");
  2752. break;
  2753. case 55: /* 22nm Atom "Silvermont" */
  2754. case 76: /* 14nm Atom "Airmont" */
  2755. case 77: /* 22nm Atom "Silvermont Avoton/Rangely" */
  2756. memcpy(hw_cache_event_ids, slm_hw_cache_event_ids,
  2757. sizeof(hw_cache_event_ids));
  2758. memcpy(hw_cache_extra_regs, slm_hw_cache_extra_regs,
  2759. sizeof(hw_cache_extra_regs));
  2760. intel_pmu_lbr_init_atom();
  2761. x86_pmu.event_constraints = intel_slm_event_constraints;
  2762. x86_pmu.pebs_constraints = intel_slm_pebs_event_constraints;
  2763. x86_pmu.extra_regs = intel_slm_extra_regs;
  2764. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2765. pr_cont("Silvermont events, ");
  2766. break;
  2767. case 37: /* 32nm Westmere */
  2768. case 44: /* 32nm Westmere-EP */
  2769. case 47: /* 32nm Westmere-EX */
  2770. memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids,
  2771. sizeof(hw_cache_event_ids));
  2772. memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs,
  2773. sizeof(hw_cache_extra_regs));
  2774. intel_pmu_lbr_init_nhm();
  2775. x86_pmu.event_constraints = intel_westmere_event_constraints;
  2776. x86_pmu.enable_all = intel_pmu_nhm_enable_all;
  2777. x86_pmu.pebs_constraints = intel_westmere_pebs_event_constraints;
  2778. x86_pmu.extra_regs = intel_westmere_extra_regs;
  2779. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2780. x86_pmu.cpu_events = nhm_events_attrs;
  2781. /* UOPS_ISSUED.STALLED_CYCLES */
  2782. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
  2783. X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1);
  2784. /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */
  2785. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] =
  2786. X86_CONFIG(.event=0xb1, .umask=0x3f, .inv=1, .cmask=1);
  2787. pr_cont("Westmere events, ");
  2788. break;
  2789. case 42: /* 32nm SandyBridge */
  2790. case 45: /* 32nm SandyBridge-E/EN/EP */
  2791. x86_add_quirk(intel_sandybridge_quirk);
  2792. x86_add_quirk(intel_ht_bug);
  2793. memcpy(hw_cache_event_ids, snb_hw_cache_event_ids,
  2794. sizeof(hw_cache_event_ids));
  2795. memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs,
  2796. sizeof(hw_cache_extra_regs));
  2797. intel_pmu_lbr_init_snb();
  2798. x86_pmu.event_constraints = intel_snb_event_constraints;
  2799. x86_pmu.pebs_constraints = intel_snb_pebs_event_constraints;
  2800. x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
  2801. if (boot_cpu_data.x86_model == 45)
  2802. x86_pmu.extra_regs = intel_snbep_extra_regs;
  2803. else
  2804. x86_pmu.extra_regs = intel_snb_extra_regs;
  2805. /* all extra regs are per-cpu when HT is on */
  2806. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2807. x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
  2808. x86_pmu.cpu_events = snb_events_attrs;
  2809. /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
  2810. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
  2811. X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1);
  2812. /* UOPS_DISPATCHED.THREAD,c=1,i=1 to count stall cycles*/
  2813. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] =
  2814. X86_CONFIG(.event=0xb1, .umask=0x01, .inv=1, .cmask=1);
  2815. pr_cont("SandyBridge events, ");
  2816. break;
  2817. case 58: /* 22nm IvyBridge */
  2818. case 62: /* 22nm IvyBridge-EP/EX */
  2819. x86_add_quirk(intel_ht_bug);
  2820. memcpy(hw_cache_event_ids, snb_hw_cache_event_ids,
  2821. sizeof(hw_cache_event_ids));
  2822. /* dTLB-load-misses on IVB is different than SNB */
  2823. hw_cache_event_ids[C(DTLB)][C(OP_READ)][C(RESULT_MISS)] = 0x8108; /* DTLB_LOAD_MISSES.DEMAND_LD_MISS_CAUSES_A_WALK */
  2824. memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs,
  2825. sizeof(hw_cache_extra_regs));
  2826. intel_pmu_lbr_init_snb();
  2827. x86_pmu.event_constraints = intel_ivb_event_constraints;
  2828. x86_pmu.pebs_constraints = intel_ivb_pebs_event_constraints;
  2829. x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
  2830. if (boot_cpu_data.x86_model == 62)
  2831. x86_pmu.extra_regs = intel_snbep_extra_regs;
  2832. else
  2833. x86_pmu.extra_regs = intel_snb_extra_regs;
  2834. /* all extra regs are per-cpu when HT is on */
  2835. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2836. x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
  2837. x86_pmu.cpu_events = snb_events_attrs;
  2838. /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */
  2839. intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] =
  2840. X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1);
  2841. pr_cont("IvyBridge events, ");
  2842. break;
  2843. case 60: /* 22nm Haswell Core */
  2844. case 63: /* 22nm Haswell Server */
  2845. case 69: /* 22nm Haswell ULT */
  2846. case 70: /* 22nm Haswell + GT3e (Intel Iris Pro graphics) */
  2847. x86_add_quirk(intel_ht_bug);
  2848. x86_pmu.late_ack = true;
  2849. memcpy(hw_cache_event_ids, hsw_hw_cache_event_ids, sizeof(hw_cache_event_ids));
  2850. memcpy(hw_cache_extra_regs, hsw_hw_cache_extra_regs, sizeof(hw_cache_extra_regs));
  2851. intel_pmu_lbr_init_hsw();
  2852. x86_pmu.event_constraints = intel_hsw_event_constraints;
  2853. x86_pmu.pebs_constraints = intel_hsw_pebs_event_constraints;
  2854. x86_pmu.extra_regs = intel_snbep_extra_regs;
  2855. x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
  2856. /* all extra regs are per-cpu when HT is on */
  2857. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2858. x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
  2859. x86_pmu.hw_config = hsw_hw_config;
  2860. x86_pmu.get_event_constraints = hsw_get_event_constraints;
  2861. x86_pmu.cpu_events = hsw_events_attrs;
  2862. x86_pmu.lbr_double_abort = true;
  2863. pr_cont("Haswell events, ");
  2864. break;
  2865. case 61: /* 14nm Broadwell Core-M */
  2866. case 86: /* 14nm Broadwell Xeon D */
  2867. x86_pmu.late_ack = true;
  2868. memcpy(hw_cache_event_ids, hsw_hw_cache_event_ids, sizeof(hw_cache_event_ids));
  2869. memcpy(hw_cache_extra_regs, hsw_hw_cache_extra_regs, sizeof(hw_cache_extra_regs));
  2870. /* L3_MISS_LOCAL_DRAM is BIT(26) in Broadwell */
  2871. hw_cache_extra_regs[C(LL)][C(OP_READ)][C(RESULT_MISS)] = HSW_DEMAND_READ |
  2872. BDW_L3_MISS|HSW_SNOOP_DRAM;
  2873. hw_cache_extra_regs[C(LL)][C(OP_WRITE)][C(RESULT_MISS)] = HSW_DEMAND_WRITE|BDW_L3_MISS|
  2874. HSW_SNOOP_DRAM;
  2875. hw_cache_extra_regs[C(NODE)][C(OP_READ)][C(RESULT_ACCESS)] = HSW_DEMAND_READ|
  2876. BDW_L3_MISS_LOCAL|HSW_SNOOP_DRAM;
  2877. hw_cache_extra_regs[C(NODE)][C(OP_WRITE)][C(RESULT_ACCESS)] = HSW_DEMAND_WRITE|
  2878. BDW_L3_MISS_LOCAL|HSW_SNOOP_DRAM;
  2879. intel_pmu_lbr_init_hsw();
  2880. x86_pmu.event_constraints = intel_bdw_event_constraints;
  2881. x86_pmu.pebs_constraints = intel_hsw_pebs_event_constraints;
  2882. x86_pmu.extra_regs = intel_snbep_extra_regs;
  2883. x86_pmu.pebs_aliases = intel_pebs_aliases_snb;
  2884. /* all extra regs are per-cpu when HT is on */
  2885. x86_pmu.flags |= PMU_FL_HAS_RSP_1;
  2886. x86_pmu.flags |= PMU_FL_NO_HT_SHARING;
  2887. x86_pmu.hw_config = hsw_hw_config;
  2888. x86_pmu.get_event_constraints = hsw_get_event_constraints;
  2889. x86_pmu.cpu_events = hsw_events_attrs;
  2890. x86_pmu.limit_period = bdw_limit_period;
  2891. pr_cont("Broadwell events, ");
  2892. break;
  2893. default:
  2894. switch (x86_pmu.version) {
  2895. case 1:
  2896. x86_pmu.event_constraints = intel_v1_event_constraints;
  2897. pr_cont("generic architected perfmon v1, ");
  2898. break;
  2899. default:
  2900. /*
  2901. * default constraints for v2 and up
  2902. */
  2903. x86_pmu.event_constraints = intel_gen_event_constraints;
  2904. pr_cont("generic architected perfmon, ");
  2905. break;
  2906. }
  2907. }
  2908. if (x86_pmu.num_counters > INTEL_PMC_MAX_GENERIC) {
  2909. WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!",
  2910. x86_pmu.num_counters, INTEL_PMC_MAX_GENERIC);
  2911. x86_pmu.num_counters = INTEL_PMC_MAX_GENERIC;
  2912. }
  2913. x86_pmu.intel_ctrl = (1 << x86_pmu.num_counters) - 1;
  2914. if (x86_pmu.num_counters_fixed > INTEL_PMC_MAX_FIXED) {
  2915. WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!",
  2916. x86_pmu.num_counters_fixed, INTEL_PMC_MAX_FIXED);
  2917. x86_pmu.num_counters_fixed = INTEL_PMC_MAX_FIXED;
  2918. }
  2919. x86_pmu.intel_ctrl |=
  2920. ((1LL << x86_pmu.num_counters_fixed)-1) << INTEL_PMC_IDX_FIXED;
  2921. if (x86_pmu.event_constraints) {
  2922. /*
  2923. * event on fixed counter2 (REF_CYCLES) only works on this
  2924. * counter, so do not extend mask to generic counters
  2925. */
  2926. for_each_event_constraint(c, x86_pmu.event_constraints) {
  2927. if (c->cmask != FIXED_EVENT_FLAGS
  2928. || c->idxmsk64 == INTEL_PMC_MSK_FIXED_REF_CYCLES) {
  2929. continue;
  2930. }
  2931. c->idxmsk64 |= (1ULL << x86_pmu.num_counters) - 1;
  2932. c->weight += x86_pmu.num_counters;
  2933. }
  2934. }
  2935. /*
  2936. * Access LBR MSR may cause #GP under certain circumstances.
  2937. * E.g. KVM doesn't support LBR MSR
  2938. * Check all LBT MSR here.
  2939. * Disable LBR access if any LBR MSRs can not be accessed.
  2940. */
  2941. if (x86_pmu.lbr_nr && !check_msr(x86_pmu.lbr_tos, 0x3UL))
  2942. x86_pmu.lbr_nr = 0;
  2943. for (i = 0; i < x86_pmu.lbr_nr; i++) {
  2944. if (!(check_msr(x86_pmu.lbr_from + i, 0xffffUL) &&
  2945. check_msr(x86_pmu.lbr_to + i, 0xffffUL)))
  2946. x86_pmu.lbr_nr = 0;
  2947. }
  2948. /*
  2949. * Access extra MSR may cause #GP under certain circumstances.
  2950. * E.g. KVM doesn't support offcore event
  2951. * Check all extra_regs here.
  2952. */
  2953. if (x86_pmu.extra_regs) {
  2954. for (er = x86_pmu.extra_regs; er->msr; er++) {
  2955. er->extra_msr_access = check_msr(er->msr, 0x1ffUL);
  2956. /* Disable LBR select mapping */
  2957. if ((er->idx == EXTRA_REG_LBR) && !er->extra_msr_access)
  2958. x86_pmu.lbr_sel_map = NULL;
  2959. }
  2960. }
  2961. /* Support full width counters using alternative MSR range */
  2962. if (x86_pmu.intel_cap.full_width_write) {
  2963. x86_pmu.max_period = x86_pmu.cntval_mask;
  2964. x86_pmu.perfctr = MSR_IA32_PMC0;
  2965. pr_cont("full-width counters, ");
  2966. }
  2967. return 0;
  2968. }
  2969. /*
  2970. * HT bug: phase 2 init
  2971. * Called once we have valid topology information to check
  2972. * whether or not HT is enabled
  2973. * If HT is off, then we disable the workaround
  2974. */
  2975. static __init int fixup_ht_bug(void)
  2976. {
  2977. int cpu = smp_processor_id();
  2978. int w, c;
  2979. /*
  2980. * problem not present on this CPU model, nothing to do
  2981. */
  2982. if (!(x86_pmu.flags & PMU_FL_EXCL_ENABLED))
  2983. return 0;
  2984. w = cpumask_weight(topology_thread_cpumask(cpu));
  2985. if (w > 1) {
  2986. pr_info("PMU erratum BJ122, BV98, HSD29 worked around, HT is on\n");
  2987. return 0;
  2988. }
  2989. watchdog_nmi_disable_all();
  2990. x86_pmu.flags &= ~(PMU_FL_EXCL_CNTRS | PMU_FL_EXCL_ENABLED);
  2991. x86_pmu.commit_scheduling = NULL;
  2992. x86_pmu.start_scheduling = NULL;
  2993. x86_pmu.stop_scheduling = NULL;
  2994. watchdog_nmi_enable_all();
  2995. get_online_cpus();
  2996. for_each_online_cpu(c) {
  2997. free_excl_cntrs(c);
  2998. }
  2999. put_online_cpus();
  3000. pr_info("PMU erratum BJ122, BV98, HSD29 workaround disabled, HT off\n");
  3001. return 0;
  3002. }
  3003. subsys_initcall(fixup_ht_bug)