trace_sched_wakeup.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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 (ftrace_graph_ignore_func(trace))
  195. return 0;
  196. /*
  197. * Do not trace a function if it's filtered by set_graph_notrace.
  198. * Make the index of ret stack negative to indicate that it should
  199. * ignore further functions. But it needs its own ret stack entry
  200. * to recover the original index in order to continue tracing after
  201. * returning from the function.
  202. */
  203. if (ftrace_graph_notrace_addr(trace->func))
  204. return 1;
  205. if (!func_prolog_preempt_disable(tr, &data, &pc))
  206. return 0;
  207. local_save_flags(flags);
  208. ret = __trace_graph_entry(tr, trace, flags, pc);
  209. atomic_dec(&data->disabled);
  210. preempt_enable_notrace();
  211. return ret;
  212. }
  213. static void wakeup_graph_return(struct ftrace_graph_ret *trace)
  214. {
  215. struct trace_array *tr = wakeup_trace;
  216. struct trace_array_cpu *data;
  217. unsigned long flags;
  218. int pc;
  219. if (!func_prolog_preempt_disable(tr, &data, &pc))
  220. return;
  221. local_save_flags(flags);
  222. __trace_graph_return(tr, trace, flags, pc);
  223. atomic_dec(&data->disabled);
  224. preempt_enable_notrace();
  225. return;
  226. }
  227. static void wakeup_trace_open(struct trace_iterator *iter)
  228. {
  229. if (is_graph(iter->tr))
  230. graph_trace_open(iter);
  231. }
  232. static void wakeup_trace_close(struct trace_iterator *iter)
  233. {
  234. if (iter->private)
  235. graph_trace_close(iter);
  236. }
  237. #define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_PROC | \
  238. TRACE_GRAPH_PRINT_ABS_TIME | \
  239. TRACE_GRAPH_PRINT_DURATION)
  240. static enum print_line_t wakeup_print_line(struct trace_iterator *iter)
  241. {
  242. /*
  243. * In graph mode call the graph tracer output function,
  244. * otherwise go with the TRACE_FN event handler
  245. */
  246. if (is_graph(iter->tr))
  247. return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS);
  248. return TRACE_TYPE_UNHANDLED;
  249. }
  250. static void wakeup_print_header(struct seq_file *s)
  251. {
  252. if (is_graph(wakeup_trace))
  253. print_graph_headers_flags(s, GRAPH_TRACER_FLAGS);
  254. else
  255. trace_default_header(s);
  256. }
  257. static void
  258. __trace_function(struct trace_array *tr,
  259. unsigned long ip, unsigned long parent_ip,
  260. unsigned long flags, int pc)
  261. {
  262. if (is_graph(tr))
  263. trace_graph_function(tr, ip, parent_ip, flags, pc);
  264. else
  265. trace_function(tr, ip, parent_ip, flags, pc);
  266. }
  267. #else
  268. #define __trace_function trace_function
  269. static enum print_line_t wakeup_print_line(struct trace_iterator *iter)
  270. {
  271. return TRACE_TYPE_UNHANDLED;
  272. }
  273. static void wakeup_trace_open(struct trace_iterator *iter) { }
  274. static void wakeup_trace_close(struct trace_iterator *iter) { }
  275. #ifdef CONFIG_FUNCTION_TRACER
  276. static int wakeup_graph_entry(struct ftrace_graph_ent *trace)
  277. {
  278. return -1;
  279. }
  280. static void wakeup_graph_return(struct ftrace_graph_ret *trace) { }
  281. static void wakeup_print_header(struct seq_file *s)
  282. {
  283. trace_default_header(s);
  284. }
  285. #else
  286. static void wakeup_print_header(struct seq_file *s)
  287. {
  288. trace_latency_header(s);
  289. }
  290. #endif /* CONFIG_FUNCTION_TRACER */
  291. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  292. /*
  293. * Should this new latency be reported/recorded?
  294. */
  295. static bool report_latency(struct trace_array *tr, u64 delta)
  296. {
  297. if (tracing_thresh) {
  298. if (delta < tracing_thresh)
  299. return false;
  300. } else {
  301. if (delta <= tr->max_latency)
  302. return false;
  303. }
  304. return true;
  305. }
  306. static void
  307. probe_wakeup_migrate_task(void *ignore, struct task_struct *task, int cpu)
  308. {
  309. if (task != wakeup_task)
  310. return;
  311. wakeup_current_cpu = cpu;
  312. }
  313. static void
  314. tracing_sched_switch_trace(struct trace_array *tr,
  315. struct task_struct *prev,
  316. struct task_struct *next,
  317. unsigned long flags, int pc)
  318. {
  319. struct trace_event_call *call = &event_context_switch;
  320. struct ring_buffer *buffer = tr->trace_buffer.buffer;
  321. struct ring_buffer_event *event;
  322. struct ctx_switch_entry *entry;
  323. event = trace_buffer_lock_reserve(buffer, TRACE_CTX,
  324. sizeof(*entry), flags, pc);
  325. if (!event)
  326. return;
  327. entry = ring_buffer_event_data(event);
  328. entry->prev_pid = prev->pid;
  329. entry->prev_prio = prev->prio;
  330. entry->prev_state = prev->state;
  331. entry->next_pid = next->pid;
  332. entry->next_prio = next->prio;
  333. entry->next_state = next->state;
  334. entry->next_cpu = task_cpu(next);
  335. if (!call_filter_check_discard(call, entry, buffer, event))
  336. trace_buffer_unlock_commit(tr, buffer, event, flags, pc);
  337. }
  338. static void
  339. tracing_sched_wakeup_trace(struct trace_array *tr,
  340. struct task_struct *wakee,
  341. struct task_struct *curr,
  342. unsigned long flags, int pc)
  343. {
  344. struct trace_event_call *call = &event_wakeup;
  345. struct ring_buffer_event *event;
  346. struct ctx_switch_entry *entry;
  347. struct ring_buffer *buffer = tr->trace_buffer.buffer;
  348. event = trace_buffer_lock_reserve(buffer, TRACE_WAKE,
  349. sizeof(*entry), flags, pc);
  350. if (!event)
  351. return;
  352. entry = ring_buffer_event_data(event);
  353. entry->prev_pid = curr->pid;
  354. entry->prev_prio = curr->prio;
  355. entry->prev_state = curr->state;
  356. entry->next_pid = wakee->pid;
  357. entry->next_prio = wakee->prio;
  358. entry->next_state = wakee->state;
  359. entry->next_cpu = task_cpu(wakee);
  360. if (!call_filter_check_discard(call, entry, buffer, event))
  361. trace_buffer_unlock_commit(tr, buffer, event, flags, pc);
  362. }
  363. static void notrace
  364. probe_wakeup_sched_switch(void *ignore, bool preempt,
  365. struct task_struct *prev, struct task_struct *next)
  366. {
  367. struct trace_array_cpu *data;
  368. u64 T0, T1, delta;
  369. unsigned long flags;
  370. long disabled;
  371. int cpu;
  372. int pc;
  373. tracing_record_cmdline(prev);
  374. if (unlikely(!tracer_enabled))
  375. return;
  376. /*
  377. * When we start a new trace, we set wakeup_task to NULL
  378. * and then set tracer_enabled = 1. We want to make sure
  379. * that another CPU does not see the tracer_enabled = 1
  380. * and the wakeup_task with an older task, that might
  381. * actually be the same as next.
  382. */
  383. smp_rmb();
  384. if (next != wakeup_task)
  385. return;
  386. pc = preempt_count();
  387. /* disable local data, not wakeup_cpu data */
  388. cpu = raw_smp_processor_id();
  389. disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled);
  390. if (likely(disabled != 1))
  391. goto out;
  392. local_irq_save(flags);
  393. arch_spin_lock(&wakeup_lock);
  394. /* We could race with grabbing wakeup_lock */
  395. if (unlikely(!tracer_enabled || next != wakeup_task))
  396. goto out_unlock;
  397. /* The task we are waiting for is waking up */
  398. data = per_cpu_ptr(wakeup_trace->trace_buffer.data, wakeup_cpu);
  399. __trace_function(wakeup_trace, CALLER_ADDR0, CALLER_ADDR1, flags, pc);
  400. tracing_sched_switch_trace(wakeup_trace, prev, next, flags, pc);
  401. T0 = data->preempt_timestamp;
  402. T1 = ftrace_now(cpu);
  403. delta = T1-T0;
  404. if (!report_latency(wakeup_trace, delta))
  405. goto out_unlock;
  406. if (likely(!is_tracing_stopped())) {
  407. wakeup_trace->max_latency = delta;
  408. update_max_tr(wakeup_trace, wakeup_task, wakeup_cpu);
  409. }
  410. out_unlock:
  411. __wakeup_reset(wakeup_trace);
  412. arch_spin_unlock(&wakeup_lock);
  413. local_irq_restore(flags);
  414. out:
  415. atomic_dec(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled);
  416. }
  417. static void __wakeup_reset(struct trace_array *tr)
  418. {
  419. wakeup_cpu = -1;
  420. wakeup_prio = -1;
  421. tracing_dl = 0;
  422. if (wakeup_task)
  423. put_task_struct(wakeup_task);
  424. wakeup_task = NULL;
  425. }
  426. static void wakeup_reset(struct trace_array *tr)
  427. {
  428. unsigned long flags;
  429. tracing_reset_online_cpus(&tr->trace_buffer);
  430. local_irq_save(flags);
  431. arch_spin_lock(&wakeup_lock);
  432. __wakeup_reset(tr);
  433. arch_spin_unlock(&wakeup_lock);
  434. local_irq_restore(flags);
  435. }
  436. static void
  437. probe_wakeup(void *ignore, struct task_struct *p)
  438. {
  439. struct trace_array_cpu *data;
  440. int cpu = smp_processor_id();
  441. unsigned long flags;
  442. long disabled;
  443. int pc;
  444. if (likely(!tracer_enabled))
  445. return;
  446. tracing_record_cmdline(p);
  447. tracing_record_cmdline(current);
  448. /*
  449. * Semantic is like this:
  450. * - wakeup tracer handles all tasks in the system, independently
  451. * from their scheduling class;
  452. * - wakeup_rt tracer handles tasks belonging to sched_dl and
  453. * sched_rt class;
  454. * - wakeup_dl handles tasks belonging to sched_dl class only.
  455. */
  456. if (tracing_dl || (wakeup_dl && !dl_task(p)) ||
  457. (wakeup_rt && !dl_task(p) && !rt_task(p)) ||
  458. (!dl_task(p) && (p->prio >= wakeup_prio || p->prio >= current->prio)))
  459. return;
  460. pc = preempt_count();
  461. disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled);
  462. if (unlikely(disabled != 1))
  463. goto out;
  464. /* interrupts should be off from try_to_wake_up */
  465. arch_spin_lock(&wakeup_lock);
  466. /* check for races. */
  467. if (!tracer_enabled || tracing_dl ||
  468. (!dl_task(p) && p->prio >= wakeup_prio))
  469. goto out_locked;
  470. /* reset the trace */
  471. __wakeup_reset(wakeup_trace);
  472. wakeup_cpu = task_cpu(p);
  473. wakeup_current_cpu = wakeup_cpu;
  474. wakeup_prio = p->prio;
  475. /*
  476. * Once you start tracing a -deadline task, don't bother tracing
  477. * another task until the first one wakes up.
  478. */
  479. if (dl_task(p))
  480. tracing_dl = 1;
  481. else
  482. tracing_dl = 0;
  483. wakeup_task = p;
  484. get_task_struct(wakeup_task);
  485. local_save_flags(flags);
  486. data = per_cpu_ptr(wakeup_trace->trace_buffer.data, wakeup_cpu);
  487. data->preempt_timestamp = ftrace_now(cpu);
  488. tracing_sched_wakeup_trace(wakeup_trace, p, current, flags, pc);
  489. /*
  490. * We must be careful in using CALLER_ADDR2. But since wake_up
  491. * is not called by an assembly function (where as schedule is)
  492. * it should be safe to use it here.
  493. */
  494. __trace_function(wakeup_trace, CALLER_ADDR1, CALLER_ADDR2, flags, pc);
  495. out_locked:
  496. arch_spin_unlock(&wakeup_lock);
  497. out:
  498. atomic_dec(&per_cpu_ptr(wakeup_trace->trace_buffer.data, cpu)->disabled);
  499. }
  500. static void start_wakeup_tracer(struct trace_array *tr)
  501. {
  502. int ret;
  503. ret = register_trace_sched_wakeup(probe_wakeup, NULL);
  504. if (ret) {
  505. pr_info("wakeup trace: Couldn't activate tracepoint"
  506. " probe to kernel_sched_wakeup\n");
  507. return;
  508. }
  509. ret = register_trace_sched_wakeup_new(probe_wakeup, NULL);
  510. if (ret) {
  511. pr_info("wakeup trace: Couldn't activate tracepoint"
  512. " probe to kernel_sched_wakeup_new\n");
  513. goto fail_deprobe;
  514. }
  515. ret = register_trace_sched_switch(probe_wakeup_sched_switch, NULL);
  516. if (ret) {
  517. pr_info("sched trace: Couldn't activate tracepoint"
  518. " probe to kernel_sched_switch\n");
  519. goto fail_deprobe_wake_new;
  520. }
  521. ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL);
  522. if (ret) {
  523. pr_info("wakeup trace: Couldn't activate tracepoint"
  524. " probe to kernel_sched_migrate_task\n");
  525. return;
  526. }
  527. wakeup_reset(tr);
  528. /*
  529. * Don't let the tracer_enabled = 1 show up before
  530. * the wakeup_task is reset. This may be overkill since
  531. * wakeup_reset does a spin_unlock after setting the
  532. * wakeup_task to NULL, but I want to be safe.
  533. * This is a slow path anyway.
  534. */
  535. smp_wmb();
  536. if (start_func_tracer(tr, is_graph(tr)))
  537. printk(KERN_ERR "failed to start wakeup tracer\n");
  538. return;
  539. fail_deprobe_wake_new:
  540. unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
  541. fail_deprobe:
  542. unregister_trace_sched_wakeup(probe_wakeup, NULL);
  543. }
  544. static void stop_wakeup_tracer(struct trace_array *tr)
  545. {
  546. tracer_enabled = 0;
  547. stop_func_tracer(tr, is_graph(tr));
  548. unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL);
  549. unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
  550. unregister_trace_sched_wakeup(probe_wakeup, NULL);
  551. unregister_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL);
  552. }
  553. static bool wakeup_busy;
  554. static int __wakeup_tracer_init(struct trace_array *tr)
  555. {
  556. save_flags = tr->trace_flags;
  557. /* non overwrite screws up the latency tracers */
  558. set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1);
  559. set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, 1);
  560. tr->max_latency = 0;
  561. wakeup_trace = tr;
  562. ftrace_init_array_ops(tr, wakeup_tracer_call);
  563. start_wakeup_tracer(tr);
  564. wakeup_busy = true;
  565. return 0;
  566. }
  567. static int wakeup_tracer_init(struct trace_array *tr)
  568. {
  569. if (wakeup_busy)
  570. return -EBUSY;
  571. wakeup_dl = 0;
  572. wakeup_rt = 0;
  573. return __wakeup_tracer_init(tr);
  574. }
  575. static int wakeup_rt_tracer_init(struct trace_array *tr)
  576. {
  577. if (wakeup_busy)
  578. return -EBUSY;
  579. wakeup_dl = 0;
  580. wakeup_rt = 1;
  581. return __wakeup_tracer_init(tr);
  582. }
  583. static int wakeup_dl_tracer_init(struct trace_array *tr)
  584. {
  585. if (wakeup_busy)
  586. return -EBUSY;
  587. wakeup_dl = 1;
  588. wakeup_rt = 0;
  589. return __wakeup_tracer_init(tr);
  590. }
  591. static void wakeup_tracer_reset(struct trace_array *tr)
  592. {
  593. int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT;
  594. int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE;
  595. stop_wakeup_tracer(tr);
  596. /* make sure we put back any tasks we are tracing */
  597. wakeup_reset(tr);
  598. set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag);
  599. set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag);
  600. ftrace_reset_array_ops(tr);
  601. wakeup_busy = false;
  602. }
  603. static void wakeup_tracer_start(struct trace_array *tr)
  604. {
  605. wakeup_reset(tr);
  606. tracer_enabled = 1;
  607. }
  608. static void wakeup_tracer_stop(struct trace_array *tr)
  609. {
  610. tracer_enabled = 0;
  611. }
  612. static struct tracer wakeup_tracer __read_mostly =
  613. {
  614. .name = "wakeup",
  615. .init = wakeup_tracer_init,
  616. .reset = wakeup_tracer_reset,
  617. .start = wakeup_tracer_start,
  618. .stop = wakeup_tracer_stop,
  619. .print_max = true,
  620. .print_header = wakeup_print_header,
  621. .print_line = wakeup_print_line,
  622. .flag_changed = wakeup_flag_changed,
  623. #ifdef CONFIG_FTRACE_SELFTEST
  624. .selftest = trace_selftest_startup_wakeup,
  625. #endif
  626. .open = wakeup_trace_open,
  627. .close = wakeup_trace_close,
  628. .allow_instances = true,
  629. .use_max_tr = true,
  630. };
  631. static struct tracer wakeup_rt_tracer __read_mostly =
  632. {
  633. .name = "wakeup_rt",
  634. .init = wakeup_rt_tracer_init,
  635. .reset = wakeup_tracer_reset,
  636. .start = wakeup_tracer_start,
  637. .stop = wakeup_tracer_stop,
  638. .print_max = true,
  639. .print_header = wakeup_print_header,
  640. .print_line = wakeup_print_line,
  641. .flag_changed = wakeup_flag_changed,
  642. #ifdef CONFIG_FTRACE_SELFTEST
  643. .selftest = trace_selftest_startup_wakeup,
  644. #endif
  645. .open = wakeup_trace_open,
  646. .close = wakeup_trace_close,
  647. .allow_instances = true,
  648. .use_max_tr = true,
  649. };
  650. static struct tracer wakeup_dl_tracer __read_mostly =
  651. {
  652. .name = "wakeup_dl",
  653. .init = wakeup_dl_tracer_init,
  654. .reset = wakeup_tracer_reset,
  655. .start = wakeup_tracer_start,
  656. .stop = wakeup_tracer_stop,
  657. .print_max = true,
  658. .print_header = wakeup_print_header,
  659. .print_line = wakeup_print_line,
  660. .flag_changed = wakeup_flag_changed,
  661. #ifdef CONFIG_FTRACE_SELFTEST
  662. .selftest = trace_selftest_startup_wakeup,
  663. #endif
  664. .open = wakeup_trace_open,
  665. .close = wakeup_trace_close,
  666. .allow_instances = true,
  667. .use_max_tr = true,
  668. };
  669. __init static int init_wakeup_tracer(void)
  670. {
  671. int ret;
  672. ret = register_tracer(&wakeup_tracer);
  673. if (ret)
  674. return ret;
  675. ret = register_tracer(&wakeup_rt_tracer);
  676. if (ret)
  677. return ret;
  678. ret = register_tracer(&wakeup_dl_tracer);
  679. if (ret)
  680. return ret;
  681. return 0;
  682. }
  683. core_initcall(init_wakeup_tracer);