perf_event_intel_ds.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  1. #include <linux/bitops.h>
  2. #include <linux/types.h>
  3. #include <linux/slab.h>
  4. #include <asm/perf_event.h>
  5. #include <asm/insn.h>
  6. #include "perf_event.h"
  7. /* The size of a BTS record in bytes: */
  8. #define BTS_RECORD_SIZE 24
  9. #define BTS_BUFFER_SIZE (PAGE_SIZE << 4)
  10. #define PEBS_BUFFER_SIZE PAGE_SIZE
  11. /*
  12. * pebs_record_32 for p4 and core not supported
  13. struct pebs_record_32 {
  14. u32 flags, ip;
  15. u32 ax, bc, cx, dx;
  16. u32 si, di, bp, sp;
  17. };
  18. */
  19. union intel_x86_pebs_dse {
  20. u64 val;
  21. struct {
  22. unsigned int ld_dse:4;
  23. unsigned int ld_stlb_miss:1;
  24. unsigned int ld_locked:1;
  25. unsigned int ld_reserved:26;
  26. };
  27. struct {
  28. unsigned int st_l1d_hit:1;
  29. unsigned int st_reserved1:3;
  30. unsigned int st_stlb_miss:1;
  31. unsigned int st_locked:1;
  32. unsigned int st_reserved2:26;
  33. };
  34. };
  35. /*
  36. * Map PEBS Load Latency Data Source encodings to generic
  37. * memory data source information
  38. */
  39. #define P(a, b) PERF_MEM_S(a, b)
  40. #define OP_LH (P(OP, LOAD) | P(LVL, HIT))
  41. #define SNOOP_NONE_MISS (P(SNOOP, NONE) | P(SNOOP, MISS))
  42. static const u64 pebs_data_source[] = {
  43. P(OP, LOAD) | P(LVL, MISS) | P(LVL, L3) | P(SNOOP, NA),/* 0x00:ukn L3 */
  44. OP_LH | P(LVL, L1) | P(SNOOP, NONE), /* 0x01: L1 local */
  45. OP_LH | P(LVL, LFB) | P(SNOOP, NONE), /* 0x02: LFB hit */
  46. OP_LH | P(LVL, L2) | P(SNOOP, NONE), /* 0x03: L2 hit */
  47. OP_LH | P(LVL, L3) | P(SNOOP, NONE), /* 0x04: L3 hit */
  48. OP_LH | P(LVL, L3) | P(SNOOP, MISS), /* 0x05: L3 hit, snoop miss */
  49. OP_LH | P(LVL, L3) | P(SNOOP, HIT), /* 0x06: L3 hit, snoop hit */
  50. OP_LH | P(LVL, L3) | P(SNOOP, HITM), /* 0x07: L3 hit, snoop hitm */
  51. OP_LH | P(LVL, REM_CCE1) | P(SNOOP, HIT), /* 0x08: L3 miss snoop hit */
  52. OP_LH | P(LVL, REM_CCE1) | P(SNOOP, HITM), /* 0x09: L3 miss snoop hitm*/
  53. OP_LH | P(LVL, LOC_RAM) | P(SNOOP, HIT), /* 0x0a: L3 miss, shared */
  54. OP_LH | P(LVL, REM_RAM1) | P(SNOOP, HIT), /* 0x0b: L3 miss, shared */
  55. OP_LH | P(LVL, LOC_RAM) | SNOOP_NONE_MISS,/* 0x0c: L3 miss, excl */
  56. OP_LH | P(LVL, REM_RAM1) | SNOOP_NONE_MISS,/* 0x0d: L3 miss, excl */
  57. OP_LH | P(LVL, IO) | P(SNOOP, NONE), /* 0x0e: I/O */
  58. OP_LH | P(LVL, UNC) | P(SNOOP, NONE), /* 0x0f: uncached */
  59. };
  60. static u64 precise_store_data(u64 status)
  61. {
  62. union intel_x86_pebs_dse dse;
  63. u64 val = P(OP, STORE) | P(SNOOP, NA) | P(LVL, L1) | P(TLB, L2);
  64. dse.val = status;
  65. /*
  66. * bit 4: TLB access
  67. * 1 = stored missed 2nd level TLB
  68. *
  69. * so it either hit the walker or the OS
  70. * otherwise hit 2nd level TLB
  71. */
  72. if (dse.st_stlb_miss)
  73. val |= P(TLB, MISS);
  74. else
  75. val |= P(TLB, HIT);
  76. /*
  77. * bit 0: hit L1 data cache
  78. * if not set, then all we know is that
  79. * it missed L1D
  80. */
  81. if (dse.st_l1d_hit)
  82. val |= P(LVL, HIT);
  83. else
  84. val |= P(LVL, MISS);
  85. /*
  86. * bit 5: Locked prefix
  87. */
  88. if (dse.st_locked)
  89. val |= P(LOCK, LOCKED);
  90. return val;
  91. }
  92. static u64 precise_store_data_hsw(u64 status)
  93. {
  94. union perf_mem_data_src dse;
  95. dse.val = 0;
  96. dse.mem_op = PERF_MEM_OP_STORE;
  97. dse.mem_lvl = PERF_MEM_LVL_NA;
  98. if (status & 1)
  99. dse.mem_lvl = PERF_MEM_LVL_L1;
  100. /* Nothing else supported. Sorry. */
  101. return dse.val;
  102. }
  103. static u64 load_latency_data(u64 status)
  104. {
  105. union intel_x86_pebs_dse dse;
  106. u64 val;
  107. int model = boot_cpu_data.x86_model;
  108. int fam = boot_cpu_data.x86;
  109. dse.val = status;
  110. /*
  111. * use the mapping table for bit 0-3
  112. */
  113. val = pebs_data_source[dse.ld_dse];
  114. /*
  115. * Nehalem models do not support TLB, Lock infos
  116. */
  117. if (fam == 0x6 && (model == 26 || model == 30
  118. || model == 31 || model == 46)) {
  119. val |= P(TLB, NA) | P(LOCK, NA);
  120. return val;
  121. }
  122. /*
  123. * bit 4: TLB access
  124. * 0 = did not miss 2nd level TLB
  125. * 1 = missed 2nd level TLB
  126. */
  127. if (dse.ld_stlb_miss)
  128. val |= P(TLB, MISS) | P(TLB, L2);
  129. else
  130. val |= P(TLB, HIT) | P(TLB, L1) | P(TLB, L2);
  131. /*
  132. * bit 5: locked prefix
  133. */
  134. if (dse.ld_locked)
  135. val |= P(LOCK, LOCKED);
  136. return val;
  137. }
  138. struct pebs_record_core {
  139. u64 flags, ip;
  140. u64 ax, bx, cx, dx;
  141. u64 si, di, bp, sp;
  142. u64 r8, r9, r10, r11;
  143. u64 r12, r13, r14, r15;
  144. };
  145. struct pebs_record_nhm {
  146. u64 flags, ip;
  147. u64 ax, bx, cx, dx;
  148. u64 si, di, bp, sp;
  149. u64 r8, r9, r10, r11;
  150. u64 r12, r13, r14, r15;
  151. u64 status, dla, dse, lat;
  152. };
  153. /*
  154. * Same as pebs_record_nhm, with two additional fields.
  155. */
  156. struct pebs_record_hsw {
  157. u64 flags, ip;
  158. u64 ax, bx, cx, dx;
  159. u64 si, di, bp, sp;
  160. u64 r8, r9, r10, r11;
  161. u64 r12, r13, r14, r15;
  162. u64 status, dla, dse, lat;
  163. u64 real_ip; /* the actual eventing ip */
  164. u64 tsx_tuning; /* TSX abort cycles and flags */
  165. };
  166. union hsw_tsx_tuning {
  167. struct {
  168. u32 cycles_last_block : 32,
  169. hle_abort : 1,
  170. rtm_abort : 1,
  171. instruction_abort : 1,
  172. non_instruction_abort : 1,
  173. retry : 1,
  174. data_conflict : 1,
  175. capacity_writes : 1,
  176. capacity_reads : 1;
  177. };
  178. u64 value;
  179. };
  180. void init_debug_store_on_cpu(int cpu)
  181. {
  182. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  183. if (!ds)
  184. return;
  185. wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA,
  186. (u32)((u64)(unsigned long)ds),
  187. (u32)((u64)(unsigned long)ds >> 32));
  188. }
  189. void fini_debug_store_on_cpu(int cpu)
  190. {
  191. if (!per_cpu(cpu_hw_events, cpu).ds)
  192. return;
  193. wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0);
  194. }
  195. static int alloc_pebs_buffer(int cpu)
  196. {
  197. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  198. int node = cpu_to_node(cpu);
  199. int max, thresh = 1; /* always use a single PEBS record */
  200. void *buffer;
  201. if (!x86_pmu.pebs)
  202. return 0;
  203. buffer = kzalloc_node(PEBS_BUFFER_SIZE, GFP_KERNEL, node);
  204. if (unlikely(!buffer))
  205. return -ENOMEM;
  206. max = PEBS_BUFFER_SIZE / x86_pmu.pebs_record_size;
  207. ds->pebs_buffer_base = (u64)(unsigned long)buffer;
  208. ds->pebs_index = ds->pebs_buffer_base;
  209. ds->pebs_absolute_maximum = ds->pebs_buffer_base +
  210. max * x86_pmu.pebs_record_size;
  211. ds->pebs_interrupt_threshold = ds->pebs_buffer_base +
  212. thresh * x86_pmu.pebs_record_size;
  213. return 0;
  214. }
  215. static void release_pebs_buffer(int cpu)
  216. {
  217. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  218. if (!ds || !x86_pmu.pebs)
  219. return;
  220. kfree((void *)(unsigned long)ds->pebs_buffer_base);
  221. ds->pebs_buffer_base = 0;
  222. }
  223. static int alloc_bts_buffer(int cpu)
  224. {
  225. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  226. int node = cpu_to_node(cpu);
  227. int max, thresh;
  228. void *buffer;
  229. if (!x86_pmu.bts)
  230. return 0;
  231. buffer = kzalloc_node(BTS_BUFFER_SIZE, GFP_KERNEL, node);
  232. if (unlikely(!buffer))
  233. return -ENOMEM;
  234. max = BTS_BUFFER_SIZE / BTS_RECORD_SIZE;
  235. thresh = max / 16;
  236. ds->bts_buffer_base = (u64)(unsigned long)buffer;
  237. ds->bts_index = ds->bts_buffer_base;
  238. ds->bts_absolute_maximum = ds->bts_buffer_base +
  239. max * BTS_RECORD_SIZE;
  240. ds->bts_interrupt_threshold = ds->bts_absolute_maximum -
  241. thresh * BTS_RECORD_SIZE;
  242. return 0;
  243. }
  244. static void release_bts_buffer(int cpu)
  245. {
  246. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  247. if (!ds || !x86_pmu.bts)
  248. return;
  249. kfree((void *)(unsigned long)ds->bts_buffer_base);
  250. ds->bts_buffer_base = 0;
  251. }
  252. static int alloc_ds_buffer(int cpu)
  253. {
  254. int node = cpu_to_node(cpu);
  255. struct debug_store *ds;
  256. ds = kzalloc_node(sizeof(*ds), GFP_KERNEL, node);
  257. if (unlikely(!ds))
  258. return -ENOMEM;
  259. per_cpu(cpu_hw_events, cpu).ds = ds;
  260. return 0;
  261. }
  262. static void release_ds_buffer(int cpu)
  263. {
  264. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  265. if (!ds)
  266. return;
  267. per_cpu(cpu_hw_events, cpu).ds = NULL;
  268. kfree(ds);
  269. }
  270. void release_ds_buffers(void)
  271. {
  272. int cpu;
  273. if (!x86_pmu.bts && !x86_pmu.pebs)
  274. return;
  275. get_online_cpus();
  276. for_each_online_cpu(cpu)
  277. fini_debug_store_on_cpu(cpu);
  278. for_each_possible_cpu(cpu) {
  279. release_pebs_buffer(cpu);
  280. release_bts_buffer(cpu);
  281. release_ds_buffer(cpu);
  282. }
  283. put_online_cpus();
  284. }
  285. void reserve_ds_buffers(void)
  286. {
  287. int bts_err = 0, pebs_err = 0;
  288. int cpu;
  289. x86_pmu.bts_active = 0;
  290. x86_pmu.pebs_active = 0;
  291. if (!x86_pmu.bts && !x86_pmu.pebs)
  292. return;
  293. if (!x86_pmu.bts)
  294. bts_err = 1;
  295. if (!x86_pmu.pebs)
  296. pebs_err = 1;
  297. get_online_cpus();
  298. for_each_possible_cpu(cpu) {
  299. if (alloc_ds_buffer(cpu)) {
  300. bts_err = 1;
  301. pebs_err = 1;
  302. }
  303. if (!bts_err && alloc_bts_buffer(cpu))
  304. bts_err = 1;
  305. if (!pebs_err && alloc_pebs_buffer(cpu))
  306. pebs_err = 1;
  307. if (bts_err && pebs_err)
  308. break;
  309. }
  310. if (bts_err) {
  311. for_each_possible_cpu(cpu)
  312. release_bts_buffer(cpu);
  313. }
  314. if (pebs_err) {
  315. for_each_possible_cpu(cpu)
  316. release_pebs_buffer(cpu);
  317. }
  318. if (bts_err && pebs_err) {
  319. for_each_possible_cpu(cpu)
  320. release_ds_buffer(cpu);
  321. } else {
  322. if (x86_pmu.bts && !bts_err)
  323. x86_pmu.bts_active = 1;
  324. if (x86_pmu.pebs && !pebs_err)
  325. x86_pmu.pebs_active = 1;
  326. for_each_online_cpu(cpu)
  327. init_debug_store_on_cpu(cpu);
  328. }
  329. put_online_cpus();
  330. }
  331. /*
  332. * BTS
  333. */
  334. struct event_constraint bts_constraint =
  335. EVENT_CONSTRAINT(0, 1ULL << INTEL_PMC_IDX_FIXED_BTS, 0);
  336. void intel_pmu_enable_bts(u64 config)
  337. {
  338. unsigned long debugctlmsr;
  339. debugctlmsr = get_debugctlmsr();
  340. debugctlmsr |= DEBUGCTLMSR_TR;
  341. debugctlmsr |= DEBUGCTLMSR_BTS;
  342. debugctlmsr |= DEBUGCTLMSR_BTINT;
  343. if (!(config & ARCH_PERFMON_EVENTSEL_OS))
  344. debugctlmsr |= DEBUGCTLMSR_BTS_OFF_OS;
  345. if (!(config & ARCH_PERFMON_EVENTSEL_USR))
  346. debugctlmsr |= DEBUGCTLMSR_BTS_OFF_USR;
  347. update_debugctlmsr(debugctlmsr);
  348. }
  349. void intel_pmu_disable_bts(void)
  350. {
  351. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  352. unsigned long debugctlmsr;
  353. if (!cpuc->ds)
  354. return;
  355. debugctlmsr = get_debugctlmsr();
  356. debugctlmsr &=
  357. ~(DEBUGCTLMSR_TR | DEBUGCTLMSR_BTS | DEBUGCTLMSR_BTINT |
  358. DEBUGCTLMSR_BTS_OFF_OS | DEBUGCTLMSR_BTS_OFF_USR);
  359. update_debugctlmsr(debugctlmsr);
  360. }
  361. int intel_pmu_drain_bts_buffer(void)
  362. {
  363. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  364. struct debug_store *ds = cpuc->ds;
  365. struct bts_record {
  366. u64 from;
  367. u64 to;
  368. u64 flags;
  369. };
  370. struct perf_event *event = cpuc->events[INTEL_PMC_IDX_FIXED_BTS];
  371. struct bts_record *at, *top;
  372. struct perf_output_handle handle;
  373. struct perf_event_header header;
  374. struct perf_sample_data data;
  375. struct pt_regs regs;
  376. if (!event)
  377. return 0;
  378. if (!x86_pmu.bts_active)
  379. return 0;
  380. at = (struct bts_record *)(unsigned long)ds->bts_buffer_base;
  381. top = (struct bts_record *)(unsigned long)ds->bts_index;
  382. if (top <= at)
  383. return 0;
  384. memset(&regs, 0, sizeof(regs));
  385. ds->bts_index = ds->bts_buffer_base;
  386. perf_sample_data_init(&data, 0, event->hw.last_period);
  387. /*
  388. * Prepare a generic sample, i.e. fill in the invariant fields.
  389. * We will overwrite the from and to address before we output
  390. * the sample.
  391. */
  392. perf_prepare_sample(&header, &data, event, &regs);
  393. if (perf_output_begin(&handle, event, header.size * (top - at)))
  394. return 1;
  395. for (; at < top; at++) {
  396. data.ip = at->from;
  397. data.addr = at->to;
  398. perf_output_sample(&handle, &header, &data, event);
  399. }
  400. perf_output_end(&handle);
  401. /* There's new data available. */
  402. event->hw.interrupts++;
  403. event->pending_kill = POLL_IN;
  404. return 1;
  405. }
  406. /*
  407. * PEBS
  408. */
  409. struct event_constraint intel_core2_pebs_event_constraints[] = {
  410. INTEL_UEVENT_CONSTRAINT(0x00c0, 0x1), /* INST_RETIRED.ANY */
  411. INTEL_UEVENT_CONSTRAINT(0xfec1, 0x1), /* X87_OPS_RETIRED.ANY */
  412. INTEL_UEVENT_CONSTRAINT(0x00c5, 0x1), /* BR_INST_RETIRED.MISPRED */
  413. INTEL_UEVENT_CONSTRAINT(0x1fc7, 0x1), /* SIMD_INST_RETURED.ANY */
  414. INTEL_EVENT_CONSTRAINT(0xcb, 0x1), /* MEM_LOAD_RETIRED.* */
  415. EVENT_CONSTRAINT_END
  416. };
  417. struct event_constraint intel_atom_pebs_event_constraints[] = {
  418. INTEL_UEVENT_CONSTRAINT(0x00c0, 0x1), /* INST_RETIRED.ANY */
  419. INTEL_UEVENT_CONSTRAINT(0x00c5, 0x1), /* MISPREDICTED_BRANCH_RETIRED */
  420. INTEL_EVENT_CONSTRAINT(0xcb, 0x1), /* MEM_LOAD_RETIRED.* */
  421. EVENT_CONSTRAINT_END
  422. };
  423. struct event_constraint intel_slm_pebs_event_constraints[] = {
  424. INTEL_UEVENT_CONSTRAINT(0x0103, 0x1), /* REHABQ.LD_BLOCK_ST_FORWARD_PS */
  425. INTEL_UEVENT_CONSTRAINT(0x0803, 0x1), /* REHABQ.LD_SPLITS_PS */
  426. INTEL_UEVENT_CONSTRAINT(0x0204, 0x1), /* MEM_UOPS_RETIRED.L2_HIT_LOADS_PS */
  427. INTEL_UEVENT_CONSTRAINT(0x0404, 0x1), /* MEM_UOPS_RETIRED.L2_MISS_LOADS_PS */
  428. INTEL_UEVENT_CONSTRAINT(0x0804, 0x1), /* MEM_UOPS_RETIRED.DTLB_MISS_LOADS_PS */
  429. INTEL_UEVENT_CONSTRAINT(0x2004, 0x1), /* MEM_UOPS_RETIRED.HITM_PS */
  430. INTEL_UEVENT_CONSTRAINT(0x00c0, 0x1), /* INST_RETIRED.ANY_PS */
  431. INTEL_UEVENT_CONSTRAINT(0x00c4, 0x1), /* BR_INST_RETIRED.ALL_BRANCHES_PS */
  432. INTEL_UEVENT_CONSTRAINT(0x7ec4, 0x1), /* BR_INST_RETIRED.JCC_PS */
  433. INTEL_UEVENT_CONSTRAINT(0xbfc4, 0x1), /* BR_INST_RETIRED.FAR_BRANCH_PS */
  434. INTEL_UEVENT_CONSTRAINT(0xebc4, 0x1), /* BR_INST_RETIRED.NON_RETURN_IND_PS */
  435. INTEL_UEVENT_CONSTRAINT(0xf7c4, 0x1), /* BR_INST_RETIRED.RETURN_PS */
  436. INTEL_UEVENT_CONSTRAINT(0xf9c4, 0x1), /* BR_INST_RETIRED.CALL_PS */
  437. INTEL_UEVENT_CONSTRAINT(0xfbc4, 0x1), /* BR_INST_RETIRED.IND_CALL_PS */
  438. INTEL_UEVENT_CONSTRAINT(0xfdc4, 0x1), /* BR_INST_RETIRED.REL_CALL_PS */
  439. INTEL_UEVENT_CONSTRAINT(0xfec4, 0x1), /* BR_INST_RETIRED.TAKEN_JCC_PS */
  440. INTEL_UEVENT_CONSTRAINT(0x00c5, 0x1), /* BR_INST_MISP_RETIRED.ALL_BRANCHES_PS */
  441. INTEL_UEVENT_CONSTRAINT(0x7ec5, 0x1), /* BR_INST_MISP_RETIRED.JCC_PS */
  442. INTEL_UEVENT_CONSTRAINT(0xebc5, 0x1), /* BR_INST_MISP_RETIRED.NON_RETURN_IND_PS */
  443. INTEL_UEVENT_CONSTRAINT(0xf7c5, 0x1), /* BR_INST_MISP_RETIRED.RETURN_PS */
  444. INTEL_UEVENT_CONSTRAINT(0xfbc5, 0x1), /* BR_INST_MISP_RETIRED.IND_CALL_PS */
  445. INTEL_UEVENT_CONSTRAINT(0xfec5, 0x1), /* BR_INST_MISP_RETIRED.TAKEN_JCC_PS */
  446. EVENT_CONSTRAINT_END
  447. };
  448. struct event_constraint intel_nehalem_pebs_event_constraints[] = {
  449. INTEL_PLD_CONSTRAINT(0x100b, 0xf), /* MEM_INST_RETIRED.* */
  450. INTEL_EVENT_CONSTRAINT(0x0f, 0xf), /* MEM_UNCORE_RETIRED.* */
  451. INTEL_UEVENT_CONSTRAINT(0x010c, 0xf), /* MEM_STORE_RETIRED.DTLB_MISS */
  452. INTEL_EVENT_CONSTRAINT(0xc0, 0xf), /* INST_RETIRED.ANY */
  453. INTEL_EVENT_CONSTRAINT(0xc2, 0xf), /* UOPS_RETIRED.* */
  454. INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */
  455. INTEL_UEVENT_CONSTRAINT(0x02c5, 0xf), /* BR_MISP_RETIRED.NEAR_CALL */
  456. INTEL_EVENT_CONSTRAINT(0xc7, 0xf), /* SSEX_UOPS_RETIRED.* */
  457. INTEL_UEVENT_CONSTRAINT(0x20c8, 0xf), /* ITLB_MISS_RETIRED */
  458. INTEL_EVENT_CONSTRAINT(0xcb, 0xf), /* MEM_LOAD_RETIRED.* */
  459. INTEL_EVENT_CONSTRAINT(0xf7, 0xf), /* FP_ASSIST.* */
  460. EVENT_CONSTRAINT_END
  461. };
  462. struct event_constraint intel_westmere_pebs_event_constraints[] = {
  463. INTEL_PLD_CONSTRAINT(0x100b, 0xf), /* MEM_INST_RETIRED.* */
  464. INTEL_EVENT_CONSTRAINT(0x0f, 0xf), /* MEM_UNCORE_RETIRED.* */
  465. INTEL_UEVENT_CONSTRAINT(0x010c, 0xf), /* MEM_STORE_RETIRED.DTLB_MISS */
  466. INTEL_EVENT_CONSTRAINT(0xc0, 0xf), /* INSTR_RETIRED.* */
  467. INTEL_EVENT_CONSTRAINT(0xc2, 0xf), /* UOPS_RETIRED.* */
  468. INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */
  469. INTEL_EVENT_CONSTRAINT(0xc5, 0xf), /* BR_MISP_RETIRED.* */
  470. INTEL_EVENT_CONSTRAINT(0xc7, 0xf), /* SSEX_UOPS_RETIRED.* */
  471. INTEL_UEVENT_CONSTRAINT(0x20c8, 0xf), /* ITLB_MISS_RETIRED */
  472. INTEL_EVENT_CONSTRAINT(0xcb, 0xf), /* MEM_LOAD_RETIRED.* */
  473. INTEL_EVENT_CONSTRAINT(0xf7, 0xf), /* FP_ASSIST.* */
  474. EVENT_CONSTRAINT_END
  475. };
  476. struct event_constraint intel_snb_pebs_event_constraints[] = {
  477. INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PRECDIST */
  478. INTEL_UEVENT_CONSTRAINT(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
  479. INTEL_UEVENT_CONSTRAINT(0x02c2, 0xf), /* UOPS_RETIRED.RETIRE_SLOTS */
  480. INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */
  481. INTEL_EVENT_CONSTRAINT(0xc5, 0xf), /* BR_MISP_RETIRED.* */
  482. INTEL_PLD_CONSTRAINT(0x01cd, 0x8), /* MEM_TRANS_RETIRED.LAT_ABOVE_THR */
  483. INTEL_PST_CONSTRAINT(0x02cd, 0x8), /* MEM_TRANS_RETIRED.PRECISE_STORES */
  484. INTEL_EVENT_CONSTRAINT(0xd0, 0xf), /* MEM_UOP_RETIRED.* */
  485. INTEL_EVENT_CONSTRAINT(0xd1, 0xf), /* MEM_LOAD_UOPS_RETIRED.* */
  486. INTEL_EVENT_CONSTRAINT(0xd2, 0xf), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
  487. INTEL_UEVENT_CONSTRAINT(0x02d4, 0xf), /* MEM_LOAD_UOPS_MISC_RETIRED.LLC_MISS */
  488. EVENT_CONSTRAINT_END
  489. };
  490. struct event_constraint intel_ivb_pebs_event_constraints[] = {
  491. INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PRECDIST */
  492. INTEL_UEVENT_CONSTRAINT(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
  493. INTEL_UEVENT_CONSTRAINT(0x02c2, 0xf), /* UOPS_RETIRED.RETIRE_SLOTS */
  494. INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */
  495. INTEL_EVENT_CONSTRAINT(0xc5, 0xf), /* BR_MISP_RETIRED.* */
  496. INTEL_PLD_CONSTRAINT(0x01cd, 0x8), /* MEM_TRANS_RETIRED.LAT_ABOVE_THR */
  497. INTEL_PST_CONSTRAINT(0x02cd, 0x8), /* MEM_TRANS_RETIRED.PRECISE_STORES */
  498. INTEL_EVENT_CONSTRAINT(0xd0, 0xf), /* MEM_UOP_RETIRED.* */
  499. INTEL_EVENT_CONSTRAINT(0xd1, 0xf), /* MEM_LOAD_UOPS_RETIRED.* */
  500. INTEL_EVENT_CONSTRAINT(0xd2, 0xf), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
  501. INTEL_EVENT_CONSTRAINT(0xd3, 0xf), /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.* */
  502. EVENT_CONSTRAINT_END
  503. };
  504. struct event_constraint intel_hsw_pebs_event_constraints[] = {
  505. INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PRECDIST */
  506. INTEL_PST_HSW_CONSTRAINT(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
  507. INTEL_UEVENT_CONSTRAINT(0x02c2, 0xf), /* UOPS_RETIRED.RETIRE_SLOTS */
  508. INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */
  509. INTEL_UEVENT_CONSTRAINT(0x01c5, 0xf), /* BR_MISP_RETIRED.CONDITIONAL */
  510. INTEL_UEVENT_CONSTRAINT(0x04c5, 0xf), /* BR_MISP_RETIRED.ALL_BRANCHES */
  511. INTEL_UEVENT_CONSTRAINT(0x20c5, 0xf), /* BR_MISP_RETIRED.NEAR_TAKEN */
  512. INTEL_PLD_CONSTRAINT(0x01cd, 0x8), /* MEM_TRANS_RETIRED.* */
  513. /* MEM_UOPS_RETIRED.STLB_MISS_LOADS */
  514. INTEL_UEVENT_CONSTRAINT(0x11d0, 0xf),
  515. /* MEM_UOPS_RETIRED.STLB_MISS_STORES */
  516. INTEL_UEVENT_CONSTRAINT(0x12d0, 0xf),
  517. INTEL_UEVENT_CONSTRAINT(0x21d0, 0xf), /* MEM_UOPS_RETIRED.LOCK_LOADS */
  518. INTEL_UEVENT_CONSTRAINT(0x41d0, 0xf), /* MEM_UOPS_RETIRED.SPLIT_LOADS */
  519. /* MEM_UOPS_RETIRED.SPLIT_STORES */
  520. INTEL_UEVENT_CONSTRAINT(0x42d0, 0xf),
  521. INTEL_UEVENT_CONSTRAINT(0x81d0, 0xf), /* MEM_UOPS_RETIRED.ALL_LOADS */
  522. INTEL_PST_HSW_CONSTRAINT(0x82d0, 0xf), /* MEM_UOPS_RETIRED.ALL_STORES */
  523. INTEL_UEVENT_CONSTRAINT(0x01d1, 0xf), /* MEM_LOAD_UOPS_RETIRED.L1_HIT */
  524. INTEL_UEVENT_CONSTRAINT(0x02d1, 0xf), /* MEM_LOAD_UOPS_RETIRED.L2_HIT */
  525. INTEL_UEVENT_CONSTRAINT(0x04d1, 0xf), /* MEM_LOAD_UOPS_RETIRED.L3_HIT */
  526. /* MEM_LOAD_UOPS_RETIRED.HIT_LFB */
  527. INTEL_UEVENT_CONSTRAINT(0x40d1, 0xf),
  528. /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_MISS */
  529. INTEL_UEVENT_CONSTRAINT(0x01d2, 0xf),
  530. /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_HIT */
  531. INTEL_UEVENT_CONSTRAINT(0x02d2, 0xf),
  532. /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.LOCAL_DRAM */
  533. INTEL_UEVENT_CONSTRAINT(0x01d3, 0xf),
  534. INTEL_UEVENT_CONSTRAINT(0x04c8, 0xf), /* HLE_RETIRED.Abort */
  535. INTEL_UEVENT_CONSTRAINT(0x04c9, 0xf), /* RTM_RETIRED.Abort */
  536. EVENT_CONSTRAINT_END
  537. };
  538. struct event_constraint *intel_pebs_constraints(struct perf_event *event)
  539. {
  540. struct event_constraint *c;
  541. if (!event->attr.precise_ip)
  542. return NULL;
  543. if (x86_pmu.pebs_constraints) {
  544. for_each_event_constraint(c, x86_pmu.pebs_constraints) {
  545. if ((event->hw.config & c->cmask) == c->code) {
  546. event->hw.flags |= c->flags;
  547. return c;
  548. }
  549. }
  550. }
  551. return &emptyconstraint;
  552. }
  553. void intel_pmu_pebs_enable(struct perf_event *event)
  554. {
  555. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  556. struct hw_perf_event *hwc = &event->hw;
  557. hwc->config &= ~ARCH_PERFMON_EVENTSEL_INT;
  558. cpuc->pebs_enabled |= 1ULL << hwc->idx;
  559. if (event->hw.flags & PERF_X86_EVENT_PEBS_LDLAT)
  560. cpuc->pebs_enabled |= 1ULL << (hwc->idx + 32);
  561. else if (event->hw.flags & PERF_X86_EVENT_PEBS_ST)
  562. cpuc->pebs_enabled |= 1ULL << 63;
  563. }
  564. void intel_pmu_pebs_disable(struct perf_event *event)
  565. {
  566. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  567. struct hw_perf_event *hwc = &event->hw;
  568. cpuc->pebs_enabled &= ~(1ULL << hwc->idx);
  569. if (event->hw.constraint->flags & PERF_X86_EVENT_PEBS_LDLAT)
  570. cpuc->pebs_enabled &= ~(1ULL << (hwc->idx + 32));
  571. else if (event->hw.constraint->flags & PERF_X86_EVENT_PEBS_ST)
  572. cpuc->pebs_enabled &= ~(1ULL << 63);
  573. if (cpuc->enabled)
  574. wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled);
  575. hwc->config |= ARCH_PERFMON_EVENTSEL_INT;
  576. }
  577. void intel_pmu_pebs_enable_all(void)
  578. {
  579. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  580. if (cpuc->pebs_enabled)
  581. wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled);
  582. }
  583. void intel_pmu_pebs_disable_all(void)
  584. {
  585. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  586. if (cpuc->pebs_enabled)
  587. wrmsrl(MSR_IA32_PEBS_ENABLE, 0);
  588. }
  589. static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)
  590. {
  591. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  592. unsigned long from = cpuc->lbr_entries[0].from;
  593. unsigned long old_to, to = cpuc->lbr_entries[0].to;
  594. unsigned long ip = regs->ip;
  595. int is_64bit = 0;
  596. /*
  597. * We don't need to fixup if the PEBS assist is fault like
  598. */
  599. if (!x86_pmu.intel_cap.pebs_trap)
  600. return 1;
  601. /*
  602. * No LBR entry, no basic block, no rewinding
  603. */
  604. if (!cpuc->lbr_stack.nr || !from || !to)
  605. return 0;
  606. /*
  607. * Basic blocks should never cross user/kernel boundaries
  608. */
  609. if (kernel_ip(ip) != kernel_ip(to))
  610. return 0;
  611. /*
  612. * unsigned math, either ip is before the start (impossible) or
  613. * the basic block is larger than 1 page (sanity)
  614. */
  615. if ((ip - to) > PAGE_SIZE)
  616. return 0;
  617. /*
  618. * We sampled a branch insn, rewind using the LBR stack
  619. */
  620. if (ip == to) {
  621. set_linear_ip(regs, from);
  622. return 1;
  623. }
  624. do {
  625. struct insn insn;
  626. u8 buf[MAX_INSN_SIZE];
  627. void *kaddr;
  628. old_to = to;
  629. if (!kernel_ip(ip)) {
  630. int bytes, size = MAX_INSN_SIZE;
  631. bytes = copy_from_user_nmi(buf, (void __user *)to, size);
  632. if (bytes != size)
  633. return 0;
  634. kaddr = buf;
  635. } else
  636. kaddr = (void *)to;
  637. #ifdef CONFIG_X86_64
  638. is_64bit = kernel_ip(to) || !test_thread_flag(TIF_IA32);
  639. #endif
  640. insn_init(&insn, kaddr, is_64bit);
  641. insn_get_length(&insn);
  642. to += insn.length;
  643. } while (to < ip);
  644. if (to == ip) {
  645. set_linear_ip(regs, old_to);
  646. return 1;
  647. }
  648. /*
  649. * Even though we decoded the basic block, the instruction stream
  650. * never matched the given IP, either the TO or the IP got corrupted.
  651. */
  652. return 0;
  653. }
  654. static inline u64 intel_hsw_weight(struct pebs_record_hsw *pebs)
  655. {
  656. if (pebs->tsx_tuning) {
  657. union hsw_tsx_tuning tsx = { .value = pebs->tsx_tuning };
  658. return tsx.cycles_last_block;
  659. }
  660. return 0;
  661. }
  662. static void __intel_pmu_pebs_event(struct perf_event *event,
  663. struct pt_regs *iregs, void *__pebs)
  664. {
  665. /*
  666. * We cast to pebs_record_nhm to get the load latency data
  667. * if extra_reg MSR_PEBS_LD_LAT_THRESHOLD used
  668. * We cast to the biggest PEBS record are careful not
  669. * to access out-of-bounds members.
  670. */
  671. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  672. struct pebs_record_hsw *pebs = __pebs;
  673. struct perf_sample_data data;
  674. struct pt_regs regs;
  675. u64 sample_type;
  676. int fll, fst;
  677. if (!intel_pmu_save_and_restart(event))
  678. return;
  679. fll = event->hw.flags & PERF_X86_EVENT_PEBS_LDLAT;
  680. fst = event->hw.flags & (PERF_X86_EVENT_PEBS_ST |
  681. PERF_X86_EVENT_PEBS_ST_HSW);
  682. perf_sample_data_init(&data, 0, event->hw.last_period);
  683. data.period = event->hw.last_period;
  684. sample_type = event->attr.sample_type;
  685. /*
  686. * if PEBS-LL or PreciseStore
  687. */
  688. if (fll || fst) {
  689. /*
  690. * Use latency for weight (only avail with PEBS-LL)
  691. */
  692. if (fll && (sample_type & PERF_SAMPLE_WEIGHT))
  693. data.weight = pebs->lat;
  694. /*
  695. * data.data_src encodes the data source
  696. */
  697. if (sample_type & PERF_SAMPLE_DATA_SRC) {
  698. if (fll)
  699. data.data_src.val = load_latency_data(pebs->dse);
  700. else if (event->hw.flags & PERF_X86_EVENT_PEBS_ST_HSW)
  701. data.data_src.val =
  702. precise_store_data_hsw(pebs->dse);
  703. else
  704. data.data_src.val = precise_store_data(pebs->dse);
  705. }
  706. }
  707. /*
  708. * We use the interrupt regs as a base because the PEBS record
  709. * does not contain a full regs set, specifically it seems to
  710. * lack segment descriptors, which get used by things like
  711. * user_mode().
  712. *
  713. * In the simple case fix up only the IP and BP,SP regs, for
  714. * PERF_SAMPLE_IP and PERF_SAMPLE_CALLCHAIN to function properly.
  715. * A possible PERF_SAMPLE_REGS will have to transfer all regs.
  716. */
  717. regs = *iregs;
  718. regs.flags = pebs->flags;
  719. set_linear_ip(&regs, pebs->ip);
  720. regs.bp = pebs->bp;
  721. regs.sp = pebs->sp;
  722. if (event->attr.precise_ip > 1 && x86_pmu.intel_cap.pebs_format >= 2) {
  723. regs.ip = pebs->real_ip;
  724. regs.flags |= PERF_EFLAGS_EXACT;
  725. } else if (event->attr.precise_ip > 1 && intel_pmu_pebs_fixup_ip(&regs))
  726. regs.flags |= PERF_EFLAGS_EXACT;
  727. else
  728. regs.flags &= ~PERF_EFLAGS_EXACT;
  729. if ((event->attr.sample_type & PERF_SAMPLE_ADDR) &&
  730. x86_pmu.intel_cap.pebs_format >= 1)
  731. data.addr = pebs->dla;
  732. /* Only set the TSX weight when no memory weight was requested. */
  733. if ((event->attr.sample_type & PERF_SAMPLE_WEIGHT) &&
  734. !fll &&
  735. (x86_pmu.intel_cap.pebs_format >= 2))
  736. data.weight = intel_hsw_weight(pebs);
  737. if (has_branch_stack(event))
  738. data.br_stack = &cpuc->lbr_stack;
  739. if (perf_event_overflow(event, &data, &regs))
  740. x86_pmu_stop(event, 0);
  741. }
  742. static void intel_pmu_drain_pebs_core(struct pt_regs *iregs)
  743. {
  744. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  745. struct debug_store *ds = cpuc->ds;
  746. struct perf_event *event = cpuc->events[0]; /* PMC0 only */
  747. struct pebs_record_core *at, *top;
  748. int n;
  749. if (!x86_pmu.pebs_active)
  750. return;
  751. at = (struct pebs_record_core *)(unsigned long)ds->pebs_buffer_base;
  752. top = (struct pebs_record_core *)(unsigned long)ds->pebs_index;
  753. /*
  754. * Whatever else happens, drain the thing
  755. */
  756. ds->pebs_index = ds->pebs_buffer_base;
  757. if (!test_bit(0, cpuc->active_mask))
  758. return;
  759. WARN_ON_ONCE(!event);
  760. if (!event->attr.precise_ip)
  761. return;
  762. n = top - at;
  763. if (n <= 0)
  764. return;
  765. /*
  766. * Should not happen, we program the threshold at 1 and do not
  767. * set a reset value.
  768. */
  769. WARN_ONCE(n > 1, "bad leftover pebs %d\n", n);
  770. at += n - 1;
  771. __intel_pmu_pebs_event(event, iregs, at);
  772. }
  773. static void __intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, void *at,
  774. void *top)
  775. {
  776. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  777. struct debug_store *ds = cpuc->ds;
  778. struct perf_event *event = NULL;
  779. u64 status = 0;
  780. int bit;
  781. ds->pebs_index = ds->pebs_buffer_base;
  782. for (; at < top; at += x86_pmu.pebs_record_size) {
  783. struct pebs_record_nhm *p = at;
  784. for_each_set_bit(bit, (unsigned long *)&p->status,
  785. x86_pmu.max_pebs_events) {
  786. event = cpuc->events[bit];
  787. if (!test_bit(bit, cpuc->active_mask))
  788. continue;
  789. WARN_ON_ONCE(!event);
  790. if (!event->attr.precise_ip)
  791. continue;
  792. if (__test_and_set_bit(bit, (unsigned long *)&status))
  793. continue;
  794. break;
  795. }
  796. if (!event || bit >= x86_pmu.max_pebs_events)
  797. continue;
  798. __intel_pmu_pebs_event(event, iregs, at);
  799. }
  800. }
  801. static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
  802. {
  803. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  804. struct debug_store *ds = cpuc->ds;
  805. struct pebs_record_nhm *at, *top;
  806. int n;
  807. if (!x86_pmu.pebs_active)
  808. return;
  809. at = (struct pebs_record_nhm *)(unsigned long)ds->pebs_buffer_base;
  810. top = (struct pebs_record_nhm *)(unsigned long)ds->pebs_index;
  811. ds->pebs_index = ds->pebs_buffer_base;
  812. n = top - at;
  813. if (n <= 0)
  814. return;
  815. /*
  816. * Should not happen, we program the threshold at 1 and do not
  817. * set a reset value.
  818. */
  819. WARN_ONCE(n > x86_pmu.max_pebs_events,
  820. "Unexpected number of pebs records %d\n", n);
  821. return __intel_pmu_drain_pebs_nhm(iregs, at, top);
  822. }
  823. static void intel_pmu_drain_pebs_hsw(struct pt_regs *iregs)
  824. {
  825. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  826. struct debug_store *ds = cpuc->ds;
  827. struct pebs_record_hsw *at, *top;
  828. int n;
  829. if (!x86_pmu.pebs_active)
  830. return;
  831. at = (struct pebs_record_hsw *)(unsigned long)ds->pebs_buffer_base;
  832. top = (struct pebs_record_hsw *)(unsigned long)ds->pebs_index;
  833. n = top - at;
  834. if (n <= 0)
  835. return;
  836. /*
  837. * Should not happen, we program the threshold at 1 and do not
  838. * set a reset value.
  839. */
  840. WARN_ONCE(n > x86_pmu.max_pebs_events,
  841. "Unexpected number of pebs records %d\n", n);
  842. return __intel_pmu_drain_pebs_nhm(iregs, at, top);
  843. }
  844. /*
  845. * BTS, PEBS probe and setup
  846. */
  847. void intel_ds_init(void)
  848. {
  849. /*
  850. * No support for 32bit formats
  851. */
  852. if (!boot_cpu_has(X86_FEATURE_DTES64))
  853. return;
  854. x86_pmu.bts = boot_cpu_has(X86_FEATURE_BTS);
  855. x86_pmu.pebs = boot_cpu_has(X86_FEATURE_PEBS);
  856. if (x86_pmu.pebs) {
  857. char pebs_type = x86_pmu.intel_cap.pebs_trap ? '+' : '-';
  858. int format = x86_pmu.intel_cap.pebs_format;
  859. switch (format) {
  860. case 0:
  861. printk(KERN_CONT "PEBS fmt0%c, ", pebs_type);
  862. x86_pmu.pebs_record_size = sizeof(struct pebs_record_core);
  863. x86_pmu.drain_pebs = intel_pmu_drain_pebs_core;
  864. break;
  865. case 1:
  866. printk(KERN_CONT "PEBS fmt1%c, ", pebs_type);
  867. x86_pmu.pebs_record_size = sizeof(struct pebs_record_nhm);
  868. x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm;
  869. break;
  870. case 2:
  871. pr_cont("PEBS fmt2%c, ", pebs_type);
  872. x86_pmu.pebs_record_size = sizeof(struct pebs_record_hsw);
  873. x86_pmu.drain_pebs = intel_pmu_drain_pebs_hsw;
  874. break;
  875. default:
  876. printk(KERN_CONT "no PEBS fmt%d%c, ", format, pebs_type);
  877. x86_pmu.pebs = 0;
  878. }
  879. }
  880. }
  881. void perf_restore_debug_store(void)
  882. {
  883. struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds);
  884. if (!x86_pmu.bts && !x86_pmu.pebs)
  885. return;
  886. wrmsrl(MSR_IA32_DS_AREA, (unsigned long)ds);
  887. }