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