trace_sched_wakeup.c 19 KB

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