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
),
81 * timer_start - called when the timer is started
82 * @timer: pointer to struct timer_list
83 * @expires: the timers expiry time
84 * @flags: the timers expiry time
86 LTTNG_TRACEPOINT_EVENT(timer_start
,
88 TP_PROTO(struct timer_list
*timer
, unsigned long expires
,
91 TP_ARGS(timer
, expires
, flags
),
94 ctf_integer_hex(void *, timer
, timer
)
95 ctf_integer_hex(void *, function
, timer
->function
)
96 ctf_integer(unsigned long, expires
, expires
)
97 ctf_integer(unsigned long, now
, jiffies
)
98 ctf_integer(unsigned int, flags
, flags
)
102 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,2,0) || \
103 LTTNG_RHEL_KERNEL_RANGE(4,18,0,193,0,0, 4,19,0,0,0,0))
105 * timer_expire_entry - called immediately before the timer callback
106 * @timer: pointer to struct timer_list
108 * Allows to determine the timer latency.
110 LTTNG_TRACEPOINT_EVENT(timer_expire_entry
,
112 TP_PROTO(struct timer_list
*timer
, unsigned long baseclk
),
114 TP_ARGS(timer
, baseclk
),
117 ctf_integer_hex(void *, timer
, timer
)
118 ctf_integer(unsigned long, now
, jiffies
)
119 ctf_integer_hex(void *, function
, timer
->function
)
120 ctf_integer(unsigned long, baseclk
, baseclk
)
125 * timer_expire_entry - called immediately before the timer callback
126 * @timer: pointer to struct timer_list
128 * Allows to determine the timer latency.
130 LTTNG_TRACEPOINT_EVENT(timer_expire_entry
,
132 TP_PROTO(struct timer_list
*timer
),
137 ctf_integer_hex(void *, timer
, timer
)
138 ctf_integer(unsigned long, now
, jiffies
)
139 ctf_integer_hex(void *, function
, timer
->function
)
145 * timer_expire_exit - called immediately after the timer callback returns
146 * @timer: pointer to struct timer_list
148 * When used in combination with the timer_expire_entry tracepoint we can
149 * determine the runtime of the timer callback function.
151 * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
152 * be invalid. We solely track the pointer.
154 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_expire_exit
,
156 TP_PROTO(struct timer_list
*timer
),
162 * timer_cancel - called when the timer is canceled
163 * @timer: pointer to struct timer_list
165 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_cancel
,
167 TP_PROTO(struct timer_list
*timer
),
173 * hrtimer_init - called when the hrtimer is initialized
174 * @timer: pointer to struct hrtimer
175 * @clockid: the hrtimers clock
176 * @mode: the hrtimers mode
178 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_init
,
182 TP_PROTO(struct hrtimer
*hrtimer
, clockid_t clockid
,
183 enum hrtimer_mode mode
),
185 TP_ARGS(hrtimer
, clockid
, mode
),
188 ctf_integer_hex(void *, hrtimer
, hrtimer
)
189 ctf_integer(clockid_t
, clockid
, clockid
)
190 ctf_enum(hrtimer_mode
, unsigned int, mode
, mode
)
195 * hrtimer_start - called when the hrtimer is started
196 * @timer: pointer to struct hrtimer
198 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,16,0) || \
199 LTTNG_RT_KERNEL_RANGE(4,14,0,0, 4,15,0,0))
200 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
204 TP_PROTO(struct hrtimer
*hrtimer
, enum hrtimer_mode mode
),
206 TP_ARGS(hrtimer
, mode
),
209 ctf_integer_hex(void *, hrtimer
, hrtimer
)
210 ctf_integer_hex(void *, function
, hrtimer
->function
)
211 ctf_integer(s64
, expires
,
212 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
213 ctf_integer(s64
, softexpires
,
214 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
215 ctf_enum(hrtimer_mode
, unsigned int, mode
, mode
)
219 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
223 TP_PROTO(struct hrtimer
*hrtimer
),
228 ctf_integer_hex(void *, hrtimer
, hrtimer
)
229 ctf_integer_hex(void *, function
, hrtimer
->function
)
230 ctf_integer(s64
, expires
,
231 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
232 ctf_integer(s64
, softexpires
,
233 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
239 * htimmer_expire_entry - called immediately before the hrtimer callback
240 * @timer: pointer to struct hrtimer
241 * @now: pointer to variable which contains current time of the
244 * Allows to determine the timer latency.
246 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_expire_entry
,
248 timer_hrtimer_expire_entry
,
250 TP_PROTO(struct hrtimer
*hrtimer
, ktime_t
*now
),
252 TP_ARGS(hrtimer
, now
),
255 ctf_integer_hex(void *, hrtimer
, hrtimer
)
256 ctf_integer(s64
, now
, lttng_ktime_get_tv64(*now
))
257 ctf_integer_hex(void *, function
, hrtimer
->function
)
261 LTTNG_TRACEPOINT_EVENT_CLASS(timer_hrtimer_class
,
263 TP_PROTO(struct hrtimer
*hrtimer
),
268 ctf_integer_hex(void *, hrtimer
, hrtimer
)
273 * hrtimer_expire_exit - called immediately after the hrtimer callback returns
274 * @timer: pointer to struct hrtimer
276 * When used in combination with the hrtimer_expire_entry tracepoint we can
277 * determine the runtime of the callback function.
279 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_expire_exit
,
281 timer_hrtimer_expire_exit
,
283 TP_PROTO(struct hrtimer
*hrtimer
),
289 * hrtimer_cancel - called when the hrtimer is canceled
290 * @hrtimer: pointer to struct hrtimer
292 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_cancel
,
294 timer_hrtimer_cancel
,
296 TP_PROTO(struct hrtimer
*hrtimer
),
302 * itimer_state - called when itimer is started or canceled
303 * @which: name of the interval timer
304 * @value: the itimers value, itimer is canceled if value->it_value is
305 * zero, otherwise it is started
306 * @expires: the itimers expiry time
308 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,5,0))
309 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
313 TP_PROTO(int which
, const struct itimerspec64
*const value
,
314 unsigned long long expires
),
316 TP_ARGS(which
, value
, expires
),
319 ctf_integer(int, which
, which
)
320 ctf_integer(unsigned long long, expires
, expires
)
321 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
322 ctf_integer(long, value_nsec
, value
->it_value
.tv_nsec
)
323 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
324 ctf_integer(long, interval_nsec
, value
->it_interval
.tv_nsec
)
327 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0))
328 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
332 TP_PROTO(int which
, const struct itimerval
*const value
,
333 unsigned long long expires
),
335 TP_ARGS(which
, value
, expires
),
338 ctf_integer(int, which
, which
)
339 ctf_integer(unsigned long long, expires
, expires
)
340 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
341 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
342 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
343 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
346 #else /* if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
347 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
351 TP_PROTO(int which
, const struct itimerval
*const value
,
354 TP_ARGS(which
, value
, expires
),
357 ctf_integer(int, which
, which
)
358 ctf_integer(cputime_t
, expires
, expires
)
359 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
360 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
361 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
362 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
365 #endif /* #else (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
368 * itimer_expire - called when itimer expires
369 * @which: type of the interval timer
370 * @pid: pid of the process which owns the timer
371 * @now: current time, used to calculate the latency of itimer
373 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0))
374 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
378 TP_PROTO(int which
, struct pid
*pid
, unsigned long long now
),
380 TP_ARGS(which
, pid
, now
),
383 ctf_integer(int , which
, which
)
384 ctf_integer(pid_t
, pid
, pid_nr(pid
))
385 ctf_integer(unsigned long long, now
, now
)
388 #else /* if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
389 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
393 TP_PROTO(int which
, struct pid
*pid
, cputime_t now
),
395 TP_ARGS(which
, pid
, now
),
398 ctf_integer(int , which
, which
)
399 ctf_integer(pid_t
, pid
, pid_nr(pid
))
400 ctf_integer(cputime_t
, now
, now
)
403 #endif /* #else (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
405 #endif /* LTTNG_TRACE_TIMER_H */
407 /* This part must be outside protection */
408 #include <lttng/define_trace.h>