trace_irqsoff.c 17 KB

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