blob: 2402de520eca71331b324eef1dfe6528de7c055e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Steven Rostedt352ad252008-05-12 21:20:42 +02002/*
3 * trace task wakeup timings
4 *
5 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
6 * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
7 *
8 * Based on code from the latency_tracer, that is:
9 *
10 * Copyright (C) 2004-2006 Ingo Molnar
Nadia Yvette Chambers6d49e352012-12-06 10:39:54 +010011 * Copyright (C) 2004 Nadia Yvette Chambers
Steven Rostedt352ad252008-05-12 21:20:42 +020012 */
13#include <linux/module.h>
Steven Rostedt352ad252008-05-12 21:20:42 +020014#include <linux/kallsyms.h>
15#include <linux/uaccess.h>
16#include <linux/ftrace.h>
Clark Williams8bd75c72013-02-07 09:47:07 -060017#include <linux/sched/rt.h>
Dario Faggioli2d3d8912013-11-07 14:43:44 +010018#include <linux/sched/deadline.h>
Steven Rostedtad8d75f2009-04-14 19:39:12 -040019#include <trace/events/sched.h>
Steven Rostedt352ad252008-05-12 21:20:42 +020020#include "trace.h"
21
22static struct trace_array *wakeup_trace;
23static int __read_mostly tracer_enabled;
24
25static struct task_struct *wakeup_task;
26static int wakeup_cpu;
Steven Rostedt478142c32009-09-09 10:36:01 -040027static int wakeup_current_cpu;
Steven Rostedt352ad252008-05-12 21:20:42 +020028static unsigned wakeup_prio = -1;
Austin Kimbfbf8d12021-06-29 15:05:48 +010029static bool wakeup_rt;
30static bool wakeup_dl;
31static bool tracing_dl;
Steven Rostedt352ad252008-05-12 21:20:42 +020032
Thomas Gleixner445c8952009-12-02 19:49:50 +010033static arch_spinlock_t wakeup_lock =
Thomas Gleixneredc35bd2009-12-03 12:38:57 +010034 (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
Steven Rostedt352ad252008-05-12 21:20:42 +020035
Jiri Olsa7495a5b2010-09-23 14:00:53 +020036static void wakeup_reset(struct trace_array *tr);
Ingo Molnare309b412008-05-12 21:20:51 +020037static void __wakeup_reset(struct trace_array *tr);
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -050038static int start_func_tracer(struct trace_array *tr, int graph);
39static void stop_func_tracer(struct trace_array *tr, int graph);
Steven Rostedt352ad252008-05-12 21:20:42 +020040
Steven Rostedt (Red Hat)613f04a2013-03-14 15:03:53 -040041static int save_flags;
Steven Rostedte9d25fe2009-03-04 22:15:30 -050042
Jiri Olsa7495a5b2010-09-23 14:00:53 +020043#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -040044# define is_graph(tr) ((tr)->trace_flags & TRACE_ITER_DISPLAY_GRAPH)
Steven Rostedt (Red Hat)03905582015-09-28 15:37:49 -040045#else
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -040046# define is_graph(tr) false
Jiri Olsa7495a5b2010-09-23 14:00:53 +020047#endif
Jiri Olsa7495a5b2010-09-23 14:00:53 +020048
Steven Rostedt606576c2008-10-06 19:06:12 -040049#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedt542181d2010-10-05 16:38:49 -040050
Steven Rostedt352ad252008-05-12 21:20:42 +020051static bool function_enabled;
52
Steven Rostedt542181d2010-10-05 16:38:49 -040053/*
54 * Prologue for the wakeup function tracers.
55 *
56 * Returns 1 if it is OK to continue, and preemption
57 * is disabled and data->disabled is incremented.
58 * 0 if the trace is to be ignored, and preemption
59 * is not disabled and data->disabled is
60 * kept the same.
61 *
62 * Note, this function is also used outside this ifdef but
63 * inside the #ifdef of the function graph tracer below.
64 * This is OK, since the function graph tracer is
65 * dependent on the function tracer.
66 */
67static int
68func_prolog_preempt_disable(struct trace_array *tr,
69 struct trace_array_cpu **data,
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +010070 unsigned int *trace_ctx)
Steven Rostedt542181d2010-10-05 16:38:49 -040071{
72 long disabled;
73 int cpu;
74
75 if (likely(!wakeup_task))
76 return 0;
77
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +010078 *trace_ctx = tracing_gen_ctx();
Steven Rostedt542181d2010-10-05 16:38:49 -040079 preempt_disable_notrace();
80
81 cpu = raw_smp_processor_id();
82 if (cpu != wakeup_current_cpu)
83 goto out_enable;
84
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -050085 *data = per_cpu_ptr(tr->array_buffer.data, cpu);
Steven Rostedt542181d2010-10-05 16:38:49 -040086 disabled = atomic_inc_return(&(*data)->disabled);
87 if (unlikely(disabled != 1))
88 goto out;
89
90 return 1;
91
92out:
93 atomic_dec(&(*data)->disabled);
94
95out_enable:
96 preempt_enable_notrace();
97 return 0;
98}
99
Steven Rostedt (Red Hat)729358d2015-09-29 10:15:10 -0400100#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Steven Rostedt (Red Hat)328df472013-03-14 12:10:40 -0400101
Steven Rostedt (Red Hat)03905582015-09-28 15:37:49 -0400102static int wakeup_display_graph(struct trace_array *tr, int set)
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200103{
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400104 if (!(is_graph(tr) ^ set))
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200105 return 0;
106
Steven Rostedt (Red Hat)4104d322014-01-10 17:01:58 -0500107 stop_func_tracer(tr, !set);
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200108
109 wakeup_reset(wakeup_trace);
Steven Rostedt (Red Hat)6d9b3fa2014-01-14 11:28:38 -0500110 tr->max_latency = 0;
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200111
Steven Rostedt (Red Hat)4104d322014-01-10 17:01:58 -0500112 return start_func_tracer(tr, set);
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200113}
114
115static int wakeup_graph_entry(struct ftrace_graph_ent *trace)
116{
117 struct trace_array *tr = wakeup_trace;
118 struct trace_array_cpu *data;
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100119 unsigned int trace_ctx;
120 int ret = 0;
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200121
Steven Rostedt (Red Hat)1a414422016-12-08 19:28:28 -0500122 if (ftrace_graph_ignore_func(trace))
123 return 0;
124 /*
125 * Do not trace a function if it's filtered by set_graph_notrace.
126 * Make the index of ret stack negative to indicate that it should
127 * ignore further functions. But it needs its own ret stack entry
128 * to recover the original index in order to continue tracing after
129 * returning from the function.
130 */
131 if (ftrace_graph_notrace_addr(trace->func))
132 return 1;
133
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100134 if (!func_prolog_preempt_disable(tr, &data, &trace_ctx))
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200135 return 0;
136
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100137 ret = __trace_graph_entry(tr, trace, trace_ctx);
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200138 atomic_dec(&data->disabled);
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200139 preempt_enable_notrace();
Steven Rostedt542181d2010-10-05 16:38:49 -0400140
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200141 return ret;
142}
143
144static void wakeup_graph_return(struct ftrace_graph_ret *trace)
145{
146 struct trace_array *tr = wakeup_trace;
147 struct trace_array_cpu *data;
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100148 unsigned int trace_ctx;
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200149
Steven Rostedt (VMware)5cf99a0f2018-11-29 08:50:27 -0500150 ftrace_graph_addr_finish(trace);
151
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100152 if (!func_prolog_preempt_disable(tr, &data, &trace_ctx))
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200153 return;
154
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100155 __trace_graph_return(tr, trace, trace_ctx);
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200156 atomic_dec(&data->disabled);
157
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200158 preempt_enable_notrace();
159 return;
160}
161
Steven Rostedt (VMware)688f7082018-11-15 14:06:47 -0500162static struct fgraph_ops fgraph_wakeup_ops = {
163 .entryfunc = &wakeup_graph_entry,
164 .retfunc = &wakeup_graph_return,
165};
166
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200167static void wakeup_trace_open(struct trace_iterator *iter)
168{
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400169 if (is_graph(iter->tr))
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200170 graph_trace_open(iter);
171}
172
173static void wakeup_trace_close(struct trace_iterator *iter)
174{
175 if (iter->private)
176 graph_trace_close(iter);
177}
178
Jiri Olsa321e68b2011-06-03 16:58:47 +0200179#define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_PROC | \
Changbin Du97f0a3b2019-01-01 23:46:11 +0800180 TRACE_GRAPH_PRINT_CPU | \
Changbin Du9acd8de2019-01-01 23:46:10 +0800181 TRACE_GRAPH_PRINT_REL_TIME | \
Changbin Du97f0a3b2019-01-01 23:46:11 +0800182 TRACE_GRAPH_PRINT_DURATION | \
183 TRACE_GRAPH_PRINT_OVERHEAD | \
184 TRACE_GRAPH_PRINT_IRQS)
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200185
186static enum print_line_t wakeup_print_line(struct trace_iterator *iter)
187{
188 /*
189 * In graph mode call the graph tracer output function,
190 * otherwise go with the TRACE_FN event handler
191 */
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400192 if (is_graph(iter->tr))
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200193 return print_graph_function_flags(iter, GRAPH_TRACER_FLAGS);
194
195 return TRACE_TYPE_UNHANDLED;
196}
197
198static void wakeup_print_header(struct seq_file *s)
199{
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400200 if (is_graph(wakeup_trace))
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200201 print_graph_headers_flags(s, GRAPH_TRACER_FLAGS);
202 else
203 trace_default_header(s);
204}
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500205#endif /* else CONFIG_FUNCTION_GRAPH_TRACER */
206
207/*
208 * wakeup uses its own tracer function to keep the overhead down:
209 */
210static void
211wakeup_tracer_call(unsigned long ip, unsigned long parent_ip,
Steven Rostedt (VMware)d19ad072020-10-28 17:42:17 -0400212 struct ftrace_ops *op, struct ftrace_regs *fregs)
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500213{
214 struct trace_array *tr = wakeup_trace;
215 struct trace_array_cpu *data;
216 unsigned long flags;
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100217 unsigned int trace_ctx;
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500218
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100219 if (!func_prolog_preempt_disable(tr, &data, &trace_ctx))
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500220 return;
221
222 local_irq_save(flags);
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100223 trace_function(tr, ip, parent_ip, trace_ctx);
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500224 local_irq_restore(flags);
225
226 atomic_dec(&data->disabled);
227 preempt_enable_notrace();
228}
229
230static int register_wakeup_function(struct trace_array *tr, int graph, int set)
231{
232 int ret;
233
234 /* 'set' is set if TRACE_ITER_FUNCTION is about to be set */
235 if (function_enabled || (!set && !(tr->trace_flags & TRACE_ITER_FUNCTION)))
236 return 0;
237
238 if (graph)
Steven Rostedt (VMware)688f7082018-11-15 14:06:47 -0500239 ret = register_ftrace_graph(&fgraph_wakeup_ops);
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500240 else
241 ret = register_ftrace_function(tr->ops);
242
243 if (!ret)
244 function_enabled = true;
245
246 return ret;
247}
248
249static void unregister_wakeup_function(struct trace_array *tr, int graph)
250{
251 if (!function_enabled)
252 return;
253
254 if (graph)
Steven Rostedt (VMware)688f7082018-11-15 14:06:47 -0500255 unregister_ftrace_graph(&fgraph_wakeup_ops);
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500256 else
257 unregister_ftrace_function(tr->ops);
258
259 function_enabled = false;
260}
261
262static int wakeup_function_set(struct trace_array *tr, u32 mask, int set)
263{
264 if (!(mask & TRACE_ITER_FUNCTION))
265 return 0;
266
267 if (set)
268 register_wakeup_function(tr, is_graph(tr), 1);
269 else
270 unregister_wakeup_function(tr, is_graph(tr));
271 return 1;
272}
273#else /* CONFIG_FUNCTION_TRACER */
274static int register_wakeup_function(struct trace_array *tr, int graph, int set)
275{
276 return 0;
277}
278static void unregister_wakeup_function(struct trace_array *tr, int graph) { }
279static int wakeup_function_set(struct trace_array *tr, u32 mask, int set)
280{
281 return 0;
282}
283#endif /* else CONFIG_FUNCTION_TRACER */
284
285#ifndef CONFIG_FUNCTION_GRAPH_TRACER
286static enum print_line_t wakeup_print_line(struct trace_iterator *iter)
287{
288 return TRACE_TYPE_UNHANDLED;
289}
290
291static void wakeup_trace_open(struct trace_iterator *iter) { }
292static void wakeup_trace_close(struct trace_iterator *iter) { }
293
294static void wakeup_print_header(struct seq_file *s)
295{
296 trace_default_header(s);
297}
298#endif /* !CONFIG_FUNCTION_GRAPH_TRACER */
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200299
300static void
301__trace_function(struct trace_array *tr,
302 unsigned long ip, unsigned long parent_ip,
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100303 unsigned int trace_ctx)
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200304{
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400305 if (is_graph(tr))
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100306 trace_graph_function(tr, ip, parent_ip, trace_ctx);
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200307 else
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100308 trace_function(tr, ip, parent_ip, trace_ctx);
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200309}
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200310
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500311static int wakeup_flag_changed(struct trace_array *tr, u32 mask, int set)
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200312{
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500313 struct tracer *tracer = tr->current_trace;
314
315 if (wakeup_function_set(tr, mask, set))
316 return 0;
317
318#ifdef CONFIG_FUNCTION_GRAPH_TRACER
319 if (mask & TRACE_ITER_DISPLAY_GRAPH)
320 return wakeup_display_graph(tr, set);
321#endif
322
323 return trace_keep_overwrite(tracer, mask, set);
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200324}
325
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500326static int start_func_tracer(struct trace_array *tr, int graph)
327{
328 int ret;
Jiri Olsa7e9a49e2011-11-07 16:08:49 +0100329
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500330 ret = register_wakeup_function(tr, graph, 0);
331
332 if (!ret && tracing_is_enabled())
333 tracer_enabled = 1;
334 else
335 tracer_enabled = 0;
336
337 return ret;
Steven Rostedt (Red Hat)8179e8a2015-09-29 10:24:56 -0400338}
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500339
340static void stop_func_tracer(struct trace_array *tr, int graph)
Jiri Olsa7e9a49e2011-11-07 16:08:49 +0100341{
Steven Rostedt (VMware)317e04ca2018-11-28 10:26:27 -0500342 tracer_enabled = 0;
343
344 unregister_wakeup_function(tr, graph);
Jiri Olsa7e9a49e2011-11-07 16:08:49 +0100345}
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200346
Steven Rostedt352ad252008-05-12 21:20:42 +0200347/*
348 * Should this new latency be reported/recorded?
349 */
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +0100350static bool report_latency(struct trace_array *tr, u64 delta)
Steven Rostedt352ad252008-05-12 21:20:42 +0200351{
352 if (tracing_thresh) {
353 if (delta < tracing_thresh)
Yaowei Bai26ab2ef2015-09-29 22:43:29 +0800354 return false;
Steven Rostedt352ad252008-05-12 21:20:42 +0200355 } else {
Steven Rostedt (Red Hat)6d9b3fa2014-01-14 11:28:38 -0500356 if (delta <= tr->max_latency)
Yaowei Bai26ab2ef2015-09-29 22:43:29 +0800357 return false;
Steven Rostedt352ad252008-05-12 21:20:42 +0200358 }
Yaowei Bai26ab2ef2015-09-29 22:43:29 +0800359 return true;
Steven Rostedt352ad252008-05-12 21:20:42 +0200360}
361
Steven Rostedt38516ab2010-04-20 17:04:50 -0400362static void
363probe_wakeup_migrate_task(void *ignore, struct task_struct *task, int cpu)
Steven Rostedt478142c32009-09-09 10:36:01 -0400364{
365 if (task != wakeup_task)
366 return;
367
368 wakeup_current_cpu = cpu;
369}
370
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400371static void
372tracing_sched_switch_trace(struct trace_array *tr,
373 struct task_struct *prev,
374 struct task_struct *next,
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100375 unsigned int trace_ctx)
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400376{
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400377 struct trace_event_call *call = &event_context_switch;
Steven Rostedt (VMware)13292492019-12-13 13:58:57 -0500378 struct trace_buffer *buffer = tr->array_buffer.buffer;
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400379 struct ring_buffer_event *event;
380 struct ctx_switch_entry *entry;
381
382 event = trace_buffer_lock_reserve(buffer, TRACE_CTX,
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100383 sizeof(*entry), trace_ctx);
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400384 if (!event)
385 return;
386 entry = ring_buffer_event_data(event);
387 entry->prev_pid = prev->pid;
388 entry->prev_prio = prev->prio;
Peter Zijlstra1d48b082017-09-29 13:50:16 +0200389 entry->prev_state = task_state_index(prev);
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400390 entry->next_pid = next->pid;
391 entry->next_prio = next->prio;
Peter Zijlstra1d48b082017-09-29 13:50:16 +0200392 entry->next_state = task_state_index(next);
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400393 entry->next_cpu = task_cpu(next);
394
395 if (!call_filter_check_discard(call, entry, buffer, event))
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100396 trace_buffer_unlock_commit(tr, buffer, event, trace_ctx);
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400397}
398
399static void
400tracing_sched_wakeup_trace(struct trace_array *tr,
401 struct task_struct *wakee,
402 struct task_struct *curr,
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100403 unsigned int trace_ctx)
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400404{
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400405 struct trace_event_call *call = &event_wakeup;
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400406 struct ring_buffer_event *event;
407 struct ctx_switch_entry *entry;
Steven Rostedt (VMware)13292492019-12-13 13:58:57 -0500408 struct trace_buffer *buffer = tr->array_buffer.buffer;
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400409
410 event = trace_buffer_lock_reserve(buffer, TRACE_WAKE,
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100411 sizeof(*entry), trace_ctx);
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400412 if (!event)
413 return;
414 entry = ring_buffer_event_data(event);
415 entry->prev_pid = curr->pid;
416 entry->prev_prio = curr->prio;
Peter Zijlstra1d48b082017-09-29 13:50:16 +0200417 entry->prev_state = task_state_index(curr);
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400418 entry->next_pid = wakee->pid;
419 entry->next_prio = wakee->prio;
Peter Zijlstra1d48b082017-09-29 13:50:16 +0200420 entry->next_state = task_state_index(wakee);
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400421 entry->next_cpu = task_cpu(wakee);
422
423 if (!call_filter_check_discard(call, entry, buffer, event))
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100424 trace_buffer_unlock_commit(tr, buffer, event, trace_ctx);
Steven Rostedt (Red Hat)243f7612014-10-30 20:44:53 -0400425}
426
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200427static void notrace
Peter Zijlstrac73464b2015-09-28 18:06:56 +0200428probe_wakeup_sched_switch(void *ignore, bool preempt,
Steven Rostedt38516ab2010-04-20 17:04:50 -0400429 struct task_struct *prev, struct task_struct *next)
Steven Rostedt352ad252008-05-12 21:20:42 +0200430{
Steven Rostedt352ad252008-05-12 21:20:42 +0200431 struct trace_array_cpu *data;
Thomas Gleixnera5a1d1c2016-12-21 20:32:01 +0100432 u64 T0, T1, delta;
Steven Rostedt352ad252008-05-12 21:20:42 +0200433 unsigned long flags;
434 long disabled;
435 int cpu;
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100436 unsigned int trace_ctx;
Steven Rostedt352ad252008-05-12 21:20:42 +0200437
Mathieu Desnoyersb07c3f12008-07-18 12:16:17 -0400438 tracing_record_cmdline(prev);
439
Steven Rostedt352ad252008-05-12 21:20:42 +0200440 if (unlikely(!tracer_enabled))
441 return;
442
443 /*
444 * When we start a new trace, we set wakeup_task to NULL
445 * and then set tracer_enabled = 1. We want to make sure
446 * that another CPU does not see the tracer_enabled = 1
447 * and the wakeup_task with an older task, that might
448 * actually be the same as next.
449 */
450 smp_rmb();
451
452 if (next != wakeup_task)
453 return;
454
Steven Rostedt352ad252008-05-12 21:20:42 +0200455 /* disable local data, not wakeup_cpu data */
456 cpu = raw_smp_processor_id();
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -0500457 disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled);
Steven Rostedt352ad252008-05-12 21:20:42 +0200458 if (likely(disabled != 1))
459 goto out;
460
Steven Rostedte59494f2008-07-16 00:13:45 -0400461 local_irq_save(flags);
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100462 trace_ctx = tracing_gen_ctx_flags(flags);
463
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100464 arch_spin_lock(&wakeup_lock);
Steven Rostedt352ad252008-05-12 21:20:42 +0200465
466 /* We could race with grabbing wakeup_lock */
467 if (unlikely(!tracer_enabled || next != wakeup_task))
468 goto out_unlock;
469
Steven Rostedt9be24412009-03-26 10:25:24 -0400470 /* The task we are waiting for is waking up */
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -0500471 data = per_cpu_ptr(wakeup_trace->array_buffer.data, wakeup_cpu);
Steven Rostedt9be24412009-03-26 10:25:24 -0400472
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100473 __trace_function(wakeup_trace, CALLER_ADDR0, CALLER_ADDR1, trace_ctx);
474 tracing_sched_switch_trace(wakeup_trace, prev, next, trace_ctx);
475 __trace_stack(wakeup_trace, trace_ctx, 0);
Steven Rostedt352ad252008-05-12 21:20:42 +0200476
Steven Rostedt352ad252008-05-12 21:20:42 +0200477 T0 = data->preempt_timestamp;
Ingo Molnar750ed1a2008-05-12 21:20:46 +0200478 T1 = ftrace_now(cpu);
Steven Rostedt352ad252008-05-12 21:20:42 +0200479 delta = T1-T0;
480
Steven Rostedt (Red Hat)6d9b3fa2014-01-14 11:28:38 -0500481 if (!report_latency(wakeup_trace, delta))
Steven Rostedt352ad252008-05-12 21:20:42 +0200482 goto out_unlock;
483
Carsten Emdeb5130b12009-09-13 01:43:07 +0200484 if (likely(!is_tracing_stopped())) {
Steven Rostedt (Red Hat)6d9b3fa2014-01-14 11:28:38 -0500485 wakeup_trace->max_latency = delta;
Tom Zanussia35873a2019-02-13 17:42:45 -0600486 update_max_tr(wakeup_trace, wakeup_task, wakeup_cpu, NULL);
Carsten Emdeb5130b12009-09-13 01:43:07 +0200487 }
Steven Rostedt352ad252008-05-12 21:20:42 +0200488
Steven Rostedt352ad252008-05-12 21:20:42 +0200489out_unlock:
Mathieu Desnoyersb07c3f12008-07-18 12:16:17 -0400490 __wakeup_reset(wakeup_trace);
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100491 arch_spin_unlock(&wakeup_lock);
Steven Rostedte59494f2008-07-16 00:13:45 -0400492 local_irq_restore(flags);
Steven Rostedt352ad252008-05-12 21:20:42 +0200493out:
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -0500494 atomic_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled);
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200495}
496
Ingo Molnare309b412008-05-12 21:20:51 +0200497static void __wakeup_reset(struct trace_array *tr)
Steven Rostedt352ad252008-05-12 21:20:42 +0200498{
Steven Rostedt352ad252008-05-12 21:20:42 +0200499 wakeup_cpu = -1;
500 wakeup_prio = -1;
Austin Kimbfbf8d12021-06-29 15:05:48 +0100501 tracing_dl = false;
Steven Rostedt352ad252008-05-12 21:20:42 +0200502
503 if (wakeup_task)
504 put_task_struct(wakeup_task);
505
506 wakeup_task = NULL;
507}
508
Ingo Molnare309b412008-05-12 21:20:51 +0200509static void wakeup_reset(struct trace_array *tr)
Steven Rostedt352ad252008-05-12 21:20:42 +0200510{
511 unsigned long flags;
512
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -0500513 tracing_reset_online_cpus(&tr->array_buffer);
Steven Rostedt2f26ebd2009-09-01 11:06:29 -0400514
Steven Rostedte59494f2008-07-16 00:13:45 -0400515 local_irq_save(flags);
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100516 arch_spin_lock(&wakeup_lock);
Steven Rostedt352ad252008-05-12 21:20:42 +0200517 __wakeup_reset(tr);
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100518 arch_spin_unlock(&wakeup_lock);
Steven Rostedte59494f2008-07-16 00:13:45 -0400519 local_irq_restore(flags);
Steven Rostedt352ad252008-05-12 21:20:42 +0200520}
521
Ingo Molnare309b412008-05-12 21:20:51 +0200522static void
Peter Zijlstrafbd705a2015-06-09 11:13:36 +0200523probe_wakeup(void *ignore, struct task_struct *p)
Steven Rostedt352ad252008-05-12 21:20:42 +0200524{
Steven Rostedtf8ec1062009-01-21 17:17:04 -0500525 struct trace_array_cpu *data;
Steven Rostedt352ad252008-05-12 21:20:42 +0200526 int cpu = smp_processor_id();
Steven Rostedt352ad252008-05-12 21:20:42 +0200527 long disabled;
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100528 unsigned int trace_ctx;
Steven Rostedt352ad252008-05-12 21:20:42 +0200529
Mathieu Desnoyersb07c3f12008-07-18 12:16:17 -0400530 if (likely(!tracer_enabled))
Steven Rostedt352ad252008-05-12 21:20:42 +0200531 return;
532
Mathieu Desnoyersb07c3f12008-07-18 12:16:17 -0400533 tracing_record_cmdline(p);
534 tracing_record_cmdline(current);
535
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100536 /*
537 * Semantic is like this:
538 * - wakeup tracer handles all tasks in the system, independently
539 * from their scheduling class;
540 * - wakeup_rt tracer handles tasks belonging to sched_dl and
541 * sched_rt class;
542 * - wakeup_dl handles tasks belonging to sched_dl class only.
543 */
544 if (tracing_dl || (wakeup_dl && !dl_task(p)) ||
545 (wakeup_rt && !dl_task(p) && !rt_task(p)) ||
546 (!dl_task(p) && (p->prio >= wakeup_prio || p->prio >= current->prio)))
Mathieu Desnoyersb07c3f12008-07-18 12:16:17 -0400547 return;
548
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -0500549 disabled = atomic_inc_return(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled);
Steven Rostedt352ad252008-05-12 21:20:42 +0200550 if (unlikely(disabled != 1))
551 goto out;
552
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100553 trace_ctx = tracing_gen_ctx();
554
Steven Rostedt352ad252008-05-12 21:20:42 +0200555 /* interrupts should be off from try_to_wake_up */
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100556 arch_spin_lock(&wakeup_lock);
Steven Rostedt352ad252008-05-12 21:20:42 +0200557
558 /* check for races. */
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100559 if (!tracer_enabled || tracing_dl ||
560 (!dl_task(p) && p->prio >= wakeup_prio))
Steven Rostedt352ad252008-05-12 21:20:42 +0200561 goto out_locked;
562
563 /* reset the trace */
Mathieu Desnoyersb07c3f12008-07-18 12:16:17 -0400564 __wakeup_reset(wakeup_trace);
Steven Rostedt352ad252008-05-12 21:20:42 +0200565
566 wakeup_cpu = task_cpu(p);
Steven Rostedt478142c32009-09-09 10:36:01 -0400567 wakeup_current_cpu = wakeup_cpu;
Steven Rostedt352ad252008-05-12 21:20:42 +0200568 wakeup_prio = p->prio;
569
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100570 /*
571 * Once you start tracing a -deadline task, don't bother tracing
572 * another task until the first one wakes up.
573 */
574 if (dl_task(p))
Austin Kimbfbf8d12021-06-29 15:05:48 +0100575 tracing_dl = true;
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100576 else
Austin Kimbfbf8d12021-06-29 15:05:48 +0100577 tracing_dl = false;
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100578
Matthew Wilcox (Oracle)7b3c92b2019-07-04 15:13:23 -0700579 wakeup_task = get_task_struct(p);
Steven Rostedt352ad252008-05-12 21:20:42 +0200580
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -0500581 data = per_cpu_ptr(wakeup_trace->array_buffer.data, wakeup_cpu);
Steven Rostedtf8ec1062009-01-21 17:17:04 -0500582 data->preempt_timestamp = ftrace_now(cpu);
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100583 tracing_sched_wakeup_trace(wakeup_trace, p, current, trace_ctx);
584 __trace_stack(wakeup_trace, trace_ctx, 0);
Steven Rostedt301fd742009-04-03 11:12:23 -0400585
586 /*
587 * We must be careful in using CALLER_ADDR2. But since wake_up
588 * is not called by an assembly function (where as schedule is)
589 * it should be safe to use it here.
590 */
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100591 __trace_function(wakeup_trace, CALLER_ADDR1, CALLER_ADDR2, trace_ctx);
Steven Rostedt352ad252008-05-12 21:20:42 +0200592
593out_locked:
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100594 arch_spin_unlock(&wakeup_lock);
Steven Rostedt352ad252008-05-12 21:20:42 +0200595out:
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -0500596 atomic_dec(&per_cpu_ptr(wakeup_trace->array_buffer.data, cpu)->disabled);
Steven Rostedt352ad252008-05-12 21:20:42 +0200597}
598
Ingo Molnare309b412008-05-12 21:20:51 +0200599static void start_wakeup_tracer(struct trace_array *tr)
Steven Rostedt352ad252008-05-12 21:20:42 +0200600{
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200601 int ret;
602
Steven Rostedt38516ab2010-04-20 17:04:50 -0400603 ret = register_trace_sched_wakeup(probe_wakeup, NULL);
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200604 if (ret) {
Mathieu Desnoyersb07c3f12008-07-18 12:16:17 -0400605 pr_info("wakeup trace: Couldn't activate tracepoint"
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200606 " probe to kernel_sched_wakeup\n");
607 return;
608 }
609
Steven Rostedt38516ab2010-04-20 17:04:50 -0400610 ret = register_trace_sched_wakeup_new(probe_wakeup, NULL);
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200611 if (ret) {
Mathieu Desnoyersb07c3f12008-07-18 12:16:17 -0400612 pr_info("wakeup trace: Couldn't activate tracepoint"
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200613 " probe to kernel_sched_wakeup_new\n");
614 goto fail_deprobe;
615 }
616
Steven Rostedt38516ab2010-04-20 17:04:50 -0400617 ret = register_trace_sched_switch(probe_wakeup_sched_switch, NULL);
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200618 if (ret) {
Mathieu Desnoyersb07c3f12008-07-18 12:16:17 -0400619 pr_info("sched trace: Couldn't activate tracepoint"
Wenji Huang73d8b8b2009-02-17 01:10:02 -0500620 " probe to kernel_sched_switch\n");
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200621 goto fail_deprobe_wake_new;
622 }
623
Steven Rostedt38516ab2010-04-20 17:04:50 -0400624 ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL);
Steven Rostedt478142c32009-09-09 10:36:01 -0400625 if (ret) {
626 pr_info("wakeup trace: Couldn't activate tracepoint"
627 " probe to kernel_sched_migrate_task\n");
Kaitao Cheng50f9ad62019-12-31 05:35:30 -0800628 goto fail_deprobe_sched_switch;
Steven Rostedt478142c32009-09-09 10:36:01 -0400629 }
630
Steven Rostedt352ad252008-05-12 21:20:42 +0200631 wakeup_reset(tr);
632
633 /*
634 * Don't let the tracer_enabled = 1 show up before
635 * the wakeup_task is reset. This may be overkill since
636 * wakeup_reset does a spin_unlock after setting the
637 * wakeup_task to NULL, but I want to be safe.
638 * This is a slow path anyway.
639 */
640 smp_wmb();
641
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400642 if (start_func_tracer(tr, is_graph(tr)))
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200643 printk(KERN_ERR "failed to start wakeup tracer\n");
Steven Rostedtad591242008-07-10 20:58:13 -0400644
Steven Rostedt352ad252008-05-12 21:20:42 +0200645 return;
Kaitao Cheng50f9ad62019-12-31 05:35:30 -0800646fail_deprobe_sched_switch:
647 unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL);
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200648fail_deprobe_wake_new:
Steven Rostedt38516ab2010-04-20 17:04:50 -0400649 unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
Mathieu Desnoyers5b82a1b2008-05-12 21:21:10 +0200650fail_deprobe:
Steven Rostedt38516ab2010-04-20 17:04:50 -0400651 unregister_trace_sched_wakeup(probe_wakeup, NULL);
Steven Rostedt352ad252008-05-12 21:20:42 +0200652}
653
Ingo Molnare309b412008-05-12 21:20:51 +0200654static void stop_wakeup_tracer(struct trace_array *tr)
Steven Rostedt352ad252008-05-12 21:20:42 +0200655{
656 tracer_enabled = 0;
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400657 stop_func_tracer(tr, is_graph(tr));
Steven Rostedt38516ab2010-04-20 17:04:50 -0400658 unregister_trace_sched_switch(probe_wakeup_sched_switch, NULL);
659 unregister_trace_sched_wakeup_new(probe_wakeup, NULL);
660 unregister_trace_sched_wakeup(probe_wakeup, NULL);
661 unregister_trace_sched_migrate_task(probe_wakeup_migrate_task, NULL);
Steven Rostedt352ad252008-05-12 21:20:42 +0200662}
663
Steven Rostedt (Red Hat)65daaca72014-01-14 07:06:29 -0500664static bool wakeup_busy;
665
Steven Rostedt32443512009-01-21 16:24:46 -0500666static int __wakeup_tracer_init(struct trace_array *tr)
Steven Rostedt352ad252008-05-12 21:20:42 +0200667{
Steven Rostedt (Red Hat)983f9382015-09-30 09:42:05 -0400668 save_flags = tr->trace_flags;
Steven Rostedt (Red Hat)613f04a2013-03-14 15:03:53 -0400669
670 /* non overwrite screws up the latency tracers */
Steven Rostedt2b6080f2012-05-11 13:29:49 -0400671 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, 1);
672 set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, 1);
Steven Rostedte9d25fe2009-03-04 22:15:30 -0500673
Steven Rostedt (Red Hat)6d9b3fa2014-01-14 11:28:38 -0500674 tr->max_latency = 0;
Steven Rostedt352ad252008-05-12 21:20:42 +0200675 wakeup_trace = tr;
Steven Rostedt (Red Hat)4104d322014-01-10 17:01:58 -0500676 ftrace_init_array_ops(tr, wakeup_tracer_call);
Steven Rostedtc76f0692008-11-07 22:36:02 -0500677 start_wakeup_tracer(tr);
Steven Rostedt (Red Hat)65daaca72014-01-14 07:06:29 -0500678
679 wakeup_busy = true;
Frederic Weisbecker1c800252008-11-16 05:57:26 +0100680 return 0;
Steven Rostedt352ad252008-05-12 21:20:42 +0200681}
682
Steven Rostedt32443512009-01-21 16:24:46 -0500683static int wakeup_tracer_init(struct trace_array *tr)
684{
Steven Rostedt (Red Hat)65daaca72014-01-14 07:06:29 -0500685 if (wakeup_busy)
686 return -EBUSY;
687
Austin Kimbfbf8d12021-06-29 15:05:48 +0100688 wakeup_dl = false;
689 wakeup_rt = false;
Steven Rostedt32443512009-01-21 16:24:46 -0500690 return __wakeup_tracer_init(tr);
691}
692
693static int wakeup_rt_tracer_init(struct trace_array *tr)
694{
Steven Rostedt (Red Hat)65daaca72014-01-14 07:06:29 -0500695 if (wakeup_busy)
696 return -EBUSY;
697
Austin Kimbfbf8d12021-06-29 15:05:48 +0100698 wakeup_dl = false;
699 wakeup_rt = true;
Steven Rostedt32443512009-01-21 16:24:46 -0500700 return __wakeup_tracer_init(tr);
701}
702
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100703static int wakeup_dl_tracer_init(struct trace_array *tr)
704{
Steven Rostedt (Red Hat)65daaca72014-01-14 07:06:29 -0500705 if (wakeup_busy)
706 return -EBUSY;
707
Austin Kimbfbf8d12021-06-29 15:05:48 +0100708 wakeup_dl = true;
709 wakeup_rt = false;
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100710 return __wakeup_tracer_init(tr);
711}
712
Ingo Molnare309b412008-05-12 21:20:51 +0200713static void wakeup_tracer_reset(struct trace_array *tr)
Steven Rostedt352ad252008-05-12 21:20:42 +0200714{
Steven Rostedt (Red Hat)613f04a2013-03-14 15:03:53 -0400715 int lat_flag = save_flags & TRACE_ITER_LATENCY_FMT;
716 int overwrite_flag = save_flags & TRACE_ITER_OVERWRITE;
717
Steven Rostedtc76f0692008-11-07 22:36:02 -0500718 stop_wakeup_tracer(tr);
719 /* make sure we put back any tasks we are tracing */
720 wakeup_reset(tr);
Steven Rostedte9d25fe2009-03-04 22:15:30 -0500721
Steven Rostedt2b6080f2012-05-11 13:29:49 -0400722 set_tracer_flag(tr, TRACE_ITER_LATENCY_FMT, lat_flag);
723 set_tracer_flag(tr, TRACE_ITER_OVERWRITE, overwrite_flag);
Steven Rostedt (Red Hat)4104d322014-01-10 17:01:58 -0500724 ftrace_reset_array_ops(tr);
Steven Rostedt (Red Hat)65daaca72014-01-14 07:06:29 -0500725 wakeup_busy = false;
Steven Rostedt352ad252008-05-12 21:20:42 +0200726}
727
Steven Rostedt90369902008-11-05 16:05:44 -0500728static void wakeup_tracer_start(struct trace_array *tr)
729{
730 wakeup_reset(tr);
731 tracer_enabled = 1;
Steven Rostedt90369902008-11-05 16:05:44 -0500732}
733
734static void wakeup_tracer_stop(struct trace_array *tr)
735{
736 tracer_enabled = 0;
Steven Rostedt352ad252008-05-12 21:20:42 +0200737}
738
739static struct tracer wakeup_tracer __read_mostly =
740{
741 .name = "wakeup",
742 .init = wakeup_tracer_init,
743 .reset = wakeup_tracer_reset,
Steven Rostedt90369902008-11-05 16:05:44 -0500744 .start = wakeup_tracer_start,
745 .stop = wakeup_tracer_stop,
Hiraku Toyookaf43c7382012-10-02 17:27:10 +0900746 .print_max = true,
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200747 .print_header = wakeup_print_header,
748 .print_line = wakeup_print_line,
Steven Rostedt (Red Hat)328df472013-03-14 12:10:40 -0400749 .flag_changed = wakeup_flag_changed,
Steven Rostedt60a11772008-05-12 21:20:44 +0200750#ifdef CONFIG_FTRACE_SELFTEST
751 .selftest = trace_selftest_startup_wakeup,
752#endif
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200753 .open = wakeup_trace_open,
754 .close = wakeup_trace_close,
Steven Rostedt (Red Hat)65daaca72014-01-14 07:06:29 -0500755 .allow_instances = true,
Hiraku Toyookaf43c7382012-10-02 17:27:10 +0900756 .use_max_tr = true,
Steven Rostedt352ad252008-05-12 21:20:42 +0200757};
758
Steven Rostedt32443512009-01-21 16:24:46 -0500759static struct tracer wakeup_rt_tracer __read_mostly =
760{
761 .name = "wakeup_rt",
762 .init = wakeup_rt_tracer_init,
763 .reset = wakeup_tracer_reset,
764 .start = wakeup_tracer_start,
765 .stop = wakeup_tracer_stop,
Hiraku Toyookaf43c7382012-10-02 17:27:10 +0900766 .print_max = true,
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200767 .print_header = wakeup_print_header,
768 .print_line = wakeup_print_line,
Steven Rostedt (Red Hat)328df472013-03-14 12:10:40 -0400769 .flag_changed = wakeup_flag_changed,
Steven Rostedt32443512009-01-21 16:24:46 -0500770#ifdef CONFIG_FTRACE_SELFTEST
771 .selftest = trace_selftest_startup_wakeup,
772#endif
Jiri Olsa7495a5b2010-09-23 14:00:53 +0200773 .open = wakeup_trace_open,
774 .close = wakeup_trace_close,
Steven Rostedt (Red Hat)65daaca72014-01-14 07:06:29 -0500775 .allow_instances = true,
Hiraku Toyookaf43c7382012-10-02 17:27:10 +0900776 .use_max_tr = true,
Steven Rostedt32443512009-01-21 16:24:46 -0500777};
778
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100779static 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,
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100786 .print_max = true,
787 .print_header = wakeup_print_header,
788 .print_line = wakeup_print_line,
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100789 .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,
Zhou Chengming8d414bd2016-11-14 11:19:13 +0800795 .allow_instances = true,
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100796 .use_max_tr = true,
797};
798
Steven Rostedt352ad252008-05-12 21:20:42 +0200799__init static int init_wakeup_tracer(void)
800{
801 int ret;
802
803 ret = register_tracer(&wakeup_tracer);
804 if (ret)
805 return ret;
806
Steven Rostedt32443512009-01-21 16:24:46 -0500807 ret = register_tracer(&wakeup_rt_tracer);
808 if (ret)
809 return ret;
810
Dario Faggioliaf6ace72013-11-07 14:43:42 +0100811 ret = register_tracer(&wakeup_dl_tracer);
812 if (ret)
813 return ret;
814
Steven Rostedt352ad252008-05-12 21:20:42 +0200815 return 0;
816}
Steven Rostedt6f415672012-10-05 12:13:07 -0400817core_initcall(init_wakeup_tracer);