trace_sched_wakeup.c 20 KB

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