trace_irqsoff.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * trace irqs off critical timings
  4. *
  5. * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
  6. * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
  7. *
  8. * From code in the latency_tracer, that is:
  9. *
  10. * Copyright (C) 2004-2006 Ingo Molnar
  11. * Copyright (C) 2004 Nadia Yvette Chambers
  12. */
  13. #include <linux/kallsyms.h>
  14. #include <linux/uaccess.h>
  15. #include <linux/module.h>
  16. #include <linux/ftrace.h>
  17. #include <linux/kprobes.h>
  18. #include "trace.h"
  19. #include <trace/events/preemptirq.h>
  20. #if defined(CONFIG_IRQSOFF_TRACER) || defined(CONFIG_PREEMPT_TRACER)
  21. static struct trace_array *irqsoff_trace __read_mostly;
  22. static int tracer_enabled __read_mostly;
  23. static DEFINE_PER_CPU(int, tracing_cpu);
  24. static DEFINE_RAW_SPINLOCK(max_trace_lock);
  25. enum {
  26. TRACER_IRQS_OFF = (1 << 1),
  27. TRACER_PREEMPT_OFF = (1 << 2),
  28. };
  29. static int trace_type __read_mostly;
  30. static int save_flags;
  31. static void stop_irqsoff_tracer(struct trace_array *tr, int graph);
  32. static int start_irqsoff_tracer(struct trace_array *tr, int graph);
  33. #ifdef CONFIG_PREEMPT_TRACER
  34. static inline int
  35. preempt_trace(int pc)
  36. {
  37. return ((trace_type & TRACER_PREEMPT_OFF) && pc);
  38. }
  39. #else
  40. # define preempt_trace(pc) (0)
  41. #endif
  42. #ifdef CONFIG_IRQSOFF_TRACER
  43. static inline int
  44. irq_trace(void)
  45. {
  46. return ((trace_type & TRACER_IRQS_OFF) &&
  47. irqs_disabled());
  48. }
  49. #else
  50. # define irq_trace() (0)
  51. #endif
  52. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  53. static int irqsoff_display_graph(struct trace_array *tr, int set);
  54. # define is_graph(tr) ((tr)->trace_flags & TRACE_ITER(DISPLAY_GRAPH))
  55. #else
  56. static inline int irqsoff_display_graph(struct trace_array *tr, int set)
  57. {
  58. return -EINVAL;
  59. }
  60. # define is_graph(tr) false
  61. #endif
  62. /*
  63. * Sequence count - we record it when starting a measurement and
  64. * skip the latency if the sequence has changed - some other section
  65. * did a maximum and could disturb our measurement with serial console
  66. * printouts, etc. Truly coinciding maximum latencies should be rare
  67. * and what happens together happens separately as well, so this doesn't
  68. * decrease the validity of the maximum found:
  69. */
  70. static __cacheline_aligned_in_smp unsigned long max_sequence;
  71. #ifdef CONFIG_FUNCTION_TRACER
  72. /*
  73. * Prologue for the preempt and irqs off function tracers.
  74. *
  75. * Returns 1 if it is OK to continue, and data->disabled is
  76. * incremented.
  77. * 0 if the trace is to be ignored, and data->disabled
  78. * is kept the same.
  79. *
  80. * Note, this function is also used outside this ifdef but
  81. * inside the #ifdef of the function graph tracer below.
  82. * This is OK, since the function graph tracer is
  83. * dependent on the function tracer.
  84. */
  85. static int func_prolog_dec(struct trace_array *tr,
  86. struct trace_array_cpu **data,
  87. unsigned long *flags)
  88. {
  89. long disabled;
  90. int cpu;
  91. /*
  92. * Does not matter if we preempt. We test the flags
  93. * afterward, to see if irqs are disabled or not.
  94. * If we preempt and get a false positive, the flags
  95. * test will fail.
  96. */
  97. cpu = raw_smp_processor_id();
  98. if (likely(!per_cpu(tracing_cpu, cpu)))
  99. return 0;
  100. local_save_flags(*flags);
  101. /*
  102. * Slight chance to get a false positive on tracing_cpu,
  103. * although I'm starting to think there isn't a chance.
  104. * Leave this for now just to be paranoid.
  105. */
  106. if (!irqs_disabled_flags(*flags) && !preempt_count())
  107. return 0;
  108. *data = per_cpu_ptr(tr->array_buffer.data, cpu);
  109. disabled = local_inc_return(&(*data)->disabled);
  110. if (likely(disabled == 1))
  111. return 1;
  112. local_dec(&(*data)->disabled);
  113. return 0;
  114. }
  115. /*
  116. * irqsoff uses its own tracer function to keep the overhead down:
  117. */
  118. static void
  119. irqsoff_tracer_call(unsigned long ip, unsigned long parent_ip,
  120. struct ftrace_ops *op, struct ftrace_regs *fregs)
  121. {
  122. struct trace_array *tr = irqsoff_trace;
  123. struct trace_array_cpu *data;
  124. unsigned long flags;
  125. unsigned int trace_ctx;
  126. if (!func_prolog_dec(tr, &data, &flags))
  127. return;
  128. trace_ctx = tracing_gen_ctx_flags(flags);
  129. trace_function(tr, ip, parent_ip, trace_ctx, fregs);
  130. local_dec(&data->disabled);
  131. }
  132. #endif /* CONFIG_FUNCTION_TRACER */
  133. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  134. static int irqsoff_display_graph(struct trace_array *tr, int set)
  135. {
  136. int cpu;
  137. if (!(is_graph(tr) ^ set))
  138. return 0;
  139. stop_irqsoff_tracer(irqsoff_trace, !set);
  140. for_each_possible_cpu(cpu)
  141. per_cpu(tracing_cpu, cpu) = 0;
  142. tr->max_latency = 0;
  143. tracing_reset_online_cpus(&irqsoff_trace->array_buffer);
  144. return start_irqsoff_tracer(irqsoff_trace, set);
  145. }
  146. static int irqsoff_graph_entry(struct ftrace_graph_ent *trace,
  147. struct fgraph_ops *gops,
  148. struct ftrace_regs *fregs)
  149. {
  150. struct trace_array *tr = irqsoff_trace;
  151. struct trace_array_cpu *data;
  152. unsigned long flags;
  153. unsigned int trace_ctx;
  154. u64 *calltime;
  155. int ret = 0;
  156. if (ftrace_graph_ignore_func(gops, trace))
  157. return 0;
  158. /*
  159. * Do not trace a function if it's filtered by set_graph_notrace.
  160. * Make the index of ret stack negative to indicate that it should
  161. * ignore further functions. But it needs its own ret stack entry
  162. * to recover the original index in order to continue tracing after
  163. * returning from the function.
  164. */
  165. if (ftrace_graph_notrace_addr(trace->func))
  166. return 1;
  167. if (!func_prolog_dec(tr, &data, &flags))
  168. return 0;
  169. calltime = fgraph_reserve_data(gops->idx, sizeof(*calltime));
  170. if (calltime) {
  171. *calltime = trace_clock_local();
  172. trace_ctx = tracing_gen_ctx_flags(flags);
  173. ret = __trace_graph_entry(tr, trace, trace_ctx);
  174. }
  175. local_dec(&data->disabled);
  176. return ret;
  177. }
  178. static void irqsoff_graph_return(struct ftrace_graph_ret *trace,
  179. struct fgraph_ops *gops,
  180. struct ftrace_regs *fregs)
  181. {
  182. struct trace_array *tr = irqsoff_trace;
  183. struct trace_array_cpu *data;
  184. unsigned long flags;
  185. unsigned int trace_ctx;
  186. u64 *calltime;
  187. u64 rettime;
  188. int size;
  189. ftrace_graph_addr_finish(gops, trace);
  190. if (!func_prolog_dec(tr, &data, &flags))
  191. return;
  192. rettime = trace_clock_local();
  193. calltime = fgraph_retrieve_data(gops->idx, &size);
  194. if (calltime) {
  195. trace_ctx = tracing_gen_ctx_flags(flags);
  196. __trace_graph_return(tr, trace, trace_ctx, *calltime, rettime);
  197. }
  198. local_dec(&data->disabled);
  199. }
  200. static struct fgraph_ops fgraph_ops = {
  201. .entryfunc = &irqsoff_graph_entry,
  202. .retfunc = &irqsoff_graph_return,
  203. };
  204. static void irqsoff_trace_open(struct trace_iterator *iter)
  205. {
  206. if (is_graph(iter->tr))
  207. graph_trace_open(iter);
  208. }
  209. static void irqsoff_trace_close(struct trace_iterator *iter)
  210. {
  211. if (iter->private)
  212. graph_trace_close(iter);
  213. }
  214. #define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_CPU | \
  215. TRACE_GRAPH_PRINT_PROC | \
  216. TRACE_GRAPH_PRINT_REL_TIME | \
  217. TRACE_GRAPH_PRINT_DURATION)
  218. static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
  219. {
  220. /*
  221. * In graph mode call the graph tracer output function,
  222. * otherwise go with the TRACE_FN event handler
  223. */
  224. if (is_graph(iter->tr))
  225. return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS);
  226. return TRACE_TYPE_UNHANDLED;
  227. }
  228. static void irqsoff_print_header(struct seq_file *s)
  229. {
  230. struct trace_array *tr = irqsoff_trace;
  231. if (is_graph(tr))
  232. print_graph_headers_flags(s, GRAPH_TRACER_FLAGS);
  233. else
  234. trace_default_header(s);
  235. }
  236. static void
  237. __trace_function(struct trace_array *tr,
  238. unsigned long ip, unsigned long parent_ip,
  239. unsigned int trace_ctx)
  240. {
  241. if (is_graph(tr))
  242. trace_graph_function(tr, ip, parent_ip, trace_ctx);
  243. else
  244. trace_function(tr, ip, parent_ip, trace_ctx, NULL);
  245. }
  246. #else
  247. static inline void
  248. __trace_function(struct trace_array *tr,
  249. unsigned long ip, unsigned long parent_ip,
  250. unsigned int trace_ctx)
  251. {
  252. return trace_function(tr, ip, parent_ip, trace_ctx, NULL);
  253. }
  254. static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
  255. {
  256. return TRACE_TYPE_UNHANDLED;
  257. }
  258. static void irqsoff_trace_open(struct trace_iterator *iter) { }
  259. static void irqsoff_trace_close(struct trace_iterator *iter) { }
  260. #ifdef CONFIG_FUNCTION_TRACER
  261. static void irqsoff_print_header(struct seq_file *s)
  262. {
  263. trace_default_header(s);
  264. }
  265. #else
  266. static void irqsoff_print_header(struct seq_file *s)
  267. {
  268. trace_latency_header(s);
  269. }
  270. #endif /* CONFIG_FUNCTION_TRACER */
  271. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  272. /*
  273. * Should this new latency be reported/recorded?
  274. */
  275. static bool report_latency(struct trace_array *tr, u64 delta)
  276. {
  277. if (tracing_thresh) {
  278. if (delta < tracing_thresh)
  279. return false;
  280. } else {
  281. if (delta <= tr->max_latency)
  282. return false;
  283. }
  284. return true;
  285. }
  286. static void
  287. check_critical_timing(struct trace_array *tr,
  288. struct trace_array_cpu *data,
  289. unsigned long parent_ip,
  290. int cpu)
  291. {
  292. u64 T0, T1, delta;
  293. unsigned long flags;
  294. unsigned int trace_ctx;
  295. T0 = data->preempt_timestamp;
  296. T1 = ftrace_now(cpu);
  297. delta = T1-T0;
  298. trace_ctx = tracing_gen_ctx();
  299. if (!report_latency(tr, delta))
  300. goto out;
  301. raw_spin_lock_irqsave(&max_trace_lock, flags);
  302. /* check if we are still the max latency */
  303. if (!report_latency(tr, delta))
  304. goto out_unlock;
  305. __trace_function(tr, CALLER_ADDR0, parent_ip, trace_ctx);
  306. /* Skip 5 functions to get to the irq/preempt enable function */
  307. __trace_stack(tr, trace_ctx, 5);
  308. if (data->critical_sequence != max_sequence)
  309. goto out_unlock;
  310. data->critical_end = parent_ip;
  311. if (likely(!is_tracing_stopped())) {
  312. tr->max_latency = delta;
  313. update_max_tr_single(tr, current, cpu);
  314. }
  315. max_sequence++;
  316. out_unlock:
  317. raw_spin_unlock_irqrestore(&max_trace_lock, flags);
  318. out:
  319. data->critical_sequence = max_sequence;
  320. data->preempt_timestamp = ftrace_now(cpu);
  321. __trace_function(tr, CALLER_ADDR0, parent_ip, trace_ctx);
  322. }
  323. static nokprobe_inline void
  324. start_critical_timing(unsigned long ip, unsigned long parent_ip)
  325. {
  326. int cpu;
  327. struct trace_array *tr = irqsoff_trace;
  328. struct trace_array_cpu *data;
  329. long disabled;
  330. if (!tracer_enabled || !tracing_is_enabled())
  331. return;
  332. cpu = raw_smp_processor_id();
  333. if (per_cpu(tracing_cpu, cpu))
  334. return;
  335. data = per_cpu_ptr(tr->array_buffer.data, cpu);
  336. if (unlikely(!data) || local_read(&data->disabled))
  337. return;
  338. disabled = local_inc_return(&data->disabled);
  339. if (disabled == 1) {
  340. data->critical_sequence = max_sequence;
  341. data->preempt_timestamp = ftrace_now(cpu);
  342. data->critical_start = parent_ip ? : ip;
  343. __trace_function(tr, ip, parent_ip, tracing_gen_ctx());
  344. per_cpu(tracing_cpu, cpu) = 1;
  345. }
  346. local_dec(&data->disabled);
  347. }
  348. static nokprobe_inline void
  349. stop_critical_timing(unsigned long ip, unsigned long parent_ip)
  350. {
  351. int cpu;
  352. struct trace_array *tr = irqsoff_trace;
  353. struct trace_array_cpu *data;
  354. unsigned int trace_ctx;
  355. long disabled;
  356. cpu = raw_smp_processor_id();
  357. /* Always clear the tracing cpu on stopping the trace */
  358. if (unlikely(per_cpu(tracing_cpu, cpu)))
  359. per_cpu(tracing_cpu, cpu) = 0;
  360. else
  361. return;
  362. if (!tracer_enabled || !tracing_is_enabled())
  363. return;
  364. data = per_cpu_ptr(tr->array_buffer.data, cpu);
  365. if (unlikely(!data) ||
  366. !data->critical_start || local_read(&data->disabled))
  367. return;
  368. disabled = local_inc_return(&data->disabled);
  369. if (disabled == 1) {
  370. trace_ctx = tracing_gen_ctx();
  371. __trace_function(tr, ip, parent_ip, trace_ctx);
  372. check_critical_timing(tr, data, parent_ip ? : ip, cpu);
  373. data->critical_start = 0;
  374. }
  375. local_dec(&data->disabled);
  376. }
  377. /* start and stop critical timings used to for stoppage (in idle) */
  378. void start_critical_timings(void)
  379. {
  380. if (preempt_trace(preempt_count()) || irq_trace())
  381. start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  382. }
  383. EXPORT_SYMBOL_GPL(start_critical_timings);
  384. NOKPROBE_SYMBOL(start_critical_timings);
  385. void stop_critical_timings(void)
  386. {
  387. if (preempt_trace(preempt_count()) || irq_trace())
  388. stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  389. }
  390. EXPORT_SYMBOL_GPL(stop_critical_timings);
  391. NOKPROBE_SYMBOL(stop_critical_timings);
  392. #ifdef CONFIG_FUNCTION_TRACER
  393. static bool function_enabled;
  394. static int register_irqsoff_function(struct trace_array *tr, int graph, int set)
  395. {
  396. int ret;
  397. /* 'set' is set if TRACE_ITER(FUNCTION) is about to be set */
  398. if (function_enabled || (!set && !(tr->trace_flags & TRACE_ITER(FUNCTION))))
  399. return 0;
  400. if (graph)
  401. ret = register_ftrace_graph(&fgraph_ops);
  402. else
  403. ret = register_ftrace_function(tr->ops);
  404. if (!ret)
  405. function_enabled = true;
  406. return ret;
  407. }
  408. static void unregister_irqsoff_function(struct trace_array *tr, int graph)
  409. {
  410. if (!function_enabled)
  411. return;
  412. if (graph)
  413. unregister_ftrace_graph(&fgraph_ops);
  414. else
  415. unregister_ftrace_function(tr->ops);
  416. function_enabled = false;
  417. }
  418. static int irqsoff_function_set(struct trace_array *tr, u32 mask, int set)
  419. {
  420. if (!(mask & TRACE_ITER(FUNCTION)))
  421. return 0;
  422. if (set)
  423. register_irqsoff_function(tr, is_graph(tr), 1);
  424. else
  425. unregister_irqsoff_function(tr, is_graph(tr));
  426. return 1;
  427. }
  428. #else
  429. static int register_irqsoff_function(struct trace_array *tr, int graph, int set)
  430. {
  431. return 0;
  432. }
  433. static void unregister_irqsoff_function(struct trace_array *tr, int graph) { }
  434. static inline int irqsoff_function_set(struct trace_array *tr, u32 mask, int set)
  435. {
  436. return 0;
  437. }
  438. #endif /* CONFIG_FUNCTION_TRACER */
  439. static int irqsoff_flag_changed(struct trace_array *tr, u64 mask, int set)
  440. {
  441. struct tracer *tracer = tr->current_trace;
  442. if (irqsoff_function_set(tr, mask, set))
  443. return 0;
  444. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  445. if (mask & TRACE_ITER(DISPLAY_GRAPH))
  446. return irqsoff_display_graph(tr, set);
  447. #endif
  448. return trace_keep_overwrite(tracer, mask, set);
  449. }
  450. static int start_irqsoff_tracer(struct trace_array *tr, int graph)
  451. {
  452. int ret;
  453. ret = register_irqsoff_function(tr, graph, 0);
  454. if (!ret && tracing_is_enabled())
  455. tracer_enabled = 1;
  456. else
  457. tracer_enabled = 0;
  458. return ret;
  459. }
  460. static void stop_irqsoff_tracer(struct trace_array *tr, int graph)
  461. {
  462. tracer_enabled = 0;
  463. unregister_irqsoff_function(tr, graph);
  464. }
  465. static bool irqsoff_busy;
  466. static int __irqsoff_tracer_init(struct trace_array *tr)
  467. {
  468. if (irqsoff_busy)
  469. return -EBUSY;
  470. save_flags = tr->trace_flags;
  471. /* non overwrite screws up the latency tracers */
  472. set_tracer_flag(tr, TRACE_ITER(OVERWRITE), 1);
  473. set_tracer_flag(tr, TRACE_ITER(LATENCY_FMT), 1);
  474. /* without pause, we will produce garbage if another latency occurs */
  475. set_tracer_flag(tr, TRACE_ITER(PAUSE_ON_TRACE), 1);
  476. tr->max_latency = 0;
  477. irqsoff_trace = tr;
  478. /* make sure that the tracer is visible */
  479. smp_wmb();
  480. ftrace_init_array_ops(tr, irqsoff_tracer_call);
  481. /* Only toplevel instance supports graph tracing */
  482. if (start_irqsoff_tracer(tr, (tr->flags & TRACE_ARRAY_FL_GLOBAL &&
  483. is_graph(tr))))
  484. printk(KERN_ERR "failed to start irqsoff tracer\n");
  485. irqsoff_busy = true;
  486. return 0;
  487. }
  488. static void __irqsoff_tracer_reset(struct trace_array *tr)
  489. {
  490. int lat_flag = save_flags & TRACE_ITER(LATENCY_FMT);
  491. int overwrite_flag = save_flags & TRACE_ITER(OVERWRITE);
  492. int pause_flag = save_flags & TRACE_ITER(PAUSE_ON_TRACE);
  493. stop_irqsoff_tracer(tr, is_graph(tr));
  494. set_tracer_flag(tr, TRACE_ITER(LATENCY_FMT), lat_flag);
  495. set_tracer_flag(tr, TRACE_ITER(OVERWRITE), overwrite_flag);
  496. set_tracer_flag(tr, TRACE_ITER(PAUSE_ON_TRACE), pause_flag);
  497. ftrace_reset_array_ops(tr);
  498. irqsoff_busy = false;
  499. }
  500. static void irqsoff_tracer_start(struct trace_array *tr)
  501. {
  502. tracer_enabled = 1;
  503. }
  504. static void irqsoff_tracer_stop(struct trace_array *tr)
  505. {
  506. tracer_enabled = 0;
  507. }
  508. #ifdef CONFIG_IRQSOFF_TRACER
  509. /*
  510. * We are only interested in hardirq on/off events:
  511. */
  512. void tracer_hardirqs_on(unsigned long a0, unsigned long a1)
  513. {
  514. if (!preempt_trace(preempt_count()) && irq_trace())
  515. stop_critical_timing(a0, a1);
  516. }
  517. NOKPROBE_SYMBOL(tracer_hardirqs_on);
  518. void tracer_hardirqs_off(unsigned long a0, unsigned long a1)
  519. {
  520. if (!preempt_trace(preempt_count()) && irq_trace())
  521. start_critical_timing(a0, a1);
  522. }
  523. NOKPROBE_SYMBOL(tracer_hardirqs_off);
  524. static int irqsoff_tracer_init(struct trace_array *tr)
  525. {
  526. trace_type = TRACER_IRQS_OFF;
  527. return __irqsoff_tracer_init(tr);
  528. }
  529. static void irqsoff_tracer_reset(struct trace_array *tr)
  530. {
  531. __irqsoff_tracer_reset(tr);
  532. }
  533. static struct tracer irqsoff_tracer __read_mostly =
  534. {
  535. .name = "irqsoff",
  536. .init = irqsoff_tracer_init,
  537. .reset = irqsoff_tracer_reset,
  538. .start = irqsoff_tracer_start,
  539. .stop = irqsoff_tracer_stop,
  540. .print_max = true,
  541. .print_header = irqsoff_print_header,
  542. .print_line = irqsoff_print_line,
  543. .flag_changed = irqsoff_flag_changed,
  544. #ifdef CONFIG_FTRACE_SELFTEST
  545. .selftest = trace_selftest_startup_irqsoff,
  546. #endif
  547. .open = irqsoff_trace_open,
  548. .close = irqsoff_trace_close,
  549. .allow_instances = true,
  550. .use_max_tr = true,
  551. };
  552. #endif /* CONFIG_IRQSOFF_TRACER */
  553. #ifdef CONFIG_PREEMPT_TRACER
  554. void tracer_preempt_on(unsigned long a0, unsigned long a1)
  555. {
  556. if (preempt_trace(preempt_count()) && !irq_trace())
  557. stop_critical_timing(a0, a1);
  558. }
  559. void tracer_preempt_off(unsigned long a0, unsigned long a1)
  560. {
  561. if (preempt_trace(preempt_count()) && !irq_trace())
  562. start_critical_timing(a0, a1);
  563. }
  564. static int preemptoff_tracer_init(struct trace_array *tr)
  565. {
  566. trace_type = TRACER_PREEMPT_OFF;
  567. return __irqsoff_tracer_init(tr);
  568. }
  569. static void preemptoff_tracer_reset(struct trace_array *tr)
  570. {
  571. __irqsoff_tracer_reset(tr);
  572. }
  573. static struct tracer preemptoff_tracer __read_mostly =
  574. {
  575. .name = "preemptoff",
  576. .init = preemptoff_tracer_init,
  577. .reset = preemptoff_tracer_reset,
  578. .start = irqsoff_tracer_start,
  579. .stop = irqsoff_tracer_stop,
  580. .print_max = true,
  581. .print_header = irqsoff_print_header,
  582. .print_line = irqsoff_print_line,
  583. .flag_changed = irqsoff_flag_changed,
  584. #ifdef CONFIG_FTRACE_SELFTEST
  585. .selftest = trace_selftest_startup_preemptoff,
  586. #endif
  587. .open = irqsoff_trace_open,
  588. .close = irqsoff_trace_close,
  589. .allow_instances = true,
  590. .use_max_tr = true,
  591. };
  592. #endif /* CONFIG_PREEMPT_TRACER */
  593. #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
  594. static int preemptirqsoff_tracer_init(struct trace_array *tr)
  595. {
  596. trace_type = TRACER_IRQS_OFF | TRACER_PREEMPT_OFF;
  597. return __irqsoff_tracer_init(tr);
  598. }
  599. static void preemptirqsoff_tracer_reset(struct trace_array *tr)
  600. {
  601. __irqsoff_tracer_reset(tr);
  602. }
  603. static struct tracer preemptirqsoff_tracer __read_mostly =
  604. {
  605. .name = "preemptirqsoff",
  606. .init = preemptirqsoff_tracer_init,
  607. .reset = preemptirqsoff_tracer_reset,
  608. .start = irqsoff_tracer_start,
  609. .stop = irqsoff_tracer_stop,
  610. .print_max = true,
  611. .print_header = irqsoff_print_header,
  612. .print_line = irqsoff_print_line,
  613. .flag_changed = irqsoff_flag_changed,
  614. #ifdef CONFIG_FTRACE_SELFTEST
  615. .selftest = trace_selftest_startup_preemptirqsoff,
  616. #endif
  617. .open = irqsoff_trace_open,
  618. .close = irqsoff_trace_close,
  619. .allow_instances = true,
  620. .use_max_tr = true,
  621. };
  622. #endif
  623. __init static int init_irqsoff_tracer(void)
  624. {
  625. #ifdef CONFIG_IRQSOFF_TRACER
  626. register_tracer(&irqsoff_tracer);
  627. #endif
  628. #ifdef CONFIG_PREEMPT_TRACER
  629. register_tracer(&preemptoff_tracer);
  630. #endif
  631. #if defined(CONFIG_IRQSOFF_TRACER) && defined(CONFIG_PREEMPT_TRACER)
  632. register_tracer(&preemptirqsoff_tracer);
  633. #endif
  634. return 0;
  635. }
  636. core_initcall(init_irqsoff_tracer);
  637. #endif /* IRQSOFF_TRACER || PREEMPTOFF_TRACER */