trace_irqsoff.c 18 KB

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