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