1 // SPDX-FileCopyrightText: 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
3 // SPDX-License-Identifier: GPL-2.0-only
6 #define TRACE_SYSTEM timer
8 #if !defined(LTTNG_TRACE_TIMER_H) || defined(TRACE_HEADER_MULTI_READ)
9 #define LTTNG_TRACE_TIMER_H
11 #include <lttng/tracepoint-event.h>
13 #ifndef _TRACE_TIMER_DEF_
14 #define _TRACE_TIMER_DEF_
15 #include <linux/hrtimer.h>
16 #include <linux/timer.h>
17 #include <lttng/kernel-version.h>
21 #endif /* _TRACE_TIMER_DEF_ */
23 LTTNG_TRACEPOINT_ENUM(hrtimer_mode
,
25 ctf_enum_value("HRTIMER_MODE_ABS", HRTIMER_MODE_ABS
)
26 ctf_enum_value("HRTIMER_MODE_REL", HRTIMER_MODE_REL
)
27 ctf_enum_value("HRTIMER_MODE_PINNED", HRTIMER_MODE_PINNED
)
28 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,16,0))
29 ctf_enum_value("HRTIMER_MODE_SOFT", HRTIMER_MODE_SOFT
)
31 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,4,0))
32 ctf_enum_value("HRTIMER_MODE_HARD", HRTIMER_MODE_HARD
)
35 ctf_enum_value("HRTIMER_MODE_ABS_PINNED", HRTIMER_MODE_ABS_PINNED
)
36 ctf_enum_value("HRTIMER_MODE_REL_PINNED", HRTIMER_MODE_REL_PINNED
)
38 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,16,0))
39 ctf_enum_value("HRTIMER_MODE_ABS_SOFT", HRTIMER_MODE_ABS_SOFT
)
40 ctf_enum_value("HRTIMER_MODE_REL_SOFT", HRTIMER_MODE_REL_SOFT
)
42 ctf_enum_value("HRTIMER_MODE_ABS_PINNED_SOFT", HRTIMER_MODE_ABS_PINNED_SOFT
)
43 ctf_enum_value("HRTIMER_MODE_REL_PINNED_SOFT", HRTIMER_MODE_REL_PINNED_SOFT
)
45 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,4,0))
46 ctf_enum_value("HRTIMER_MODE_ABS_HARD", HRTIMER_MODE_ABS_HARD
)
47 ctf_enum_value("HRTIMER_MODE_REL_HARD", HRTIMER_MODE_REL_HARD
)
49 ctf_enum_value("HRTIMER_MODE_ABS_PINNED_HARD", HRTIMER_MODE_ABS_PINNED_HARD
)
50 ctf_enum_value("HRTIMER_MODE_REL_PINNED_HARD", HRTIMER_MODE_REL_PINNED_HARD
)
55 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0))
56 #define lttng_ktime_get_tv64(kt) (kt)
57 #else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
58 #define lttng_ktime_get_tv64(kt) ((kt).tv64)
59 #endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */
61 LTTNG_TRACEPOINT_EVENT_CLASS(timer_class
,
63 TP_PROTO(struct timer_list
*timer
),
68 ctf_integer_hex(void *, timer
, timer
)
73 * timer_init - called when the timer is initialized
74 * @timer: pointer to struct timer_list
76 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_init
,
78 TP_PROTO(struct timer_list
*timer
),
83 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,8,0) || \
84 LTTNG_RHEL_KERNEL_RANGE(5,14,0,457,0,0, 5,15,0,0,0,0))
86 * timer_start - called when the timer is started
87 * @timer: pointer to struct timer_list
88 * @expires: the timers expiry time
89 * @flags: the timers expiry time
91 LTTNG_TRACEPOINT_EVENT(timer_start
,
93 TP_PROTO(struct timer_list
*timer
, unsigned long bucket_expiry
),
95 TP_ARGS(timer
, bucket_expiry
),
98 ctf_integer_hex(void *, timer
, timer
)
99 ctf_integer_hex(void *, function
, timer
->function
)
100 ctf_integer(unsigned long, expires
, timer
->expires
)
101 ctf_integer(unsigned long, bucket_expiry
, bucket_expiry
)
102 ctf_integer(unsigned long, now
, jiffies
)
103 ctf_integer(unsigned int, flags
, timer
->flags
)
108 * timer_start - called when the timer is started
109 * @timer: pointer to struct timer_list
110 * @expires: the timers expiry time
111 * @flags: the timers expiry time
113 LTTNG_TRACEPOINT_EVENT(timer_start
,
115 TP_PROTO(struct timer_list
*timer
, unsigned long expires
,
118 TP_ARGS(timer
, expires
, flags
),
121 ctf_integer_hex(void *, timer
, timer
)
122 ctf_integer_hex(void *, function
, timer
->function
)
123 ctf_integer(unsigned long, expires
, expires
)
124 ctf_integer(unsigned long, now
, jiffies
)
125 ctf_integer(unsigned int, flags
, flags
)
130 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,2,0) || \
131 LTTNG_KERNEL_RANGE(4,19,312, 4,20,0) || \
132 LTTNG_RHEL_KERNEL_RANGE(4,18,0,193,0,0, 4,19,0,0,0,0))
134 * timer_expire_entry - called immediately before the timer callback
135 * @timer: pointer to struct timer_list
137 * Allows to determine the timer latency.
139 LTTNG_TRACEPOINT_EVENT(timer_expire_entry
,
141 TP_PROTO(struct timer_list
*timer
, unsigned long baseclk
),
143 TP_ARGS(timer
, baseclk
),
146 ctf_integer_hex(void *, timer
, timer
)
147 ctf_integer(unsigned long, now
, jiffies
)
148 ctf_integer_hex(void *, function
, timer
->function
)
149 ctf_integer(unsigned long, baseclk
, baseclk
)
154 * timer_expire_entry - called immediately before the timer callback
155 * @timer: pointer to struct timer_list
157 * Allows to determine the timer latency.
159 LTTNG_TRACEPOINT_EVENT(timer_expire_entry
,
161 TP_PROTO(struct timer_list
*timer
),
166 ctf_integer_hex(void *, timer
, timer
)
167 ctf_integer(unsigned long, now
, jiffies
)
168 ctf_integer_hex(void *, function
, timer
->function
)
174 * timer_expire_exit - called immediately after the timer callback returns
175 * @timer: pointer to struct timer_list
177 * When used in combination with the timer_expire_entry tracepoint we can
178 * determine the runtime of the timer callback function.
180 * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
181 * be invalid. We solely track the pointer.
183 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_expire_exit
,
185 TP_PROTO(struct timer_list
*timer
),
191 * timer_cancel - called when the timer is canceled
192 * @timer: pointer to struct timer_list
194 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_cancel
,
196 TP_PROTO(struct timer_list
*timer
),
202 * hrtimer_init - called when the hrtimer is initialized
203 * @timer: pointer to struct hrtimer
204 * @clockid: the hrtimers clock
205 * @mode: the hrtimers mode
207 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_init
,
211 TP_PROTO(struct hrtimer
*hrtimer
, clockid_t clockid
,
212 enum hrtimer_mode mode
),
214 TP_ARGS(hrtimer
, clockid
, mode
),
217 ctf_integer_hex(void *, hrtimer
, hrtimer
)
218 ctf_integer(clockid_t
, clockid
, clockid
)
219 ctf_enum(hrtimer_mode
, unsigned int, mode
, mode
)
224 * hrtimer_start - called when the hrtimer is started
225 * @timer: pointer to struct hrtimer
227 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,16,0) || \
228 LTTNG_RT_KERNEL_RANGE(4,14,0,0, 4,15,0,0))
229 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
233 TP_PROTO(struct hrtimer
*hrtimer
, enum hrtimer_mode mode
),
235 TP_ARGS(hrtimer
, mode
),
238 ctf_integer_hex(void *, hrtimer
, hrtimer
)
239 ctf_integer_hex(void *, function
, hrtimer
->function
)
240 ctf_integer(s64
, expires
,
241 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
242 ctf_integer(s64
, softexpires
,
243 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
244 ctf_enum(hrtimer_mode
, unsigned int, mode
, mode
)
248 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
252 TP_PROTO(struct hrtimer
*hrtimer
),
257 ctf_integer_hex(void *, hrtimer
, hrtimer
)
258 ctf_integer_hex(void *, function
, hrtimer
->function
)
259 ctf_integer(s64
, expires
,
260 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
261 ctf_integer(s64
, softexpires
,
262 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
268 * htimmer_expire_entry - called immediately before the hrtimer callback
269 * @timer: pointer to struct hrtimer
270 * @now: pointer to variable which contains current time of the
273 * Allows to determine the timer latency.
275 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_expire_entry
,
277 timer_hrtimer_expire_entry
,
279 TP_PROTO(struct hrtimer
*hrtimer
, ktime_t
*now
),
281 TP_ARGS(hrtimer
, now
),
284 ctf_integer_hex(void *, hrtimer
, hrtimer
)
285 ctf_integer(s64
, now
, lttng_ktime_get_tv64(*now
))
286 ctf_integer_hex(void *, function
, hrtimer
->function
)
290 LTTNG_TRACEPOINT_EVENT_CLASS(timer_hrtimer_class
,
292 TP_PROTO(struct hrtimer
*hrtimer
),
297 ctf_integer_hex(void *, hrtimer
, hrtimer
)
302 * hrtimer_expire_exit - called immediately after the hrtimer callback returns
303 * @timer: pointer to struct hrtimer
305 * When used in combination with the hrtimer_expire_entry tracepoint we can
306 * determine the runtime of the callback function.
308 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_expire_exit
,
310 timer_hrtimer_expire_exit
,
312 TP_PROTO(struct hrtimer
*hrtimer
),
318 * hrtimer_cancel - called when the hrtimer is canceled
319 * @hrtimer: pointer to struct hrtimer
321 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_cancel
,
323 timer_hrtimer_cancel
,
325 TP_PROTO(struct hrtimer
*hrtimer
),
331 * itimer_state - called when itimer is started or canceled
332 * @which: name of the interval timer
333 * @value: the itimers value, itimer is canceled if value->it_value is
334 * zero, otherwise it is started
335 * @expires: the itimers expiry time
337 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,5,0))
338 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
342 TP_PROTO(int which
, const struct itimerspec64
*const value
,
343 unsigned long long expires
),
345 TP_ARGS(which
, value
, expires
),
348 ctf_integer(int, which
, which
)
349 ctf_integer(unsigned long long, expires
, expires
)
350 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
351 ctf_integer(long, value_nsec
, value
->it_value
.tv_nsec
)
352 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
353 ctf_integer(long, interval_nsec
, value
->it_interval
.tv_nsec
)
356 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0))
357 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
361 TP_PROTO(int which
, const struct itimerval
*const value
,
362 unsigned long long expires
),
364 TP_ARGS(which
, value
, expires
),
367 ctf_integer(int, which
, which
)
368 ctf_integer(unsigned long long, expires
, expires
)
369 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
370 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
371 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
372 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
375 #else /* if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
376 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
380 TP_PROTO(int which
, const struct itimerval
*const value
,
383 TP_ARGS(which
, value
, expires
),
386 ctf_integer(int, which
, which
)
387 ctf_integer(cputime_t
, expires
, expires
)
388 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
389 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
390 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
391 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
394 #endif /* #else (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
397 * itimer_expire - called when itimer expires
398 * @which: type of the interval timer
399 * @pid: pid of the process which owns the timer
400 * @now: current time, used to calculate the latency of itimer
402 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0))
403 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
407 TP_PROTO(int which
, struct pid
*pid
, unsigned long long now
),
409 TP_ARGS(which
, pid
, now
),
412 ctf_integer(int , which
, which
)
413 ctf_integer(pid_t
, pid
, pid_nr(pid
))
414 ctf_integer(unsigned long long, now
, now
)
417 #else /* if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
418 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
422 TP_PROTO(int which
, struct pid
*pid
, cputime_t now
),
424 TP_ARGS(which
, pid
, now
),
427 ctf_integer(int , which
, which
)
428 ctf_integer(pid_t
, pid
, pid_nr(pid
))
429 ctf_integer(cputime_t
, now
, now
)
432 #endif /* #else (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
434 #endif /* LTTNG_TRACE_TIMER_H */
436 /* This part must be outside protection */
437 #include <lttng/define_trace.h>