trace_sched_wakeup.c 19 KB

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