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(4,2,0) || \
81 LTTNG_RHEL_KERNEL_RANGE(3,10,0,957,0,0, 3,11,0,0,0,0))
83 * timer_start - called when the timer is started
84 * @timer: pointer to struct timer_list
85 * @expires: the timers expiry time
86 * @flags: the timers expiry time
88 LTTNG_TRACEPOINT_EVENT(timer_start
,
90 TP_PROTO(struct timer_list
*timer
, unsigned long expires
,
93 TP_ARGS(timer
, expires
, flags
),
96 ctf_integer_hex(void *, timer
, timer
)
97 ctf_integer_hex(void *, function
, timer
->function
)
98 ctf_integer(unsigned long, expires
, expires
)
99 ctf_integer(unsigned long, now
, jiffies
)
100 ctf_integer(unsigned int, flags
, flags
)
103 #else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,2,0)) */
105 * timer_start - called when the timer is started
106 * @timer: pointer to struct timer_list
107 * @expires: the timers expiry time
109 LTTNG_TRACEPOINT_EVENT(timer_start
,
111 TP_PROTO(struct timer_list
*timer
, unsigned long expires
),
113 TP_ARGS(timer
, expires
),
116 ctf_integer_hex(void *, timer
, timer
)
117 ctf_integer_hex(void *, function
, timer
->function
)
118 ctf_integer(unsigned long, expires
, expires
)
119 ctf_integer(unsigned long, now
, jiffies
)
122 #endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,2,0)) */
124 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,2,0) || \
125 LTTNG_RHEL_KERNEL_RANGE(4,18,0,193,0,0, 4,19,0,0,0,0))
127 * timer_expire_entry - called immediately before the timer callback
128 * @timer: pointer to struct timer_list
130 * Allows to determine the timer latency.
132 LTTNG_TRACEPOINT_EVENT(timer_expire_entry
,
134 TP_PROTO(struct timer_list
*timer
, unsigned long baseclk
),
136 TP_ARGS(timer
, baseclk
),
139 ctf_integer_hex(void *, timer
, timer
)
140 ctf_integer(unsigned long, now
, jiffies
)
141 ctf_integer_hex(void *, function
, timer
->function
)
142 ctf_integer(unsigned long, baseclk
, baseclk
)
147 * timer_expire_entry - called immediately before the timer callback
148 * @timer: pointer to struct timer_list
150 * Allows to determine the timer latency.
152 LTTNG_TRACEPOINT_EVENT(timer_expire_entry
,
154 TP_PROTO(struct timer_list
*timer
),
159 ctf_integer_hex(void *, timer
, timer
)
160 ctf_integer(unsigned long, now
, jiffies
)
161 ctf_integer_hex(void *, function
, timer
->function
)
167 * timer_expire_exit - called immediately after the timer callback returns
168 * @timer: pointer to struct timer_list
170 * When used in combination with the timer_expire_entry tracepoint we can
171 * determine the runtime of the timer callback function.
173 * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
174 * be invalid. We solely track the pointer.
176 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_expire_exit
,
178 TP_PROTO(struct timer_list
*timer
),
184 * timer_cancel - called when the timer is canceled
185 * @timer: pointer to struct timer_list
187 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_cancel
,
189 TP_PROTO(struct timer_list
*timer
),
195 * hrtimer_init - called when the hrtimer is initialized
196 * @timer: pointer to struct hrtimer
197 * @clockid: the hrtimers clock
198 * @mode: the hrtimers mode
200 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_init
,
204 TP_PROTO(struct hrtimer
*hrtimer
, clockid_t clockid
,
205 enum hrtimer_mode mode
),
207 TP_ARGS(hrtimer
, clockid
, mode
),
210 ctf_integer_hex(void *, hrtimer
, hrtimer
)
211 ctf_integer(clockid_t
, clockid
, clockid
)
212 ctf_enum(hrtimer_mode
, unsigned int, mode
, mode
)
217 * hrtimer_start - called when the hrtimer is started
218 * @timer: pointer to struct hrtimer
220 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,16,0) || \
221 LTTNG_RT_KERNEL_RANGE(4,14,0,0, 4,15,0,0))
222 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
226 TP_PROTO(struct hrtimer
*hrtimer
, enum hrtimer_mode mode
),
228 TP_ARGS(hrtimer
, mode
),
231 ctf_integer_hex(void *, hrtimer
, hrtimer
)
232 ctf_integer_hex(void *, function
, hrtimer
->function
)
233 ctf_integer(s64
, expires
,
234 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
235 ctf_integer(s64
, softexpires
,
236 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
237 ctf_enum(hrtimer_mode
, unsigned int, mode
, mode
)
241 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
245 TP_PROTO(struct hrtimer
*hrtimer
),
250 ctf_integer_hex(void *, hrtimer
, hrtimer
)
251 ctf_integer_hex(void *, function
, hrtimer
->function
)
252 ctf_integer(s64
, expires
,
253 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
254 ctf_integer(s64
, softexpires
,
255 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
261 * htimmer_expire_entry - called immediately before the hrtimer callback
262 * @timer: pointer to struct hrtimer
263 * @now: pointer to variable which contains current time of the
266 * Allows to determine the timer latency.
268 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_expire_entry
,
270 timer_hrtimer_expire_entry
,
272 TP_PROTO(struct hrtimer
*hrtimer
, ktime_t
*now
),
274 TP_ARGS(hrtimer
, now
),
277 ctf_integer_hex(void *, hrtimer
, hrtimer
)
278 ctf_integer(s64
, now
, lttng_ktime_get_tv64(*now
))
279 ctf_integer_hex(void *, function
, hrtimer
->function
)
283 LTTNG_TRACEPOINT_EVENT_CLASS(timer_hrtimer_class
,
285 TP_PROTO(struct hrtimer
*hrtimer
),
290 ctf_integer_hex(void *, hrtimer
, hrtimer
)
295 * hrtimer_expire_exit - called immediately after the hrtimer callback returns
296 * @timer: pointer to struct hrtimer
298 * When used in combination with the hrtimer_expire_entry tracepoint we can
299 * determine the runtime of the callback function.
301 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_expire_exit
,
303 timer_hrtimer_expire_exit
,
305 TP_PROTO(struct hrtimer
*hrtimer
),
311 * hrtimer_cancel - called when the hrtimer is canceled
312 * @hrtimer: pointer to struct hrtimer
314 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_cancel
,
316 timer_hrtimer_cancel
,
318 TP_PROTO(struct hrtimer
*hrtimer
),
324 * itimer_state - called when itimer is started or canceled
325 * @which: name of the interval timer
326 * @value: the itimers value, itimer is canceled if value->it_value is
327 * zero, otherwise it is started
328 * @expires: the itimers expiry time
330 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,5,0))
331 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
335 TP_PROTO(int which
, const struct itimerspec64
*const value
,
336 unsigned long long expires
),
338 TP_ARGS(which
, value
, expires
),
341 ctf_integer(int, which
, which
)
342 ctf_integer(unsigned long long, expires
, expires
)
343 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
344 ctf_integer(long, value_nsec
, value
->it_value
.tv_nsec
)
345 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
346 ctf_integer(long, interval_nsec
, value
->it_interval
.tv_nsec
)
349 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0))
350 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
354 TP_PROTO(int which
, const struct itimerval
*const value
,
355 unsigned long long expires
),
357 TP_ARGS(which
, value
, expires
),
360 ctf_integer(int, which
, which
)
361 ctf_integer(unsigned long long, expires
, expires
)
362 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
363 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
364 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
365 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
368 #else /* if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
369 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
373 TP_PROTO(int which
, const struct itimerval
*const value
,
376 TP_ARGS(which
, value
, expires
),
379 ctf_integer(int, which
, which
)
380 ctf_integer(cputime_t
, expires
, expires
)
381 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
382 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
383 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
384 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
387 #endif /* #else (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
390 * itimer_expire - called when itimer expires
391 * @which: type of the interval timer
392 * @pid: pid of the process which owns the timer
393 * @now: current time, used to calculate the latency of itimer
395 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0))
396 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
400 TP_PROTO(int which
, struct pid
*pid
, unsigned long long now
),
402 TP_ARGS(which
, pid
, now
),
405 ctf_integer(int , which
, which
)
406 ctf_integer(pid_t
, pid
, pid_nr(pid
))
407 ctf_integer(unsigned long long, now
, now
)
410 #else /* if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
411 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
415 TP_PROTO(int which
, struct pid
*pid
, cputime_t now
),
417 TP_ARGS(which
, pid
, now
),
420 ctf_integer(int , which
, which
)
421 ctf_integer(pid_t
, pid
, pid_nr(pid
))
422 ctf_integer(cputime_t
, now
, now
)
425 #endif /* #else (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
427 #endif /* LTTNG_TRACE_TIMER_H */
429 /* This part must be outside protection */
430 #include <lttng/define_trace.h>