Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * trace task wakeup timings |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com> |
| 5 | * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com> |
| 6 | * |
| 7 | * Based on code from the latency_tracer, that is: |
| 8 | * |
| 9 | * Copyright (C) 2004-2006 Ingo Molnar |
| 10 | * Copyright (C) 2004 William Lee Irwin III |
| 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> |
Steven Rostedt | ad8d75f | 2009-04-14 19:39:12 -0400 | [diff] [blame] | 18 | #include <trace/events/sched.h> |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 19 | |
| 20 | #include "trace.h" |
| 21 | |
| 22 | static struct trace_array *wakeup_trace; |
| 23 | static int __read_mostly tracer_enabled; |
| 24 | |
| 25 | static struct task_struct *wakeup_task; |
| 26 | static int wakeup_cpu; |
Steven Rostedt | 478142c3 | 2009-09-09 10:36:01 -0400 | [diff] [blame] | 27 | static int wakeup_current_cpu; |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 28 | static unsigned wakeup_prio = -1; |
Steven Rostedt | 3244351 | 2009-01-21 16:24:46 -0500 | [diff] [blame] | 29 | static int wakeup_rt; |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 30 | |
Steven Rostedt | e59494f | 2008-07-16 00:13:45 -0400 | [diff] [blame] | 31 | static raw_spinlock_t wakeup_lock = |
| 32 | (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED; |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 33 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 34 | static void __wakeup_reset(struct trace_array *tr); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 35 | |
Steven Rostedt | e9d25fe | 2009-03-04 22:15:30 -0500 | [diff] [blame] | 36 | static int save_lat_flag; |
| 37 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 38 | #ifdef CONFIG_FUNCTION_TRACER |
Steven Rostedt | 7e18d8e | 2008-05-22 00:22:19 -0400 | [diff] [blame] | 39 | /* |
| 40 | * irqsoff uses its own tracer function to keep the overhead down: |
| 41 | */ |
| 42 | static void |
| 43 | wakeup_tracer_call(unsigned long ip, unsigned long parent_ip) |
| 44 | { |
| 45 | struct trace_array *tr = wakeup_trace; |
| 46 | struct trace_array_cpu *data; |
| 47 | unsigned long flags; |
| 48 | long disabled; |
| 49 | int resched; |
| 50 | int cpu; |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 51 | int pc; |
Steven Rostedt | 7e18d8e | 2008-05-22 00:22:19 -0400 | [diff] [blame] | 52 | |
| 53 | if (likely(!wakeup_task)) |
| 54 | return; |
| 55 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 56 | pc = preempt_count(); |
Steven Rostedt | 182e9f5 | 2008-11-03 23:15:56 -0500 | [diff] [blame] | 57 | resched = ftrace_preempt_disable(); |
Steven Rostedt | 7e18d8e | 2008-05-22 00:22:19 -0400 | [diff] [blame] | 58 | |
| 59 | cpu = raw_smp_processor_id(); |
Steven Rostedt | 478142c3 | 2009-09-09 10:36:01 -0400 | [diff] [blame] | 60 | if (cpu != wakeup_current_cpu) |
| 61 | goto out_enable; |
| 62 | |
Steven Rostedt | 7e18d8e | 2008-05-22 00:22:19 -0400 | [diff] [blame] | 63 | data = tr->data[cpu]; |
| 64 | disabled = atomic_inc_return(&data->disabled); |
| 65 | if (unlikely(disabled != 1)) |
| 66 | goto out; |
| 67 | |
Steven Rostedt | e59494f | 2008-07-16 00:13:45 -0400 | [diff] [blame] | 68 | local_irq_save(flags); |
Steven Rostedt | 7e18d8e | 2008-05-22 00:22:19 -0400 | [diff] [blame] | 69 | |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 70 | trace_function(tr, ip, parent_ip, flags, pc); |
Steven Rostedt | 7e18d8e | 2008-05-22 00:22:19 -0400 | [diff] [blame] | 71 | |
Steven Rostedt | e59494f | 2008-07-16 00:13:45 -0400 | [diff] [blame] | 72 | local_irq_restore(flags); |
Steven Rostedt | 7e18d8e | 2008-05-22 00:22:19 -0400 | [diff] [blame] | 73 | |
| 74 | out: |
| 75 | atomic_dec(&data->disabled); |
Steven Rostedt | 478142c3 | 2009-09-09 10:36:01 -0400 | [diff] [blame] | 76 | out_enable: |
Steven Rostedt | 182e9f5 | 2008-11-03 23:15:56 -0500 | [diff] [blame] | 77 | ftrace_preempt_enable(resched); |
Steven Rostedt | 7e18d8e | 2008-05-22 00:22:19 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static struct ftrace_ops trace_ops __read_mostly = |
| 81 | { |
| 82 | .func = wakeup_tracer_call, |
| 83 | }; |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 84 | #endif /* CONFIG_FUNCTION_TRACER */ |
Steven Rostedt | 7e18d8e | 2008-05-22 00:22:19 -0400 | [diff] [blame] | 85 | |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 86 | /* |
| 87 | * Should this new latency be reported/recorded? |
| 88 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 89 | static int report_latency(cycle_t delta) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 90 | { |
| 91 | if (tracing_thresh) { |
| 92 | if (delta < tracing_thresh) |
| 93 | return 0; |
| 94 | } else { |
| 95 | if (delta <= tracing_max_latency) |
| 96 | return 0; |
| 97 | } |
| 98 | return 1; |
| 99 | } |
| 100 | |
Steven Rostedt | 478142c3 | 2009-09-09 10:36:01 -0400 | [diff] [blame] | 101 | static void probe_wakeup_migrate_task(struct task_struct *task, int cpu) |
| 102 | { |
| 103 | if (task != wakeup_task) |
| 104 | return; |
| 105 | |
| 106 | wakeup_current_cpu = cpu; |
| 107 | } |
| 108 | |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 109 | static void notrace |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 110 | probe_wakeup_sched_switch(struct rq *rq, struct task_struct *prev, |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 111 | struct task_struct *next) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 112 | { |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 113 | struct trace_array_cpu *data; |
| 114 | cycle_t T0, T1, delta; |
| 115 | unsigned long flags; |
| 116 | long disabled; |
| 117 | int cpu; |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 118 | int pc; |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 119 | |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 120 | tracing_record_cmdline(prev); |
| 121 | |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 122 | if (unlikely(!tracer_enabled)) |
| 123 | return; |
| 124 | |
| 125 | /* |
| 126 | * When we start a new trace, we set wakeup_task to NULL |
| 127 | * and then set tracer_enabled = 1. We want to make sure |
| 128 | * that another CPU does not see the tracer_enabled = 1 |
| 129 | * and the wakeup_task with an older task, that might |
| 130 | * actually be the same as next. |
| 131 | */ |
| 132 | smp_rmb(); |
| 133 | |
| 134 | if (next != wakeup_task) |
| 135 | return; |
| 136 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 137 | pc = preempt_count(); |
| 138 | |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 139 | /* disable local data, not wakeup_cpu data */ |
| 140 | cpu = raw_smp_processor_id(); |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 141 | disabled = atomic_inc_return(&wakeup_trace->data[cpu]->disabled); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 142 | if (likely(disabled != 1)) |
| 143 | goto out; |
| 144 | |
Steven Rostedt | e59494f | 2008-07-16 00:13:45 -0400 | [diff] [blame] | 145 | local_irq_save(flags); |
| 146 | __raw_spin_lock(&wakeup_lock); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 147 | |
| 148 | /* We could race with grabbing wakeup_lock */ |
| 149 | if (unlikely(!tracer_enabled || next != wakeup_task)) |
| 150 | goto out_unlock; |
| 151 | |
Steven Rostedt | 9be2441 | 2009-03-26 10:25:24 -0400 | [diff] [blame] | 152 | /* The task we are waiting for is waking up */ |
| 153 | data = wakeup_trace->data[wakeup_cpu]; |
| 154 | |
Steven Rostedt | 301fd74 | 2009-04-03 11:12:23 -0400 | [diff] [blame] | 155 | trace_function(wakeup_trace, CALLER_ADDR0, CALLER_ADDR1, flags, pc); |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 156 | tracing_sched_switch_trace(wakeup_trace, prev, next, flags, pc); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 157 | |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 158 | T0 = data->preempt_timestamp; |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 159 | T1 = ftrace_now(cpu); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 160 | delta = T1-T0; |
| 161 | |
| 162 | if (!report_latency(delta)) |
| 163 | goto out_unlock; |
| 164 | |
Carsten Emde | b5130b1 | 2009-09-13 01:43:07 +0200 | [diff] [blame] | 165 | if (likely(!is_tracing_stopped())) { |
| 166 | tracing_max_latency = delta; |
| 167 | update_max_tr(wakeup_trace, wakeup_task, wakeup_cpu); |
| 168 | } |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 169 | |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 170 | out_unlock: |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 171 | __wakeup_reset(wakeup_trace); |
Steven Rostedt | e59494f | 2008-07-16 00:13:45 -0400 | [diff] [blame] | 172 | __raw_spin_unlock(&wakeup_lock); |
| 173 | local_irq_restore(flags); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 174 | out: |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 175 | atomic_dec(&wakeup_trace->data[cpu]->disabled); |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 178 | static void __wakeup_reset(struct trace_array *tr) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 179 | { |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 180 | wakeup_cpu = -1; |
| 181 | wakeup_prio = -1; |
| 182 | |
| 183 | if (wakeup_task) |
| 184 | put_task_struct(wakeup_task); |
| 185 | |
| 186 | wakeup_task = NULL; |
| 187 | } |
| 188 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 189 | static void wakeup_reset(struct trace_array *tr) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 190 | { |
| 191 | unsigned long flags; |
| 192 | |
Steven Rostedt | 2f26ebd | 2009-09-01 11:06:29 -0400 | [diff] [blame] | 193 | tracing_reset_online_cpus(tr); |
| 194 | |
Steven Rostedt | e59494f | 2008-07-16 00:13:45 -0400 | [diff] [blame] | 195 | local_irq_save(flags); |
| 196 | __raw_spin_lock(&wakeup_lock); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 197 | __wakeup_reset(tr); |
Steven Rostedt | e59494f | 2008-07-16 00:13:45 -0400 | [diff] [blame] | 198 | __raw_spin_unlock(&wakeup_lock); |
| 199 | local_irq_restore(flags); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 200 | } |
| 201 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 202 | static void |
Peter Zijlstra | 468a15b | 2008-12-16 08:07:03 +0100 | [diff] [blame] | 203 | probe_wakeup(struct rq *rq, struct task_struct *p, int success) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 204 | { |
Steven Rostedt | f8ec106 | 2009-01-21 17:17:04 -0500 | [diff] [blame] | 205 | struct trace_array_cpu *data; |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 206 | int cpu = smp_processor_id(); |
| 207 | unsigned long flags; |
| 208 | long disabled; |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 209 | int pc; |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 210 | |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 211 | if (likely(!tracer_enabled)) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 212 | return; |
| 213 | |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 214 | tracing_record_cmdline(p); |
| 215 | tracing_record_cmdline(current); |
| 216 | |
Steven Rostedt | 3244351 | 2009-01-21 16:24:46 -0500 | [diff] [blame] | 217 | if ((wakeup_rt && !rt_task(p)) || |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 218 | p->prio >= wakeup_prio || |
| 219 | p->prio >= current->prio) |
| 220 | return; |
| 221 | |
Steven Rostedt | 3869705 | 2008-10-01 13:14:09 -0400 | [diff] [blame] | 222 | pc = preempt_count(); |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 223 | disabled = atomic_inc_return(&wakeup_trace->data[cpu]->disabled); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 224 | if (unlikely(disabled != 1)) |
| 225 | goto out; |
| 226 | |
| 227 | /* interrupts should be off from try_to_wake_up */ |
Steven Rostedt | e59494f | 2008-07-16 00:13:45 -0400 | [diff] [blame] | 228 | __raw_spin_lock(&wakeup_lock); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 229 | |
| 230 | /* check for races. */ |
| 231 | if (!tracer_enabled || p->prio >= wakeup_prio) |
| 232 | goto out_locked; |
| 233 | |
| 234 | /* reset the trace */ |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 235 | __wakeup_reset(wakeup_trace); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 236 | |
| 237 | wakeup_cpu = task_cpu(p); |
Steven Rostedt | 478142c3 | 2009-09-09 10:36:01 -0400 | [diff] [blame] | 238 | wakeup_current_cpu = wakeup_cpu; |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 239 | wakeup_prio = p->prio; |
| 240 | |
| 241 | wakeup_task = p; |
| 242 | get_task_struct(wakeup_task); |
| 243 | |
| 244 | local_save_flags(flags); |
| 245 | |
Steven Rostedt | f8ec106 | 2009-01-21 17:17:04 -0500 | [diff] [blame] | 246 | data = wakeup_trace->data[wakeup_cpu]; |
| 247 | data->preempt_timestamp = ftrace_now(cpu); |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 248 | tracing_sched_wakeup_trace(wakeup_trace, p, current, flags, pc); |
Steven Rostedt | 301fd74 | 2009-04-03 11:12:23 -0400 | [diff] [blame] | 249 | |
| 250 | /* |
| 251 | * We must be careful in using CALLER_ADDR2. But since wake_up |
| 252 | * is not called by an assembly function (where as schedule is) |
| 253 | * it should be safe to use it here. |
| 254 | */ |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 255 | trace_function(wakeup_trace, CALLER_ADDR1, CALLER_ADDR2, flags, pc); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 256 | |
| 257 | out_locked: |
Steven Rostedt | e59494f | 2008-07-16 00:13:45 -0400 | [diff] [blame] | 258 | __raw_spin_unlock(&wakeup_lock); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 259 | out: |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 260 | atomic_dec(&wakeup_trace->data[cpu]->disabled); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 261 | } |
| 262 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 263 | static void start_wakeup_tracer(struct trace_array *tr) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 264 | { |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 265 | int ret; |
| 266 | |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 267 | ret = register_trace_sched_wakeup(probe_wakeup); |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 268 | if (ret) { |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 269 | pr_info("wakeup trace: Couldn't activate tracepoint" |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 270 | " probe to kernel_sched_wakeup\n"); |
| 271 | return; |
| 272 | } |
| 273 | |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 274 | ret = register_trace_sched_wakeup_new(probe_wakeup); |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 275 | if (ret) { |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 276 | pr_info("wakeup trace: Couldn't activate tracepoint" |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 277 | " probe to kernel_sched_wakeup_new\n"); |
| 278 | goto fail_deprobe; |
| 279 | } |
| 280 | |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 281 | ret = register_trace_sched_switch(probe_wakeup_sched_switch); |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 282 | if (ret) { |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 283 | pr_info("sched trace: Couldn't activate tracepoint" |
Wenji Huang | 73d8b8b | 2009-02-17 01:10:02 -0500 | [diff] [blame] | 284 | " probe to kernel_sched_switch\n"); |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 285 | goto fail_deprobe_wake_new; |
| 286 | } |
| 287 | |
Steven Rostedt | 478142c3 | 2009-09-09 10:36:01 -0400 | [diff] [blame] | 288 | ret = register_trace_sched_migrate_task(probe_wakeup_migrate_task); |
| 289 | if (ret) { |
| 290 | pr_info("wakeup trace: Couldn't activate tracepoint" |
| 291 | " probe to kernel_sched_migrate_task\n"); |
| 292 | return; |
| 293 | } |
| 294 | |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 295 | wakeup_reset(tr); |
| 296 | |
| 297 | /* |
| 298 | * Don't let the tracer_enabled = 1 show up before |
| 299 | * the wakeup_task is reset. This may be overkill since |
| 300 | * wakeup_reset does a spin_unlock after setting the |
| 301 | * wakeup_task to NULL, but I want to be safe. |
| 302 | * This is a slow path anyway. |
| 303 | */ |
| 304 | smp_wmb(); |
| 305 | |
Steven Rostedt | 7e18d8e | 2008-05-22 00:22:19 -0400 | [diff] [blame] | 306 | register_ftrace_function(&trace_ops); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 307 | |
Steven Rostedt | 5bc4564 | 2009-01-21 14:36:52 -0500 | [diff] [blame] | 308 | if (tracing_is_enabled()) |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 309 | tracer_enabled = 1; |
Steven Rostedt | 5bc4564 | 2009-01-21 14:36:52 -0500 | [diff] [blame] | 310 | else |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 311 | tracer_enabled = 0; |
Steven Rostedt | ad59124 | 2008-07-10 20:58:13 -0400 | [diff] [blame] | 312 | |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 313 | return; |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 314 | fail_deprobe_wake_new: |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 315 | unregister_trace_sched_wakeup_new(probe_wakeup); |
Mathieu Desnoyers | 5b82a1b | 2008-05-12 21:21:10 +0200 | [diff] [blame] | 316 | fail_deprobe: |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 317 | unregister_trace_sched_wakeup(probe_wakeup); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 318 | } |
| 319 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 320 | static void stop_wakeup_tracer(struct trace_array *tr) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 321 | { |
| 322 | tracer_enabled = 0; |
Steven Rostedt | 7e18d8e | 2008-05-22 00:22:19 -0400 | [diff] [blame] | 323 | unregister_ftrace_function(&trace_ops); |
Mathieu Desnoyers | b07c3f1 | 2008-07-18 12:16:17 -0400 | [diff] [blame] | 324 | unregister_trace_sched_switch(probe_wakeup_sched_switch); |
| 325 | unregister_trace_sched_wakeup_new(probe_wakeup); |
| 326 | unregister_trace_sched_wakeup(probe_wakeup); |
Steven Rostedt | 478142c3 | 2009-09-09 10:36:01 -0400 | [diff] [blame] | 327 | unregister_trace_sched_migrate_task(probe_wakeup_migrate_task); |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 328 | } |
| 329 | |
Steven Rostedt | 3244351 | 2009-01-21 16:24:46 -0500 | [diff] [blame] | 330 | static int __wakeup_tracer_init(struct trace_array *tr) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 331 | { |
Steven Rostedt | e9d25fe | 2009-03-04 22:15:30 -0500 | [diff] [blame] | 332 | save_lat_flag = trace_flags & TRACE_ITER_LATENCY_FMT; |
| 333 | trace_flags |= TRACE_ITER_LATENCY_FMT; |
| 334 | |
Steven Rostedt | 745b162 | 2009-01-15 23:40:11 -0500 | [diff] [blame] | 335 | tracing_max_latency = 0; |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 336 | wakeup_trace = tr; |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 337 | start_wakeup_tracer(tr); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 338 | return 0; |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Steven Rostedt | 3244351 | 2009-01-21 16:24:46 -0500 | [diff] [blame] | 341 | static int wakeup_tracer_init(struct trace_array *tr) |
| 342 | { |
| 343 | wakeup_rt = 0; |
| 344 | return __wakeup_tracer_init(tr); |
| 345 | } |
| 346 | |
| 347 | static int wakeup_rt_tracer_init(struct trace_array *tr) |
| 348 | { |
| 349 | wakeup_rt = 1; |
| 350 | return __wakeup_tracer_init(tr); |
| 351 | } |
| 352 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 353 | static void wakeup_tracer_reset(struct trace_array *tr) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 354 | { |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 355 | stop_wakeup_tracer(tr); |
| 356 | /* make sure we put back any tasks we are tracing */ |
| 357 | wakeup_reset(tr); |
Steven Rostedt | e9d25fe | 2009-03-04 22:15:30 -0500 | [diff] [blame] | 358 | |
| 359 | if (!save_lat_flag) |
| 360 | trace_flags &= ~TRACE_ITER_LATENCY_FMT; |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 361 | } |
| 362 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 363 | static void wakeup_tracer_start(struct trace_array *tr) |
| 364 | { |
| 365 | wakeup_reset(tr); |
| 366 | tracer_enabled = 1; |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | static void wakeup_tracer_stop(struct trace_array *tr) |
| 370 | { |
| 371 | tracer_enabled = 0; |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static struct tracer wakeup_tracer __read_mostly = |
| 375 | { |
| 376 | .name = "wakeup", |
| 377 | .init = wakeup_tracer_init, |
| 378 | .reset = wakeup_tracer_reset, |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 379 | .start = wakeup_tracer_start, |
| 380 | .stop = wakeup_tracer_stop, |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 381 | .print_max = 1, |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 382 | #ifdef CONFIG_FTRACE_SELFTEST |
| 383 | .selftest = trace_selftest_startup_wakeup, |
| 384 | #endif |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 385 | }; |
| 386 | |
Steven Rostedt | 3244351 | 2009-01-21 16:24:46 -0500 | [diff] [blame] | 387 | static struct tracer wakeup_rt_tracer __read_mostly = |
| 388 | { |
| 389 | .name = "wakeup_rt", |
| 390 | .init = wakeup_rt_tracer_init, |
| 391 | .reset = wakeup_tracer_reset, |
| 392 | .start = wakeup_tracer_start, |
| 393 | .stop = wakeup_tracer_stop, |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 394 | .wait_pipe = poll_wait_pipe, |
Steven Rostedt | 3244351 | 2009-01-21 16:24:46 -0500 | [diff] [blame] | 395 | .print_max = 1, |
| 396 | #ifdef CONFIG_FTRACE_SELFTEST |
| 397 | .selftest = trace_selftest_startup_wakeup, |
| 398 | #endif |
| 399 | }; |
| 400 | |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 401 | __init static int init_wakeup_tracer(void) |
| 402 | { |
| 403 | int ret; |
| 404 | |
| 405 | ret = register_tracer(&wakeup_tracer); |
| 406 | if (ret) |
| 407 | return ret; |
| 408 | |
Steven Rostedt | 3244351 | 2009-01-21 16:24:46 -0500 | [diff] [blame] | 409 | ret = register_tracer(&wakeup_rt_tracer); |
| 410 | if (ret) |
| 411 | return ret; |
| 412 | |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 413 | return 0; |
| 414 | } |
| 415 | device_initcall(init_wakeup_tracer); |