Commit | Line | Data |
---|---|---|
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> |
7c68b363 AG |
9 | #include <linux/binfmts.h> |
10 | #include <linux/version.h> | |
090db00e MJ |
11 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0)) |
12 | #include <linux/sched/rt.h> | |
13 | #endif | |
f62b389e MD |
14 | |
15 | #ifndef _TRACE_SCHED_DEF_ | |
16 | #define _TRACE_SCHED_DEF_ | |
17 | ||
857b6f4f MD |
18 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,0)) |
19 | ||
20 | static inline long __trace_sched_switch_state(struct task_struct *p) | |
21 | { | |
22 | long state = p->state; | |
23 | ||
24 | #ifdef CONFIG_PREEMPT | |
25 | #ifdef CONFIG_SCHED_DEBUG | |
26 | BUG_ON(p != current); | |
27 | #endif /* CONFIG_SCHED_DEBUG */ | |
28 | /* | |
29 | * For all intents and purposes a preempted task is a running task. | |
30 | */ | |
31 | if (preempt_count() & PREEMPT_ACTIVE) | |
32 | state = TASK_RUNNING | TASK_STATE_MAX; | |
33 | #endif /* CONFIG_PREEMPT */ | |
34 | ||
35 | return state; | |
36 | } | |
37 | ||
38 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,13,0)) | |
33673ee7 MD |
39 | |
40 | static inline long __trace_sched_switch_state(struct task_struct *p) | |
41 | { | |
42 | long state = p->state; | |
43 | ||
44 | #ifdef CONFIG_PREEMPT | |
45 | /* | |
46 | * For all intents and purposes a preempted task is a running task. | |
47 | */ | |
48 | if (task_preempt_count(p) & PREEMPT_ACTIVE) | |
49 | state = TASK_RUNNING | TASK_STATE_MAX; | |
50 | #endif | |
51 | ||
52 | return state; | |
53 | } | |
54 | ||
55 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0)) | |
7c68b363 | 56 | |
f62b389e MD |
57 | static inline long __trace_sched_switch_state(struct task_struct *p) |
58 | { | |
59 | long state = p->state; | |
60 | ||
61 | #ifdef CONFIG_PREEMPT | |
62 | /* | |
63 | * For all intents and purposes a preempted task is a running task. | |
64 | */ | |
65 | if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE) | |
7c68b363 | 66 | state = TASK_RUNNING | TASK_STATE_MAX; |
7c68b363 | 67 | #endif |
33673ee7 MD |
68 | |
69 | return state; | |
70 | } | |
71 | ||
72 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) | |
73 | ||
74 | static inline long __trace_sched_switch_state(struct task_struct *p) | |
75 | { | |
76 | long state = p->state; | |
77 | ||
78 | #ifdef CONFIG_PREEMPT | |
79 | /* | |
80 | * For all intents and purposes a preempted task is a running task. | |
81 | */ | |
82 | if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE) | |
83 | state = TASK_RUNNING; | |
f62b389e MD |
84 | #endif |
85 | ||
86 | return state; | |
87 | } | |
88 | ||
7c68b363 AG |
89 | #endif |
90 | ||
f62b389e MD |
91 | #endif /* _TRACE_SCHED_DEF_ */ |
92 | ||
93 | /* | |
94 | * Tracepoint for calling kthread_stop, performed to end a kthread: | |
95 | */ | |
3bc29f0a | 96 | LTTNG_TRACEPOINT_EVENT(sched_kthread_stop, |
f62b389e MD |
97 | |
98 | TP_PROTO(struct task_struct *t), | |
99 | ||
100 | TP_ARGS(t), | |
101 | ||
f127e61e MD |
102 | TP_FIELDS( |
103 | ctf_array_text(char, comm, t->comm, TASK_COMM_LEN) | |
104 | ctf_integer(pid_t, tid, t->pid) | |
105 | ) | |
f62b389e MD |
106 | ) |
107 | ||
108 | /* | |
109 | * Tracepoint for the return value of the kthread stopping: | |
110 | */ | |
3bc29f0a | 111 | LTTNG_TRACEPOINT_EVENT(sched_kthread_stop_ret, |
f62b389e MD |
112 | |
113 | TP_PROTO(int ret), | |
114 | ||
115 | TP_ARGS(ret), | |
116 | ||
f127e61e MD |
117 | TP_FIELDS( |
118 | ctf_integer(int, ret, ret) | |
119 | ) | |
f62b389e MD |
120 | ) |
121 | ||
122 | /* | |
123 | * Tracepoint for waking up a task: | |
124 | */ | |
3bc29f0a | 125 | LTTNG_TRACEPOINT_EVENT_CLASS(sched_wakeup_template, |
f62b389e | 126 | |
3a523f5b | 127 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) |
f62b389e MD |
128 | TP_PROTO(struct task_struct *p, int success), |
129 | ||
130 | TP_ARGS(p, success), | |
3a523f5b MD |
131 | #else |
132 | TP_PROTO(struct rq *rq, struct task_struct *p, int success), | |
133 | ||
134 | TP_ARGS(rq, p, success), | |
135 | #endif | |
f62b389e | 136 | |
f127e61e MD |
137 | TP_FIELDS( |
138 | ctf_array_text(char, comm, p->comm, TASK_COMM_LEN) | |
139 | ctf_integer(pid_t, tid, p->pid) | |
140 | ctf_integer(int, prio, p->prio) | |
141 | ctf_integer(int, success, success) | |
7c68b363 | 142 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) |
f127e61e | 143 | ctf_integer(int, target_cpu, task_cpu(p)) |
7c68b363 | 144 | #endif |
7c68b363 | 145 | ) |
f62b389e MD |
146 | ) |
147 | ||
3a523f5b MD |
148 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) |
149 | ||
3bc29f0a | 150 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup, |
f62b389e MD |
151 | TP_PROTO(struct task_struct *p, int success), |
152 | TP_ARGS(p, success)) | |
153 | ||
154 | /* | |
155 | * Tracepoint for waking up a new task: | |
156 | */ | |
3bc29f0a | 157 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup_new, |
f62b389e MD |
158 | TP_PROTO(struct task_struct *p, int success), |
159 | TP_ARGS(p, success)) | |
160 | ||
3a523f5b MD |
161 | #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */ |
162 | ||
3bc29f0a | 163 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup, |
3a523f5b MD |
164 | TP_PROTO(struct rq *rq, struct task_struct *p, int success), |
165 | TP_ARGS(rq, p, success)) | |
166 | ||
167 | /* | |
168 | * Tracepoint for waking up a new task: | |
169 | */ | |
3bc29f0a | 170 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_wakeup_template, sched_wakeup_new, |
3a523f5b MD |
171 | TP_PROTO(struct rq *rq, struct task_struct *p, int success), |
172 | TP_ARGS(rq, p, success)) | |
173 | ||
174 | #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */ | |
175 | ||
f62b389e MD |
176 | /* |
177 | * Tracepoint for task switches, performed by the scheduler: | |
178 | */ | |
3bc29f0a | 179 | LTTNG_TRACEPOINT_EVENT(sched_switch, |
f62b389e | 180 | |
3a523f5b | 181 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) |
f62b389e MD |
182 | TP_PROTO(struct task_struct *prev, |
183 | struct task_struct *next), | |
184 | ||
185 | TP_ARGS(prev, next), | |
3a523f5b MD |
186 | #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */ |
187 | TP_PROTO(struct rq *rq, struct task_struct *prev, | |
188 | struct task_struct *next), | |
189 | ||
190 | TP_ARGS(rq, prev, next), | |
191 | #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */ | |
f62b389e | 192 | |
f127e61e MD |
193 | TP_FIELDS( |
194 | ctf_array_text(char, prev_comm, prev->comm, TASK_COMM_LEN) | |
195 | ctf_integer(pid_t, prev_tid, prev->pid) | |
196 | ctf_integer(int, prev_prio, prev->prio - MAX_RT_PRIO) | |
7c68b363 | 197 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) |
f127e61e | 198 | ctf_integer(long, prev_state, __trace_sched_switch_state(prev)) |
7c68b363 | 199 | #else |
f127e61e | 200 | ctf_integer(long, prev_state, prev->state) |
7c68b363 | 201 | #endif |
f127e61e MD |
202 | ctf_array_text(char, next_comm, next->comm, TASK_COMM_LEN) |
203 | ctf_integer(pid_t, next_tid, next->pid) | |
204 | ctf_integer(int, next_prio, next->prio - MAX_RT_PRIO) | |
205 | ) | |
f62b389e MD |
206 | ) |
207 | ||
208 | /* | |
209 | * Tracepoint for a task being migrated: | |
210 | */ | |
3bc29f0a | 211 | LTTNG_TRACEPOINT_EVENT(sched_migrate_task, |
f62b389e MD |
212 | |
213 | TP_PROTO(struct task_struct *p, int dest_cpu), | |
214 | ||
215 | TP_ARGS(p, dest_cpu), | |
216 | ||
f127e61e MD |
217 | TP_FIELDS( |
218 | ctf_array_text(char, comm, p->comm, TASK_COMM_LEN) | |
219 | ctf_integer(pid_t, tid, p->pid) | |
220 | ctf_integer(int, prio, p->prio - MAX_RT_PRIO) | |
221 | ctf_integer(int, orig_cpu, task_cpu(p)) | |
222 | ctf_integer(int, dest_cpu, dest_cpu) | |
223 | ) | |
f62b389e MD |
224 | ) |
225 | ||
3bc29f0a | 226 | LTTNG_TRACEPOINT_EVENT_CLASS(sched_process_template, |
f62b389e MD |
227 | |
228 | TP_PROTO(struct task_struct *p), | |
229 | ||
230 | TP_ARGS(p), | |
231 | ||
f127e61e MD |
232 | TP_FIELDS( |
233 | ctf_array_text(char, comm, p->comm, TASK_COMM_LEN) | |
234 | ctf_integer(pid_t, tid, p->pid) | |
235 | ctf_integer(int, prio, p->prio - MAX_RT_PRIO) | |
236 | ) | |
f62b389e MD |
237 | ) |
238 | ||
239 | /* | |
240 | * Tracepoint for freeing a task: | |
241 | */ | |
3bc29f0a | 242 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_process_free, |
f62b389e MD |
243 | TP_PROTO(struct task_struct *p), |
244 | TP_ARGS(p)) | |
245 | ||
246 | ||
247 | /* | |
248 | * Tracepoint for a task exiting: | |
249 | */ | |
3bc29f0a | 250 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_process_exit, |
f62b389e MD |
251 | TP_PROTO(struct task_struct *p), |
252 | TP_ARGS(p)) | |
253 | ||
254 | /* | |
255 | * Tracepoint for waiting on task to unschedule: | |
256 | */ | |
3a523f5b | 257 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) |
3bc29f0a | 258 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_wait_task, |
f62b389e MD |
259 | TP_PROTO(struct task_struct *p), |
260 | TP_ARGS(p)) | |
3a523f5b | 261 | #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */ |
3bc29f0a | 262 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_process_template, sched_wait_task, |
3a523f5b MD |
263 | TP_PROTO(struct rq *rq, struct task_struct *p), |
264 | TP_ARGS(rq, p)) | |
265 | #endif /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)) */ | |
f62b389e MD |
266 | |
267 | /* | |
268 | * Tracepoint for a waiting task: | |
269 | */ | |
3bc29f0a | 270 | LTTNG_TRACEPOINT_EVENT(sched_process_wait, |
f62b389e MD |
271 | |
272 | TP_PROTO(struct pid *pid), | |
273 | ||
274 | TP_ARGS(pid), | |
275 | ||
f127e61e MD |
276 | TP_FIELDS( |
277 | ctf_array_text(char, comm, current->comm, TASK_COMM_LEN) | |
278 | ctf_integer(pid_t, tid, pid_nr(pid)) | |
279 | ctf_integer(int, prio, current->prio - MAX_RT_PRIO) | |
280 | ) | |
f62b389e MD |
281 | ) |
282 | ||
283 | /* | |
79b18ef7 MD |
284 | * Tracepoint for do_fork. |
285 | * Saving both TID and PID information, especially for the child, allows | |
286 | * trace analyzers to distinguish between creation of a new process and | |
287 | * creation of a new thread. Newly created processes will have child_tid | |
288 | * == child_pid, while creation of a thread yields to child_tid != | |
289 | * child_pid. | |
f62b389e | 290 | */ |
3bc29f0a | 291 | LTTNG_TRACEPOINT_EVENT(sched_process_fork, |
f62b389e MD |
292 | |
293 | TP_PROTO(struct task_struct *parent, struct task_struct *child), | |
294 | ||
295 | TP_ARGS(parent, child), | |
296 | ||
f127e61e MD |
297 | TP_FIELDS( |
298 | ctf_array_text(char, parent_comm, parent->comm, TASK_COMM_LEN) | |
299 | ctf_integer(pid_t, parent_tid, parent->pid) | |
300 | ctf_integer(pid_t, parent_pid, parent->tgid) | |
301 | ctf_array_text(char, child_comm, child->comm, TASK_COMM_LEN) | |
302 | ctf_integer(pid_t, child_tid, child->pid) | |
303 | ctf_integer(pid_t, child_pid, child->tgid) | |
304 | ) | |
f62b389e MD |
305 | ) |
306 | ||
7c68b363 AG |
307 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)) |
308 | /* | |
309 | * Tracepoint for sending a signal: | |
310 | */ | |
3bc29f0a | 311 | LTTNG_TRACEPOINT_EVENT(sched_signal_send, |
7c68b363 AG |
312 | |
313 | TP_PROTO(int sig, struct task_struct *p), | |
314 | ||
315 | TP_ARGS(sig, p), | |
316 | ||
f127e61e MD |
317 | TP_FIELDS( |
318 | ctf_integer(int, sig, sig) | |
319 | ctf_array_text(char, comm, p->comm, TASK_COMM_LEN) | |
320 | ctf_integer(pid_t, tid, p->pid) | |
321 | ) | |
7c68b363 AG |
322 | ) |
323 | #endif | |
324 | ||
c94b2508 | 325 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) |
46142a81 PW |
326 | /* |
327 | * Tracepoint for exec: | |
328 | */ | |
3bc29f0a | 329 | LTTNG_TRACEPOINT_EVENT(sched_process_exec, |
46142a81 PW |
330 | |
331 | TP_PROTO(struct task_struct *p, pid_t old_pid, | |
332 | struct linux_binprm *bprm), | |
333 | ||
334 | TP_ARGS(p, old_pid, bprm), | |
335 | ||
f127e61e MD |
336 | TP_FIELDS( |
337 | ctf_string(filename, bprm->filename) | |
338 | ctf_integer(pid_t, tid, p->pid) | |
339 | ctf_integer(pid_t, old_tid, old_pid) | |
340 | ) | |
46142a81 | 341 | ) |
c94b2508 | 342 | #endif |
46142a81 | 343 | |
7c68b363 | 344 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) |
f62b389e MD |
345 | /* |
346 | * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE | |
347 | * adding sched_stat support to SCHED_FIFO/RR would be welcome. | |
348 | */ | |
3bc29f0a | 349 | LTTNG_TRACEPOINT_EVENT_CLASS(sched_stat_template, |
f62b389e MD |
350 | |
351 | TP_PROTO(struct task_struct *tsk, u64 delay), | |
352 | ||
353 | TP_ARGS(tsk, delay), | |
354 | ||
f127e61e MD |
355 | TP_FIELDS( |
356 | ctf_array_text(char, comm, tsk->comm, TASK_COMM_LEN) | |
357 | ctf_integer(pid_t, tid, tsk->pid) | |
358 | ctf_integer(u64, delay, delay) | |
f62b389e | 359 | ) |
f62b389e MD |
360 | ) |
361 | ||
362 | ||
363 | /* | |
364 | * Tracepoint for accounting wait time (time the task is runnable | |
365 | * but not actually running due to scheduler contention). | |
366 | */ | |
3bc29f0a | 367 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_wait, |
f62b389e MD |
368 | TP_PROTO(struct task_struct *tsk, u64 delay), |
369 | TP_ARGS(tsk, delay)) | |
370 | ||
371 | /* | |
372 | * Tracepoint for accounting sleep time (time the task is not runnable, | |
373 | * including iowait, see below). | |
374 | */ | |
3bc29f0a | 375 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_sleep, |
f62b389e MD |
376 | TP_PROTO(struct task_struct *tsk, u64 delay), |
377 | TP_ARGS(tsk, delay)) | |
378 | ||
379 | /* | |
380 | * Tracepoint for accounting iowait time (time the task is not runnable | |
381 | * due to waiting on IO to complete). | |
382 | */ | |
3bc29f0a | 383 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_iowait, |
f62b389e MD |
384 | TP_PROTO(struct task_struct *tsk, u64 delay), |
385 | TP_ARGS(tsk, delay)) | |
386 | ||
7c68b363 AG |
387 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)) |
388 | /* | |
389 | * Tracepoint for accounting blocked time (time the task is in uninterruptible). | |
390 | */ | |
3bc29f0a | 391 | LTTNG_TRACEPOINT_EVENT_INSTANCE(sched_stat_template, sched_stat_blocked, |
7c68b363 AG |
392 | TP_PROTO(struct task_struct *tsk, u64 delay), |
393 | TP_ARGS(tsk, delay)) | |
394 | #endif | |
395 | ||
f62b389e MD |
396 | /* |
397 | * Tracepoint for accounting runtime (time the task is executing | |
398 | * on a CPU). | |
399 | */ | |
3bc29f0a | 400 | LTTNG_TRACEPOINT_EVENT(sched_stat_runtime, |
f62b389e MD |
401 | |
402 | TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime), | |
403 | ||
404 | TP_ARGS(tsk, runtime, vruntime), | |
405 | ||
f127e61e MD |
406 | TP_FIELDS( |
407 | ctf_array_text(char, comm, tsk->comm, TASK_COMM_LEN) | |
408 | ctf_integer(pid_t, tid, tsk->pid) | |
409 | ctf_integer(u64, runtime, runtime) | |
410 | ctf_integer(u64, vruntime, vruntime) | |
f62b389e | 411 | ) |
f62b389e | 412 | ) |
7c68b363 | 413 | #endif |
f62b389e | 414 | |
7c68b363 | 415 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) |
f62b389e MD |
416 | /* |
417 | * Tracepoint for showing priority inheritance modifying a tasks | |
418 | * priority. | |
419 | */ | |
3bc29f0a | 420 | LTTNG_TRACEPOINT_EVENT(sched_pi_setprio, |
f62b389e MD |
421 | |
422 | TP_PROTO(struct task_struct *tsk, int newprio), | |
423 | ||
424 | TP_ARGS(tsk, newprio), | |
425 | ||
f127e61e MD |
426 | TP_FIELDS( |
427 | ctf_array_text(char, comm, tsk->comm, TASK_COMM_LEN) | |
428 | ctf_integer(pid_t, tid, tsk->pid) | |
429 | ctf_integer(int, oldprio, tsk->prio - MAX_RT_PRIO) | |
430 | ctf_integer(int, newprio, newprio - MAX_RT_PRIO) | |
431 | ) | |
f62b389e | 432 | ) |
7c68b363 | 433 | #endif |
f62b389e | 434 | |
3bc29f0a | 435 | #endif /* LTTNG_TRACE_SCHED_H */ |
f62b389e MD |
436 | |
437 | /* This part must be outside protection */ | |
5b88d86e | 438 | #include "../../../probes/define_trace.h" |