lttng-module: sched.h: Fix compilation on 3.9 kernel
[lttng-modules.git] / instrumentation / events / lttng-module / sched.h
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 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,9,0))
10 #include <linux/sched/rt.h>
11 #endif
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(
43 __array_text( char, comm, TASK_COMM_LEN )
44 __field( pid_t, tid )
45 ),
46
47 TP_fast_assign(
48 tp_memcpy(comm, t->comm, TASK_COMM_LEN)
49 tp_assign(tid, t->pid)
50 ),
51
52 TP_printk("comm=%s tid=%d", __entry->comm, __entry->tid)
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
80 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
81 TP_PROTO(struct task_struct *p, int success),
82
83 TP_ARGS(p, success),
84 #else
85 TP_PROTO(struct rq *rq, struct task_struct *p, int success),
86
87 TP_ARGS(rq, p, success),
88 #endif
89
90 TP_STRUCT__entry(
91 __array_text( char, comm, TASK_COMM_LEN )
92 __field( pid_t, tid )
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)
100 tp_assign(tid, p->pid)
101 tp_assign(prio, p->prio)
102 tp_assign(success, success)
103 tp_assign(target_cpu, task_cpu(p))
104 ),
105
106 TP_printk("comm=%s tid=%d prio=%d success=%d target_cpu=%03d",
107 __entry->comm, __entry->tid, __entry->prio,
108 __entry->success, __entry->target_cpu)
109 )
110
111 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
112
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
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
139 /*
140 * Tracepoint for task switches, performed by the scheduler:
141 */
142 TRACE_EVENT(sched_switch,
143
144 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
145 TP_PROTO(struct task_struct *prev,
146 struct task_struct *next),
147
148 TP_ARGS(prev, next),
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)) */
155
156 TP_STRUCT__entry(
157 __array_text( char, prev_comm, TASK_COMM_LEN )
158 __field( pid_t, prev_tid )
159 __field( int, prev_prio )
160 __field( long, prev_state )
161 __array_text( char, next_comm, TASK_COMM_LEN )
162 __field( pid_t, next_tid )
163 __field( int, next_prio )
164 ),
165
166 TP_fast_assign(
167 tp_memcpy(next_comm, next->comm, TASK_COMM_LEN)
168 tp_assign(prev_tid, prev->pid)
169 tp_assign(prev_prio, prev->prio - MAX_RT_PRIO)
170 tp_assign(prev_state, __trace_sched_switch_state(prev))
171 tp_memcpy(prev_comm, prev->comm, TASK_COMM_LEN)
172 tp_assign(next_tid, next->pid)
173 tp_assign(next_prio, next->prio - MAX_RT_PRIO)
174 ),
175
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,
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",
183 __entry->next_comm, __entry->next_tid, __entry->next_prio)
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(
196 __array_text( char, comm, TASK_COMM_LEN )
197 __field( pid_t, tid )
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)
205 tp_assign(tid, p->pid)
206 tp_assign(prio, p->prio - MAX_RT_PRIO)
207 tp_assign(orig_cpu, task_cpu(p))
208 tp_assign(dest_cpu, dest_cpu)
209 ),
210
211 TP_printk("comm=%s tid=%d prio=%d orig_cpu=%d dest_cpu=%d",
212 __entry->comm, __entry->tid, __entry->prio,
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(
223 __array_text( char, comm, TASK_COMM_LEN )
224 __field( pid_t, tid )
225 __field( int, prio )
226 ),
227
228 TP_fast_assign(
229 tp_memcpy(comm, p->comm, TASK_COMM_LEN)
230 tp_assign(tid, p->pid)
231 tp_assign(prio, p->prio - MAX_RT_PRIO)
232 ),
233
234 TP_printk("comm=%s tid=%d prio=%d",
235 __entry->comm, __entry->tid, __entry->prio)
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 */
256 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
257 DEFINE_EVENT(sched_process_template, sched_wait_task,
258 TP_PROTO(struct task_struct *p),
259 TP_ARGS(p))
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)) */
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(
276 __array_text( char, comm, TASK_COMM_LEN )
277 __field( pid_t, tid )
278 __field( int, prio )
279 ),
280
281 TP_fast_assign(
282 tp_memcpy(comm, current->comm, TASK_COMM_LEN)
283 tp_assign(tid, pid_nr(pid))
284 tp_assign(prio, current->prio - MAX_RT_PRIO)
285 ),
286
287 TP_printk("comm=%s tid=%d prio=%d",
288 __entry->comm, __entry->tid, __entry->prio)
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(
301 __array_text( char, parent_comm, TASK_COMM_LEN )
302 __field( pid_t, parent_tid )
303 __array_text( char, child_comm, TASK_COMM_LEN )
304 __field( pid_t, child_tid )
305 ),
306
307 TP_fast_assign(
308 tp_memcpy(parent_comm, parent->comm, TASK_COMM_LEN)
309 tp_assign(parent_tid, parent->pid)
310 tp_memcpy(child_comm, child->comm, TASK_COMM_LEN)
311 tp_assign(child_tid, child->pid)
312 ),
313
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)
317 )
318
319 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
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 )
345 #endif
346
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(
358 __array_text( char, comm, TASK_COMM_LEN )
359 __field( pid_t, tid )
360 __field( u64, delay )
361 ),
362
363 TP_fast_assign(
364 tp_memcpy(comm, tsk->comm, TASK_COMM_LEN)
365 tp_assign(tid, tsk->pid)
366 tp_assign(delay, delay)
367 )
368 TP_perf_assign(
369 __perf_count(delay)
370 ),
371
372 TP_printk("comm=%s tid=%d delay=%Lu [ns]",
373 __entry->comm, __entry->tid,
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(
413 __array_text( char, comm, TASK_COMM_LEN )
414 __field( pid_t, tid )
415 __field( u64, runtime )
416 __field( u64, vruntime )
417 ),
418
419 TP_fast_assign(
420 tp_memcpy(comm, tsk->comm, TASK_COMM_LEN)
421 tp_assign(tid, tsk->pid)
422 tp_assign(runtime, runtime)
423 tp_assign(vruntime, vruntime)
424 )
425 TP_perf_assign(
426 __perf_count(runtime)
427 ),
428
429 TP_printk("comm=%s tid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
430 __entry->comm, __entry->tid,
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(
446 __array_text( char, comm, TASK_COMM_LEN )
447 __field( pid_t, tid )
448 __field( int, oldprio )
449 __field( int, newprio )
450 ),
451
452 TP_fast_assign(
453 tp_memcpy(comm, tsk->comm, TASK_COMM_LEN)
454 tp_assign(tid, tsk->pid)
455 tp_assign(oldprio, tsk->prio - MAX_RT_PRIO)
456 tp_assign(newprio, newprio - MAX_RT_PRIO)
457 ),
458
459 TP_printk("comm=%s tid=%d oldprio=%d newprio=%d",
460 __entry->comm, __entry->tid,
461 __entry->oldprio, __entry->newprio)
462 )
463
464 #endif /* _TRACE_SCHED_H */
465
466 /* This part must be outside protection */
467 #include "../../../probes/define_trace.h"
This page took 0.039214 seconds and 4 git commands to generate.