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