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