trace_sched_wakeup.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. /*
  2. * trace task wakeup timings
  3. *
  4. * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
  5. * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
  6. *
  7. * Based on code from the latency_tracer, that is:
  8. *
  9. * Copyright (C) 2004-2006 Ingo Molnar
  10. * Copyright (C) 2004 Nadia Yvette Chambers
  11. */
  12. #include <linux/module.h>
  13. #include <linux/fs.h>
  14. #include <linux/debugfs.h>
  15. #include <linux/kallsyms.h>
  16. #include <linux/uaccess.h>
  17. #include <linux/ftrace.h>
  18. #include <linux/sched/rt.h>
  19. #include <linux/sched/deadline.h>
  20. #include <trace/events/sched.h>
  21. #include "trace.h"
  22. static struct trace_array *wakeup_trace;
  23. static int __read_mostly tracer_enabled;
  24. static struct task_struct *wakeup_task;
  25. static int wakeup_cpu;
  26. static int wakeup_current_cpu;
  27. static unsigned wakeup_prio = -1;
  28. static int wakeup_rt;
  29. static int wakeup_dl;
  30. static int tracing_dl = 0;
  31. static arch_spinlock_t wakeup_lock =
  32. (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
  33. static void wakeup_reset(struct trace_array *tr);
  34. static void __wakeup_reset(struct trace_array *tr);
  35. static int wakeup_graph_entry(struct ftrace_graph_ent *trace);
  36. static void wakeup_graph_return(struct ftrace_graph_ret *trace);
  37. static int save_flags;
  38. static bool function_enabled;
  39. #define TRACE_DISPLAY_GRAPH 1
  40. static struct tracer_opt trace_opts[] = {
  41. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  42. /* display latency trace as call graph */
  43. { TRACER_OPT(display-graph, TRACE_DISPLAY_GRAPH) },
  44. #endif
  45. { } /* Empty entry */
  46. };
  47. static struct tracer_flags tracer_flags = {
  48. .val = 0,
  49. .opts = trace_opts,
  50. };
  51. #define is_graph() (tracer_flags.val & TRACE_DISPLAY_GRAPH)
  52. #ifdef CONFIG_FUNCTION_TRACER
  53. /*
  54. * Prologue for the wakeup function tracers.
  55. *
  56. * Returns 1 if it is OK to continue, and preemption
  57. * is disabled and data->disabled is incremented.
  58. * 0 if the trace is to be ignored, and preemption
  59. * is not disabled and data->disabled is
  60. * kept the same.
  61. *
  62. * Note, this function is also used outside this ifdef but
  63. * inside the #ifdef of the function graph tracer below.
  64. * This is OK, since the function graph tracer is
  65. * dependent on the function tracer.
  66. */
  67. static int
  68. func_prolog_preempt_disable(struct trace_array *tr,
  69. struct trace_array_cpu **data,
  70. int *pc)
  71. {
  72. long disabled;
  73. int cpu;
  74. if (likely(!wakeup_task))
  75. return 0;
  76. *pc = preempt_count();
  77. preempt_disable_notrace();
  78. cpu = raw_smp_processor_id();
  79. if (cpu != wakeup_current_cpu)
  80. goto out_enable;
  81. *data = per_cpu_ptr(tr->trace_buffer.data, cpu);
  82. disabled = atomic_inc_return(&(*data)->disabled);
  83. if (unlikely(disabled != 1))
  84. goto out;
  85. return 1;
  86. out:
  87. atomic_dec(&(*data)->disabled);
  88. out_enable:
  89. preempt_enable_notrace();
  90. return 0;
  91. }
  92. /*
  93. * wakeup uses its own tracer function to keep the overhead down:
  94. */
  95. static void
  96. wakeup_tracer_call(unsigned long ip, unsigned long parent_ip,
  97. struct ftrace_ops *op, struct pt_regs *pt_regs)
  98. {
  99. struct trace_array *tr = wakeup_trace;
  100. struct trace_array_cpu *data;
  101. unsigned long flags;
  102. int pc;
  103. if (!func_prolog_preempt_disable(tr, &data, &pc))
  104. return;
  105. local_irq_save(flags);
  106. trace_function(tr, ip, parent_ip, flags, pc);
  107. local_irq_restore(flags);
  108. atomic_dec(&data->disabled);
  109. preempt_enable_notrace();
  110. }
  111. #endif /* CONFIG_FUNCTION_TRACER */
  112. static int register_wakeup_function(struct trace_array *tr, int graph, int set)
  113. {
  114. int ret;
  115. /* 'set' is set if TRACE_ITER_FUNCTION is about to be set */
  116. if (function_enabled || (!set && !(trace_flags & TRACE_ITER_FUNCTION)))
  117. return 0;
  118. if (graph)
  119. ret = register_ftrace_graph(&wakeup_graph_return,
  120. &wakeup_graph_entry);
  121. else
  122. ret = register_ftrace_function(tr->ops);
  123. if (!ret)
  124. function_enabled = true;
  125. return ret;
  126. }
  127. static void unregister_wakeup_function(struct trace_array *tr, int graph)
  128. {
  129. if (!function_enabled)
  130. return;
  131. if (graph)
  132. unregister_ftrace_graph();
  133. else
  134. unregister_ftrace_function(tr->ops);
  135. function_enabled = false;
  136. }
  137. static void wakeup_function_set(struct trace_array *tr, int set)
  138. {
  139. if (set)
  140. register_wakeup_function(tr, is_graph(), 1);
  141. else
  142. unregister_wakeup_function(tr, is_graph());
  143. }
  144. static int wakeup_flag_changed(struct trace_array *tr, u32 mask, int set)
  145. {
  146. struct tracer *tracer = tr->current_trace;
  147. if (mask & TRACE_ITER_FUNCTION)
  148. wakeup_function_set(tr, set);
  149. return trace_keep_overwrite(tracer, mask, set);
  150. }
  151. static int start_func_tracer(struct trace_array *tr, int graph)
  152. {
  153. int ret;
  154. ret = register_wakeup_function(tr, graph, 0);
  155. if (!ret && tracing_is_enabled())
  156. tracer_enabled = 1;
  157. else
  158. tracer_enabled = 0;
  159. return ret;
  160. }
  161. static void stop_func_tracer(struct trace_array *tr, int graph)
  162. {
  163. tracer_enabled = 0;
  164. unregister_wakeup_function(tr, graph);
  165. }
  166. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  167. static int
  168. wakeup_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
  169. {
  170. if (!(bit & TRACE_DISPLAY_GRAPH))
  171. return -EINVAL;
  172. if (!(is_graph() ^ set))
  173. return 0;
  174. stop_func_tracer(tr, !set);
  175. wakeup_reset(wakeup_trace);
  176. tr->max_latency = 0;
  177. return start_func_tracer(tr, set);
  178. }
  179. static int wakeup_graph_entry(struct ftrace_graph_ent *trace)
  180. {
  181. struct trace_array *tr = wakeup_trace;
  182. struct trace_array_cpu *data;
  183. unsigned long flags;
  184. int pc, ret = 0;
  185. if (!func_prolog_preempt_disable(tr, &data, &pc))
  186. return 0;
  187. local_save_flags(flags);
  188. ret = __trace_graph_entry(tr, trace, flags, pc);
  189. atomic_dec(&data->disabled);
  190. preempt_enable_notrace();
  191. return ret;
  192. }
  193. static void wakeup_graph_return(struct ftrace_graph_ret *trace)
  194. {
  195. struct trace_array *tr = wakeup_trace;
  196. struct trace_array_cpu *data;
  197. unsigned long flags;
  198. int pc;
  199. if (!func_prolog_preempt_disable(tr, &data, &pc))
  200. return;
  201. local_save_flags(flags);
  202. __trace_graph_return(tr, trace, flags, pc);
  203. atomic_dec(&data->disabled);
  204. preempt_enable_notrace();
  205. return;
  206. }
  207. static void wakeup_trace_open(struct trace_iterator *iter)
  208. {
  209. if (is_graph())
  210. graph_trace_open(iter);
  211. }
  212. static void wakeup_trace_close(struct trace_iterator *iter)
  213. {
  214. if (iter->private)
  215. graph_trace_close(iter);
  216. }
  217. #define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_PROC | \
  218. TRACE_GRAPH_PRINT_ABS_TIME | \
  219. TRACE_GRAPH_PRINT_DURATION)
  220. static enum print_line_t wakeup_print_line(struct trace_iterator *iter)
  221. {
  222. /*
  223. * In graph mode call the graph tracer output function,
  224. * otherwise go with the TRACE_FN event handler
  225. */
  226. if (is_graph())
  227. return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS);
  228. return TRACE_TYPE_UNHANDLED;
  229. }
  230. static void wakeup_print_header(struct seq_file *s)
  231. {
  232. if (is_graph())
  233. print_graph_headers_flags(s, GRAPH_TRACER_FLAGS);
  234. else
  235. trace_default_header(s);
  236. }
  237. static void
  238. __trace_function(struct trace_array *tr,
  239. unsigned long ip, unsigned long parent_ip,
  240. unsigned long flags, int pc)
  241. {
  242. if (is_graph())
  243. trace_graph_function(tr, ip, parent_ip, flags, pc);
  244. else
  245. trace_function(tr, ip, parent_ip, flags, pc);
  246. }
  247. #else
  248. #define __trace_function trace_function
  249. static int
  250. wakeup_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
  251. {
  252. return -EINVAL;
  253. }
  254. static int wakeup_graph_entry(struct ftrace_graph_ent *trace)
  255. {
  256. return -1;
  257. }
  258. static enum print_line_t wakeup_print_line(struct trace_iterator *iter)
  259. {
  260. return TRACE_TYPE_UNHANDLED;
  261. }
  262. static void wakeup_graph_return(struct ftrace_graph_ret *trace) { }
  263. static void wakeup_trace_open(struct trace_iterator *iter) { }
  264. static void wakeup_trace_close(struct trace_iterator *iter) { }
  265. #ifdef CONFIG_FUNCTION_TRACER
  266. static void wakeup_print_header(struct seq_file *s)
  267. {
  268. trace_default_header(s);
  269. }
  270. #else
  271. static void wakeup_print_header(struct seq_file *s)
  272. {
  273. trace_latency_header(s);
  274. }
  275. #endif /* CONFIG_FUNCTION_TRACER */
  276. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  277. /*
  278. * Should this new latency be reported/recorded?
  279. */
  280. static int report_latency(struct trace_array *tr, cycle_t delta)
  281. {
  282. if (tracing_thresh) {
  283. if (delta < tracing_thresh)
  284. return 0;
  285. } else {
  286. if (delta <= tr->max_latency)
  287. return 0;
  288. }
  289. return 1;
  290. }
  291. static void
  292. probe_wakeup_migrate_task(void *ignore, struct task_struct *task, int cpu)
  293. {
  294. if (task != wakeup_task)
  295. return;
  296. wakeup_current_cpu = cpu;
  297. }
  298. static void
  299. tracing_sched_switch_trace(struct trace_array *tr,
  300. struct task_struct *prev,
  301. struct task_struct *next,
  302. unsigned long flags, int pc)
  303. {
  304. struct ftrace_event_call *call = &event_context_switch;
  305. struct ring_buffer *buffer = tr->trace_buffer.buffer;
  306. struct ring_buffer_event *event;
  307. struct ctx_switch_entry *entry;
  308. event = trace_buffer_lock_reserve(buffer, TRACE_CTX,
  309. sizeof(*entry), flags, pc);
  310. if (!event)
  311. return;
  312. entry = ring_buffer_event_data(event);
  313. entry->prev_pid = prev->pid;
  314. entry->prev_prio = prev->prio;
  315. entry->prev_state = prev->state;
  316. entry->next_pid = next->pid;
  317. entry->next_prio = next->prio;
  318. entry->next_state = next->state;
  319. entry->next_cpu = task_cpu(next);
  320. if (!call_filter_check_discard(call, entry, buffer, event))
  321. trace_buffer_unlock_commit(buffer, event, flags, pc);
  322. }
  323. static void
  324. tracing_sched_wakeup_trace(struct trace_array *tr,
  325. struct task_struct *wakee,
  326. struct task_struct *curr,
  327. unsigned long flags, int pc)
  328. {
  329. struct ftrace_event_call *call = &event_wakeup;
  330. struct ring_buffer_event *event;
  331. struct ctx_switch_entry *entry;
  332. struct ring_buffer *buffer = tr->trace_buffer.buffer;
  333. event = trace_buffer_lock_reserve(buffer, TRACE_WAKE,
  334. sizeof(*entry), flags, pc);
  335. if (!event)
  336. return;
  337. entry = ring_buffer_event_data(event);
  338. entry->prev_pid = curr->pid;
  339. entry->prev_prio = curr->prio;
  340. entry->prev_state = curr->state;
  341. entry->next_pid = wakee->pid;
  342. entry->next_prio = wakee->prio;
  343. entry->next_state = wakee->state;
  344. entry->next_cpu = task_cpu(wakee);
  345. if (!call_filter_check_discard(call, entry, buffer, event))
  346. trace_buffer_unlock_commit(buffer, event, flags, pc);
  347. }
  348. static void notrace
  349. probe_wakeup_sched_switch(void *ignore,
  350. struct task_struct *prev, struct task_struct *next)
  351. {
  352. struct trace_array_cpu *data;
  353. cycle_t T0, T1, delta;
  354. unsigned long flags;
  355. long disabled;
  356. int cpu;
  357. int pc;
  358. tracing_record_cmdline(prev);
  359. if (unlikely(!tracer_enabled))
  360. return;
  361. /*
  362. * When we start a new trace, we set wakeup_task to NULL
  363. * and then set tracer_enabled = 1. We want to make sure
  364. * that another CPU does not see the tracer_enabled = 1
  365. * and the wakeup_task with an older task, that might
  366. * actually be the same as next.
  367. */
  368. smp_rmb();
  369. if (next != wakeup_task)
  370. return;
  371. pc = preempt_count();
  372. /* disable local data, not wakeup_cpu data */
  373. cpu = raw_smp_processor_id();
  374. disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled);
  375. if (likely(disabled != 1))
  376. goto out;
  377. local_irq_save(flags);
  378. arch_spin_lock(&wakeup_lock);
  379. /* We could race with grabbing wakeup_lock */
  380. if (unlikely(!tracer_enabled || next != wakeup_task))
  381. goto out_unlock;
  382. /* The task we are waiting for is waking up */
  383. data = per_cpu_ptr(wakeup_trace->trace_buffer.data, wakeup_cpu);
  384. __trace_function(wakeup_trace, CALLER_ADDR0, CALLER_ADDR1, flags, pc);
  385. tracing_sched_switch_trace(wakeup_trace, prev, next, flags, pc);
  386. T0 = data->preempt_timestamp;
  387. T1 = ftrace_now(cpu);
  388. delta = T1-T0;
  389. if (!report_latency(wakeup_trace, delta))
  390. goto out_unlock;
  391. if (likely(!is_tracing_stopped())) {
  392. wakeup_trace->max_latency = delta;
  393. update_max_tr(wakeup_trace, wakeup_task, wakeup_cpu);
  394. }
  395. out_unlock:
  396. __wakeup_reset(wakeup_trace);
  397. arch_spin_unlock(&wakeup_lock);
  398. local_irq_restore(flags);
  399. out:
  400. atomic_dec(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled);
  401. }
  402. static void __wakeup_reset(struct trace_array *tr)
  403. {
  404. wakeup_cpu = -1;
  405. wakeup_prio = -1;
  406. tracing_dl = 0;
  407. if (wakeup_task)
  408. put_task_struct(wakeup_task);
  409. wakeup_task = NULL;
  410. }
  411. static void wakeup_reset(struct trace_array *tr)
  412. {
  413. unsigned long flags;
  414. tracing_reset_online_cpus(&tr->trace_buffer);
  415. local_irq_save(flags);
  416. arch_spin_lock(&wakeup_lock);
  417. __wakeup_reset(tr);
  418. arch_spin_unlock(&wakeup_lock);
  419. local_irq_restore(flags);
  420. }
  421. static void
  422. probe_wakeup(void *ignore, struct task_struct *p, int success)
  423. {
  424. struct trace_array_cpu *data;
  425. int cpu = smp_processor_id();
  426. unsigned long flags;
  427. long disabled;
  428. int pc;
  429. if (likely(!tracer_enabled))
  430. return;
  431. tracing_record_cmdline(p);
  432. tracing_record_cmdline(current);
  433. /*
  434. * Semantic is like this:
  435. * - wakeup tracer handles all tasks in the system, independently
  436. * from their scheduling class;
  437. * - wakeup_rt tracer handles tasks belonging to sched_dl and
  438. * sched_rt class;
  439. * - wakeup_dl handles tasks belonging to sched_dl class only.
  440. */
  441. if (tracing_dl || (wakeup_dl && !dl_task(p)) ||
  442. (wakeup_rt && !dl_task(p) && !rt_task(p)) ||
  443. (!dl_task(p) && (p->prio >= wakeup_prio || p->prio >= current->prio)))
  444. return;
  445. pc = preempt_count();
  446. disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled);
  447. if (unlikely(disabled != 1))
  448. goto out;
  449. /* interrupts should be off from try_to_wake_up */
  450. arch_spin_lock(&wakeup_lock);
  451. /* check for races. */
  452. if (!tracer_enabled || tracing_dl ||
  453. (!dl_task(p) && p->prio >= wakeup_prio))
  454. goto out_locked;
  455. /* reset the trace */
  456. __wakeup_reset(wakeup_trace);
  457. wakeup_cpu = task_cpu(p);
  458. wakeup_current_cpu = wakeup_cpu;
  459. wakeup_prio = p->prio;
  460. /*
  461. * Once you start tracing a -deadline task, don't bother tracing
  462. * another task until the first one wakes up.
  463. */
  464. if (dl_task(p))
  465. tracing_dl = 1;
  466. else
  467. tracing_dl = 0;
  468. wakeup_task = p;
  469. get_task_struct(wakeup_task);
  470. local_save_flags(flags);
  471. data = per_cpu_ptr(wakeup_trace->trace_buffer.data, wakeup_cpu);
  472. data->preempt_timestamp = ftrace_now(cpu);
  473. tracing_sched_wakeup_trace(wakeup_trace, p, current, flags, pc);
  474. /*
  475. * We must be careful in using CALLER_ADDR2. But since wake_up
  476. * is not called by an assembly function (where as schedule is)
  477. * it should be safe to use it here.
  478. */
  479. __trace_function(wakeup_trace, CALLER_ADDR1, CALLER_ADDR2, flags, pc);
  480. out_locked:
  481. arch_spin_unlock(&wakeup_lock);
  482. out:
  483. atomic_dec(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled);
  484. }
  485. static void start_wakeup_tracer(struct trace_array *tr)
  486. {
  487. int ret;
  488. ret = register_trace_sched_wakeup(probe_wakeup, NULL);
  489. if (ret) {
  490. pr_info("wakeup trace: Couldn't activate tracepoint"
  491. " probe to kernel_sched_wakeup\n");
  492. return;
  493. }
  494. ret = register_trace_sched_wakeup_new(probe_wakeup, NULL);
  495. if (ret) {
  496. pr_info("wakeup trace: Couldn't activate tracepoint"
  497. " probe to kernel_sched_wakeup_new\n");
  498. goto fail_deprobe;
  499. }
  500. ret = register_trace_sched_switch(probe_wakeup_sched_switch, NULL);
  501. if (ret) {
  502. pr_info("sched trace: Couldn't activate tracepoint"
  503. " probe to kernel_sched_switch\n");
  504. goto fail_deprobe_wake_new;
  505. }
  506. ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL);
  507. if (ret) {
  508. pr_info("wakeup trace: Couldn't activate tracepoint"
  509. " probe to kernel_sched_migrate_task\n");
  510. return;
  511. }
  512. wakeup_reset(tr);
  513. /*
  514. * Don't let the tracer_enabled = 1 show up before
  515. * the wakeup_task is reset. This may be overkill since
  516. * wakeup_reset does a spin_unlock after setting the
  517. * wakeup_task to NULL, but I want to be safe.
  518. * This is a slow path anyway.
  519. */
  520. smp_wmb();
  521. if (start_func_tracer(tr, is_graph()))
  522. printk(KERN_ERR "failed to start wakeup tracer\n");
  523. return;
  524. fail_deprobe_wake_new:
  525. unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
  526. fail_deprobe:
  527. unregister_trace_sched_wakeup(probe_wakeup, NULL);
  528. }
  529. static void stop_wakeup_tracer(struct trace_array *tr)
  530. {
  531. tracer_enabled = 0;
  532. stop_func_tracer(tr, is_graph());
  533. unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL);
  534. unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
  535. unregister_trace_sched_wakeup(probe_wakeup, NULL);
  536. unregister_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL);
  537. }
  538. static bool wakeup_busy;
  539. static int __wakeup_tracer_init(struct trace_array *tr)
  540. {
  541. save_flags = trace_flags;
  542. /* non overwrite screws up the latency tracers */
  543. set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1);
  544. set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, 1);
  545. tr->max_latency = 0;
  546. wakeup_trace = tr;
  547. ftrace_init_array_ops(tr, wakeup_tracer_call);
  548. start_wakeup_tracer(tr);
  549. wakeup_busy = true;
  550. return 0;
  551. }
  552. static int wakeup_tracer_init(struct trace_array *tr)
  553. {
  554. if (wakeup_busy)
  555. return -EBUSY;
  556. wakeup_dl = 0;
  557. wakeup_rt = 0;
  558. return __wakeup_tracer_init(tr);
  559. }
  560. static int wakeup_rt_tracer_init(struct trace_array *tr)
  561. {
  562. if (wakeup_busy)
  563. return -EBUSY;
  564. wakeup_dl = 0;
  565. wakeup_rt = 1;
  566. return __wakeup_tracer_init(tr);
  567. }
  568. static int wakeup_dl_tracer_init(struct trace_array *tr)
  569. {
  570. if (wakeup_busy)
  571. return -EBUSY;
  572. wakeup_dl = 1;
  573. wakeup_rt = 0;
  574. return __wakeup_tracer_init(tr);
  575. }
  576. static void wakeup_tracer_reset(struct trace_array *tr)
  577. {
  578. int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT;
  579. int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE;
  580. stop_wakeup_tracer(tr);
  581. /* make sure we put back any tasks we are tracing */
  582. wakeup_reset(tr);
  583. set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag);
  584. set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag);
  585. ftrace_reset_array_ops(tr);
  586. wakeup_busy = false;
  587. }
  588. static void wakeup_tracer_start(struct trace_array *tr)
  589. {
  590. wakeup_reset(tr);
  591. tracer_enabled = 1;
  592. }
  593. static void wakeup_tracer_stop(struct trace_array *tr)
  594. {
  595. tracer_enabled = 0;
  596. }
  597. static struct tracer wakeup_tracer __read_mostly =
  598. {
  599. .name = "wakeup",
  600. .init = wakeup_tracer_init,
  601. .reset = wakeup_tracer_reset,
  602. .start = wakeup_tracer_start,
  603. .stop = wakeup_tracer_stop,
  604. .print_max = true,
  605. .print_header = wakeup_print_header,
  606. .print_line = wakeup_print_line,
  607. .flags = &tracer_flags,
  608. .set_flag = wakeup_set_flag,
  609. .flag_changed = wakeup_flag_changed,
  610. #ifdef CONFIG_FTRACE_SELFTEST
  611. .selftest = trace_selftest_startup_wakeup,
  612. #endif
  613. .open = wakeup_trace_open,
  614. .close = wakeup_trace_close,
  615. .allow_instances = true,
  616. .use_max_tr = true,
  617. };
  618. static struct tracer wakeup_rt_tracer __read_mostly =
  619. {
  620. .name = "wakeup_rt",
  621. .init = wakeup_rt_tracer_init,
  622. .reset = wakeup_tracer_reset,
  623. .start = wakeup_tracer_start,
  624. .stop = wakeup_tracer_stop,
  625. .print_max = true,
  626. .print_header = wakeup_print_header,
  627. .print_line = wakeup_print_line,
  628. .flags = &tracer_flags,
  629. .set_flag = wakeup_set_flag,
  630. .flag_changed = wakeup_flag_changed,
  631. #ifdef CONFIG_FTRACE_SELFTEST
  632. .selftest = trace_selftest_startup_wakeup,
  633. #endif
  634. .open = wakeup_trace_open,
  635. .close = wakeup_trace_close,
  636. .allow_instances = true,
  637. .use_max_tr = true,
  638. };
  639. static struct tracer wakeup_dl_tracer __read_mostly =
  640. {
  641. .name = "wakeup_dl",
  642. .init = wakeup_dl_tracer_init,
  643. .reset = wakeup_tracer_reset,
  644. .start = wakeup_tracer_start,
  645. .stop = wakeup_tracer_stop,
  646. .print_max = true,
  647. .print_header = wakeup_print_header,
  648. .print_line = wakeup_print_line,
  649. .flags = &tracer_flags,
  650. .set_flag = wakeup_set_flag,
  651. .flag_changed = wakeup_flag_changed,
  652. #ifdef CONFIG_FTRACE_SELFTEST
  653. .selftest = trace_selftest_startup_wakeup,
  654. #endif
  655. .open = wakeup_trace_open,
  656. .close = wakeup_trace_close,
  657. .use_max_tr = true,
  658. };
  659. __init static int init_wakeup_tracer(void)
  660. {
  661. int ret;
  662. ret = register_tracer(&wakeup_tracer);
  663. if (ret)
  664. return ret;
  665. ret = register_tracer(&wakeup_rt_tracer);
  666. if (ret)
  667. return ret;
  668. ret = register_tracer(&wakeup_dl_tracer);
  669. if (ret)
  670. return ret;
  671. return 0;
  672. }
  673. core_initcall(init_wakeup_tracer);