Tracepoint event: add "TP_code_post()"
[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(3,19,0))
28
29 static 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))
48
49 static 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))
65
66 static 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)
75 state = TASK_RUNNING | TASK_STATE_MAX;
76 #endif
77
78 return state;
79 }
80
81 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
82
83 static 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;
93 #endif
94
95 return state;
96 }
97
98 #endif
99
100 #endif /* _TRACE_SCHED_DEF_ */
101
102 /*
103 * Tracepoint for calling kthread_stop, performed to end a kthread:
104 */
105 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop,
106
107 TP_PROTO(struct task_struct *t),
108
109 TP_ARGS(t),
110
111 TP_FIELDS(
112 ctf_array_text(char, comm, t->comm, TASK_COMM_LEN)
113 ctf_integer(pid_t, tid, t->pid)
114 )
115 )
116
117 /*
118 * Tracepoint for the return value of the kthread stopping:
119 */
120 LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret,
121
122 TP_PROTO(int ret),
123
124 TP_ARGS(ret),
125
126 TP_FIELDS(
127 ctf_integer(int, ret, ret)
128 )
129 )
130
131 /*
132 * Tracepoint for waking up a task:
133 */
134 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0))
135 LTTNG_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)) */
149 LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template,
150
151 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
152 TP_PROTO(struct task_struct *p, int success),
153
154 TP_ARGS(p, success),
155 #else
156 TP_PROTO(struct rq *rq, struct task_struct *p, int success),
157
158 TP_ARGS(rq, p, success),
159 #endif
160
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)
166 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
167 ctf_integer(int, target_cpu, task_cpu(p))
168 #endif
169 )
170 )
171 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)) */
172
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 */
179 LTTNG_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 */
187 LTTNG_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 */
194 LTTNG_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))
199
200 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup,
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 */
207 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup_new,
208 TP_PROTO(struct task_struct *p, int success),
209 TP_ARGS(p, success))
210
211 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
212
213 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup,
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 */
220 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup_new,
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
226 /*
227 * Tracepoint for task switches, performed by the scheduler:
228 */
229 LTTNG_TRACEPOINT_EVENT(sched_switch,
230
231 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
232 TP_PROTO(struct task_struct *prev,
233 struct task_struct *next),
234
235 TP_ARGS(prev, next),
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)) */
242
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)
247 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
248 ctf_integer(long, prev_state, __trace_sched_switch_state(prev))
249 #else
250 ctf_integer(long, prev_state, prev->state)
251 #endif
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 )
256 )
257
258 /*
259 * Tracepoint for a task being migrated:
260 */
261 LTTNG_TRACEPOINT_EVENT(sched_migrate_task,
262
263 TP_PROTO(struct task_struct *p, int dest_cpu),
264
265 TP_ARGS(p, dest_cpu),
266
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 )
274 )
275
276 LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template,
277
278 TP_PROTO(struct task_struct *p),
279
280 TP_ARGS(p),
281
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 )
287 )
288
289 /*
290 * Tracepoint for freeing a task:
291 */
292 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_process_free,
293 TP_PROTO(struct task_struct *p),
294 TP_ARGS(p))
295
296
297 /*
298 * Tracepoint for a task exiting:
299 */
300 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_process_exit,
301 TP_PROTO(struct task_struct *p),
302 TP_ARGS(p))
303
304 /*
305 * Tracepoint for waiting on task to unschedule:
306 */
307 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
308 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_wait_task,
309 TP_PROTO(struct task_struct *p),
310 TP_ARGS(p))
311 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */
312 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_wait_task,
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)) */
316
317 /*
318 * Tracepoint for a waiting task:
319 */
320 LTTNG_TRACEPOINT_EVENT(sched_process_wait,
321
322 TP_PROTO(struct pid *pid),
323
324 TP_ARGS(pid),
325
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 )
331 )
332
333 /*
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.
340 */
341 LTTNG_TRACEPOINT_EVENT_CODE(sched_process_fork,
342
343 TP_PROTO(struct task_struct *parent, struct task_struct *child),
344
345 TP_ARGS(parent, child),
346
347 TP_locvar(
348 pid_t vtids[LTTNG_MAX_PID_NS_LEVEL];
349 unsigned int ns_level;
350 ),
351
352 TP_code_pre(
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
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)
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
386 ctf_array_text(char, child_comm, child->comm, TASK_COMM_LEN)
387 ctf_integer(pid_t, child_tid, child->pid)
388 ctf_sequence(pid_t, vtids, tp_locvar->vtids, u8, tp_locvar->ns_level)
389 ctf_integer(pid_t, child_pid, child->tgid)
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
406 ),
407
408 TP_code_post()
409 )
410
411 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
412 /*
413 * Tracepoint for sending a signal:
414 */
415 LTTNG_TRACEPOINT_EVENT(sched_signal_send,
416
417 TP_PROTO(int sig, struct task_struct *p),
418
419 TP_ARGS(sig, p),
420
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 )
426 )
427 #endif
428
429 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
430 /*
431 * Tracepoint for exec:
432 */
433 LTTNG_TRACEPOINT_EVENT(sched_process_exec,
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
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 )
445 )
446 #endif
447
448 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32))
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 */
453 LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template,
454
455 TP_PROTO(struct task_struct *tsk, u64 delay),
456
457 TP_ARGS(tsk, delay),
458
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)
463 )
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 */
471 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_wait,
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 */
479 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_sleep,
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 */
487 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_iowait,
488 TP_PROTO(struct task_struct *tsk, u64 delay),
489 TP_ARGS(tsk, delay))
490
491 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0))
492 /*
493 * Tracepoint for accounting blocked time (time the task is in uninterruptible).
494 */
495 LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_blocked,
496 TP_PROTO(struct task_struct *tsk, u64 delay),
497 TP_ARGS(tsk, delay))
498 #endif
499
500 /*
501 * Tracepoint for accounting runtime (time the task is executing
502 * on a CPU).
503 */
504 LTTNG_TRACEPOINT_EVENT(sched_stat_runtime,
505
506 TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
507
508 TP_ARGS(tsk, runtime, vruntime),
509
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)
515 )
516 )
517 #endif
518
519 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
520 /*
521 * Tracepoint for showing priority inheritance modifying a tasks
522 * priority.
523 */
524 LTTNG_TRACEPOINT_EVENT(sched_pi_setprio,
525
526 TP_PROTO(struct task_struct *tsk, int newprio),
527
528 TP_ARGS(tsk, newprio),
529
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 )
536 )
537 #endif
538
539 #endif /* LTTNG_TRACE_SCHED_H */
540
541 /* This part must be outside protection */
542 #include "../../../probes/define_trace.h"
This page took 0.040607 seconds and 5 git commands to generate.