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