1bea326135a428e0db10c42388a9683d58edd745
[lttng-modules.git] / instrumentation / events / lttng-module / sched.h
1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM sched
3
4 #if !defined(LTTNG_TRACE_SCHED_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define LTTNG_TRACE_SCHED_H
6
7 #include "../../../probes/lttng-tracepoint-event.h"
8 #include <linux/sched.h>
9 #include <linux/binfmts.h>
10 #include <linux/version.h>
11 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
12 #include <linux/sched/rt.h>
13 #endif
14
15 #ifndef _TRACE_SCHED_DEF_
16 #define _TRACE_SCHED_DEF_
17
18 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0))
19
20 static inline long __trace_sched_switch_state(struct task_struct *p)
21 {
22 long state = p->state;
23
24 #ifdef CONFIG_PREEMPT
25 #ifdef CONFIG_SCHED_DEBUG
26 BUG_ON(p != current);
27 #endif /* CONFIG_SCHED_DEBUG */
28 /*
29 * For all intents and purposes a preempted task is a running task.
30 */
31 if (preempt_count() & PREEMPT_ACTIVE)
32 state = TASK_RUNNING | TASK_STATE_MAX;
33 #endif /* CONFIG_PREEMPT */
34
35 return state;
36 }
37
38 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0))
39
40 static inline long __trace_sched_switch_state(struct task_struct *p)
41 {
42 long state = p->state;
43
44 #ifdef CONFIG_PREEMPT
45 /*
46 * For all intents and purposes a preempted task is a running task.
47 */
48 if (task_preempt_count(p) & PREEMPT_ACTIVE)
49 state = TASK_RUNNING | TASK_STATE_MAX;
50 #endif
51
52 return state;
53 }
54
55 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
56
57 static inline long __trace_sched_switch_state(struct task_struct *p)
58 {
59 long state = p->state;
60
61 #ifdef CONFIG_PREEMPT
62 /*
63 * For all intents and purposes a preempted task is a running task.
64 */
65 if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE)
66 state = TASK_RUNNING | TASK_STATE_MAX;
67 #endif
68
69 return state;
70 }
71
72 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
73
74 static inline long __trace_sched_switch_state(struct task_struct *p)
75 {
76 long state = p->state;
77
78 #ifdef CONFIG_PREEMPT
79 /*
80 * For all intents and purposes a preempted task is a running task.
81 */
82 if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE)
83 state = TASK_RUNNING;
84 #endif
85
86 return state;
87 }
88
89 #endif
90
91 #endif /* _TRACE_SCHED_DEF_ */
92
93 /*
94 * Tracepoint for calling kthread_stop, performed to end a kthread:
95 */
96 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop,
97
98 TP_PROTO(struct task_struct *t),
99
100 TP_ARGS(t),
101
102 TP_STRUCT__entry(
103 __array_text( char, comm, TASK_COMM_LEN )
104 __field( pid_t, tid )
105 ),
106
107 TP_fast_assign(
108 tp_memcpy(comm, t->comm, TASK_COMM_LEN)
109 tp_assign(tid, t->pid)
110 ),
111
112 TP_printk("comm=%s tid=%d", __entry->comm, __entry->tid)
113 )
114
115 /*
116 * Tracepoint for the return value of the kthread stopping:
117 */
118 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret,
119
120 TP_PROTO(int ret),
121
122 TP_ARGS(ret),
123
124 TP_STRUCT__entry(
125 __field( int, ret )
126 ),
127
128 TP_fast_assign(
129 tp_assign(ret, ret)
130 ),
131
132 TP_printk("ret=%d", __entry->ret)
133 )
134
135 /*
136 * Tracepoint for waking up a task:
137 */
138 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template,
139
140 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
141 TP_PROTO(struct task_struct *p, int success),
142
143 TP_ARGS(p, success),
144 #else
145 TP_PROTO(struct rq *rq, struct task_struct *p, int success),
146
147 TP_ARGS(rq, p, success),
148 #endif
149
150 TP_STRUCT__entry(
151 __array_text( char, comm, TASK_COMM_LEN )
152 __field( pid_t, tid )
153 __field( int, prio )
154 __field( int, success )
155 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
156 __field( int, target_cpu )
157 #endif
158 ),
159
160 TP_fast_assign(
161 tp_memcpy(comm, p->comm, TASK_COMM_LEN)
162 tp_assign(tid, p->pid)
163 tp_assign(prio, p->prio)
164 tp_assign(success, success)
165 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
166 tp_assign(target_cpu, task_cpu(p))
167 #endif
168 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
169 )
170 TP_perf_assign(
171 __perf_task(p)
172 #endif
173 ),
174
175 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
176 TP_printk("comm=%s tid=%d prio=%d success=%d target_cpu=%03d",
177 __entry->comm, __entry->tid, __entry->prio,
178 __entry->success, __entry->target_cpu)
179 #else
180 TP_printk("comm=%s tid=%d prio=%d success=%d",
181 __entry->comm, __entry->tid, __entry->prio,
182 __entry->success)
183 #endif
184 )
185
186 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
187
188 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup,
189 TP_PROTO(struct task_struct *p, int success),
190 TP_ARGS(p, success))
191
192 /*
193 * Tracepoint for waking up a new task:
194 */
195 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup_new,
196 TP_PROTO(struct task_struct *p, int success),
197 TP_ARGS(p, success))
198
199 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
200
201 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup,
202 TP_PROTO(struct rq *rq, struct task_struct *p, int success),
203 TP_ARGS(rq, p, success))
204
205 /*
206 * Tracepoint for waking up a new task:
207 */
208 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup_new,
209 TP_PROTO(struct rq *rq, struct task_struct *p, int success),
210 TP_ARGS(rq, p, success))
211
212 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
213
214 /*
215 * Tracepoint for task switches, performed by the scheduler:
216 */
217 LTTNG_TRACEPOINT_EVENT(sched_switch,
218
219 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
220 TP_PROTO(struct task_struct *prev,
221 struct task_struct *next),
222
223 TP_ARGS(prev, next),
224 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
225 TP_PROTO(struct rq *rq, struct task_struct *prev,
226 struct task_struct *next),
227
228 TP_ARGS(rq, prev, next),
229 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
230
231 TP_STRUCT__entry(
232 __array_text( char, prev_comm, TASK_COMM_LEN )
233 __field( pid_t, prev_tid )
234 __field( int, prev_prio )
235 __field( long, prev_state )
236 __array_text( char, next_comm, TASK_COMM_LEN )
237 __field( pid_t, next_tid )
238 __field( int, next_prio )
239 ),
240
241 TP_fast_assign(
242 tp_memcpy(next_comm, next->comm, TASK_COMM_LEN)
243 tp_assign(prev_tid, prev->pid)
244 tp_assign(prev_prio, prev->prio - MAX_RT_PRIO)
245 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
246 tp_assign(prev_state, __trace_sched_switch_state(prev))
247 #else
248 tp_assign(prev_state, prev->state)
249 #endif
250 tp_memcpy(prev_comm, prev->comm, TASK_COMM_LEN)
251 tp_assign(next_tid, next->pid)
252 tp_assign(next_prio, next->prio - MAX_RT_PRIO)
253 ),
254
255 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0))
256 TP_printk("prev_comm=%s prev_tid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_tid=%d next_prio=%d",
257 __entry->prev_comm, __entry->prev_tid, __entry->prev_prio,
258 __entry->prev_state & (TASK_STATE_MAX-1) ?
259 __print_flags(__entry->prev_state & (TASK_STATE_MAX-1), "|",
260 { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
261 { 16, "Z" }, { 32, "X" }, { 64, "x" },
262 { 128, "W" }) : "R",
263 __entry->prev_state & TASK_STATE_MAX ? "+" : "",
264 __entry->next_comm, __entry->next_tid, __entry->next_prio)
265 #else
266 TP_printk("prev_comm=%s prev_tid=%d prev_prio=%d prev_state=%s ==> next_comm=%s next_tid=%d next_prio=%d",
267 __entry->prev_comm, __entry->prev_tid, __entry->prev_prio,
268 __entry->prev_state ?
269 __print_flags(__entry->prev_state, "|",
270 { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
271 { 16, "Z" }, { 32, "X" }, { 64, "x" },
272 { 128, "W" }) : "R",
273 __entry->next_comm, __entry->next_tid, __entry->next_prio)
274 #endif
275 )
276
277 /*
278 * Tracepoint for a task being migrated:
279 */
280 LTTNG_TRACEPOINT_EVENT(sched_migrate_task,
281
282 TP_PROTO(struct task_struct *p, int dest_cpu),
283
284 TP_ARGS(p, dest_cpu),
285
286 TP_STRUCT__entry(
287 __array_text( char, comm, TASK_COMM_LEN )
288 __field( pid_t, tid )
289 __field( int, prio )
290 __field( int, orig_cpu )
291 __field( int, dest_cpu )
292 ),
293
294 TP_fast_assign(
295 tp_memcpy(comm, p->comm, TASK_COMM_LEN)
296 tp_assign(tid, p->pid)
297 tp_assign(prio, p->prio - MAX_RT_PRIO)
298 tp_assign(orig_cpu, task_cpu(p))
299 tp_assign(dest_cpu, dest_cpu)
300 ),
301
302 TP_printk("comm=%s tid=%d prio=%d orig_cpu=%d dest_cpu=%d",
303 __entry->comm, __entry->tid, __entry->prio,
304 __entry->orig_cpu, __entry->dest_cpu)
305 )
306
307 LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template,
308
309 TP_PROTO(struct task_struct *p),
310
311 TP_ARGS(p),
312
313 TP_STRUCT__entry(
314 __array_text( char, comm, TASK_COMM_LEN )
315 __field( pid_t, tid )
316 __field( int, prio )
317 ),
318
319 TP_fast_assign(
320 tp_memcpy(comm, p->comm, TASK_COMM_LEN)
321 tp_assign(tid, p->pid)
322 tp_assign(prio, p->prio - MAX_RT_PRIO)
323 ),
324
325 TP_printk("comm=%s tid=%d prio=%d",
326 __entry->comm, __entry->tid, __entry->prio)
327 )
328
329 /*
330 * Tracepoint for freeing a task:
331 */
332 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_process_free,
333 TP_PROTO(struct task_struct *p),
334 TP_ARGS(p))
335
336
337 /*
338 * Tracepoint for a task exiting:
339 */
340 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_process_exit,
341 TP_PROTO(struct task_struct *p),
342 TP_ARGS(p))
343
344 /*
345 * Tracepoint for waiting on task to unschedule:
346 */
347 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
348 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_wait_task,
349 TP_PROTO(struct task_struct *p),
350 TP_ARGS(p))
351 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
352 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_wait_task,
353 TP_PROTO(struct rq *rq, struct task_struct *p),
354 TP_ARGS(rq, p))
355 #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
356
357 /*
358 * Tracepoint for a waiting task:
359 */
360 LTTNG_TRACEPOINT_EVENT(sched_process_wait,
361
362 TP_PROTO(struct pid *pid),
363
364 TP_ARGS(pid),
365
366 TP_STRUCT__entry(
367 __array_text( char, comm, TASK_COMM_LEN )
368 __field( pid_t, tid )
369 __field( int, prio )
370 ),
371
372 TP_fast_assign(
373 tp_memcpy(comm, current->comm, TASK_COMM_LEN)
374 tp_assign(tid, pid_nr(pid))
375 tp_assign(prio, current->prio - MAX_RT_PRIO)
376 ),
377
378 TP_printk("comm=%s tid=%d prio=%d",
379 __entry->comm, __entry->tid, __entry->prio)
380 )
381
382 /*
383 * Tracepoint for do_fork.
384 * Saving both TID and PID information, especially for the child, allows
385 * trace analyzers to distinguish between creation of a new process and
386 * creation of a new thread. Newly created processes will have child_tid
387 * == child_pid, while creation of a thread yields to child_tid !=
388 * child_pid.
389 */
390 LTTNG_TRACEPOINT_EVENT(sched_process_fork,
391
392 TP_PROTO(struct task_struct *parent, struct task_struct *child),
393
394 TP_ARGS(parent, child),
395
396 TP_STRUCT__entry(
397 __array_text( char, parent_comm, TASK_COMM_LEN )
398 __field( pid_t, parent_tid )
399 __field( pid_t, parent_pid )
400 __array_text( char, child_comm, TASK_COMM_LEN )
401 __field( pid_t, child_tid )
402 __field( pid_t, child_pid )
403 ),
404
405 TP_fast_assign(
406 tp_memcpy(parent_comm, parent->comm, TASK_COMM_LEN)
407 tp_assign(parent_tid, parent->pid)
408 tp_assign(parent_pid, parent->tgid)
409 tp_memcpy(child_comm, child->comm, TASK_COMM_LEN)
410 tp_assign(child_tid, child->pid)
411 tp_assign(child_pid, child->tgid)
412 ),
413
414 TP_printk("comm=%s tid=%d child_comm=%s child_tid=%d",
415 __entry->parent_comm, __entry->parent_tid,
416 __entry->child_comm, __entry->child_tid)
417 )
418
419 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
420 /*
421 * Tracepoint for sending a signal:
422 */
423 LTTNG_TRACEPOINT_EVENT(sched_signal_send,
424
425 TP_PROTO(int sig, struct task_struct *p),
426
427 TP_ARGS(sig, p),
428
429 TP_STRUCT__entry(
430 __field( int, sig )
431 __array( char, comm, TASK_COMM_LEN )
432 __field( pid_t, pid )
433 ),
434
435 TP_fast_assign(
436 tp_memcpy(comm, p->comm, TASK_COMM_LEN)
437 tp_assign(pid, p->pid)
438 tp_assign(sig, sig)
439 ),
440
441 TP_printk("sig=%d comm=%s pid=%d",
442 __entry->sig, __entry->comm, __entry->pid)
443 )
444 #endif
445
446 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
447 /*
448 * Tracepoint for exec:
449 */
450 LTTNG_TRACEPOINT_EVENT(sched_process_exec,
451
452 TP_PROTO(struct task_struct *p, pid_t old_pid,
453 struct linux_binprm *bprm),
454
455 TP_ARGS(p, old_pid, bprm),
456
457 TP_STRUCT__entry(
458 __string( filename, bprm->filename )
459 __field( pid_t, tid )
460 __field( pid_t, old_tid )
461 ),
462
463 TP_fast_assign(
464 tp_strcpy(filename, bprm->filename)
465 tp_assign(tid, p->pid)
466 tp_assign(old_tid, old_pid)
467 ),
468
469 TP_printk("filename=%s tid=%d old_tid=%d", __get_str(filename),
470 __entry->tid, __entry->old_tid)
471 )
472 #endif
473
474 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
475 /*
476 * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
477 * adding sched_stat support to SCHED_FIFO/RR would be welcome.
478 */
479 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template,
480
481 TP_PROTO(struct task_struct *tsk, u64 delay),
482
483 TP_ARGS(tsk, delay),
484
485 TP_STRUCT__entry(
486 __array_text( char, comm, TASK_COMM_LEN )
487 __field( pid_t, tid )
488 __field( u64, delay )
489 ),
490
491 TP_fast_assign(
492 tp_memcpy(comm, tsk->comm, TASK_COMM_LEN)
493 tp_assign(tid, tsk->pid)
494 tp_assign(delay, delay)
495 )
496 TP_perf_assign(
497 __perf_count(delay)
498 ),
499
500 TP_printk("comm=%s tid=%d delay=%Lu [ns]",
501 __entry->comm, __entry->tid,
502 (unsigned long long)__entry->delay)
503 )
504
505
506 /*
507 * Tracepoint for accounting wait time (time the task is runnable
508 * but not actually running due to scheduler contention).
509 */
510 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_wait,
511 TP_PROTO(struct task_struct *tsk, u64 delay),
512 TP_ARGS(tsk, delay))
513
514 /*
515 * Tracepoint for accounting sleep time (time the task is not runnable,
516 * including iowait, see below).
517 */
518 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_sleep,
519 TP_PROTO(struct task_struct *tsk, u64 delay),
520 TP_ARGS(tsk, delay))
521
522 /*
523 * Tracepoint for accounting iowait time (time the task is not runnable
524 * due to waiting on IO to complete).
525 */
526 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_iowait,
527 TP_PROTO(struct task_struct *tsk, u64 delay),
528 TP_ARGS(tsk, delay))
529
530 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
531 /*
532 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
533 */
534 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_blocked,
535 TP_PROTO(struct task_struct *tsk, u64 delay),
536 TP_ARGS(tsk, delay))
537 #endif
538
539 /*
540 * Tracepoint for accounting runtime (time the task is executing
541 * on a CPU).
542 */
543 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime,
544
545 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
546
547 TP_ARGS(tsk, runtime, vruntime),
548
549 TP_STRUCT__entry(
550 __array_text( char, comm, TASK_COMM_LEN )
551 __field( pid_t, tid )
552 __field( u64, runtime )
553 __field( u64, vruntime )
554 ),
555
556 TP_fast_assign(
557 tp_memcpy(comm, tsk->comm, TASK_COMM_LEN)
558 tp_assign(tid, tsk->pid)
559 tp_assign(runtime, runtime)
560 tp_assign(vruntime, vruntime)
561 )
562 TP_perf_assign(
563 __perf_count(runtime)
564 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
565 __perf_task(tsk)
566 #endif
567 ),
568
569 TP_printk("comm=%s tid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
570 __entry->comm, __entry->tid,
571 (unsigned long long)__entry->runtime,
572 (unsigned long long)__entry->vruntime)
573 )
574 #endif
575
576 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
577 /*
578 * Tracepoint for showing priority inheritance modifying a tasks
579 * priority.
580 */
581 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio,
582
583 TP_PROTO(struct task_struct *tsk, int newprio),
584
585 TP_ARGS(tsk, newprio),
586
587 TP_STRUCT__entry(
588 __array_text( char, comm, TASK_COMM_LEN )
589 __field( pid_t, tid )
590 __field( int, oldprio )
591 __field( int, newprio )
592 ),
593
594 TP_fast_assign(
595 tp_memcpy(comm, tsk->comm, TASK_COMM_LEN)
596 tp_assign(tid, tsk->pid)
597 tp_assign(oldprio, tsk->prio - MAX_RT_PRIO)
598 tp_assign(newprio, newprio - MAX_RT_PRIO)
599 ),
600
601 TP_printk("comm=%s tid=%d oldprio=%d newprio=%d",
602 __entry->comm, __entry->tid,
603 __entry->oldprio, __entry->newprio)
604 )
605 #endif
606
607 #endif /* LTTNG_TRACE_SCHED_H */
608
609 /* This part must be outside protection */
610 #include "../../../probes/define_trace.h"
This page took 0.042603 seconds and 3 git commands to generate.