blob: 41f8607ec9ed284abb77293f2a9bc93f8bec585c [file] [log] [blame]
Li Zefand0b6e042009-07-13 10:33:21 +08001#undef TRACE_SYSTEM
2#define TRACE_SYSTEM sched
3
Steven Rostedtea20d922009-04-10 08:54:16 -04004#if !defined(_TRACE_SCHED_H) || defined(TRACE_HEADER_MULTI_READ)
Mathieu Desnoyers0a16b602008-07-18 12:16:17 -04005#define _TRACE_SCHED_H
6
7#include <linux/sched.h>
8#include <linux/tracepoint.h>
David Smith4ff16c22012-02-07 10:11:05 -06009#include <linux/binfmts.h>
Mathieu Desnoyers0a16b602008-07-18 12:16:17 -040010
Steven Rostedtea20d922009-04-10 08:54:16 -040011/*
12 * Tracepoint for calling kthread_stop, performed to end a kthread:
13 */
14TRACE_EVENT(sched_kthread_stop,
15
16 TP_PROTO(struct task_struct *t),
17
18 TP_ARGS(t),
19
20 TP_STRUCT__entry(
21 __array( char, comm, TASK_COMM_LEN )
22 __field( pid_t, pid )
23 ),
24
25 TP_fast_assign(
26 memcpy(__entry->comm, t->comm, TASK_COMM_LEN);
27 __entry->pid = t->pid;
28 ),
29
Ingo Molnar434a83c2009-10-15 11:50:39 +020030 TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
Steven Rostedtea20d922009-04-10 08:54:16 -040031);
32
33/*
34 * Tracepoint for the return value of the kthread stopping:
35 */
36TRACE_EVENT(sched_kthread_stop_ret,
37
38 TP_PROTO(int ret),
39
40 TP_ARGS(ret),
41
42 TP_STRUCT__entry(
43 __field( int, ret )
44 ),
45
46 TP_fast_assign(
47 __entry->ret = ret;
48 ),
49
Ingo Molnar434a83c2009-10-15 11:50:39 +020050 TP_printk("ret=%d", __entry->ret)
Steven Rostedtea20d922009-04-10 08:54:16 -040051);
52
53/*
Arun Bharadwaj4dc47fb2013-06-19 16:55:29 -070054 * Tracepoint for task enqueue/dequeue:
55 */
56TRACE_EVENT(sched_enq_deq_task,
57
58 TP_PROTO(struct task_struct *p, int enqueue),
59
60 TP_ARGS(p, enqueue),
61
62 TP_STRUCT__entry(
63 __array( char, comm, TASK_COMM_LEN )
64 __field( pid_t, pid )
65 __field( int, prio )
66 __field( int, cpu )
67 __field( int, enqueue )
68 __field(unsigned int, nr_running )
69 __field(unsigned long, cpu_load )
70 __field(unsigned int, rt_nr_running )
71 ),
72
73 TP_fast_assign(
74 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
75 __entry->pid = p->pid;
76 __entry->prio = p->prio;
77 __entry->cpu = task_cpu(p);
78 __entry->enqueue = enqueue;
79 __entry->nr_running = task_rq(p)->nr_running;
80 __entry->cpu_load = task_rq(p)->cpu_load[0];
81 __entry->rt_nr_running = task_rq(p)->rt.rt_nr_running;
82 ),
83
84 TP_printk("cpu=%d %s comm=%s pid=%d prio=%d nr_running=%u cpu_load=%lu rt_nr_running=%u",
85 __entry->cpu, __entry->enqueue ? "enqueue" : "dequeue",
86 __entry->comm, __entry->pid,
87 __entry->prio, __entry->nr_running,
88 __entry->cpu_load, __entry->rt_nr_running)
89);
90
91/*
Steven Rostedtea20d922009-04-10 08:54:16 -040092 * Tracepoint for waking up a task:
Steven Rostedtea20d922009-04-10 08:54:16 -040093 */
Ingo Molnar091ad362009-11-26 09:04:55 +010094DECLARE_EVENT_CLASS(sched_wakeup_template,
Steven Rostedtea20d922009-04-10 08:54:16 -040095
Peter Zijlstra27a9da62010-05-04 20:36:56 +020096 TP_PROTO(struct task_struct *p, int success),
Steven Rostedtea20d922009-04-10 08:54:16 -040097
Peter Zijlstra27a9da62010-05-04 20:36:56 +020098 TP_ARGS(p, success),
Steven Rostedtea20d922009-04-10 08:54:16 -040099
100 TP_STRUCT__entry(
101 __array( char, comm, TASK_COMM_LEN )
102 __field( pid_t, pid )
103 __field( int, prio )
104 __field( int, success )
Ingo Molnar434a83c2009-10-15 11:50:39 +0200105 __field( int, target_cpu )
Steven Rostedtea20d922009-04-10 08:54:16 -0400106 ),
107
108 TP_fast_assign(
109 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
110 __entry->pid = p->pid;
111 __entry->prio = p->prio;
112 __entry->success = success;
Ingo Molnar434a83c2009-10-15 11:50:39 +0200113 __entry->target_cpu = task_cpu(p);
Steven Rostedtea20d922009-04-10 08:54:16 -0400114 ),
115
Ingo Molnar434a83c2009-10-15 11:50:39 +0200116 TP_printk("comm=%s pid=%d prio=%d success=%d target_cpu=%03d",
Steven Rostedtea20d922009-04-10 08:54:16 -0400117 __entry->comm, __entry->pid, __entry->prio,
Ingo Molnar434a83c2009-10-15 11:50:39 +0200118 __entry->success, __entry->target_cpu)
Steven Rostedtea20d922009-04-10 08:54:16 -0400119);
120
Steven Rostedt75ec29a2009-11-18 20:48:08 -0500121DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
Peter Zijlstra27a9da62010-05-04 20:36:56 +0200122 TP_PROTO(struct task_struct *p, int success),
123 TP_ARGS(p, success));
Steven Rostedt75ec29a2009-11-18 20:48:08 -0500124
Steven Rostedtea20d922009-04-10 08:54:16 -0400125/*
126 * Tracepoint for waking up a new task:
Steven Rostedtea20d922009-04-10 08:54:16 -0400127 */
Steven Rostedt75ec29a2009-11-18 20:48:08 -0500128DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
Peter Zijlstra27a9da62010-05-04 20:36:56 +0200129 TP_PROTO(struct task_struct *p, int success),
130 TP_ARGS(p, success));
Steven Rostedtea20d922009-04-10 08:54:16 -0400131
Peter Zijlstra02f72692010-05-31 18:13:25 +0200132#ifdef CREATE_TRACE_POINTS
133static inline long __trace_sched_switch_state(struct task_struct *p)
134{
135 long state = p->state;
136
137#ifdef CONFIG_PREEMPT
138 /*
139 * For all intents and purposes a preempted task is a running task.
140 */
141 if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE)
Peter Zijlstra557ab422011-09-16 11:16:43 +0200142 state = TASK_RUNNING | TASK_STATE_MAX;
Peter Zijlstra02f72692010-05-31 18:13:25 +0200143#endif
144
145 return state;
146}
147#endif
148
Steven Rostedtea20d922009-04-10 08:54:16 -0400149/*
150 * Tracepoint for task switches, performed by the scheduler:
Steven Rostedtea20d922009-04-10 08:54:16 -0400151 */
152TRACE_EVENT(sched_switch,
153
Peter Zijlstra27a9da62010-05-04 20:36:56 +0200154 TP_PROTO(struct task_struct *prev,
Steven Rostedtea20d922009-04-10 08:54:16 -0400155 struct task_struct *next),
156
Peter Zijlstra27a9da62010-05-04 20:36:56 +0200157 TP_ARGS(prev, next),
Steven Rostedtea20d922009-04-10 08:54:16 -0400158
159 TP_STRUCT__entry(
160 __array( char, prev_comm, TASK_COMM_LEN )
161 __field( pid_t, prev_pid )
162 __field( int, prev_prio )
Steven Rostedt937cdb92009-05-15 10:51:13 -0400163 __field( long, prev_state )
Steven Rostedtea20d922009-04-10 08:54:16 -0400164 __array( char, next_comm, TASK_COMM_LEN )
165 __field( pid_t, next_pid )
166 __field( int, next_prio )
167 ),
168
169 TP_fast_assign(
170 memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
171 __entry->prev_pid = prev->pid;
172 __entry->prev_prio = prev->prio;
Peter Zijlstra02f72692010-05-31 18:13:25 +0200173 __entry->prev_state = __trace_sched_switch_state(prev);
Steven Rostedtea20d922009-04-10 08:54:16 -0400174 memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
175 __entry->next_pid = next->pid;
176 __entry->next_prio = next->prio;
177 ),
178
Peter Zijlstra557ab422011-09-16 11:16:43 +0200179 TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d",
Steven Rostedtea20d922009-04-10 08:54:16 -0400180 __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
Peter Zijlstra557ab422011-09-16 11:16:43 +0200181 __entry->prev_state & (TASK_STATE_MAX-1) ?
182 __print_flags(__entry->prev_state & (TASK_STATE_MAX-1), "|",
Steven Rostedt937cdb92009-05-15 10:51:13 -0400183 { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
184 { 16, "Z" }, { 32, "X" }, { 64, "x" },
185 { 128, "W" }) : "R",
Peter Zijlstra557ab422011-09-16 11:16:43 +0200186 __entry->prev_state & TASK_STATE_MAX ? "+" : "",
Steven Rostedtea20d922009-04-10 08:54:16 -0400187 __entry->next_comm, __entry->next_pid, __entry->next_prio)
188);
189
190/*
191 * Tracepoint for a task being migrated:
192 */
193TRACE_EVENT(sched_migrate_task,
194
Mathieu Desnoyersde1d7282009-05-05 16:49:59 +0800195 TP_PROTO(struct task_struct *p, int dest_cpu),
Steven Rostedtea20d922009-04-10 08:54:16 -0400196
Mathieu Desnoyersde1d7282009-05-05 16:49:59 +0800197 TP_ARGS(p, dest_cpu),
Steven Rostedtea20d922009-04-10 08:54:16 -0400198
199 TP_STRUCT__entry(
200 __array( char, comm, TASK_COMM_LEN )
201 __field( pid_t, pid )
202 __field( int, prio )
203 __field( int, orig_cpu )
204 __field( int, dest_cpu )
205 ),
206
207 TP_fast_assign(
208 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
209 __entry->pid = p->pid;
210 __entry->prio = p->prio;
Mathieu Desnoyersde1d7282009-05-05 16:49:59 +0800211 __entry->orig_cpu = task_cpu(p);
Steven Rostedtea20d922009-04-10 08:54:16 -0400212 __entry->dest_cpu = dest_cpu;
213 ),
214
Ingo Molnar434a83c2009-10-15 11:50:39 +0200215 TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
Steven Rostedtea20d922009-04-10 08:54:16 -0400216 __entry->comm, __entry->pid, __entry->prio,
217 __entry->orig_cpu, __entry->dest_cpu)
218);
219
Arun Bharadwaj1d097322013-07-03 10:35:02 -0700220/*
221 * Tracepoint for a CPU going offline/online:
222 */
223TRACE_EVENT(sched_cpu_hotplug,
224
225 TP_PROTO(int affected_cpu, int error, int status),
226
227 TP_ARGS(affected_cpu, error, status),
228
229 TP_STRUCT__entry(
230 __field( int, affected_cpu )
231 __field( int, error )
232 __field( int, status )
233 ),
234
235 TP_fast_assign(
236 __entry->affected_cpu = affected_cpu;
237 __entry->error = error;
238 __entry->status = status;
239 ),
240
241 TP_printk("cpu %d %s error=%d", __entry->affected_cpu,
242 __entry->status ? "online" : "offline", __entry->error)
243);
244
Ingo Molnar091ad362009-11-26 09:04:55 +0100245DECLARE_EVENT_CLASS(sched_process_template,
Steven Rostedtea20d922009-04-10 08:54:16 -0400246
247 TP_PROTO(struct task_struct *p),
248
249 TP_ARGS(p),
250
251 TP_STRUCT__entry(
252 __array( char, comm, TASK_COMM_LEN )
253 __field( pid_t, pid )
254 __field( int, prio )
255 ),
256
257 TP_fast_assign(
258 memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
259 __entry->pid = p->pid;
260 __entry->prio = p->prio;
261 ),
262
Ingo Molnar434a83c2009-10-15 11:50:39 +0200263 TP_printk("comm=%s pid=%d prio=%d",
Steven Rostedtea20d922009-04-10 08:54:16 -0400264 __entry->comm, __entry->pid, __entry->prio)
265);
266
267/*
Steven Rostedt75ec29a2009-11-18 20:48:08 -0500268 * Tracepoint for freeing a task:
269 */
270DEFINE_EVENT(sched_process_template, sched_process_free,
271 TP_PROTO(struct task_struct *p),
272 TP_ARGS(p));
273
274
275/*
Steven Rostedtea20d922009-04-10 08:54:16 -0400276 * Tracepoint for a task exiting:
277 */
Steven Rostedt75ec29a2009-11-18 20:48:08 -0500278DEFINE_EVENT(sched_process_template, sched_process_exit,
279 TP_PROTO(struct task_struct *p),
280 TP_ARGS(p));
Steven Rostedtea20d922009-04-10 08:54:16 -0400281
282/*
Li Zefan210f7662010-05-24 16:23:35 +0800283 * Tracepoint for waiting on task to unschedule:
284 */
285DEFINE_EVENT(sched_process_template, sched_wait_task,
286 TP_PROTO(struct task_struct *p),
287 TP_ARGS(p));
288
289/*
Steven Rostedtea20d922009-04-10 08:54:16 -0400290 * Tracepoint for a waiting task:
291 */
292TRACE_EVENT(sched_process_wait,
293
294 TP_PROTO(struct pid *pid),
295
296 TP_ARGS(pid),
297
298 TP_STRUCT__entry(
299 __array( char, comm, TASK_COMM_LEN )
300 __field( pid_t, pid )
301 __field( int, prio )
302 ),
303
304 TP_fast_assign(
305 memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
306 __entry->pid = pid_nr(pid);
307 __entry->prio = current->prio;
308 ),
309
Ingo Molnar434a83c2009-10-15 11:50:39 +0200310 TP_printk("comm=%s pid=%d prio=%d",
Steven Rostedtea20d922009-04-10 08:54:16 -0400311 __entry->comm, __entry->pid, __entry->prio)
312);
313
314/*
315 * Tracepoint for do_fork:
316 */
317TRACE_EVENT(sched_process_fork,
318
319 TP_PROTO(struct task_struct *parent, struct task_struct *child),
320
321 TP_ARGS(parent, child),
322
323 TP_STRUCT__entry(
324 __array( char, parent_comm, TASK_COMM_LEN )
325 __field( pid_t, parent_pid )
326 __array( char, child_comm, TASK_COMM_LEN )
327 __field( pid_t, child_pid )
328 ),
329
330 TP_fast_assign(
331 memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
332 __entry->parent_pid = parent->pid;
333 memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
334 __entry->child_pid = child->pid;
335 ),
336
Ingo Molnar434a83c2009-10-15 11:50:39 +0200337 TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
Steven Rostedtea20d922009-04-10 08:54:16 -0400338 __entry->parent_comm, __entry->parent_pid,
339 __entry->child_comm, __entry->child_pid)
340);
341
342/*
David Smith4ff16c22012-02-07 10:11:05 -0600343 * Tracepoint for exec:
344 */
345TRACE_EVENT(sched_process_exec,
346
347 TP_PROTO(struct task_struct *p, pid_t old_pid,
348 struct linux_binprm *bprm),
349
350 TP_ARGS(p, old_pid, bprm),
351
352 TP_STRUCT__entry(
353 __string( filename, bprm->filename )
354 __field( pid_t, pid )
355 __field( pid_t, old_pid )
356 ),
357
358 TP_fast_assign(
359 __assign_str(filename, bprm->filename);
360 __entry->pid = p->pid;
Oleg Nesterov63081912012-03-30 18:26:36 +0200361 __entry->old_pid = old_pid;
David Smith4ff16c22012-02-07 10:11:05 -0600362 ),
363
364 TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
365 __entry->pid, __entry->old_pid)
366);
367
368/*
Peter Zijlstra768d0c22009-07-23 20:13:26 +0200369 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
370 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
371 */
Ingo Molnar091ad362009-11-26 09:04:55 +0100372DECLARE_EVENT_CLASS(sched_stat_template,
Peter Zijlstra768d0c22009-07-23 20:13:26 +0200373
374 TP_PROTO(struct task_struct *tsk, u64 delay),
375
376 TP_ARGS(tsk, delay),
377
378 TP_STRUCT__entry(
379 __array( char, comm, TASK_COMM_LEN )
380 __field( pid_t, pid )
381 __field( u64, delay )
382 ),
383
384 TP_fast_assign(
385 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
386 __entry->pid = tsk->pid;
387 __entry->delay = delay;
388 )
389 TP_perf_assign(
390 __perf_count(delay);
391 ),
392
Ingo Molnar434a83c2009-10-15 11:50:39 +0200393 TP_printk("comm=%s pid=%d delay=%Lu [ns]",
Peter Zijlstra768d0c22009-07-23 20:13:26 +0200394 __entry->comm, __entry->pid,
395 (unsigned long long)__entry->delay)
396);
397
Steven Rostedt75ec29a2009-11-18 20:48:08 -0500398
399/*
400 * Tracepoint for accounting wait time (time the task is runnable
401 * but not actually running due to scheduler contention).
402 */
403DEFINE_EVENT(sched_stat_template, sched_stat_wait,
404 TP_PROTO(struct task_struct *tsk, u64 delay),
405 TP_ARGS(tsk, delay));
406
407/*
408 * Tracepoint for accounting sleep time (time the task is not runnable,
409 * including iowait, see below).
410 */
Li Zefan470dda72009-11-26 15:08:01 +0800411DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
412 TP_PROTO(struct task_struct *tsk, u64 delay),
413 TP_ARGS(tsk, delay));
Steven Rostedt75ec29a2009-11-18 20:48:08 -0500414
415/*
416 * Tracepoint for accounting iowait time (time the task is not runnable
417 * due to waiting on IO to complete).
418 */
Li Zefan470dda72009-11-26 15:08:01 +0800419DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
420 TP_PROTO(struct task_struct *tsk, u64 delay),
421 TP_ARGS(tsk, delay));
Steven Rostedt75ec29a2009-11-18 20:48:08 -0500422
Peter Zijlstra768d0c22009-07-23 20:13:26 +0200423/*
Andrew Vaginb781a602011-11-28 12:03:35 +0300424 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
425 */
426DEFINE_EVENT(sched_stat_template, sched_stat_blocked,
427 TP_PROTO(struct task_struct *tsk, u64 delay),
428 TP_ARGS(tsk, delay));
429
430/*
Ingo Molnarf977bb42009-09-13 18:15:54 +0200431 * Tracepoint for accounting runtime (time the task is executing
432 * on a CPU).
433 */
434TRACE_EVENT(sched_stat_runtime,
435
436 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
437
438 TP_ARGS(tsk, runtime, vruntime),
439
440 TP_STRUCT__entry(
441 __array( char, comm, TASK_COMM_LEN )
442 __field( pid_t, pid )
443 __field( u64, runtime )
444 __field( u64, vruntime )
445 ),
446
447 TP_fast_assign(
448 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
449 __entry->pid = tsk->pid;
450 __entry->runtime = runtime;
451 __entry->vruntime = vruntime;
452 )
453 TP_perf_assign(
454 __perf_count(runtime);
455 ),
456
Ingo Molnar434a83c2009-10-15 11:50:39 +0200457 TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
Ingo Molnarf977bb42009-09-13 18:15:54 +0200458 __entry->comm, __entry->pid,
459 (unsigned long long)__entry->runtime,
460 (unsigned long long)__entry->vruntime)
461);
462
Steven Rostedta8027072010-09-20 15:13:34 -0400463/*
464 * Tracepoint for showing priority inheritance modifying a tasks
465 * priority.
466 */
467TRACE_EVENT(sched_pi_setprio,
468
469 TP_PROTO(struct task_struct *tsk, int newprio),
470
471 TP_ARGS(tsk, newprio),
472
473 TP_STRUCT__entry(
474 __array( char, comm, TASK_COMM_LEN )
475 __field( pid_t, pid )
476 __field( int, oldprio )
477 __field( int, newprio )
478 ),
479
480 TP_fast_assign(
481 memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
482 __entry->pid = tsk->pid;
483 __entry->oldprio = tsk->prio;
484 __entry->newprio = newprio;
485 ),
486
487 TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
488 __entry->comm, __entry->pid,
489 __entry->oldprio, __entry->newprio)
490);
491
Steven Rostedtea20d922009-04-10 08:54:16 -0400492#endif /* _TRACE_SCHED_H */
Steven Rostedta8d154b2009-04-10 09:36:00 -0400493
494/* This part must be outside protection */
495#include <trace/define_trace.h>