trace_irqsoff.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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 (!func_prolog_dec(tr, &data, &flags))
  148. return 0;
  149. pc = preempt_count();
  150. ret = __trace_graph_entry(tr, trace, flags, pc);
  151. atomic_dec(&data->disabled);
  152. return ret;
  153. }
  154. static void irqsoff_graph_return(struct ftrace_graph_ret *trace)
  155. {
  156. struct trace_array *tr = irqsoff_trace;
  157. struct trace_array_cpu *data;
  158. unsigned long flags;
  159. int pc;
  160. if (!func_prolog_dec(tr, &data, &flags))
  161. return;
  162. pc = preempt_count();
  163. __trace_graph_return(tr, trace, flags, pc);
  164. atomic_dec(&data->disabled);
  165. }
  166. static void irqsoff_trace_open(struct trace_iterator *iter)
  167. {
  168. if (is_graph(iter->tr))
  169. graph_trace_open(iter);
  170. }
  171. static void irqsoff_trace_close(struct trace_iterator *iter)
  172. {
  173. if (iter->private)
  174. graph_trace_close(iter);
  175. }
  176. #define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_CPU | \
  177. TRACE_GRAPH_PRINT_PROC | \
  178. TRACE_GRAPH_PRINT_ABS_TIME | \
  179. TRACE_GRAPH_PRINT_DURATION)
  180. static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
  181. {
  182. /*
  183. * In graph mode call the graph tracer output function,
  184. * otherwise go with the TRACE_FN event handler
  185. */
  186. if (is_graph(iter->tr))
  187. return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS);
  188. return TRACE_TYPE_UNHANDLED;
  189. }
  190. static void irqsoff_print_header(struct seq_file *s)
  191. {
  192. struct trace_array *tr = irqsoff_trace;
  193. if (is_graph(tr))
  194. print_graph_headers_flags(s, GRAPH_TRACER_FLAGS);
  195. else
  196. trace_default_header(s);
  197. }
  198. static void
  199. __trace_function(struct trace_array *tr,
  200. unsigned long ip, unsigned long parent_ip,
  201. unsigned long flags, int pc)
  202. {
  203. if (is_graph(tr))
  204. trace_graph_function(tr, ip, parent_ip, flags, pc);
  205. else
  206. trace_function(tr, ip, parent_ip, flags, pc);
  207. }
  208. #else
  209. #define __trace_function trace_function
  210. #ifdef CONFIG_FUNCTION_TRACER
  211. static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
  212. {
  213. return -1;
  214. }
  215. #endif
  216. static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
  217. {
  218. return TRACE_TYPE_UNHANDLED;
  219. }
  220. static void irqsoff_trace_open(struct trace_iterator *iter) { }
  221. static void irqsoff_trace_close(struct trace_iterator *iter) { }
  222. #ifdef CONFIG_FUNCTION_TRACER
  223. static void irqsoff_graph_return(struct ftrace_graph_ret *trace) { }
  224. static void irqsoff_print_header(struct seq_file *s)
  225. {
  226. trace_default_header(s);
  227. }
  228. #else
  229. static void irqsoff_print_header(struct seq_file *s)
  230. {
  231. trace_latency_header(s);
  232. }
  233. #endif /* CONFIG_FUNCTION_TRACER */
  234. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  235. /*
  236. * Should this new latency be reported/recorded?
  237. */
  238. static bool report_latency(struct trace_array *tr, cycle_t delta)
  239. {
  240. if (tracing_thresh) {
  241. if (delta < tracing_thresh)
  242. return false;
  243. } else {
  244. if (delta <= tr->max_latency)
  245. return false;
  246. }
  247. return true;
  248. }
  249. static void
  250. check_critical_timing(struct trace_array *tr,
  251. struct trace_array_cpu *data,
  252. unsigned long parent_ip,
  253. int cpu)
  254. {
  255. cycle_t T0, T1, delta;
  256. unsigned long flags;
  257. int pc;
  258. T0 = data->preempt_timestamp;
  259. T1 = ftrace_now(cpu);
  260. delta = T1-T0;
  261. local_save_flags(flags);
  262. pc = preempt_count();
  263. if (!report_latency(tr, delta))
  264. goto out;
  265. raw_spin_lock_irqsave(&max_trace_lock, flags);
  266. /* check if we are still the max latency */
  267. if (!report_latency(tr, delta))
  268. goto out_unlock;
  269. __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
  270. /* Skip 5 functions to get to the irq/preempt enable function */
  271. __trace_stack(tr, flags, 5, pc);
  272. if (data->critical_sequence != max_sequence)
  273. goto out_unlock;
  274. data->critical_end = parent_ip;
  275. if (likely(!is_tracing_stopped())) {
  276. tr->max_latency = delta;
  277. update_max_tr_single(tr, current, cpu);
  278. }
  279. max_sequence++;
  280. out_unlock:
  281. raw_spin_unlock_irqrestore(&max_trace_lock, flags);
  282. out:
  283. data->critical_sequence = max_sequence;
  284. data->preempt_timestamp = ftrace_now(cpu);
  285. __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
  286. }
  287. static inline void
  288. start_critical_timing(unsigned long ip, unsigned long parent_ip)
  289. {
  290. int cpu;
  291. struct trace_array *tr = irqsoff_trace;
  292. struct trace_array_cpu *data;
  293. unsigned long flags;
  294. if (!tracer_enabled || !tracing_is_enabled())
  295. return;
  296. cpu = raw_smp_processor_id();
  297. if (per_cpu(tracing_cpu, cpu))
  298. return;
  299. data = per_cpu_ptr(tr->trace_buffer.data, cpu);
  300. if (unlikely(!data) || atomic_read(&data->disabled))
  301. return;
  302. atomic_inc(&data->disabled);
  303. data->critical_sequence = max_sequence;
  304. data->preempt_timestamp = ftrace_now(cpu);
  305. data->critical_start = parent_ip ? : ip;
  306. local_save_flags(flags);
  307. __trace_function(tr, ip, parent_ip, flags, preempt_count());
  308. per_cpu(tracing_cpu, cpu) = 1;
  309. atomic_dec(&data->disabled);
  310. }
  311. static inline void
  312. stop_critical_timing(unsigned long ip, unsigned long parent_ip)
  313. {
  314. int cpu;
  315. struct trace_array *tr = irqsoff_trace;
  316. struct trace_array_cpu *data;
  317. unsigned long flags;
  318. cpu = raw_smp_processor_id();
  319. /* Always clear the tracing cpu on stopping the trace */
  320. if (unlikely(per_cpu(tracing_cpu, cpu)))
  321. per_cpu(tracing_cpu, cpu) = 0;
  322. else
  323. return;
  324. if (!tracer_enabled || !tracing_is_enabled())
  325. return;
  326. data = per_cpu_ptr(tr->trace_buffer.data, cpu);
  327. if (unlikely(!data) ||
  328. !data->critical_start || atomic_read(&data->disabled))
  329. return;
  330. atomic_inc(&data->disabled);
  331. local_save_flags(flags);
  332. __trace_function(tr, ip, parent_ip, flags, preempt_count());
  333. check_critical_timing(tr, data, parent_ip ? : ip, cpu);
  334. data->critical_start = 0;
  335. atomic_dec(&data->disabled);
  336. }
  337. /* start and stop critical timings used to for stoppage (in idle) */
  338. void start_critical_timings(void)
  339. {
  340. if (preempt_trace() || irq_trace())
  341. start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  342. }
  343. EXPORT_SYMBOL_GPL(start_critical_timings);
  344. void stop_critical_timings(void)
  345. {
  346. if (preempt_trace() || irq_trace())
  347. stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  348. }
  349. EXPORT_SYMBOL_GPL(stop_critical_timings);
  350. #ifdef CONFIG_IRQSOFF_TRACER
  351. #ifdef CONFIG_PROVE_LOCKING
  352. void time_hardirqs_on(unsigned long a0, unsigned long a1)
  353. {
  354. if (!preempt_trace() && irq_trace())
  355. stop_critical_timing(a0, a1);
  356. }
  357. void time_hardirqs_off(unsigned long a0, unsigned long a1)
  358. {
  359. if (!preempt_trace() && irq_trace())
  360. start_critical_timing(a0, a1);
  361. }
  362. #else /* !CONFIG_PROVE_LOCKING */
  363. /*
  364. * Stubs:
  365. */
  366. void trace_softirqs_on(unsigned long ip)
  367. {
  368. }
  369. void trace_softirqs_off(unsigned long ip)
  370. {
  371. }
  372. inline void print_irqtrace_events(struct task_struct *curr)
  373. {
  374. }
  375. /*
  376. * We are only interested in hardirq on/off events:
  377. */
  378. void trace_hardirqs_on(void)
  379. {
  380. if (!preempt_trace() && irq_trace())
  381. stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  382. }
  383. EXPORT_SYMBOL(trace_hardirqs_on);
  384. void trace_hardirqs_off(void)
  385. {
  386. if (!preempt_trace() && irq_trace())
  387. start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  388. }
  389. EXPORT_SYMBOL(trace_hardirqs_off);
  390. __visible void trace_hardirqs_on_caller(unsigned long caller_addr)
  391. {
  392. if (!preempt_trace() && irq_trace())
  393. stop_critical_timing(CALLER_ADDR0, caller_addr);
  394. }
  395. EXPORT_SYMBOL(trace_hardirqs_on_caller);
  396. __visible void trace_hardirqs_off_caller(unsigned long caller_addr)
  397. {
  398. if (!preempt_trace() && irq_trace())
  399. start_critical_timing(CALLER_ADDR0, caller_addr);
  400. }
  401. EXPORT_SYMBOL(trace_hardirqs_off_caller);
  402. #endif /* CONFIG_PROVE_LOCKING */
  403. #endif /* CONFIG_IRQSOFF_TRACER */
  404. #ifdef CONFIG_PREEMPT_TRACER
  405. void trace_preempt_on(unsigned long a0, unsigned long a1)
  406. {
  407. if (preempt_trace() && !irq_trace())
  408. stop_critical_timing(a0, a1);
  409. }
  410. void trace_preempt_off(unsigned long a0, unsigned long a1)
  411. {
  412. if (preempt_trace() && !irq_trace())
  413. start_critical_timing(a0, a1);
  414. }
  415. #endif /* CONFIG_PREEMPT_TRACER */
  416. #ifdef CONFIG_FUNCTION_TRACER
  417. static bool function_enabled;
  418. static int register_irqsoff_function(struct trace_array *tr, int graph, int set)
  419. {
  420. int ret;
  421. /* 'set' is set if TRACE_ITER_FUNCTION is about to be set */
  422. if (function_enabled || (!set && !(tr->trace_flags & TRACE_ITER_FUNCTION)))
  423. return 0;
  424. if (graph)
  425. ret = register_ftrace_graph(&irqsoff_graph_return,
  426. &irqsoff_graph_entry);
  427. else
  428. ret = register_ftrace_function(tr->ops);
  429. if (!ret)
  430. function_enabled = true;
  431. return ret;
  432. }
  433. static void unregister_irqsoff_function(struct trace_array *tr, int graph)
  434. {
  435. if (!function_enabled)
  436. return;
  437. if (graph)
  438. unregister_ftrace_graph();
  439. else
  440. unregister_ftrace_function(tr->ops);
  441. function_enabled = false;
  442. }
  443. static int irqsoff_function_set(struct trace_array *tr, u32 mask, int set)
  444. {
  445. if (!(mask & TRACE_ITER_FUNCTION))
  446. return 0;
  447. if (set)
  448. register_irqsoff_function(tr, is_graph(tr), 1);
  449. else
  450. unregister_irqsoff_function(tr, is_graph(tr));
  451. return 1;
  452. }
  453. #else
  454. static int register_irqsoff_function(struct trace_array *tr, int graph, int set)
  455. {
  456. return 0;
  457. }
  458. static void unregister_irqsoff_function(struct trace_array *tr, int graph) { }
  459. static inline int irqsoff_function_set(struct trace_array *tr, u32 mask, int set)
  460. {
  461. return 0;
  462. }
  463. #endif /* CONFIG_FUNCTION_TRACER */
  464. static int irqsoff_flag_changed(struct trace_array *tr, u32 mask, int set)
  465. {
  466. struct tracer *tracer = tr->current_trace;
  467. if (irqsoff_function_set(tr, mask, set))
  468. return 0;
  469. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  470. if (mask & TRACE_ITER_DISPLAY_GRAPH)
  471. return irqsoff_display_graph(tr, set);
  472. #endif
  473. return trace_keep_overwrite(tracer, mask, set);
  474. }
  475. static int start_irqsoff_tracer(struct trace_array *tr, int graph)
  476. {
  477. int ret;
  478. ret = register_irqsoff_function(tr, graph, 0);
  479. if (!ret && tracing_is_enabled())
  480. tracer_enabled = 1;
  481. else
  482. tracer_enabled = 0;
  483. return ret;
  484. }
  485. static void stop_irqsoff_tracer(struct trace_array *tr, int graph)
  486. {
  487. tracer_enabled = 0;
  488. unregister_irqsoff_function(tr, graph);
  489. }
  490. static bool irqsoff_busy;
  491. static int __irqsoff_tracer_init(struct trace_array *tr)
  492. {
  493. if (irqsoff_busy)
  494. return -EBUSY;
  495. save_flags = tr->trace_flags;
  496. /* non overwrite screws up the latency tracers */
  497. set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1);
  498. set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, 1);
  499. tr->max_latency = 0;
  500. irqsoff_trace = tr;
  501. /* make sure that the tracer is visible */
  502. smp_wmb();
  503. ftrace_init_array_ops(tr, irqsoff_tracer_call);
  504. /* Only toplevel instance supports graph tracing */
  505. if (start_irqsoff_tracer(tr, (tr->flags & TRACE_ARRAY_FL_GLOBAL &&
  506. is_graph(tr))))
  507. printk(KERN_ERR "failed to start irqsoff tracer\n");
  508. irqsoff_busy = true;
  509. return 0;
  510. }
  511. static void irqsoff_tracer_reset(struct trace_array *tr)
  512. {
  513. int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT;
  514. int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE;
  515. stop_irqsoff_tracer(tr, is_graph(tr));
  516. set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag);
  517. set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag);
  518. ftrace_reset_array_ops(tr);
  519. irqsoff_busy = false;
  520. }
  521. static void irqsoff_tracer_start(struct trace_array *tr)
  522. {
  523. tracer_enabled = 1;
  524. }
  525. static void irqsoff_tracer_stop(struct trace_array *tr)
  526. {
  527. tracer_enabled = 0;
  528. }
  529. #ifdef CONFIG_IRQSOFF_TRACER
  530. static int irqsoff_tracer_init(struct trace_array *tr)
  531. {
  532. trace_type = TRACER_IRQS_OFF;
  533. return __irqsoff_tracer_init(tr);
  534. }
  535. static struct tracer irqsoff_tracer __read_mostly =
  536. {
  537. .name = "irqsoff",
  538. .init = irqsoff_tracer_init,
  539. .reset = irqsoff_tracer_reset,
  540. .start = irqsoff_tracer_start,
  541. .stop = irqsoff_tracer_stop,
  542. .print_max = true,
  543. .print_header = irqsoff_print_header,
  544. .print_line = irqsoff_print_line,
  545. .flag_changed = irqsoff_flag_changed,
  546. #ifdef CONFIG_FTRACE_SELFTEST
  547. .selftest = trace_selftest_startup_irqsoff,
  548. #endif
  549. .open = irqsoff_trace_open,
  550. .close = irqsoff_trace_close,
  551. .allow_instances = true,
  552. .use_max_tr = true,
  553. };
  554. # define register_irqsoff(trace) register_tracer(&trace)
  555. #else
  556. # define register_irqsoff(trace) do { } while (0)
  557. #endif
  558. #ifdef CONFIG_PREEMPT_TRACER
  559. static int preemptoff_tracer_init(struct trace_array *tr)
  560. {
  561. trace_type = TRACER_PREEMPT_OFF;
  562. return __irqsoff_tracer_init(tr);
  563. }
  564. static struct tracer preemptoff_tracer __read_mostly =
  565. {
  566. .name = "preemptoff",
  567. .init = preemptoff_tracer_init,
  568. .reset = irqsoff_tracer_reset,
  569. .start = irqsoff_tracer_start,
  570. .stop = irqsoff_tracer_stop,
  571. .print_max = true,
  572. .print_header = irqsoff_print_header,
  573. .print_line = irqsoff_print_line,
  574. .flag_changed = irqsoff_flag_changed,
  575. #ifdef CONFIG_FTRACE_SELFTEST
  576. .selftest = trace_selftest_startup_preemptoff,
  577. #endif
  578. .open = irqsoff_trace_open,
  579. .close = irqsoff_trace_close,
  580. .allow_instances = true,
  581. .use_max_tr = true,
  582. };
  583. # define register_preemptoff(trace) register_tracer(&trace)
  584. #else
  585. # define register_preemptoff(trace) do { } while (0)
  586. #endif
  587. #if defined(CONFIG_IRQSOFF_TRACER) && \
  588. defined(CONFIG_PREEMPT_TRACER)
  589. static int preemptirqsoff_tracer_init(struct trace_array *tr)
  590. {
  591. trace_type = TRACER_IRQS_OFF | TRACER_PREEMPT_OFF;
  592. return __irqsoff_tracer_init(tr);
  593. }
  594. static struct tracer preemptirqsoff_tracer __read_mostly =
  595. {
  596. .name = "preemptirqsoff",
  597. .init = preemptirqsoff_tracer_init,
  598. .reset = irqsoff_tracer_reset,
  599. .start = irqsoff_tracer_start,
  600. .stop = irqsoff_tracer_stop,
  601. .print_max = true,
  602. .print_header = irqsoff_print_header,
  603. .print_line = irqsoff_print_line,
  604. .flag_changed = irqsoff_flag_changed,
  605. #ifdef CONFIG_FTRACE_SELFTEST
  606. .selftest = trace_selftest_startup_preemptirqsoff,
  607. #endif
  608. .open = irqsoff_trace_open,
  609. .close = irqsoff_trace_close,
  610. .allow_instances = true,
  611. .use_max_tr = true,
  612. };
  613. # define register_preemptirqsoff(trace) register_tracer(&trace)
  614. #else
  615. # define register_preemptirqsoff(trace) do { } while (0)
  616. #endif
  617. __init static int init_irqsoff_tracer(void)
  618. {
  619. register_irqsoff(irqsoff_tracer);
  620. register_preemptoff(preemptoff_tracer);
  621. register_preemptirqsoff(preemptirqsoff_tracer);
  622. return 0;
  623. }
  624. core_initcall(init_irqsoff_tracer);