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