ds.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. /*
  2. * Debug Store support
  3. *
  4. * This provides a low-level interface to the hardware's Debug Store
  5. * feature that is used for branch trace store (BTS) and
  6. * precise-event based sampling (PEBS).
  7. *
  8. * It manages:
  9. * - per-thread and per-cpu allocation of BTS and PEBS
  10. * - buffer overflow handling (to be done)
  11. * - buffer access
  12. *
  13. * It assumes:
  14. * - get_task_struct on all traced tasks
  15. * - current is allowed to trace tasks
  16. *
  17. *
  18. * Copyright (C) 2007-2008 Intel Corporation.
  19. * Markus Metzger <markus.t.metzger@intel.com>, 2007-2008
  20. */
  21. #include <asm/ds.h>
  22. #include <linux/errno.h>
  23. #include <linux/string.h>
  24. #include <linux/slab.h>
  25. #include <linux/sched.h>
  26. #include <linux/mm.h>
  27. #include <linux/kernel.h>
  28. /*
  29. * The configuration for a particular DS hardware implementation.
  30. */
  31. struct ds_configuration {
  32. /* the size of the DS structure in bytes */
  33. unsigned char sizeof_ds;
  34. /* the size of one pointer-typed field in the DS structure in bytes;
  35. this covers the first 8 fields related to buffer management. */
  36. unsigned char sizeof_field;
  37. /* the size of a BTS/PEBS record in bytes */
  38. unsigned char sizeof_rec[2];
  39. };
  40. static struct ds_configuration ds_cfg;
  41. /*
  42. * A BTS or PEBS tracer.
  43. *
  44. * This holds the configuration of the tracer and serves as a handle
  45. * to identify tracers.
  46. */
  47. struct ds_tracer {
  48. /* the DS context (partially) owned by this tracer */
  49. struct ds_context *context;
  50. /* the buffer provided on ds_request() and its size in bytes */
  51. void *buffer;
  52. size_t size;
  53. };
  54. struct bts_tracer {
  55. /* the common DS part */
  56. struct ds_tracer ds;
  57. /* buffer overflow notification function */
  58. bts_ovfl_callback_t ovfl;
  59. };
  60. struct pebs_tracer {
  61. /* the common DS part */
  62. struct ds_tracer ds;
  63. /* buffer overflow notification function */
  64. pebs_ovfl_callback_t ovfl;
  65. };
  66. /*
  67. * Debug Store (DS) save area configuration (see Intel64 and IA32
  68. * Architectures Software Developer's Manual, section 18.5)
  69. *
  70. * The DS configuration consists of the following fields; different
  71. * architetures vary in the size of those fields.
  72. * - double-word aligned base linear address of the BTS buffer
  73. * - write pointer into the BTS buffer
  74. * - end linear address of the BTS buffer (one byte beyond the end of
  75. * the buffer)
  76. * - interrupt pointer into BTS buffer
  77. * (interrupt occurs when write pointer passes interrupt pointer)
  78. * - double-word aligned base linear address of the PEBS buffer
  79. * - write pointer into the PEBS buffer
  80. * - end linear address of the PEBS buffer (one byte beyond the end of
  81. * the buffer)
  82. * - interrupt pointer into PEBS buffer
  83. * (interrupt occurs when write pointer passes interrupt pointer)
  84. * - value to which counter is reset following counter overflow
  85. *
  86. * Later architectures use 64bit pointers throughout, whereas earlier
  87. * architectures use 32bit pointers in 32bit mode.
  88. *
  89. *
  90. * We compute the base address for the first 8 fields based on:
  91. * - the field size stored in the DS configuration
  92. * - the relative field position
  93. * - an offset giving the start of the respective region
  94. *
  95. * This offset is further used to index various arrays holding
  96. * information for BTS and PEBS at the respective index.
  97. *
  98. * On later 32bit processors, we only access the lower 32bit of the
  99. * 64bit pointer fields. The upper halves will be zeroed out.
  100. */
  101. enum ds_field {
  102. ds_buffer_base = 0,
  103. ds_index,
  104. ds_absolute_maximum,
  105. ds_interrupt_threshold,
  106. };
  107. enum ds_qualifier {
  108. ds_bts = 0,
  109. ds_pebs
  110. };
  111. static inline unsigned long ds_get(const unsigned char *base,
  112. enum ds_qualifier qual, enum ds_field field)
  113. {
  114. base += (ds_cfg.sizeof_field * (field + (4 * qual)));
  115. return *(unsigned long *)base;
  116. }
  117. static inline void ds_set(unsigned char *base, enum ds_qualifier qual,
  118. enum ds_field field, unsigned long value)
  119. {
  120. base += (ds_cfg.sizeof_field * (field + (4 * qual)));
  121. (*(unsigned long *)base) = value;
  122. }
  123. #define DS_ALIGNMENT (1 << 3) /* BTS and PEBS buffer alignment */
  124. /*
  125. * Locking is done only for allocating BTS or PEBS resources.
  126. */
  127. static spinlock_t ds_lock = __SPIN_LOCK_UNLOCKED(ds_lock);
  128. /*
  129. * We either support (system-wide) per-cpu or per-thread allocation.
  130. * We distinguish the two based on the task_struct pointer, where a
  131. * NULL pointer indicates per-cpu allocation for the current cpu.
  132. *
  133. * Allocations are use-counted. As soon as resources are allocated,
  134. * further allocations must be of the same type (per-cpu or
  135. * per-thread). We model this by counting allocations (i.e. the number
  136. * of tracers of a certain type) for one type negatively:
  137. * =0 no tracers
  138. * >0 number of per-thread tracers
  139. * <0 number of per-cpu tracers
  140. *
  141. * The below functions to get and put tracers and to check the
  142. * allocation type require the ds_lock to be held by the caller.
  143. *
  144. * Tracers essentially gives the number of ds contexts for a certain
  145. * type of allocation.
  146. */
  147. static long tracers;
  148. static inline void get_tracer(struct task_struct *task)
  149. {
  150. tracers += (task ? 1 : -1);
  151. }
  152. static inline void put_tracer(struct task_struct *task)
  153. {
  154. tracers -= (task ? 1 : -1);
  155. }
  156. static inline int check_tracer(struct task_struct *task)
  157. {
  158. return (task ? (tracers >= 0) : (tracers <= 0));
  159. }
  160. /*
  161. * The DS context is either attached to a thread or to a cpu:
  162. * - in the former case, the thread_struct contains a pointer to the
  163. * attached context.
  164. * - in the latter case, we use a static array of per-cpu context
  165. * pointers.
  166. *
  167. * Contexts are use-counted. They are allocated on first access and
  168. * deallocated when the last user puts the context.
  169. */
  170. static DEFINE_PER_CPU(struct ds_context *, system_context);
  171. #define this_system_context per_cpu(system_context, smp_processor_id())
  172. static inline struct ds_context *ds_get_context(struct task_struct *task)
  173. {
  174. struct ds_context **p_context =
  175. (task ? &task->thread.ds_ctx : &this_system_context);
  176. struct ds_context *context = *p_context;
  177. unsigned long irq;
  178. if (!context) {
  179. context = kzalloc(sizeof(*context), GFP_KERNEL);
  180. if (!context)
  181. return NULL;
  182. spin_lock_irqsave(&ds_lock, irq);
  183. if (*p_context) {
  184. kfree(context);
  185. context = *p_context;
  186. } else {
  187. *p_context = context;
  188. context->this = p_context;
  189. context->task = task;
  190. if (task)
  191. set_tsk_thread_flag(task, TIF_DS_AREA_MSR);
  192. if (!task || (task == current))
  193. wrmsrl(MSR_IA32_DS_AREA,
  194. (unsigned long)context->ds);
  195. }
  196. spin_unlock_irqrestore(&ds_lock, irq);
  197. }
  198. context->count++;
  199. return context;
  200. }
  201. static inline void ds_put_context(struct ds_context *context)
  202. {
  203. unsigned long irq;
  204. if (!context)
  205. return;
  206. spin_lock_irqsave(&ds_lock, irq);
  207. if (--context->count)
  208. goto out;
  209. *(context->this) = NULL;
  210. if (context->task)
  211. clear_tsk_thread_flag(context->task, TIF_DS_AREA_MSR);
  212. if (!context->task || (context->task == current))
  213. wrmsrl(MSR_IA32_DS_AREA, 0);
  214. kfree(context);
  215. out:
  216. spin_unlock_irqrestore(&ds_lock, irq);
  217. }
  218. /*
  219. * Handle a buffer overflow
  220. *
  221. * context: the ds context
  222. * qual: the buffer type
  223. */
  224. static void ds_overflow(struct ds_context *context, enum ds_qualifier qual)
  225. {
  226. switch (qual) {
  227. case ds_bts: {
  228. struct bts_tracer *tracer =
  229. container_of(context->owner[qual],
  230. struct bts_tracer, ds);
  231. if (tracer->ovfl)
  232. tracer->ovfl(tracer);
  233. }
  234. break;
  235. case ds_pebs: {
  236. struct pebs_tracer *tracer =
  237. container_of(context->owner[qual],
  238. struct pebs_tracer, ds);
  239. if (tracer->ovfl)
  240. tracer->ovfl(tracer);
  241. }
  242. break;
  243. }
  244. }
  245. static void ds_install_ds_config(struct ds_context *context,
  246. enum ds_qualifier qual,
  247. void *base, size_t size, size_t ith)
  248. {
  249. unsigned long buffer, adj;
  250. /* adjust the buffer address and size to meet alignment
  251. * constraints:
  252. * - buffer is double-word aligned
  253. * - size is multiple of record size
  254. *
  255. * We checked the size at the very beginning; we have enough
  256. * space to do the adjustment.
  257. */
  258. buffer = (unsigned long)base;
  259. adj = ALIGN(buffer, DS_ALIGNMENT) - buffer;
  260. buffer += adj;
  261. size -= adj;
  262. size /= ds_cfg.sizeof_rec[qual];
  263. size *= ds_cfg.sizeof_rec[qual];
  264. ds_set(context->ds, qual, ds_buffer_base, buffer);
  265. ds_set(context->ds, qual, ds_index, buffer);
  266. ds_set(context->ds, qual, ds_absolute_maximum, buffer + size);
  267. /* The value for 'no threshold' is -1, which will set the
  268. * threshold outside of the buffer, just like we want it.
  269. */
  270. ds_set(context->ds, qual,
  271. ds_interrupt_threshold, buffer + size - ith);
  272. }
  273. static int ds_request(struct ds_tracer *tracer, enum ds_qualifier qual,
  274. struct task_struct *task,
  275. void *base, size_t size, size_t th)
  276. {
  277. struct ds_context *context;
  278. unsigned long irq;
  279. int error;
  280. error = -EOPNOTSUPP;
  281. if (!ds_cfg.sizeof_ds)
  282. goto out;
  283. error = -EINVAL;
  284. if (!base)
  285. goto out;
  286. /* we require some space to do alignment adjustments below */
  287. error = -EINVAL;
  288. if (size < (DS_ALIGNMENT + ds_cfg.sizeof_rec[qual]))
  289. goto out;
  290. if (th != (size_t)-1) {
  291. th *= ds_cfg.sizeof_rec[qual];
  292. error = -EINVAL;
  293. if (size <= th)
  294. goto out;
  295. }
  296. tracer->buffer = base;
  297. tracer->size = size;
  298. error = -ENOMEM;
  299. context = ds_get_context(task);
  300. if (!context)
  301. goto out;
  302. tracer->context = context;
  303. spin_lock_irqsave(&ds_lock, irq);
  304. error = -EPERM;
  305. if (!check_tracer(task))
  306. goto out_unlock;
  307. get_tracer(task);
  308. error = -EPERM;
  309. if (context->owner[qual])
  310. goto out_put_tracer;
  311. context->owner[qual] = tracer;
  312. spin_unlock_irqrestore(&ds_lock, irq);
  313. ds_install_ds_config(context, qual, base, size, th);
  314. return 0;
  315. out_put_tracer:
  316. put_tracer(task);
  317. out_unlock:
  318. spin_unlock_irqrestore(&ds_lock, irq);
  319. ds_put_context(context);
  320. tracer->context = NULL;
  321. out:
  322. return error;
  323. }
  324. struct bts_tracer *ds_request_bts(struct task_struct *task,
  325. void *base, size_t size,
  326. bts_ovfl_callback_t ovfl, size_t th)
  327. {
  328. struct bts_tracer *tracer;
  329. int error;
  330. /* buffer overflow notification is not yet implemented */
  331. error = -EOPNOTSUPP;
  332. if (ovfl)
  333. goto out;
  334. error = -ENOMEM;
  335. tracer = kzalloc(sizeof(*tracer), GFP_KERNEL);
  336. if (!tracer)
  337. goto out;
  338. tracer->ovfl = ovfl;
  339. error = ds_request(&tracer->ds, ds_bts, task, base, size, th);
  340. if (error < 0)
  341. goto out_tracer;
  342. return tracer;
  343. out_tracer:
  344. kfree(tracer);
  345. out:
  346. return ERR_PTR(error);
  347. }
  348. struct pebs_tracer *ds_request_pebs(struct task_struct *task,
  349. void *base, size_t size,
  350. pebs_ovfl_callback_t ovfl, size_t th)
  351. {
  352. struct pebs_tracer *tracer;
  353. int error;
  354. /* buffer overflow notification is not yet implemented */
  355. error = -EOPNOTSUPP;
  356. if (ovfl)
  357. goto out;
  358. error = -ENOMEM;
  359. tracer = kzalloc(sizeof(*tracer), GFP_KERNEL);
  360. if (!tracer)
  361. goto out;
  362. tracer->ovfl = ovfl;
  363. error = ds_request(&tracer->ds, ds_pebs, task, base, size, th);
  364. if (error < 0)
  365. goto out_tracer;
  366. return tracer;
  367. out_tracer:
  368. kfree(tracer);
  369. out:
  370. return ERR_PTR(error);
  371. }
  372. static void ds_release(struct ds_tracer *tracer, enum ds_qualifier qual)
  373. {
  374. WARN_ON_ONCE(tracer->context->owner[qual] != tracer);
  375. tracer->context->owner[qual] = NULL;
  376. put_tracer(tracer->context->task);
  377. ds_put_context(tracer->context);
  378. }
  379. int ds_release_bts(struct bts_tracer *tracer)
  380. {
  381. if (!tracer)
  382. return -EINVAL;
  383. ds_release(&tracer->ds, ds_bts);
  384. kfree(tracer);
  385. return 0;
  386. }
  387. int ds_release_pebs(struct pebs_tracer *tracer)
  388. {
  389. if (!tracer)
  390. return -EINVAL;
  391. ds_release(&tracer->ds, ds_pebs);
  392. kfree(tracer);
  393. return 0;
  394. }
  395. static size_t ds_get_index(struct ds_context *context, enum ds_qualifier qual)
  396. {
  397. unsigned long base, index;
  398. base = ds_get(context->ds, qual, ds_buffer_base);
  399. index = ds_get(context->ds, qual, ds_index);
  400. return (index - base) / ds_cfg.sizeof_rec[qual];
  401. }
  402. int ds_get_bts_index(struct bts_tracer *tracer, size_t *pos)
  403. {
  404. if (!tracer)
  405. return -EINVAL;
  406. if (!pos)
  407. return -EINVAL;
  408. *pos = ds_get_index(tracer->ds.context, ds_bts);
  409. return 0;
  410. }
  411. int ds_get_pebs_index(struct pebs_tracer *tracer, size_t *pos)
  412. {
  413. if (!tracer)
  414. return -EINVAL;
  415. if (!pos)
  416. return -EINVAL;
  417. *pos = ds_get_index(tracer->ds.context, ds_pebs);
  418. return 0;
  419. }
  420. static size_t ds_get_end(struct ds_context *context, enum ds_qualifier qual)
  421. {
  422. unsigned long base, max;
  423. base = ds_get(context->ds, qual, ds_buffer_base);
  424. max = ds_get(context->ds, qual, ds_absolute_maximum);
  425. return (max - base) / ds_cfg.sizeof_rec[qual];
  426. }
  427. int ds_get_bts_end(struct bts_tracer *tracer, size_t *pos)
  428. {
  429. if (!tracer)
  430. return -EINVAL;
  431. if (!pos)
  432. return -EINVAL;
  433. *pos = ds_get_end(tracer->ds.context, ds_bts);
  434. return 0;
  435. }
  436. int ds_get_pebs_end(struct pebs_tracer *tracer, size_t *pos)
  437. {
  438. if (!tracer)
  439. return -EINVAL;
  440. if (!pos)
  441. return -EINVAL;
  442. *pos = ds_get_end(tracer->ds.context, ds_pebs);
  443. return 0;
  444. }
  445. static int ds_access(struct ds_context *context, enum ds_qualifier qual,
  446. size_t index, const void **record)
  447. {
  448. unsigned long base, idx;
  449. if (!record)
  450. return -EINVAL;
  451. base = ds_get(context->ds, qual, ds_buffer_base);
  452. idx = base + (index * ds_cfg.sizeof_rec[qual]);
  453. if (idx > ds_get(context->ds, qual, ds_absolute_maximum))
  454. return -EINVAL;
  455. *record = (const void *)idx;
  456. return ds_cfg.sizeof_rec[qual];
  457. }
  458. int ds_access_bts(struct bts_tracer *tracer, size_t index,
  459. const void **record)
  460. {
  461. if (!tracer)
  462. return -EINVAL;
  463. return ds_access(tracer->ds.context, ds_bts, index, record);
  464. }
  465. int ds_access_pebs(struct pebs_tracer *tracer, size_t index,
  466. const void **record)
  467. {
  468. if (!tracer)
  469. return -EINVAL;
  470. return ds_access(tracer->ds.context, ds_pebs, index, record);
  471. }
  472. static int ds_write(struct ds_context *context, enum ds_qualifier qual,
  473. const void *record, size_t size)
  474. {
  475. int bytes_written = 0;
  476. if (!record)
  477. return -EINVAL;
  478. while (size) {
  479. unsigned long base, index, end, write_end, int_th;
  480. unsigned long write_size, adj_write_size;
  481. /*
  482. * write as much as possible without producing an
  483. * overflow interrupt.
  484. *
  485. * interrupt_threshold must either be
  486. * - bigger than absolute_maximum or
  487. * - point to a record between buffer_base and absolute_maximum
  488. *
  489. * index points to a valid record.
  490. */
  491. base = ds_get(context->ds, qual, ds_buffer_base);
  492. index = ds_get(context->ds, qual, ds_index);
  493. end = ds_get(context->ds, qual, ds_absolute_maximum);
  494. int_th = ds_get(context->ds, qual, ds_interrupt_threshold);
  495. write_end = min(end, int_th);
  496. /* if we are already beyond the interrupt threshold,
  497. * we fill the entire buffer */
  498. if (write_end <= index)
  499. write_end = end;
  500. if (write_end <= index)
  501. break;
  502. write_size = min((unsigned long) size, write_end - index);
  503. memcpy((void *)index, record, write_size);
  504. record = (const char *)record + write_size;
  505. size -= write_size;
  506. bytes_written += write_size;
  507. adj_write_size = write_size / ds_cfg.sizeof_rec[qual];
  508. adj_write_size *= ds_cfg.sizeof_rec[qual];
  509. /* zero out trailing bytes */
  510. memset((char *)index + write_size, 0,
  511. adj_write_size - write_size);
  512. index += adj_write_size;
  513. if (index >= end)
  514. index = base;
  515. ds_set(context->ds, qual, ds_index, index);
  516. if (index >= int_th)
  517. ds_overflow(context, qual);
  518. }
  519. return bytes_written;
  520. }
  521. int ds_write_bts(struct bts_tracer *tracer, const void *record, size_t size)
  522. {
  523. if (!tracer)
  524. return -EINVAL;
  525. return ds_write(tracer->ds.context, ds_bts, record, size);
  526. }
  527. int ds_write_pebs(struct pebs_tracer *tracer, const void *record, size_t size)
  528. {
  529. if (!tracer)
  530. return -EINVAL;
  531. return ds_write(tracer->ds.context, ds_pebs, record, size);
  532. }
  533. static void ds_reset_or_clear(struct ds_context *context,
  534. enum ds_qualifier qual, int clear)
  535. {
  536. unsigned long base, end;
  537. base = ds_get(context->ds, qual, ds_buffer_base);
  538. end = ds_get(context->ds, qual, ds_absolute_maximum);
  539. if (clear)
  540. memset((void *)base, 0, end - base);
  541. ds_set(context->ds, qual, ds_index, base);
  542. }
  543. int ds_reset_bts(struct bts_tracer *tracer)
  544. {
  545. if (!tracer)
  546. return -EINVAL;
  547. ds_reset_or_clear(tracer->ds.context, ds_bts, /* clear = */ 0);
  548. return 0;
  549. }
  550. int ds_reset_pebs(struct pebs_tracer *tracer)
  551. {
  552. if (!tracer)
  553. return -EINVAL;
  554. ds_reset_or_clear(tracer->ds.context, ds_pebs, /* clear = */ 0);
  555. return 0;
  556. }
  557. int ds_clear_bts(struct bts_tracer *tracer)
  558. {
  559. if (!tracer)
  560. return -EINVAL;
  561. ds_reset_or_clear(tracer->ds.context, ds_bts, /* clear = */ 1);
  562. return 0;
  563. }
  564. int ds_clear_pebs(struct pebs_tracer *tracer)
  565. {
  566. if (!tracer)
  567. return -EINVAL;
  568. ds_reset_or_clear(tracer->ds.context, ds_pebs, /* clear = */ 1);
  569. return 0;
  570. }
  571. int ds_get_pebs_reset(struct pebs_tracer *tracer, u64 *value)
  572. {
  573. if (!tracer)
  574. return -EINVAL;
  575. if (!value)
  576. return -EINVAL;
  577. *value = *(u64 *)(tracer->ds.context->ds + (ds_cfg.sizeof_field * 8));
  578. return 0;
  579. }
  580. int ds_set_pebs_reset(struct pebs_tracer *tracer, u64 value)
  581. {
  582. if (!tracer)
  583. return -EINVAL;
  584. *(u64 *)(tracer->ds.context->ds + (ds_cfg.sizeof_field * 8)) = value;
  585. return 0;
  586. }
  587. static const struct ds_configuration ds_cfg_var = {
  588. .sizeof_ds = sizeof(long) * 12,
  589. .sizeof_field = sizeof(long),
  590. .sizeof_rec[ds_bts] = sizeof(long) * 3,
  591. #ifdef __i386__
  592. .sizeof_rec[ds_pebs] = sizeof(long) * 10
  593. #else
  594. .sizeof_rec[ds_pebs] = sizeof(long) * 18
  595. #endif
  596. };
  597. static const struct ds_configuration ds_cfg_64 = {
  598. .sizeof_ds = 8 * 12,
  599. .sizeof_field = 8,
  600. .sizeof_rec[ds_bts] = 8 * 3,
  601. #ifdef __i386__
  602. .sizeof_rec[ds_pebs] = 8 * 10
  603. #else
  604. .sizeof_rec[ds_pebs] = 8 * 18
  605. #endif
  606. };
  607. static inline void
  608. ds_configure(const struct ds_configuration *cfg)
  609. {
  610. ds_cfg = *cfg;
  611. printk(KERN_INFO "DS available\n");
  612. WARN_ON_ONCE(MAX_SIZEOF_DS < ds_cfg.sizeof_ds);
  613. }
  614. void __cpuinit ds_init_intel(struct cpuinfo_x86 *c)
  615. {
  616. switch (c->x86) {
  617. case 0x6:
  618. switch (c->x86_model) {
  619. case 0 ... 0xC:
  620. /* sorry, don't know about them */
  621. break;
  622. case 0xD:
  623. case 0xE: /* Pentium M */
  624. ds_configure(&ds_cfg_var);
  625. break;
  626. default: /* Core2, Atom, ... */
  627. ds_configure(&ds_cfg_64);
  628. break;
  629. }
  630. break;
  631. case 0xF:
  632. switch (c->x86_model) {
  633. case 0x0:
  634. case 0x1:
  635. case 0x2: /* Netburst */
  636. ds_configure(&ds_cfg_var);
  637. break;
  638. default:
  639. /* sorry, don't know about them */
  640. break;
  641. }
  642. break;
  643. default:
  644. /* sorry, don't know about them */
  645. break;
  646. }
  647. }
  648. void ds_free(struct ds_context *context)
  649. {
  650. /* This is called when the task owning the parameter context
  651. * is dying. There should not be any user of that context left
  652. * to disturb us, anymore. */
  653. unsigned long leftovers = context->count;
  654. while (leftovers--) {
  655. put_tracer(context->task);
  656. ds_put_context(context);
  657. }
  658. }