trace_selftest.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. /* Include in trace.c */
  2. #include <linux/stringify.h>
  3. #include <linux/kthread.h>
  4. #include <linux/delay.h>
  5. #include <linux/slab.h>
  6. static inline int trace_valid_entry(struct trace_entry *entry)
  7. {
  8. switch (entry->type) {
  9. case TRACE_FN:
  10. case TRACE_CTX:
  11. case TRACE_WAKE:
  12. case TRACE_STACK:
  13. case TRACE_PRINT:
  14. case TRACE_SPECIAL:
  15. case TRACE_BRANCH:
  16. case TRACE_GRAPH_ENT:
  17. case TRACE_GRAPH_RET:
  18. case TRACE_KSYM:
  19. return 1;
  20. }
  21. return 0;
  22. }
  23. static int trace_test_buffer_cpu(struct trace_array *tr, int cpu)
  24. {
  25. struct ring_buffer_event *event;
  26. struct trace_entry *entry;
  27. unsigned int loops = 0;
  28. while ((event = ring_buffer_consume(tr->buffer, cpu, NULL, NULL))) {
  29. entry = ring_buffer_event_data(event);
  30. /*
  31. * The ring buffer is a size of trace_buf_size, if
  32. * we loop more than the size, there's something wrong
  33. * with the ring buffer.
  34. */
  35. if (loops++ > trace_buf_size) {
  36. printk(KERN_CONT ".. bad ring buffer ");
  37. goto failed;
  38. }
  39. if (!trace_valid_entry(entry)) {
  40. printk(KERN_CONT ".. invalid entry %d ",
  41. entry->type);
  42. goto failed;
  43. }
  44. }
  45. return 0;
  46. failed:
  47. /* disable tracing */
  48. tracing_disabled = 1;
  49. printk(KERN_CONT ".. corrupted trace buffer .. ");
  50. return -1;
  51. }
  52. /*
  53. * Test the trace buffer to see if all the elements
  54. * are still sane.
  55. */
  56. static int trace_test_buffer(struct trace_array *tr, unsigned long *count)
  57. {
  58. unsigned long flags, cnt = 0;
  59. int cpu, ret = 0;
  60. /* Don't allow flipping of max traces now */
  61. local_irq_save(flags);
  62. arch_spin_lock(&ftrace_max_lock);
  63. cnt = ring_buffer_entries(tr->buffer);
  64. /*
  65. * The trace_test_buffer_cpu runs a while loop to consume all data.
  66. * If the calling tracer is broken, and is constantly filling
  67. * the buffer, this will run forever, and hard lock the box.
  68. * We disable the ring buffer while we do this test to prevent
  69. * a hard lock up.
  70. */
  71. tracing_off();
  72. for_each_possible_cpu(cpu) {
  73. ret = trace_test_buffer_cpu(tr, cpu);
  74. if (ret)
  75. break;
  76. }
  77. tracing_on();
  78. arch_spin_unlock(&ftrace_max_lock);
  79. local_irq_restore(flags);
  80. if (count)
  81. *count = cnt;
  82. return ret;
  83. }
  84. static inline void warn_failed_init_tracer(struct tracer *trace, int init_ret)
  85. {
  86. printk(KERN_WARNING "Failed to init %s tracer, init returned %d\n",
  87. trace->name, init_ret);
  88. }
  89. #ifdef CONFIG_FUNCTION_TRACER
  90. #ifdef CONFIG_DYNAMIC_FTRACE
  91. /* Test dynamic code modification and ftrace filters */
  92. int trace_selftest_startup_dynamic_tracing(struct tracer *trace,
  93. struct trace_array *tr,
  94. int (*func)(void))
  95. {
  96. int save_ftrace_enabled = ftrace_enabled;
  97. int save_tracer_enabled = tracer_enabled;
  98. unsigned long count;
  99. char *func_name;
  100. int ret;
  101. /* The ftrace test PASSED */
  102. printk(KERN_CONT "PASSED\n");
  103. pr_info("Testing dynamic ftrace: ");
  104. /* enable tracing, and record the filter function */
  105. ftrace_enabled = 1;
  106. tracer_enabled = 1;
  107. /* passed in by parameter to fool gcc from optimizing */
  108. func();
  109. /*
  110. * Some archs *cough*PowerPC*cough* add characters to the
  111. * start of the function names. We simply put a '*' to
  112. * accommodate them.
  113. */
  114. func_name = "*" __stringify(DYN_FTRACE_TEST_NAME);
  115. /* filter only on our function */
  116. ftrace_set_filter(func_name, strlen(func_name), 1);
  117. /* enable tracing */
  118. ret = tracer_init(trace, tr);
  119. if (ret) {
  120. warn_failed_init_tracer(trace, ret);
  121. goto out;
  122. }
  123. /* Sleep for a 1/10 of a second */
  124. msleep(100);
  125. /* we should have nothing in the buffer */
  126. ret = trace_test_buffer(tr, &count);
  127. if (ret)
  128. goto out;
  129. if (count) {
  130. ret = -1;
  131. printk(KERN_CONT ".. filter did not filter .. ");
  132. goto out;
  133. }
  134. /* call our function again */
  135. func();
  136. /* sleep again */
  137. msleep(100);
  138. /* stop the tracing. */
  139. tracing_stop();
  140. ftrace_enabled = 0;
  141. /* check the trace buffer */
  142. ret = trace_test_buffer(tr, &count);
  143. trace->reset(tr);
  144. tracing_start();
  145. /* we should only have one item */
  146. if (!ret && count != 1) {
  147. printk(KERN_CONT ".. filter failed count=%ld ..", count);
  148. ret = -1;
  149. goto out;
  150. }
  151. out:
  152. ftrace_enabled = save_ftrace_enabled;
  153. tracer_enabled = save_tracer_enabled;
  154. /* Enable tracing on all functions again */
  155. ftrace_set_filter(NULL, 0, 1);
  156. return ret;
  157. }
  158. #else
  159. # define trace_selftest_startup_dynamic_tracing(trace, tr, func) ({ 0; })
  160. #endif /* CONFIG_DYNAMIC_FTRACE */
  161. /*
  162. * Simple verification test of ftrace function tracer.
  163. * Enable ftrace, sleep 1/10 second, and then read the trace
  164. * buffer to see if all is in order.
  165. */
  166. int
  167. trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr)
  168. {
  169. int save_ftrace_enabled = ftrace_enabled;
  170. int save_tracer_enabled = tracer_enabled;
  171. unsigned long count;
  172. int ret;
  173. /* make sure msleep has been recorded */
  174. msleep(1);
  175. /* start the tracing */
  176. ftrace_enabled = 1;
  177. tracer_enabled = 1;
  178. ret = tracer_init(trace, tr);
  179. if (ret) {
  180. warn_failed_init_tracer(trace, ret);
  181. goto out;
  182. }
  183. /* Sleep for a 1/10 of a second */
  184. msleep(100);
  185. /* stop the tracing. */
  186. tracing_stop();
  187. ftrace_enabled = 0;
  188. /* check the trace buffer */
  189. ret = trace_test_buffer(tr, &count);
  190. trace->reset(tr);
  191. tracing_start();
  192. if (!ret && !count) {
  193. printk(KERN_CONT ".. no entries found ..");
  194. ret = -1;
  195. goto out;
  196. }
  197. ret = trace_selftest_startup_dynamic_tracing(trace, tr,
  198. DYN_FTRACE_TEST_NAME);
  199. out:
  200. ftrace_enabled = save_ftrace_enabled;
  201. tracer_enabled = save_tracer_enabled;
  202. /* kill ftrace totally if we failed */
  203. if (ret)
  204. ftrace_kill();
  205. return ret;
  206. }
  207. #endif /* CONFIG_FUNCTION_TRACER */
  208. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  209. /* Maximum number of functions to trace before diagnosing a hang */
  210. #define GRAPH_MAX_FUNC_TEST 100000000
  211. static void
  212. __ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode);
  213. static unsigned int graph_hang_thresh;
  214. /* Wrap the real function entry probe to avoid possible hanging */
  215. static int trace_graph_entry_watchdog(struct ftrace_graph_ent *trace)
  216. {
  217. /* This is harmlessly racy, we want to approximately detect a hang */
  218. if (unlikely(++graph_hang_thresh > GRAPH_MAX_FUNC_TEST)) {
  219. ftrace_graph_stop();
  220. printk(KERN_WARNING "BUG: Function graph tracer hang!\n");
  221. if (ftrace_dump_on_oops)
  222. __ftrace_dump(false, DUMP_ALL);
  223. return 0;
  224. }
  225. return trace_graph_entry(trace);
  226. }
  227. /*
  228. * Pretty much the same than for the function tracer from which the selftest
  229. * has been borrowed.
  230. */
  231. int
  232. trace_selftest_startup_function_graph(struct tracer *trace,
  233. struct trace_array *tr)
  234. {
  235. int ret;
  236. unsigned long count;
  237. /*
  238. * Simulate the init() callback but we attach a watchdog callback
  239. * to detect and recover from possible hangs
  240. */
  241. tracing_reset_online_cpus(tr);
  242. set_graph_array(tr);
  243. ret = register_ftrace_graph(&trace_graph_return,
  244. &trace_graph_entry_watchdog);
  245. if (ret) {
  246. warn_failed_init_tracer(trace, ret);
  247. goto out;
  248. }
  249. tracing_start_cmdline_record();
  250. /* Sleep for a 1/10 of a second */
  251. msleep(100);
  252. /* Have we just recovered from a hang? */
  253. if (graph_hang_thresh > GRAPH_MAX_FUNC_TEST) {
  254. tracing_selftest_disabled = true;
  255. ret = -1;
  256. goto out;
  257. }
  258. tracing_stop();
  259. /* check the trace buffer */
  260. ret = trace_test_buffer(tr, &count);
  261. trace->reset(tr);
  262. tracing_start();
  263. if (!ret && !count) {
  264. printk(KERN_CONT ".. no entries found ..");
  265. ret = -1;
  266. goto out;
  267. }
  268. /* Don't test dynamic tracing, the function tracer already did */
  269. out:
  270. /* Stop it if we failed */
  271. if (ret)
  272. ftrace_graph_stop();
  273. return ret;
  274. }
  275. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  276. #ifdef CONFIG_IRQSOFF_TRACER
  277. int
  278. trace_selftest_startup_irqsoff(struct tracer *trace, struct trace_array *tr)
  279. {
  280. unsigned long save_max = tracing_max_latency;
  281. unsigned long count;
  282. int ret;
  283. /* start the tracing */
  284. ret = tracer_init(trace, tr);
  285. if (ret) {
  286. warn_failed_init_tracer(trace, ret);
  287. return ret;
  288. }
  289. /* reset the max latency */
  290. tracing_max_latency = 0;
  291. /* disable interrupts for a bit */
  292. local_irq_disable();
  293. udelay(100);
  294. local_irq_enable();
  295. /*
  296. * Stop the tracer to avoid a warning subsequent
  297. * to buffer flipping failure because tracing_stop()
  298. * disables the tr and max buffers, making flipping impossible
  299. * in case of parallels max irqs off latencies.
  300. */
  301. trace->stop(tr);
  302. /* stop the tracing. */
  303. tracing_stop();
  304. /* check both trace buffers */
  305. ret = trace_test_buffer(tr, NULL);
  306. if (!ret)
  307. ret = trace_test_buffer(&max_tr, &count);
  308. trace->reset(tr);
  309. tracing_start();
  310. if (!ret && !count) {
  311. printk(KERN_CONT ".. no entries found ..");
  312. ret = -1;
  313. }
  314. tracing_max_latency = save_max;
  315. return ret;
  316. }
  317. #endif /* CONFIG_IRQSOFF_TRACER */
  318. #ifdef CONFIG_PREEMPT_TRACER
  319. int
  320. trace_selftest_startup_preemptoff(struct tracer *trace, struct trace_array *tr)
  321. {
  322. unsigned long save_max = tracing_max_latency;
  323. unsigned long count;
  324. int ret;
  325. /*
  326. * Now that the big kernel lock is no longer preemptable,
  327. * and this is called with the BKL held, it will always
  328. * fail. If preemption is already disabled, simply
  329. * pass the test. When the BKL is removed, or becomes
  330. * preemptible again, we will once again test this,
  331. * so keep it in.
  332. */
  333. if (preempt_count()) {
  334. printk(KERN_CONT "can not test ... force ");
  335. return 0;
  336. }
  337. /* start the tracing */
  338. ret = tracer_init(trace, tr);
  339. if (ret) {
  340. warn_failed_init_tracer(trace, ret);
  341. return ret;
  342. }
  343. /* reset the max latency */
  344. tracing_max_latency = 0;
  345. /* disable preemption for a bit */
  346. preempt_disable();
  347. udelay(100);
  348. preempt_enable();
  349. /*
  350. * Stop the tracer to avoid a warning subsequent
  351. * to buffer flipping failure because tracing_stop()
  352. * disables the tr and max buffers, making flipping impossible
  353. * in case of parallels max preempt off latencies.
  354. */
  355. trace->stop(tr);
  356. /* stop the tracing. */
  357. tracing_stop();
  358. /* check both trace buffers */
  359. ret = trace_test_buffer(tr, NULL);
  360. if (!ret)
  361. ret = trace_test_buffer(&max_tr, &count);
  362. trace->reset(tr);
  363. tracing_start();
  364. if (!ret && !count) {
  365. printk(KERN_CONT ".. no entries found ..");
  366. ret = -1;
  367. }
  368. tracing_max_latency = save_max;
  369. return ret;
  370. }
  371. #endif /* CONFIG_PREEMPT_TRACER */
  372. #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
  373. int
  374. trace_selftest_startup_preemptirqsoff(struct tracer *trace, struct trace_array *tr)
  375. {
  376. unsigned long save_max = tracing_max_latency;
  377. unsigned long count;
  378. int ret;
  379. /*
  380. * Now that the big kernel lock is no longer preemptable,
  381. * and this is called with the BKL held, it will always
  382. * fail. If preemption is already disabled, simply
  383. * pass the test. When the BKL is removed, or becomes
  384. * preemptible again, we will once again test this,
  385. * so keep it in.
  386. */
  387. if (preempt_count()) {
  388. printk(KERN_CONT "can not test ... force ");
  389. return 0;
  390. }
  391. /* start the tracing */
  392. ret = tracer_init(trace, tr);
  393. if (ret) {
  394. warn_failed_init_tracer(trace, ret);
  395. goto out_no_start;
  396. }
  397. /* reset the max latency */
  398. tracing_max_latency = 0;
  399. /* disable preemption and interrupts for a bit */
  400. preempt_disable();
  401. local_irq_disable();
  402. udelay(100);
  403. preempt_enable();
  404. /* reverse the order of preempt vs irqs */
  405. local_irq_enable();
  406. /*
  407. * Stop the tracer to avoid a warning subsequent
  408. * to buffer flipping failure because tracing_stop()
  409. * disables the tr and max buffers, making flipping impossible
  410. * in case of parallels max irqs/preempt off latencies.
  411. */
  412. trace->stop(tr);
  413. /* stop the tracing. */
  414. tracing_stop();
  415. /* check both trace buffers */
  416. ret = trace_test_buffer(tr, NULL);
  417. if (ret)
  418. goto out;
  419. ret = trace_test_buffer(&max_tr, &count);
  420. if (ret)
  421. goto out;
  422. if (!ret && !count) {
  423. printk(KERN_CONT ".. no entries found ..");
  424. ret = -1;
  425. goto out;
  426. }
  427. /* do the test by disabling interrupts first this time */
  428. tracing_max_latency = 0;
  429. tracing_start();
  430. trace->start(tr);
  431. preempt_disable();
  432. local_irq_disable();
  433. udelay(100);
  434. preempt_enable();
  435. /* reverse the order of preempt vs irqs */
  436. local_irq_enable();
  437. trace->stop(tr);
  438. /* stop the tracing. */
  439. tracing_stop();
  440. /* check both trace buffers */
  441. ret = trace_test_buffer(tr, NULL);
  442. if (ret)
  443. goto out;
  444. ret = trace_test_buffer(&max_tr, &count);
  445. if (!ret && !count) {
  446. printk(KERN_CONT ".. no entries found ..");
  447. ret = -1;
  448. goto out;
  449. }
  450. out:
  451. tracing_start();
  452. out_no_start:
  453. trace->reset(tr);
  454. tracing_max_latency = save_max;
  455. return ret;
  456. }
  457. #endif /* CONFIG_IRQSOFF_TRACER && CONFIG_PREEMPT_TRACER */
  458. #ifdef CONFIG_NOP_TRACER
  459. int
  460. trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr)
  461. {
  462. /* What could possibly go wrong? */
  463. return 0;
  464. }
  465. #endif
  466. #ifdef CONFIG_SCHED_TRACER
  467. static int trace_wakeup_test_thread(void *data)
  468. {
  469. /* Make this a RT thread, doesn't need to be too high */
  470. struct sched_param param = { .sched_priority = 5 };
  471. struct completion *x = data;
  472. sched_setscheduler(current, SCHED_FIFO, &param);
  473. /* Make it know we have a new prio */
  474. complete(x);
  475. /* now go to sleep and let the test wake us up */
  476. set_current_state(TASK_INTERRUPTIBLE);
  477. schedule();
  478. /* we are awake, now wait to disappear */
  479. while (!kthread_should_stop()) {
  480. /*
  481. * This is an RT task, do short sleeps to let
  482. * others run.
  483. */
  484. msleep(100);
  485. }
  486. return 0;
  487. }
  488. int
  489. trace_selftest_startup_wakeup(struct tracer *trace, struct trace_array *tr)
  490. {
  491. unsigned long save_max = tracing_max_latency;
  492. struct task_struct *p;
  493. struct completion isrt;
  494. unsigned long count;
  495. int ret;
  496. init_completion(&isrt);
  497. /* create a high prio thread */
  498. p = kthread_run(trace_wakeup_test_thread, &isrt, "ftrace-test");
  499. if (IS_ERR(p)) {
  500. printk(KERN_CONT "Failed to create ftrace wakeup test thread ");
  501. return -1;
  502. }
  503. /* make sure the thread is running at an RT prio */
  504. wait_for_completion(&isrt);
  505. /* start the tracing */
  506. ret = tracer_init(trace, tr);
  507. if (ret) {
  508. warn_failed_init_tracer(trace, ret);
  509. return ret;
  510. }
  511. /* reset the max latency */
  512. tracing_max_latency = 0;
  513. /* sleep to let the RT thread sleep too */
  514. msleep(100);
  515. /*
  516. * Yes this is slightly racy. It is possible that for some
  517. * strange reason that the RT thread we created, did not
  518. * call schedule for 100ms after doing the completion,
  519. * and we do a wakeup on a task that already is awake.
  520. * But that is extremely unlikely, and the worst thing that
  521. * happens in such a case, is that we disable tracing.
  522. * Honestly, if this race does happen something is horrible
  523. * wrong with the system.
  524. */
  525. wake_up_process(p);
  526. /* give a little time to let the thread wake up */
  527. msleep(100);
  528. /* stop the tracing. */
  529. tracing_stop();
  530. /* check both trace buffers */
  531. ret = trace_test_buffer(tr, NULL);
  532. if (!ret)
  533. ret = trace_test_buffer(&max_tr, &count);
  534. trace->reset(tr);
  535. tracing_start();
  536. tracing_max_latency = save_max;
  537. /* kill the thread */
  538. kthread_stop(p);
  539. if (!ret && !count) {
  540. printk(KERN_CONT ".. no entries found ..");
  541. ret = -1;
  542. }
  543. return ret;
  544. }
  545. #endif /* CONFIG_SCHED_TRACER */
  546. #ifdef CONFIG_CONTEXT_SWITCH_TRACER
  547. int
  548. trace_selftest_startup_sched_switch(struct tracer *trace, struct trace_array *tr)
  549. {
  550. unsigned long count;
  551. int ret;
  552. /* start the tracing */
  553. ret = tracer_init(trace, tr);
  554. if (ret) {
  555. warn_failed_init_tracer(trace, ret);
  556. return ret;
  557. }
  558. /* Sleep for a 1/10 of a second */
  559. msleep(100);
  560. /* stop the tracing. */
  561. tracing_stop();
  562. /* check the trace buffer */
  563. ret = trace_test_buffer(tr, &count);
  564. trace->reset(tr);
  565. tracing_start();
  566. if (!ret && !count) {
  567. printk(KERN_CONT ".. no entries found ..");
  568. ret = -1;
  569. }
  570. return ret;
  571. }
  572. #endif /* CONFIG_CONTEXT_SWITCH_TRACER */
  573. #ifdef CONFIG_SYSPROF_TRACER
  574. int
  575. trace_selftest_startup_sysprof(struct tracer *trace, struct trace_array *tr)
  576. {
  577. unsigned long count;
  578. int ret;
  579. /* start the tracing */
  580. ret = tracer_init(trace, tr);
  581. if (ret) {
  582. warn_failed_init_tracer(trace, ret);
  583. return ret;
  584. }
  585. /* Sleep for a 1/10 of a second */
  586. msleep(100);
  587. /* stop the tracing. */
  588. tracing_stop();
  589. /* check the trace buffer */
  590. ret = trace_test_buffer(tr, &count);
  591. trace->reset(tr);
  592. tracing_start();
  593. if (!ret && !count) {
  594. printk(KERN_CONT ".. no entries found ..");
  595. ret = -1;
  596. }
  597. return ret;
  598. }
  599. #endif /* CONFIG_SYSPROF_TRACER */
  600. #ifdef CONFIG_BRANCH_TRACER
  601. int
  602. trace_selftest_startup_branch(struct tracer *trace, struct trace_array *tr)
  603. {
  604. unsigned long count;
  605. int ret;
  606. /* start the tracing */
  607. ret = tracer_init(trace, tr);
  608. if (ret) {
  609. warn_failed_init_tracer(trace, ret);
  610. return ret;
  611. }
  612. /* Sleep for a 1/10 of a second */
  613. msleep(100);
  614. /* stop the tracing. */
  615. tracing_stop();
  616. /* check the trace buffer */
  617. ret = trace_test_buffer(tr, &count);
  618. trace->reset(tr);
  619. tracing_start();
  620. if (!ret && !count) {
  621. printk(KERN_CONT ".. no entries found ..");
  622. ret = -1;
  623. }
  624. return ret;
  625. }
  626. #endif /* CONFIG_BRANCH_TRACER */
  627. #ifdef CONFIG_KSYM_TRACER
  628. static int ksym_selftest_dummy;
  629. int
  630. trace_selftest_startup_ksym(struct tracer *trace, struct trace_array *tr)
  631. {
  632. unsigned long count;
  633. int ret;
  634. /* start the tracing */
  635. ret = tracer_init(trace, tr);
  636. if (ret) {
  637. warn_failed_init_tracer(trace, ret);
  638. return ret;
  639. }
  640. ksym_selftest_dummy = 0;
  641. /* Register the read-write tracing request */
  642. ret = process_new_ksym_entry("ksym_selftest_dummy",
  643. HW_BREAKPOINT_R | HW_BREAKPOINT_W,
  644. (unsigned long)(&ksym_selftest_dummy));
  645. if (ret < 0) {
  646. printk(KERN_CONT "ksym_trace read-write startup test failed\n");
  647. goto ret_path;
  648. }
  649. /* Perform a read and a write operation over the dummy variable to
  650. * trigger the tracer
  651. */
  652. if (ksym_selftest_dummy == 0)
  653. ksym_selftest_dummy++;
  654. /* stop the tracing. */
  655. tracing_stop();
  656. /* check the trace buffer */
  657. ret = trace_test_buffer(tr, &count);
  658. trace->reset(tr);
  659. tracing_start();
  660. /* read & write operations - one each is performed on the dummy variable
  661. * triggering two entries in the trace buffer
  662. */
  663. if (!ret && count != 2) {
  664. printk(KERN_CONT "Ksym tracer startup test failed");
  665. ret = -1;
  666. }
  667. ret_path:
  668. return ret;
  669. }
  670. #endif /* CONFIG_KSYM_TRACER */