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 <probes/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 <linux/version.h>
18 #endif /* _TRACE_TIMER_DEF_ */
20 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
21 #define lttng_ktime_get_tv64(kt) (kt)
22 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
23 #define lttng_ktime_get_tv64(kt) ((kt).tv64)
24 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
26 LTTNG_TRACEPOINT_EVENT_CLASS(timer_class
,
28 TP_PROTO(struct timer_list
*timer
),
33 ctf_integer_hex(void *, timer
, timer
)
38 * timer_init - called when the timer is initialized
39 * @timer: pointer to struct timer_list
41 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_init
,
43 TP_PROTO(struct timer_list
*timer
),
48 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0) || \
49 LTTNG_RHEL_KERNEL_RANGE(3,10,0,957,0,0, 3,11,0,0,0,0))
51 * timer_start - called when the timer is started
52 * @timer: pointer to struct timer_list
53 * @expires: the timers expiry time
54 * @flags: the timers expiry time
56 LTTNG_TRACEPOINT_EVENT(timer_start
,
58 TP_PROTO(struct timer_list
*timer
, unsigned long expires
,
61 TP_ARGS(timer
, expires
, flags
),
64 ctf_integer_hex(void *, timer
, timer
)
65 ctf_integer_hex(void *, function
, timer
->function
)
66 ctf_integer(unsigned long, expires
, expires
)
67 ctf_integer(unsigned long, now
, jiffies
)
68 ctf_integer(unsigned int, flags
, flags
)
71 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */
73 * timer_start - called when the timer is started
74 * @timer: pointer to struct timer_list
75 * @expires: the timers expiry time
77 LTTNG_TRACEPOINT_EVENT(timer_start
,
79 TP_PROTO(struct timer_list
*timer
, unsigned long expires
),
81 TP_ARGS(timer
, expires
),
84 ctf_integer_hex(void *, timer
, timer
)
85 ctf_integer_hex(void *, function
, timer
->function
)
86 ctf_integer(unsigned long, expires
, expires
)
87 ctf_integer(unsigned long, now
, jiffies
)
90 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */
92 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,2,0))
94 * timer_expire_entry - called immediately before the timer callback
95 * @timer: pointer to struct timer_list
97 * Allows to determine the timer latency.
99 LTTNG_TRACEPOINT_EVENT(timer_expire_entry
,
101 TP_PROTO(struct timer_list
*timer
, unsigned long baseclk
),
103 TP_ARGS(timer
, baseclk
),
106 ctf_integer_hex(void *, timer
, timer
)
107 ctf_integer(unsigned long, now
, jiffies
)
108 ctf_integer_hex(void *, function
, timer
->function
)
109 ctf_integer(unsigned long, baseclk
, baseclk
)
114 * timer_expire_entry - called immediately before the timer callback
115 * @timer: pointer to struct timer_list
117 * Allows to determine the timer latency.
119 LTTNG_TRACEPOINT_EVENT(timer_expire_entry
,
121 TP_PROTO(struct timer_list
*timer
),
126 ctf_integer_hex(void *, timer
, timer
)
127 ctf_integer(unsigned long, now
, jiffies
)
128 ctf_integer_hex(void *, function
, timer
->function
)
134 * timer_expire_exit - called immediately after the timer callback returns
135 * @timer: pointer to struct timer_list
137 * When used in combination with the timer_expire_entry tracepoint we can
138 * determine the runtime of the timer callback function.
140 * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
141 * be invalid. We solely track the pointer.
143 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_expire_exit
,
145 TP_PROTO(struct timer_list
*timer
),
151 * timer_cancel - called when the timer is canceled
152 * @timer: pointer to struct timer_list
154 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_cancel
,
156 TP_PROTO(struct timer_list
*timer
),
162 * hrtimer_init - called when the hrtimer is initialized
163 * @timer: pointer to struct hrtimer
164 * @clockid: the hrtimers clock
165 * @mode: the hrtimers mode
167 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_init
,
171 TP_PROTO(struct hrtimer
*hrtimer
, clockid_t clockid
,
172 enum hrtimer_mode mode
),
174 TP_ARGS(hrtimer
, clockid
, mode
),
177 ctf_integer_hex(void *, hrtimer
, hrtimer
)
178 ctf_integer(clockid_t
, clockid
, clockid
)
179 ctf_integer(enum hrtimer_mode
, mode
, mode
)
184 * hrtimer_start - called when the hrtimer is started
185 * @timer: pointer to struct hrtimer
187 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,16,0) || \
188 LTTNG_RT_KERNEL_RANGE(4,14,0,0, 4,15,0,0))
189 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
193 TP_PROTO(struct hrtimer
*hrtimer
, enum hrtimer_mode mode
),
195 TP_ARGS(hrtimer
, mode
),
198 ctf_integer_hex(void *, hrtimer
, hrtimer
)
199 ctf_integer_hex(void *, function
, hrtimer
->function
)
200 ctf_integer(s64
, expires
,
201 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
202 ctf_integer(s64
, softexpires
,
203 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
204 ctf_integer(enum hrtimer_mode
, mode
, mode
)
208 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
212 TP_PROTO(struct hrtimer
*hrtimer
),
217 ctf_integer_hex(void *, hrtimer
, hrtimer
)
218 ctf_integer_hex(void *, function
, hrtimer
->function
)
219 ctf_integer(s64
, expires
,
220 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
221 ctf_integer(s64
, softexpires
,
222 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
228 * htimmer_expire_entry - called immediately before the hrtimer callback
229 * @timer: pointer to struct hrtimer
230 * @now: pointer to variable which contains current time of the
233 * Allows to determine the timer latency.
235 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_expire_entry
,
237 timer_hrtimer_expire_entry
,
239 TP_PROTO(struct hrtimer
*hrtimer
, ktime_t
*now
),
241 TP_ARGS(hrtimer
, now
),
244 ctf_integer_hex(void *, hrtimer
, hrtimer
)
245 ctf_integer(s64
, now
, lttng_ktime_get_tv64(*now
))
246 ctf_integer_hex(void *, function
, hrtimer
->function
)
250 LTTNG_TRACEPOINT_EVENT_CLASS(timer_hrtimer_class
,
252 TP_PROTO(struct hrtimer
*hrtimer
),
257 ctf_integer_hex(void *, hrtimer
, hrtimer
)
262 * hrtimer_expire_exit - called immediately after the hrtimer callback returns
263 * @timer: pointer to struct hrtimer
265 * When used in combination with the hrtimer_expire_entry tracepoint we can
266 * determine the runtime of the callback function.
268 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_expire_exit
,
270 timer_hrtimer_expire_exit
,
272 TP_PROTO(struct hrtimer
*hrtimer
),
278 * hrtimer_cancel - called when the hrtimer is canceled
279 * @hrtimer: pointer to struct hrtimer
281 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_cancel
,
283 timer_hrtimer_cancel
,
285 TP_PROTO(struct hrtimer
*hrtimer
),
291 * itimer_state - called when itimer is started or canceled
292 * @which: name of the interval timer
293 * @value: the itimers value, itimer is canceled if value->it_value is
294 * zero, otherwise it is started
295 * @expires: the itimers expiry time
297 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0))
298 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
302 TP_PROTO(int which
, const struct itimerspec64
*const value
,
303 unsigned long long expires
),
305 TP_ARGS(which
, value
, expires
),
308 ctf_integer(int, which
, which
)
309 ctf_integer(unsigned long long, expires
, expires
)
310 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
311 ctf_integer(long, value_nsec
, value
->it_value
.tv_nsec
)
312 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
313 ctf_integer(long, interval_nsec
, value
->it_interval
.tv_nsec
)
316 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0))
317 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
321 TP_PROTO(int which
, const struct itimerval
*const value
,
322 unsigned long long expires
),
324 TP_ARGS(which
, value
, expires
),
327 ctf_integer(int, which
, which
)
328 ctf_integer(unsigned long long, expires
, expires
)
329 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
330 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
331 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
332 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
335 #else /* if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
336 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
340 TP_PROTO(int which
, const struct itimerval
*const value
,
343 TP_ARGS(which
, value
, expires
),
346 ctf_integer(int, which
, which
)
347 ctf_integer(cputime_t
, expires
, expires
)
348 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
349 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
350 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
351 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
354 #endif /* #else (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
357 * itimer_expire - called when itimer expires
358 * @which: type of the interval timer
359 * @pid: pid of the process which owns the timer
360 * @now: current time, used to calculate the latency of itimer
362 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0))
363 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
367 TP_PROTO(int which
, struct pid
*pid
, unsigned long long now
),
369 TP_ARGS(which
, pid
, now
),
372 ctf_integer(int , which
, which
)
373 ctf_integer(pid_t
, pid
, pid_nr(pid
))
374 ctf_integer(unsigned long long, now
, now
)
377 #else /* if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
378 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
382 TP_PROTO(int which
, struct pid
*pid
, cputime_t now
),
384 TP_ARGS(which
, pid
, now
),
387 ctf_integer(int , which
, which
)
388 ctf_integer(pid_t
, pid
, pid_nr(pid
))
389 ctf_integer(cputime_t
, now
, now
)
392 #endif /* #else (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
394 #endif /* LTTNG_TRACE_TIMER_H */
396 /* This part must be outside protection */
397 #include <probes/define_trace.h>