perf_event_intel_ds.c 28 KB

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