perf_event_intel_ds.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  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. struct pebs_record_nhm nhm;
  158. /*
  159. * Real IP of the event. In the Intel documentation this
  160. * is called eventingrip.
  161. */
  162. u64 real_ip;
  163. /*
  164. * TSX tuning information field: abort cycles and abort flags.
  165. */
  166. u64 tsx_tuning;
  167. };
  168. void init_debug_store_on_cpu(int cpu)
  169. {
  170. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  171. if (!ds)
  172. return;
  173. wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA,
  174. (u32)((u64)(unsigned long)ds),
  175. (u32)((u64)(unsigned long)ds >> 32));
  176. }
  177. void fini_debug_store_on_cpu(int cpu)
  178. {
  179. if (!per_cpu(cpu_hw_events, cpu).ds)
  180. return;
  181. wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0);
  182. }
  183. static int alloc_pebs_buffer(int cpu)
  184. {
  185. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  186. int node = cpu_to_node(cpu);
  187. int max, thresh = 1; /* always use a single PEBS record */
  188. void *buffer;
  189. if (!x86_pmu.pebs)
  190. return 0;
  191. buffer = kzalloc_node(PEBS_BUFFER_SIZE, GFP_KERNEL, node);
  192. if (unlikely(!buffer))
  193. return -ENOMEM;
  194. max = PEBS_BUFFER_SIZE / x86_pmu.pebs_record_size;
  195. ds->pebs_buffer_base = (u64)(unsigned long)buffer;
  196. ds->pebs_index = ds->pebs_buffer_base;
  197. ds->pebs_absolute_maximum = ds->pebs_buffer_base +
  198. max * x86_pmu.pebs_record_size;
  199. ds->pebs_interrupt_threshold = ds->pebs_buffer_base +
  200. thresh * x86_pmu.pebs_record_size;
  201. return 0;
  202. }
  203. static void release_pebs_buffer(int cpu)
  204. {
  205. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  206. if (!ds || !x86_pmu.pebs)
  207. return;
  208. kfree((void *)(unsigned long)ds->pebs_buffer_base);
  209. ds->pebs_buffer_base = 0;
  210. }
  211. static int alloc_bts_buffer(int cpu)
  212. {
  213. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  214. int node = cpu_to_node(cpu);
  215. int max, thresh;
  216. void *buffer;
  217. if (!x86_pmu.bts)
  218. return 0;
  219. buffer = kzalloc_node(BTS_BUFFER_SIZE, GFP_KERNEL, node);
  220. if (unlikely(!buffer))
  221. return -ENOMEM;
  222. max = BTS_BUFFER_SIZE / BTS_RECORD_SIZE;
  223. thresh = max / 16;
  224. ds->bts_buffer_base = (u64)(unsigned long)buffer;
  225. ds->bts_index = ds->bts_buffer_base;
  226. ds->bts_absolute_maximum = ds->bts_buffer_base +
  227. max * BTS_RECORD_SIZE;
  228. ds->bts_interrupt_threshold = ds->bts_absolute_maximum -
  229. thresh * BTS_RECORD_SIZE;
  230. return 0;
  231. }
  232. static void release_bts_buffer(int cpu)
  233. {
  234. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  235. if (!ds || !x86_pmu.bts)
  236. return;
  237. kfree((void *)(unsigned long)ds->bts_buffer_base);
  238. ds->bts_buffer_base = 0;
  239. }
  240. static int alloc_ds_buffer(int cpu)
  241. {
  242. int node = cpu_to_node(cpu);
  243. struct debug_store *ds;
  244. ds = kzalloc_node(sizeof(*ds), GFP_KERNEL, node);
  245. if (unlikely(!ds))
  246. return -ENOMEM;
  247. per_cpu(cpu_hw_events, cpu).ds = ds;
  248. return 0;
  249. }
  250. static void release_ds_buffer(int cpu)
  251. {
  252. struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
  253. if (!ds)
  254. return;
  255. per_cpu(cpu_hw_events, cpu).ds = NULL;
  256. kfree(ds);
  257. }
  258. void release_ds_buffers(void)
  259. {
  260. int cpu;
  261. if (!x86_pmu.bts && !x86_pmu.pebs)
  262. return;
  263. get_online_cpus();
  264. for_each_online_cpu(cpu)
  265. fini_debug_store_on_cpu(cpu);
  266. for_each_possible_cpu(cpu) {
  267. release_pebs_buffer(cpu);
  268. release_bts_buffer(cpu);
  269. release_ds_buffer(cpu);
  270. }
  271. put_online_cpus();
  272. }
  273. void reserve_ds_buffers(void)
  274. {
  275. int bts_err = 0, pebs_err = 0;
  276. int cpu;
  277. x86_pmu.bts_active = 0;
  278. x86_pmu.pebs_active = 0;
  279. if (!x86_pmu.bts && !x86_pmu.pebs)
  280. return;
  281. if (!x86_pmu.bts)
  282. bts_err = 1;
  283. if (!x86_pmu.pebs)
  284. pebs_err = 1;
  285. get_online_cpus();
  286. for_each_possible_cpu(cpu) {
  287. if (alloc_ds_buffer(cpu)) {
  288. bts_err = 1;
  289. pebs_err = 1;
  290. }
  291. if (!bts_err && alloc_bts_buffer(cpu))
  292. bts_err = 1;
  293. if (!pebs_err && alloc_pebs_buffer(cpu))
  294. pebs_err = 1;
  295. if (bts_err && pebs_err)
  296. break;
  297. }
  298. if (bts_err) {
  299. for_each_possible_cpu(cpu)
  300. release_bts_buffer(cpu);
  301. }
  302. if (pebs_err) {
  303. for_each_possible_cpu(cpu)
  304. release_pebs_buffer(cpu);
  305. }
  306. if (bts_err && pebs_err) {
  307. for_each_possible_cpu(cpu)
  308. release_ds_buffer(cpu);
  309. } else {
  310. if (x86_pmu.bts && !bts_err)
  311. x86_pmu.bts_active = 1;
  312. if (x86_pmu.pebs && !pebs_err)
  313. x86_pmu.pebs_active = 1;
  314. for_each_online_cpu(cpu)
  315. init_debug_store_on_cpu(cpu);
  316. }
  317. put_online_cpus();
  318. }
  319. /*
  320. * BTS
  321. */
  322. struct event_constraint bts_constraint =
  323. EVENT_CONSTRAINT(0, 1ULL << INTEL_PMC_IDX_FIXED_BTS, 0);
  324. void intel_pmu_enable_bts(u64 config)
  325. {
  326. unsigned long debugctlmsr;
  327. debugctlmsr = get_debugctlmsr();
  328. debugctlmsr |= DEBUGCTLMSR_TR;
  329. debugctlmsr |= DEBUGCTLMSR_BTS;
  330. debugctlmsr |= DEBUGCTLMSR_BTINT;
  331. if (!(config & ARCH_PERFMON_EVENTSEL_OS))
  332. debugctlmsr |= DEBUGCTLMSR_BTS_OFF_OS;
  333. if (!(config & ARCH_PERFMON_EVENTSEL_USR))
  334. debugctlmsr |= DEBUGCTLMSR_BTS_OFF_USR;
  335. update_debugctlmsr(debugctlmsr);
  336. }
  337. void intel_pmu_disable_bts(void)
  338. {
  339. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  340. unsigned long debugctlmsr;
  341. if (!cpuc->ds)
  342. return;
  343. debugctlmsr = get_debugctlmsr();
  344. debugctlmsr &=
  345. ~(DEBUGCTLMSR_TR | DEBUGCTLMSR_BTS | DEBUGCTLMSR_BTINT |
  346. DEBUGCTLMSR_BTS_OFF_OS | DEBUGCTLMSR_BTS_OFF_USR);
  347. update_debugctlmsr(debugctlmsr);
  348. }
  349. int intel_pmu_drain_bts_buffer(void)
  350. {
  351. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  352. struct debug_store *ds = cpuc->ds;
  353. struct bts_record {
  354. u64 from;
  355. u64 to;
  356. u64 flags;
  357. };
  358. struct perf_event *event = cpuc->events[INTEL_PMC_IDX_FIXED_BTS];
  359. struct bts_record *at, *top;
  360. struct perf_output_handle handle;
  361. struct perf_event_header header;
  362. struct perf_sample_data data;
  363. struct pt_regs regs;
  364. if (!event)
  365. return 0;
  366. if (!x86_pmu.bts_active)
  367. return 0;
  368. at = (struct bts_record *)(unsigned long)ds->bts_buffer_base;
  369. top = (struct bts_record *)(unsigned long)ds->bts_index;
  370. if (top <= at)
  371. return 0;
  372. memset(&regs, 0, sizeof(regs));
  373. ds->bts_index = ds->bts_buffer_base;
  374. perf_sample_data_init(&data, 0, event->hw.last_period);
  375. /*
  376. * Prepare a generic sample, i.e. fill in the invariant fields.
  377. * We will overwrite the from and to address before we output
  378. * the sample.
  379. */
  380. perf_prepare_sample(&header, &data, event, &regs);
  381. if (perf_output_begin(&handle, event, header.size * (top - at)))
  382. return 1;
  383. for (; at < top; at++) {
  384. data.ip = at->from;
  385. data.addr = at->to;
  386. perf_output_sample(&handle, &header, &data, event);
  387. }
  388. perf_output_end(&handle);
  389. /* There's new data available. */
  390. event->hw.interrupts++;
  391. event->pending_kill = POLL_IN;
  392. return 1;
  393. }
  394. /*
  395. * PEBS
  396. */
  397. struct event_constraint intel_core2_pebs_event_constraints[] = {
  398. INTEL_UEVENT_CONSTRAINT(0x00c0, 0x1), /* INST_RETIRED.ANY */
  399. INTEL_UEVENT_CONSTRAINT(0xfec1, 0x1), /* X87_OPS_RETIRED.ANY */
  400. INTEL_UEVENT_CONSTRAINT(0x00c5, 0x1), /* BR_INST_RETIRED.MISPRED */
  401. INTEL_UEVENT_CONSTRAINT(0x1fc7, 0x1), /* SIMD_INST_RETURED.ANY */
  402. INTEL_EVENT_CONSTRAINT(0xcb, 0x1), /* MEM_LOAD_RETIRED.* */
  403. EVENT_CONSTRAINT_END
  404. };
  405. struct event_constraint intel_atom_pebs_event_constraints[] = {
  406. INTEL_UEVENT_CONSTRAINT(0x00c0, 0x1), /* INST_RETIRED.ANY */
  407. INTEL_UEVENT_CONSTRAINT(0x00c5, 0x1), /* MISPREDICTED_BRANCH_RETIRED */
  408. INTEL_EVENT_CONSTRAINT(0xcb, 0x1), /* MEM_LOAD_RETIRED.* */
  409. EVENT_CONSTRAINT_END
  410. };
  411. struct event_constraint intel_slm_pebs_event_constraints[] = {
  412. INTEL_UEVENT_CONSTRAINT(0x0103, 0x1), /* REHABQ.LD_BLOCK_ST_FORWARD_PS */
  413. INTEL_UEVENT_CONSTRAINT(0x0803, 0x1), /* REHABQ.LD_SPLITS_PS */
  414. INTEL_UEVENT_CONSTRAINT(0x0204, 0x1), /* MEM_UOPS_RETIRED.L2_HIT_LOADS_PS */
  415. INTEL_UEVENT_CONSTRAINT(0x0404, 0x1), /* MEM_UOPS_RETIRED.L2_MISS_LOADS_PS */
  416. INTEL_UEVENT_CONSTRAINT(0x0804, 0x1), /* MEM_UOPS_RETIRED.DTLB_MISS_LOADS_PS */
  417. INTEL_UEVENT_CONSTRAINT(0x2004, 0x1), /* MEM_UOPS_RETIRED.HITM_PS */
  418. INTEL_UEVENT_CONSTRAINT(0x00c0, 0x1), /* INST_RETIRED.ANY_PS */
  419. INTEL_UEVENT_CONSTRAINT(0x00c4, 0x1), /* BR_INST_RETIRED.ALL_BRANCHES_PS */
  420. INTEL_UEVENT_CONSTRAINT(0x7ec4, 0x1), /* BR_INST_RETIRED.JCC_PS */
  421. INTEL_UEVENT_CONSTRAINT(0xbfc4, 0x1), /* BR_INST_RETIRED.FAR_BRANCH_PS */
  422. INTEL_UEVENT_CONSTRAINT(0xebc4, 0x1), /* BR_INST_RETIRED.NON_RETURN_IND_PS */
  423. INTEL_UEVENT_CONSTRAINT(0xf7c4, 0x1), /* BR_INST_RETIRED.RETURN_PS */
  424. INTEL_UEVENT_CONSTRAINT(0xf9c4, 0x1), /* BR_INST_RETIRED.CALL_PS */
  425. INTEL_UEVENT_CONSTRAINT(0xfbc4, 0x1), /* BR_INST_RETIRED.IND_CALL_PS */
  426. INTEL_UEVENT_CONSTRAINT(0xfdc4, 0x1), /* BR_INST_RETIRED.REL_CALL_PS */
  427. INTEL_UEVENT_CONSTRAINT(0xfec4, 0x1), /* BR_INST_RETIRED.TAKEN_JCC_PS */
  428. INTEL_UEVENT_CONSTRAINT(0x00c5, 0x1), /* BR_INST_MISP_RETIRED.ALL_BRANCHES_PS */
  429. INTEL_UEVENT_CONSTRAINT(0x7ec5, 0x1), /* BR_INST_MISP_RETIRED.JCC_PS */
  430. INTEL_UEVENT_CONSTRAINT(0xebc5, 0x1), /* BR_INST_MISP_RETIRED.NON_RETURN_IND_PS */
  431. INTEL_UEVENT_CONSTRAINT(0xf7c5, 0x1), /* BR_INST_MISP_RETIRED.RETURN_PS */
  432. INTEL_UEVENT_CONSTRAINT(0xfbc5, 0x1), /* BR_INST_MISP_RETIRED.IND_CALL_PS */
  433. INTEL_UEVENT_CONSTRAINT(0xfec5, 0x1), /* BR_INST_MISP_RETIRED.TAKEN_JCC_PS */
  434. EVENT_CONSTRAINT_END
  435. };
  436. struct event_constraint intel_nehalem_pebs_event_constraints[] = {
  437. INTEL_PLD_CONSTRAINT(0x100b, 0xf), /* MEM_INST_RETIRED.* */
  438. INTEL_EVENT_CONSTRAINT(0x0f, 0xf), /* MEM_UNCORE_RETIRED.* */
  439. INTEL_UEVENT_CONSTRAINT(0x010c, 0xf), /* MEM_STORE_RETIRED.DTLB_MISS */
  440. INTEL_EVENT_CONSTRAINT(0xc0, 0xf), /* INST_RETIRED.ANY */
  441. INTEL_EVENT_CONSTRAINT(0xc2, 0xf), /* UOPS_RETIRED.* */
  442. INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */
  443. INTEL_UEVENT_CONSTRAINT(0x02c5, 0xf), /* BR_MISP_RETIRED.NEAR_CALL */
  444. INTEL_EVENT_CONSTRAINT(0xc7, 0xf), /* SSEX_UOPS_RETIRED.* */
  445. INTEL_UEVENT_CONSTRAINT(0x20c8, 0xf), /* ITLB_MISS_RETIRED */
  446. INTEL_EVENT_CONSTRAINT(0xcb, 0xf), /* MEM_LOAD_RETIRED.* */
  447. INTEL_EVENT_CONSTRAINT(0xf7, 0xf), /* FP_ASSIST.* */
  448. EVENT_CONSTRAINT_END
  449. };
  450. struct event_constraint intel_westmere_pebs_event_constraints[] = {
  451. INTEL_PLD_CONSTRAINT(0x100b, 0xf), /* MEM_INST_RETIRED.* */
  452. INTEL_EVENT_CONSTRAINT(0x0f, 0xf), /* MEM_UNCORE_RETIRED.* */
  453. INTEL_UEVENT_CONSTRAINT(0x010c, 0xf), /* MEM_STORE_RETIRED.DTLB_MISS */
  454. INTEL_EVENT_CONSTRAINT(0xc0, 0xf), /* INSTR_RETIRED.* */
  455. INTEL_EVENT_CONSTRAINT(0xc2, 0xf), /* UOPS_RETIRED.* */
  456. INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */
  457. INTEL_EVENT_CONSTRAINT(0xc5, 0xf), /* BR_MISP_RETIRED.* */
  458. INTEL_EVENT_CONSTRAINT(0xc7, 0xf), /* SSEX_UOPS_RETIRED.* */
  459. INTEL_UEVENT_CONSTRAINT(0x20c8, 0xf), /* ITLB_MISS_RETIRED */
  460. INTEL_EVENT_CONSTRAINT(0xcb, 0xf), /* MEM_LOAD_RETIRED.* */
  461. INTEL_EVENT_CONSTRAINT(0xf7, 0xf), /* FP_ASSIST.* */
  462. EVENT_CONSTRAINT_END
  463. };
  464. struct event_constraint intel_snb_pebs_event_constraints[] = {
  465. INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PRECDIST */
  466. INTEL_UEVENT_CONSTRAINT(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
  467. INTEL_UEVENT_CONSTRAINT(0x02c2, 0xf), /* UOPS_RETIRED.RETIRE_SLOTS */
  468. INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */
  469. INTEL_EVENT_CONSTRAINT(0xc5, 0xf), /* BR_MISP_RETIRED.* */
  470. INTEL_PLD_CONSTRAINT(0x01cd, 0x8), /* MEM_TRANS_RETIRED.LAT_ABOVE_THR */
  471. INTEL_PST_CONSTRAINT(0x02cd, 0x8), /* MEM_TRANS_RETIRED.PRECISE_STORES */
  472. INTEL_EVENT_CONSTRAINT(0xd0, 0xf), /* MEM_UOP_RETIRED.* */
  473. INTEL_EVENT_CONSTRAINT(0xd1, 0xf), /* MEM_LOAD_UOPS_RETIRED.* */
  474. INTEL_EVENT_CONSTRAINT(0xd2, 0xf), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
  475. INTEL_UEVENT_CONSTRAINT(0x02d4, 0xf), /* MEM_LOAD_UOPS_MISC_RETIRED.LLC_MISS */
  476. EVENT_CONSTRAINT_END
  477. };
  478. struct event_constraint intel_ivb_pebs_event_constraints[] = {
  479. INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PRECDIST */
  480. INTEL_UEVENT_CONSTRAINT(0x01c2, 0xf), /* UOPS_RETIRED.ALL */
  481. INTEL_UEVENT_CONSTRAINT(0x02c2, 0xf), /* UOPS_RETIRED.RETIRE_SLOTS */
  482. INTEL_EVENT_CONSTRAINT(0xc4, 0xf), /* BR_INST_RETIRED.* */
  483. INTEL_EVENT_CONSTRAINT(0xc5, 0xf), /* BR_MISP_RETIRED.* */
  484. INTEL_PLD_CONSTRAINT(0x01cd, 0x8), /* MEM_TRANS_RETIRED.LAT_ABOVE_THR */
  485. INTEL_PST_CONSTRAINT(0x02cd, 0x8), /* MEM_TRANS_RETIRED.PRECISE_STORES */
  486. INTEL_EVENT_CONSTRAINT(0xd0, 0xf), /* MEM_UOP_RETIRED.* */
  487. INTEL_EVENT_CONSTRAINT(0xd1, 0xf), /* MEM_LOAD_UOPS_RETIRED.* */
  488. INTEL_EVENT_CONSTRAINT(0xd2, 0xf), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */
  489. INTEL_EVENT_CONSTRAINT(0xd3, 0xf), /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.* */
  490. EVENT_CONSTRAINT_END
  491. };
  492. struct event_constraint intel_hsw_pebs_event_constraints[] = {
  493. INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PRECDIST */
  494. INTEL_PST_HSW_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_UEVENT_CONSTRAINT(0x01c5, 0xf), /* BR_MISP_RETIRED.CONDITIONAL */
  498. INTEL_UEVENT_CONSTRAINT(0x04c5, 0xf), /* BR_MISP_RETIRED.ALL_BRANCHES */
  499. INTEL_UEVENT_CONSTRAINT(0x20c5, 0xf), /* BR_MISP_RETIRED.NEAR_TAKEN */
  500. INTEL_PLD_CONSTRAINT(0x01cd, 0x8), /* MEM_TRANS_RETIRED.* */
  501. /* MEM_UOPS_RETIRED.STLB_MISS_LOADS */
  502. INTEL_UEVENT_CONSTRAINT(0x11d0, 0xf),
  503. /* MEM_UOPS_RETIRED.STLB_MISS_STORES */
  504. INTEL_UEVENT_CONSTRAINT(0x12d0, 0xf),
  505. INTEL_UEVENT_CONSTRAINT(0x21d0, 0xf), /* MEM_UOPS_RETIRED.LOCK_LOADS */
  506. INTEL_UEVENT_CONSTRAINT(0x41d0, 0xf), /* MEM_UOPS_RETIRED.SPLIT_LOADS */
  507. /* MEM_UOPS_RETIRED.SPLIT_STORES */
  508. INTEL_UEVENT_CONSTRAINT(0x42d0, 0xf),
  509. INTEL_UEVENT_CONSTRAINT(0x81d0, 0xf), /* MEM_UOPS_RETIRED.ALL_LOADS */
  510. INTEL_PST_HSW_CONSTRAINT(0x82d0, 0xf), /* MEM_UOPS_RETIRED.ALL_STORES */
  511. INTEL_UEVENT_CONSTRAINT(0x01d1, 0xf), /* MEM_LOAD_UOPS_RETIRED.L1_HIT */
  512. INTEL_UEVENT_CONSTRAINT(0x02d1, 0xf), /* MEM_LOAD_UOPS_RETIRED.L2_HIT */
  513. INTEL_UEVENT_CONSTRAINT(0x04d1, 0xf), /* MEM_LOAD_UOPS_RETIRED.L3_HIT */
  514. /* MEM_LOAD_UOPS_RETIRED.HIT_LFB */
  515. INTEL_UEVENT_CONSTRAINT(0x40d1, 0xf),
  516. /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_MISS */
  517. INTEL_UEVENT_CONSTRAINT(0x01d2, 0xf),
  518. /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_HIT */
  519. INTEL_UEVENT_CONSTRAINT(0x02d2, 0xf),
  520. /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.LOCAL_DRAM */
  521. INTEL_UEVENT_CONSTRAINT(0x01d3, 0xf),
  522. INTEL_UEVENT_CONSTRAINT(0x04c8, 0xf), /* HLE_RETIRED.Abort */
  523. INTEL_UEVENT_CONSTRAINT(0x04c9, 0xf), /* RTM_RETIRED.Abort */
  524. EVENT_CONSTRAINT_END
  525. };
  526. struct event_constraint *intel_pebs_constraints(struct perf_event *event)
  527. {
  528. struct event_constraint *c;
  529. if (!event->attr.precise_ip)
  530. return NULL;
  531. if (x86_pmu.pebs_constraints) {
  532. for_each_event_constraint(c, x86_pmu.pebs_constraints) {
  533. if ((event->hw.config & c->cmask) == c->code) {
  534. event->hw.flags |= c->flags;
  535. return c;
  536. }
  537. }
  538. }
  539. return &emptyconstraint;
  540. }
  541. void intel_pmu_pebs_enable(struct perf_event *event)
  542. {
  543. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  544. struct hw_perf_event *hwc = &event->hw;
  545. hwc->config &= ~ARCH_PERFMON_EVENTSEL_INT;
  546. cpuc->pebs_enabled |= 1ULL << hwc->idx;
  547. if (event->hw.flags & PERF_X86_EVENT_PEBS_LDLAT)
  548. cpuc->pebs_enabled |= 1ULL << (hwc->idx + 32);
  549. else if (event->hw.flags & PERF_X86_EVENT_PEBS_ST)
  550. cpuc->pebs_enabled |= 1ULL << 63;
  551. }
  552. void intel_pmu_pebs_disable(struct perf_event *event)
  553. {
  554. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  555. struct hw_perf_event *hwc = &event->hw;
  556. cpuc->pebs_enabled &= ~(1ULL << hwc->idx);
  557. if (event->hw.constraint->flags & PERF_X86_EVENT_PEBS_LDLAT)
  558. cpuc->pebs_enabled &= ~(1ULL << (hwc->idx + 32));
  559. else if (event->hw.constraint->flags & PERF_X86_EVENT_PEBS_ST)
  560. cpuc->pebs_enabled &= ~(1ULL << 63);
  561. if (cpuc->enabled)
  562. wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled);
  563. hwc->config |= ARCH_PERFMON_EVENTSEL_INT;
  564. }
  565. void intel_pmu_pebs_enable_all(void)
  566. {
  567. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  568. if (cpuc->pebs_enabled)
  569. wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled);
  570. }
  571. void intel_pmu_pebs_disable_all(void)
  572. {
  573. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  574. if (cpuc->pebs_enabled)
  575. wrmsrl(MSR_IA32_PEBS_ENABLE, 0);
  576. }
  577. static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)
  578. {
  579. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  580. unsigned long from = cpuc->lbr_entries[0].from;
  581. unsigned long old_to, to = cpuc->lbr_entries[0].to;
  582. unsigned long ip = regs->ip;
  583. int is_64bit = 0;
  584. /*
  585. * We don't need to fixup if the PEBS assist is fault like
  586. */
  587. if (!x86_pmu.intel_cap.pebs_trap)
  588. return 1;
  589. /*
  590. * No LBR entry, no basic block, no rewinding
  591. */
  592. if (!cpuc->lbr_stack.nr || !from || !to)
  593. return 0;
  594. /*
  595. * Basic blocks should never cross user/kernel boundaries
  596. */
  597. if (kernel_ip(ip) != kernel_ip(to))
  598. return 0;
  599. /*
  600. * unsigned math, either ip is before the start (impossible) or
  601. * the basic block is larger than 1 page (sanity)
  602. */
  603. if ((ip - to) > PAGE_SIZE)
  604. return 0;
  605. /*
  606. * We sampled a branch insn, rewind using the LBR stack
  607. */
  608. if (ip == to) {
  609. set_linear_ip(regs, from);
  610. return 1;
  611. }
  612. do {
  613. struct insn insn;
  614. u8 buf[MAX_INSN_SIZE];
  615. void *kaddr;
  616. old_to = to;
  617. if (!kernel_ip(ip)) {
  618. int bytes, size = MAX_INSN_SIZE;
  619. bytes = copy_from_user_nmi(buf, (void __user *)to, size);
  620. if (bytes != size)
  621. return 0;
  622. kaddr = buf;
  623. } else
  624. kaddr = (void *)to;
  625. #ifdef CONFIG_X86_64
  626. is_64bit = kernel_ip(to) || !test_thread_flag(TIF_IA32);
  627. #endif
  628. insn_init(&insn, kaddr, is_64bit);
  629. insn_get_length(&insn);
  630. to += insn.length;
  631. } while (to < ip);
  632. if (to == ip) {
  633. set_linear_ip(regs, old_to);
  634. return 1;
  635. }
  636. /*
  637. * Even though we decoded the basic block, the instruction stream
  638. * never matched the given IP, either the TO or the IP got corrupted.
  639. */
  640. return 0;
  641. }
  642. static void __intel_pmu_pebs_event(struct perf_event *event,
  643. struct pt_regs *iregs, void *__pebs)
  644. {
  645. /*
  646. * We cast to pebs_record_nhm to get the load latency data
  647. * if extra_reg MSR_PEBS_LD_LAT_THRESHOLD used
  648. */
  649. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  650. struct pebs_record_nhm *pebs = __pebs;
  651. struct pebs_record_hsw *pebs_hsw = __pebs;
  652. struct perf_sample_data data;
  653. struct pt_regs regs;
  654. u64 sample_type;
  655. int fll, fst;
  656. if (!intel_pmu_save_and_restart(event))
  657. return;
  658. fll = event->hw.flags & PERF_X86_EVENT_PEBS_LDLAT;
  659. fst = event->hw.flags & (PERF_X86_EVENT_PEBS_ST |
  660. PERF_X86_EVENT_PEBS_ST_HSW);
  661. perf_sample_data_init(&data, 0, event->hw.last_period);
  662. data.period = event->hw.last_period;
  663. sample_type = event->attr.sample_type;
  664. /*
  665. * if PEBS-LL or PreciseStore
  666. */
  667. if (fll || fst) {
  668. /*
  669. * Use latency for weight (only avail with PEBS-LL)
  670. */
  671. if (fll && (sample_type & PERF_SAMPLE_WEIGHT))
  672. data.weight = pebs->lat;
  673. /*
  674. * data.data_src encodes the data source
  675. */
  676. if (sample_type & PERF_SAMPLE_DATA_SRC) {
  677. if (fll)
  678. data.data_src.val = load_latency_data(pebs->dse);
  679. else if (event->hw.flags & PERF_X86_EVENT_PEBS_ST_HSW)
  680. data.data_src.val =
  681. precise_store_data_hsw(pebs->dse);
  682. else
  683. data.data_src.val = precise_store_data(pebs->dse);
  684. }
  685. }
  686. /*
  687. * We use the interrupt regs as a base because the PEBS record
  688. * does not contain a full regs set, specifically it seems to
  689. * lack segment descriptors, which get used by things like
  690. * user_mode().
  691. *
  692. * In the simple case fix up only the IP and BP,SP regs, for
  693. * PERF_SAMPLE_IP and PERF_SAMPLE_CALLCHAIN to function properly.
  694. * A possible PERF_SAMPLE_REGS will have to transfer all regs.
  695. */
  696. regs = *iregs;
  697. regs.flags = pebs->flags;
  698. set_linear_ip(&regs, pebs->ip);
  699. regs.bp = pebs->bp;
  700. regs.sp = pebs->sp;
  701. if (event->attr.precise_ip > 1 && x86_pmu.intel_cap.pebs_format >= 2) {
  702. regs.ip = pebs_hsw->real_ip;
  703. regs.flags |= PERF_EFLAGS_EXACT;
  704. } else if (event->attr.precise_ip > 1 && intel_pmu_pebs_fixup_ip(&regs))
  705. regs.flags |= PERF_EFLAGS_EXACT;
  706. else
  707. regs.flags &= ~PERF_EFLAGS_EXACT;
  708. if ((event->attr.sample_type & PERF_SAMPLE_ADDR) &&
  709. x86_pmu.intel_cap.pebs_format >= 1)
  710. data.addr = pebs->dla;
  711. if (has_branch_stack(event))
  712. data.br_stack = &cpuc->lbr_stack;
  713. if (perf_event_overflow(event, &data, &regs))
  714. x86_pmu_stop(event, 0);
  715. }
  716. static void intel_pmu_drain_pebs_core(struct pt_regs *iregs)
  717. {
  718. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  719. struct debug_store *ds = cpuc->ds;
  720. struct perf_event *event = cpuc->events[0]; /* PMC0 only */
  721. struct pebs_record_core *at, *top;
  722. int n;
  723. if (!x86_pmu.pebs_active)
  724. return;
  725. at = (struct pebs_record_core *)(unsigned long)ds->pebs_buffer_base;
  726. top = (struct pebs_record_core *)(unsigned long)ds->pebs_index;
  727. /*
  728. * Whatever else happens, drain the thing
  729. */
  730. ds->pebs_index = ds->pebs_buffer_base;
  731. if (!test_bit(0, cpuc->active_mask))
  732. return;
  733. WARN_ON_ONCE(!event);
  734. if (!event->attr.precise_ip)
  735. return;
  736. n = top - at;
  737. if (n <= 0)
  738. return;
  739. /*
  740. * Should not happen, we program the threshold at 1 and do not
  741. * set a reset value.
  742. */
  743. WARN_ONCE(n > 1, "bad leftover pebs %d\n", n);
  744. at += n - 1;
  745. __intel_pmu_pebs_event(event, iregs, at);
  746. }
  747. static void __intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, void *at,
  748. void *top)
  749. {
  750. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  751. struct debug_store *ds = cpuc->ds;
  752. struct perf_event *event = NULL;
  753. u64 status = 0;
  754. int bit;
  755. ds->pebs_index = ds->pebs_buffer_base;
  756. for (; at < top; at += x86_pmu.pebs_record_size) {
  757. struct pebs_record_nhm *p = at;
  758. for_each_set_bit(bit, (unsigned long *)&p->status,
  759. x86_pmu.max_pebs_events) {
  760. event = cpuc->events[bit];
  761. if (!test_bit(bit, cpuc->active_mask))
  762. continue;
  763. WARN_ON_ONCE(!event);
  764. if (!event->attr.precise_ip)
  765. continue;
  766. if (__test_and_set_bit(bit, (unsigned long *)&status))
  767. continue;
  768. break;
  769. }
  770. if (!event || bit >= x86_pmu.max_pebs_events)
  771. continue;
  772. __intel_pmu_pebs_event(event, iregs, at);
  773. }
  774. }
  775. static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
  776. {
  777. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  778. struct debug_store *ds = cpuc->ds;
  779. struct pebs_record_nhm *at, *top;
  780. int n;
  781. if (!x86_pmu.pebs_active)
  782. return;
  783. at = (struct pebs_record_nhm *)(unsigned long)ds->pebs_buffer_base;
  784. top = (struct pebs_record_nhm *)(unsigned long)ds->pebs_index;
  785. ds->pebs_index = ds->pebs_buffer_base;
  786. n = top - at;
  787. if (n <= 0)
  788. return;
  789. /*
  790. * Should not happen, we program the threshold at 1 and do not
  791. * set a reset value.
  792. */
  793. WARN_ONCE(n > x86_pmu.max_pebs_events,
  794. "Unexpected number of pebs records %d\n", n);
  795. return __intel_pmu_drain_pebs_nhm(iregs, at, top);
  796. }
  797. static void intel_pmu_drain_pebs_hsw(struct pt_regs *iregs)
  798. {
  799. struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
  800. struct debug_store *ds = cpuc->ds;
  801. struct pebs_record_hsw *at, *top;
  802. int n;
  803. if (!x86_pmu.pebs_active)
  804. return;
  805. at = (struct pebs_record_hsw *)(unsigned long)ds->pebs_buffer_base;
  806. top = (struct pebs_record_hsw *)(unsigned long)ds->pebs_index;
  807. n = top - at;
  808. if (n <= 0)
  809. return;
  810. /*
  811. * Should not happen, we program the threshold at 1 and do not
  812. * set a reset value.
  813. */
  814. WARN_ONCE(n > x86_pmu.max_pebs_events,
  815. "Unexpected number of pebs records %d\n", n);
  816. return __intel_pmu_drain_pebs_nhm(iregs, at, top);
  817. }
  818. /*
  819. * BTS, PEBS probe and setup
  820. */
  821. void intel_ds_init(void)
  822. {
  823. /*
  824. * No support for 32bit formats
  825. */
  826. if (!boot_cpu_has(X86_FEATURE_DTES64))
  827. return;
  828. x86_pmu.bts = boot_cpu_has(X86_FEATURE_BTS);
  829. x86_pmu.pebs = boot_cpu_has(X86_FEATURE_PEBS);
  830. if (x86_pmu.pebs) {
  831. char pebs_type = x86_pmu.intel_cap.pebs_trap ? '+' : '-';
  832. int format = x86_pmu.intel_cap.pebs_format;
  833. switch (format) {
  834. case 0:
  835. printk(KERN_CONT "PEBS fmt0%c, ", pebs_type);
  836. x86_pmu.pebs_record_size = sizeof(struct pebs_record_core);
  837. x86_pmu.drain_pebs = intel_pmu_drain_pebs_core;
  838. break;
  839. case 1:
  840. printk(KERN_CONT "PEBS fmt1%c, ", pebs_type);
  841. x86_pmu.pebs_record_size = sizeof(struct pebs_record_nhm);
  842. x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm;
  843. break;
  844. case 2:
  845. pr_cont("PEBS fmt2%c, ", pebs_type);
  846. x86_pmu.pebs_record_size = sizeof(struct pebs_record_hsw);
  847. x86_pmu.drain_pebs = intel_pmu_drain_pebs_hsw;
  848. break;
  849. default:
  850. printk(KERN_CONT "no PEBS fmt%d%c, ", format, pebs_type);
  851. x86_pmu.pebs = 0;
  852. }
  853. }
  854. }
  855. void perf_restore_debug_store(void)
  856. {
  857. struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds);
  858. if (!x86_pmu.bts && !x86_pmu.pebs)
  859. return;
  860. wrmsrl(MSR_IA32_DS_AREA, (unsigned long)ds);
  861. }