tracing: fix warnings in kernel/trace/trace_sched_switch.c
[deliverable/linux.git] / kernel / trace / trace_sched_switch.c
CommitLineData
35e8e302
SR
1/*
2 * trace context switch
3 *
4 * Copyright (C) 2007 Steven Rostedt <srostedt@redhat.com>
5 *
6 */
7#include <linux/module.h>
8#include <linux/fs.h>
9#include <linux/debugfs.h>
10#include <linux/kallsyms.h>
11#include <linux/uaccess.h>
35e8e302 12#include <linux/ftrace.h>
b07c3f19 13#include <trace/sched.h>
35e8e302
SR
14
15#include "trace.h"
16
17static struct trace_array *ctx_trace;
18static int __read_mostly tracer_enabled;
efade6e7
FW
19static int sched_ref;
20static DEFINE_MUTEX(sched_register_mutex);
35e8e302 21
e309b41d 22static void
b07c3f19 23probe_sched_switch(struct rq *__rq, struct task_struct *prev,
5b82a1b0 24 struct task_struct *next)
35e8e302 25{
35e8e302
SR
26 struct trace_array_cpu *data;
27 unsigned long flags;
35e8e302 28 int cpu;
38697053 29 int pc;
35e8e302 30
efade6e7 31 if (!sched_ref)
b07c3f19
MD
32 return;
33
41bc8144
SR
34 tracing_record_cmdline(prev);
35 tracing_record_cmdline(next);
36
35e8e302
SR
37 if (!tracer_enabled)
38 return;
39
38697053 40 pc = preempt_count();
18cef379 41 local_irq_save(flags);
35e8e302 42 cpu = raw_smp_processor_id();
b07c3f19 43 data = ctx_trace->data[cpu];
35e8e302 44
3ea2e6d7 45 if (likely(!atomic_read(&data->disabled)))
38697053 46 tracing_sched_switch_trace(ctx_trace, data, prev, next, flags, pc);
35e8e302 47
18cef379 48 local_irq_restore(flags);
35e8e302
SR
49}
50
4e655519 51static void
b07c3f19 52probe_sched_wakeup(struct rq *__rq, struct task_struct *wakee)
57422797 53{
57422797
IM
54 struct trace_array_cpu *data;
55 unsigned long flags;
38697053 56 int cpu, pc;
57422797 57
b07c3f19 58 if (!likely(tracer_enabled))
57422797
IM
59 return;
60
38697053 61 pc = preempt_count();
b07c3f19 62 tracing_record_cmdline(current);
d9af56fb 63
57422797
IM
64 local_irq_save(flags);
65 cpu = raw_smp_processor_id();
b07c3f19 66 data = ctx_trace->data[cpu];
57422797 67
3ea2e6d7 68 if (likely(!atomic_read(&data->disabled)))
b07c3f19 69 tracing_sched_wakeup_trace(ctx_trace, data, wakee, current,
38697053 70 flags, pc);
57422797 71
57422797
IM
72 local_irq_restore(flags);
73}
74
e309b41d 75static void sched_switch_reset(struct trace_array *tr)
35e8e302
SR
76{
77 int cpu;
78
750ed1a4 79 tr->time_start = ftrace_now(tr->cpu);
35e8e302
SR
80
81 for_each_online_cpu(cpu)
3928a8a2 82 tracing_reset(tr, cpu);
35e8e302
SR
83}
84
5b82a1b0
MD
85static int tracing_sched_register(void)
86{
87 int ret;
88
b07c3f19 89 ret = register_trace_sched_wakeup(probe_sched_wakeup);
5b82a1b0 90 if (ret) {
b07c3f19 91 pr_info("wakeup trace: Couldn't activate tracepoint"
5b82a1b0
MD
92 " probe to kernel_sched_wakeup\n");
93 return ret;
94 }
95
b07c3f19 96 ret = register_trace_sched_wakeup_new(probe_sched_wakeup);
5b82a1b0 97 if (ret) {
b07c3f19 98 pr_info("wakeup trace: Couldn't activate tracepoint"
5b82a1b0
MD
99 " probe to kernel_sched_wakeup_new\n");
100 goto fail_deprobe;
101 }
102
b07c3f19 103 ret = register_trace_sched_switch(probe_sched_switch);
5b82a1b0 104 if (ret) {
b07c3f19 105 pr_info("sched trace: Couldn't activate tracepoint"
5b82a1b0
MD
106 " probe to kernel_sched_schedule\n");
107 goto fail_deprobe_wake_new;
108 }
109
110 return ret;
111fail_deprobe_wake_new:
b07c3f19 112 unregister_trace_sched_wakeup_new(probe_sched_wakeup);
5b82a1b0 113fail_deprobe:
b07c3f19 114 unregister_trace_sched_wakeup(probe_sched_wakeup);
5b82a1b0
MD
115 return ret;
116}
117
118static void tracing_sched_unregister(void)
119{
b07c3f19
MD
120 unregister_trace_sched_switch(probe_sched_switch);
121 unregister_trace_sched_wakeup_new(probe_sched_wakeup);
122 unregister_trace_sched_wakeup(probe_sched_wakeup);
5b82a1b0
MD
123}
124
f2252935 125static void tracing_start_sched_switch(void)
5b82a1b0 126{
efade6e7 127 mutex_lock(&sched_register_mutex);
e168e051 128 if (!(sched_ref++))
5b82a1b0 129 tracing_sched_register();
efade6e7 130 mutex_unlock(&sched_register_mutex);
5b82a1b0
MD
131}
132
f2252935 133static void tracing_stop_sched_switch(void)
5b82a1b0 134{
efade6e7 135 mutex_lock(&sched_register_mutex);
e168e051 136 if (!(--sched_ref))
5b82a1b0 137 tracing_sched_unregister();
efade6e7 138 mutex_unlock(&sched_register_mutex);
5b82a1b0
MD
139}
140
41bc8144
SR
141void tracing_start_cmdline_record(void)
142{
143 tracing_start_sched_switch();
144}
145
146void tracing_stop_cmdline_record(void)
147{
148 tracing_stop_sched_switch();
149}
150
75f5c47d 151/**
e168e051
SR
152 * tracing_start_sched_switch_record - start tracing context switches
153 *
154 * Turns on context switch tracing for a tracer.
155 */
156void tracing_start_sched_switch_record(void)
157{
158 if (unlikely(!ctx_trace)) {
159 WARN_ON(1);
160 return;
161 }
162
163 tracing_start_sched_switch();
164
165 mutex_lock(&sched_register_mutex);
166 tracer_enabled++;
167 mutex_unlock(&sched_register_mutex);
168}
169
170/**
171 * tracing_stop_sched_switch_record - start tracing context switches
172 *
173 * Turns off context switch tracing for a tracer.
174 */
175void tracing_stop_sched_switch_record(void)
176{
177 mutex_lock(&sched_register_mutex);
178 tracer_enabled--;
179 WARN_ON(tracer_enabled < 0);
180 mutex_unlock(&sched_register_mutex);
181
182 tracing_stop_sched_switch();
183}
184
185/**
186 * tracing_sched_switch_assign_trace - assign a trace array for ctx switch
75f5c47d
SR
187 * @tr: trace array pointer to assign
188 *
189 * Some tracers might want to record the context switches in their
190 * trace. This function lets those tracers assign the trace array
191 * to use.
192 */
e168e051 193void tracing_sched_switch_assign_trace(struct trace_array *tr)
75f5c47d
SR
194{
195 ctx_trace = tr;
196}
197
e309b41d 198static void start_sched_trace(struct trace_array *tr)
35e8e302
SR
199{
200 sched_switch_reset(tr);
e168e051 201 tracing_start_sched_switch_record();
35e8e302
SR
202}
203
e309b41d 204static void stop_sched_trace(struct trace_array *tr)
35e8e302 205{
e168e051 206 tracing_stop_sched_switch_record();
35e8e302
SR
207}
208
1c80025a 209static int sched_switch_trace_init(struct trace_array *tr)
35e8e302
SR
210{
211 ctx_trace = tr;
c76f0694 212 start_sched_trace(tr);
1c80025a 213 return 0;
35e8e302
SR
214}
215
e309b41d 216static void sched_switch_trace_reset(struct trace_array *tr)
35e8e302 217{
c76f0694 218 if (sched_ref)
35e8e302
SR
219 stop_sched_trace(tr);
220}
221
9036990d
SR
222static void sched_switch_trace_start(struct trace_array *tr)
223{
224 sched_switch_reset(tr);
225 tracing_start_sched_switch();
226}
227
228static void sched_switch_trace_stop(struct trace_array *tr)
229{
230 tracing_stop_sched_switch();
231}
232
75f5c47d 233static struct tracer sched_switch_trace __read_mostly =
35e8e302
SR
234{
235 .name = "sched_switch",
236 .init = sched_switch_trace_init,
237 .reset = sched_switch_trace_reset,
9036990d
SR
238 .start = sched_switch_trace_start,
239 .stop = sched_switch_trace_stop,
60a11774
SR
240#ifdef CONFIG_FTRACE_SELFTEST
241 .selftest = trace_selftest_startup_sched_switch,
242#endif
35e8e302
SR
243};
244
245__init static int init_sched_switch_trace(void)
246{
247 return register_tracer(&sched_switch_trace);
248}
249device_initcall(init_sched_switch_trace);
c71dd42d 250
This page took 0.075096 seconds and 5 git commands to generate.