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