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