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