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