1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #define TRACE_SYSTEM timer
5 #if !defined(LTTNG_TRACE_TIMER_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define LTTNG_TRACE_TIMER_H
8 #include <lttng/tracepoint-event.h>
10 #ifndef _TRACE_TIMER_DEF_
11 #define _TRACE_TIMER_DEF_
12 #include <linux/hrtimer.h>
13 #include <linux/timer.h>
14 #include <lttng/kernel-version.h>
18 #endif /* _TRACE_TIMER_DEF_ */
20 LTTNG_TRACEPOINT_ENUM(hrtimer_mode
,
22 ctf_enum_value("HRTIMER_MODE_ABS", HRTIMER_MODE_ABS
)
23 ctf_enum_value("HRTIMER_MODE_REL", HRTIMER_MODE_REL
)
24 ctf_enum_value("HRTIMER_MODE_PINNED", HRTIMER_MODE_PINNED
)
25 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,16,0))
26 ctf_enum_value("HRTIMER_MODE_SOFT", HRTIMER_MODE_SOFT
)
28 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,4,0))
29 ctf_enum_value("HRTIMER_MODE_HARD", HRTIMER_MODE_HARD
)
32 ctf_enum_value("HRTIMER_MODE_ABS_PINNED", HRTIMER_MODE_ABS_PINNED
)
33 ctf_enum_value("HRTIMER_MODE_REL_PINNED", HRTIMER_MODE_REL_PINNED
)
35 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,16,0))
36 ctf_enum_value("HRTIMER_MODE_ABS_SOFT", HRTIMER_MODE_ABS_SOFT
)
37 ctf_enum_value("HRTIMER_MODE_REL_SOFT", HRTIMER_MODE_REL_SOFT
)
39 ctf_enum_value("HRTIMER_MODE_ABS_PINNED_SOFT", HRTIMER_MODE_ABS_PINNED_SOFT
)
40 ctf_enum_value("HRTIMER_MODE_REL_PINNED_SOFT", HRTIMER_MODE_REL_PINNED_SOFT
)
42 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,4,0))
43 ctf_enum_value("HRTIMER_MODE_ABS_HARD", HRTIMER_MODE_ABS_HARD
)
44 ctf_enum_value("HRTIMER_MODE_REL_HARD", HRTIMER_MODE_REL_HARD
)
46 ctf_enum_value("HRTIMER_MODE_ABS_PINNED_HARD", HRTIMER_MODE_ABS_PINNED_HARD
)
47 ctf_enum_value("HRTIMER_MODE_REL_PINNED_HARD", HRTIMER_MODE_REL_PINNED_HARD
)
52 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
53 #define lttng_ktime_get_tv64(kt) (kt)
54 #else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
55 #define lttng_ktime_get_tv64(kt) ((kt).tv64)
56 #endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
58 LTTNG_TRACEPOINT_EVENT_CLASS(timer_class
,
60 TP_PROTO(struct timer_list
*timer
),
65 ctf_integer_hex(void *, timer
, timer
)
70 * timer_init - called when the timer is initialized
71 * @timer: pointer to struct timer_list
73 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_init
,
75 TP_PROTO(struct timer_list
*timer
),
80 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,8,0))
82 * timer_start - called when the timer is started
83 * @timer: pointer to struct timer_list
84 * @expires: the timers expiry time
85 * @flags: the timers expiry time
87 LTTNG_TRACEPOINT_EVENT(timer_start
,
89 TP_PROTO(struct timer_list
*timer
, unsigned long bucket_expiry
),
91 TP_ARGS(timer
, bucket_expiry
),
94 ctf_integer_hex(void *, timer
, timer
)
95 ctf_integer_hex(void *, function
, timer
->function
)
96 ctf_integer(unsigned long, expires
, timer
->expires
)
97 ctf_integer(unsigned long, bucket_expiry
, bucket_expiry
)
98 ctf_integer(unsigned long, now
, jiffies
)
99 ctf_integer(unsigned int, flags
, timer
->flags
)
104 * timer_start - called when the timer is started
105 * @timer: pointer to struct timer_list
106 * @expires: the timers expiry time
107 * @flags: the timers expiry time
109 LTTNG_TRACEPOINT_EVENT(timer_start
,
111 TP_PROTO(struct timer_list
*timer
, unsigned long expires
,
114 TP_ARGS(timer
, expires
, flags
),
117 ctf_integer_hex(void *, timer
, timer
)
118 ctf_integer_hex(void *, function
, timer
->function
)
119 ctf_integer(unsigned long, expires
, expires
)
120 ctf_integer(unsigned long, now
, jiffies
)
121 ctf_integer(unsigned int, flags
, flags
)
126 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,2,0) || \
127 LTTNG_KERNEL_RANGE(4,19,312, 4,20,0) || \
128 LTTNG_RHEL_KERNEL_RANGE(4,18,0,193,0,0, 4,19,0,0,0,0))
130 * timer_expire_entry - called immediately before the timer callback
131 * @timer: pointer to struct timer_list
133 * Allows to determine the timer latency.
135 LTTNG_TRACEPOINT_EVENT(timer_expire_entry
,
137 TP_PROTO(struct timer_list
*timer
, unsigned long baseclk
),
139 TP_ARGS(timer
, baseclk
),
142 ctf_integer_hex(void *, timer
, timer
)
143 ctf_integer(unsigned long, now
, jiffies
)
144 ctf_integer_hex(void *, function
, timer
->function
)
145 ctf_integer(unsigned long, baseclk
, baseclk
)
150 * timer_expire_entry - called immediately before the timer callback
151 * @timer: pointer to struct timer_list
153 * Allows to determine the timer latency.
155 LTTNG_TRACEPOINT_EVENT(timer_expire_entry
,
157 TP_PROTO(struct timer_list
*timer
),
162 ctf_integer_hex(void *, timer
, timer
)
163 ctf_integer(unsigned long, now
, jiffies
)
164 ctf_integer_hex(void *, function
, timer
->function
)
170 * timer_expire_exit - called immediately after the timer callback returns
171 * @timer: pointer to struct timer_list
173 * When used in combination with the timer_expire_entry tracepoint we can
174 * determine the runtime of the timer callback function.
176 * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
177 * be invalid. We solely track the pointer.
179 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_expire_exit
,
181 TP_PROTO(struct timer_list
*timer
),
187 * timer_cancel - called when the timer is canceled
188 * @timer: pointer to struct timer_list
190 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_cancel
,
192 TP_PROTO(struct timer_list
*timer
),
198 * hrtimer_init - called when the hrtimer is initialized
199 * @timer: pointer to struct hrtimer
200 * @clockid: the hrtimers clock
201 * @mode: the hrtimers mode
203 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_init
,
207 TP_PROTO(struct hrtimer
*hrtimer
, clockid_t clockid
,
208 enum hrtimer_mode mode
),
210 TP_ARGS(hrtimer
, clockid
, mode
),
213 ctf_integer_hex(void *, hrtimer
, hrtimer
)
214 ctf_integer(clockid_t
, clockid
, clockid
)
215 ctf_enum(hrtimer_mode
, unsigned int, mode
, mode
)
220 * hrtimer_start - called when the hrtimer is started
221 * @timer: pointer to struct hrtimer
223 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,16,0) || \
224 LTTNG_RT_KERNEL_RANGE(4,14,0,0, 4,15,0,0))
225 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
229 TP_PROTO(struct hrtimer
*hrtimer
, enum hrtimer_mode mode
),
231 TP_ARGS(hrtimer
, mode
),
234 ctf_integer_hex(void *, hrtimer
, hrtimer
)
235 ctf_integer_hex(void *, function
, hrtimer
->function
)
236 ctf_integer(s64
, expires
,
237 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
238 ctf_integer(s64
, softexpires
,
239 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
240 ctf_enum(hrtimer_mode
, unsigned int, mode
, mode
)
244 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
248 TP_PROTO(struct hrtimer
*hrtimer
),
253 ctf_integer_hex(void *, hrtimer
, hrtimer
)
254 ctf_integer_hex(void *, function
, hrtimer
->function
)
255 ctf_integer(s64
, expires
,
256 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
257 ctf_integer(s64
, softexpires
,
258 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
264 * htimmer_expire_entry - called immediately before the hrtimer callback
265 * @timer: pointer to struct hrtimer
266 * @now: pointer to variable which contains current time of the
269 * Allows to determine the timer latency.
271 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_expire_entry
,
273 timer_hrtimer_expire_entry
,
275 TP_PROTO(struct hrtimer
*hrtimer
, ktime_t
*now
),
277 TP_ARGS(hrtimer
, now
),
280 ctf_integer_hex(void *, hrtimer
, hrtimer
)
281 ctf_integer(s64
, now
, lttng_ktime_get_tv64(*now
))
282 ctf_integer_hex(void *, function
, hrtimer
->function
)
286 LTTNG_TRACEPOINT_EVENT_CLASS(timer_hrtimer_class
,
288 TP_PROTO(struct hrtimer
*hrtimer
),
293 ctf_integer_hex(void *, hrtimer
, hrtimer
)
298 * hrtimer_expire_exit - called immediately after the hrtimer callback returns
299 * @timer: pointer to struct hrtimer
301 * When used in combination with the hrtimer_expire_entry tracepoint we can
302 * determine the runtime of the callback function.
304 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_expire_exit
,
306 timer_hrtimer_expire_exit
,
308 TP_PROTO(struct hrtimer
*hrtimer
),
314 * hrtimer_cancel - called when the hrtimer is canceled
315 * @hrtimer: pointer to struct hrtimer
317 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_cancel
,
319 timer_hrtimer_cancel
,
321 TP_PROTO(struct hrtimer
*hrtimer
),
327 * itimer_state - called when itimer is started or canceled
328 * @which: name of the interval timer
329 * @value: the itimers value, itimer is canceled if value->it_value is
330 * zero, otherwise it is started
331 * @expires: the itimers expiry time
333 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,5,0))
334 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
338 TP_PROTO(int which
, const struct itimerspec64
*const value
,
339 unsigned long long expires
),
341 TP_ARGS(which
, value
, expires
),
344 ctf_integer(int, which
, which
)
345 ctf_integer(unsigned long long, expires
, expires
)
346 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
347 ctf_integer(long, value_nsec
, value
->it_value
.tv_nsec
)
348 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
349 ctf_integer(long, interval_nsec
, value
->it_interval
.tv_nsec
)
352 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0))
353 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
357 TP_PROTO(int which
, const struct itimerval
*const value
,
358 unsigned long long expires
),
360 TP_ARGS(which
, value
, expires
),
363 ctf_integer(int, which
, which
)
364 ctf_integer(unsigned long long, expires
, expires
)
365 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
366 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
367 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
368 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
371 #else /* if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
372 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
376 TP_PROTO(int which
, const struct itimerval
*const value
,
379 TP_ARGS(which
, value
, expires
),
382 ctf_integer(int, which
, which
)
383 ctf_integer(cputime_t
, expires
, expires
)
384 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
385 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
386 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
387 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
390 #endif /* #else (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
393 * itimer_expire - called when itimer expires
394 * @which: type of the interval timer
395 * @pid: pid of the process which owns the timer
396 * @now: current time, used to calculate the latency of itimer
398 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0))
399 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
403 TP_PROTO(int which
, struct pid
*pid
, unsigned long long now
),
405 TP_ARGS(which
, pid
, now
),
408 ctf_integer(int , which
, which
)
409 ctf_integer(pid_t
, pid
, pid_nr(pid
))
410 ctf_integer(unsigned long long, now
, now
)
413 #else /* if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
414 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
418 TP_PROTO(int which
, struct pid
*pid
, cputime_t now
),
420 TP_ARGS(which
, pid
, now
),
423 ctf_integer(int , which
, which
)
424 ctf_integer(pid_t
, pid
, pid_nr(pid
))
425 ctf_integer(cputime_t
, now
, now
)
428 #endif /* #else (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
430 #endif /* LTTNG_TRACE_TIMER_H */
432 /* This part must be outside protection */
433 #include <lttng/define_trace.h>