1 /* SPDX-License-Identifier: GPL-2.0 */
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))
50 * timer_start - called when the timer is started
51 * @timer: pointer to struct timer_list
52 * @expires: the timers expiry time
53 * @flags: the timers expiry time
55 LTTNG_TRACEPOINT_EVENT(timer_start
,
57 TP_PROTO(struct timer_list
*timer
, unsigned long expires
,
60 TP_ARGS(timer
, expires
, flags
),
63 ctf_integer_hex(void *, timer
, timer
)
64 ctf_integer_hex(void *, function
, timer
->function
)
65 ctf_integer(unsigned long, expires
, expires
)
66 ctf_integer(unsigned long, now
, jiffies
)
67 ctf_integer(unsigned int, flags
, flags
)
70 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */
72 * timer_start - called when the timer is started
73 * @timer: pointer to struct timer_list
74 * @expires: the timers expiry time
76 LTTNG_TRACEPOINT_EVENT(timer_start
,
78 TP_PROTO(struct timer_list
*timer
, unsigned long expires
),
80 TP_ARGS(timer
, expires
),
83 ctf_integer_hex(void *, timer
, timer
)
84 ctf_integer_hex(void *, function
, timer
->function
)
85 ctf_integer(unsigned long, expires
, expires
)
86 ctf_integer(unsigned long, now
, jiffies
)
89 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */
92 * timer_expire_entry - called immediately before the timer callback
93 * @timer: pointer to struct timer_list
95 * Allows to determine the timer latency.
97 LTTNG_TRACEPOINT_EVENT(timer_expire_entry
,
99 TP_PROTO(struct timer_list
*timer
),
104 ctf_integer_hex(void *, timer
, timer
)
105 ctf_integer(unsigned long, now
, jiffies
)
106 ctf_integer_hex(void *, function
, timer
->function
)
111 * timer_expire_exit - called immediately after the timer callback returns
112 * @timer: pointer to struct timer_list
114 * When used in combination with the timer_expire_entry tracepoint we can
115 * determine the runtime of the timer callback function.
117 * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
118 * be invalid. We solely track the pointer.
120 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_expire_exit
,
122 TP_PROTO(struct timer_list
*timer
),
128 * timer_cancel - called when the timer is canceled
129 * @timer: pointer to struct timer_list
131 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class
, timer_cancel
,
133 TP_PROTO(struct timer_list
*timer
),
139 * hrtimer_init - called when the hrtimer is initialized
140 * @timer: pointer to struct hrtimer
141 * @clockid: the hrtimers clock
142 * @mode: the hrtimers mode
144 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_init
,
148 TP_PROTO(struct hrtimer
*hrtimer
, clockid_t clockid
,
149 enum hrtimer_mode mode
),
151 TP_ARGS(hrtimer
, clockid
, mode
),
154 ctf_integer_hex(void *, hrtimer
, hrtimer
)
155 ctf_integer(clockid_t
, clockid
, clockid
)
156 ctf_integer(enum hrtimer_mode
, mode
, mode
)
161 * hrtimer_start - called when the hrtimer is started
162 * @timer: pointer to struct hrtimer
164 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,16,0) || \
165 LTTNG_RT_KERNEL_RANGE(4,14,0,0, 4,15,0,0))
166 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
170 TP_PROTO(struct hrtimer
*hrtimer
, enum hrtimer_mode mode
),
172 TP_ARGS(hrtimer
, mode
),
175 ctf_integer_hex(void *, hrtimer
, hrtimer
)
176 ctf_integer_hex(void *, function
, hrtimer
->function
)
177 ctf_integer(s64
, expires
,
178 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
179 ctf_integer(s64
, softexpires
,
180 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
181 ctf_integer(enum hrtimer_mode
, mode
, mode
)
185 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start
,
189 TP_PROTO(struct hrtimer
*hrtimer
),
194 ctf_integer_hex(void *, hrtimer
, hrtimer
)
195 ctf_integer_hex(void *, function
, hrtimer
->function
)
196 ctf_integer(s64
, expires
,
197 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer
)))
198 ctf_integer(s64
, softexpires
,
199 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer
)))
205 * htimmer_expire_entry - called immediately before the hrtimer callback
206 * @timer: pointer to struct hrtimer
207 * @now: pointer to variable which contains current time of the
210 * Allows to determine the timer latency.
212 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_expire_entry
,
214 timer_hrtimer_expire_entry
,
216 TP_PROTO(struct hrtimer
*hrtimer
, ktime_t
*now
),
218 TP_ARGS(hrtimer
, now
),
221 ctf_integer_hex(void *, hrtimer
, hrtimer
)
222 ctf_integer(s64
, now
, lttng_ktime_get_tv64(*now
))
223 ctf_integer_hex(void *, function
, hrtimer
->function
)
227 LTTNG_TRACEPOINT_EVENT_CLASS(timer_hrtimer_class
,
229 TP_PROTO(struct hrtimer
*hrtimer
),
234 ctf_integer_hex(void *, hrtimer
, hrtimer
)
239 * hrtimer_expire_exit - called immediately after the hrtimer callback returns
240 * @timer: pointer to struct hrtimer
242 * When used in combination with the hrtimer_expire_entry tracepoint we can
243 * determine the runtime of the callback function.
245 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_expire_exit
,
247 timer_hrtimer_expire_exit
,
249 TP_PROTO(struct hrtimer
*hrtimer
),
255 * hrtimer_cancel - called when the hrtimer is canceled
256 * @hrtimer: pointer to struct hrtimer
258 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class
, hrtimer_cancel
,
260 timer_hrtimer_cancel
,
262 TP_PROTO(struct hrtimer
*hrtimer
),
268 * itimer_state - called when itimer is started or canceled
269 * @which: name of the interval timer
270 * @value: the itimers value, itimer is canceled if value->it_value is
271 * zero, otherwise it is started
272 * @expires: the itimers expiry time
274 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0))
275 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
279 TP_PROTO(int which
, const struct itimerval
*const value
,
280 unsigned long long expires
),
282 TP_ARGS(which
, value
, expires
),
285 ctf_integer(int, which
, which
)
286 ctf_integer(unsigned long long, expires
, expires
)
287 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
288 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
289 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
290 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
293 #else /* if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
294 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state
,
298 TP_PROTO(int which
, const struct itimerval
*const value
,
301 TP_ARGS(which
, value
, expires
),
304 ctf_integer(int, which
, which
)
305 ctf_integer(cputime_t
, expires
, expires
)
306 ctf_integer(long, value_sec
, value
->it_value
.tv_sec
)
307 ctf_integer(long, value_usec
, value
->it_value
.tv_usec
)
308 ctf_integer(long, interval_sec
, value
->it_interval
.tv_sec
)
309 ctf_integer(long, interval_usec
, value
->it_interval
.tv_usec
)
312 #endif /* #else (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
315 * itimer_expire - called when itimer expires
316 * @which: type of the interval timer
317 * @pid: pid of the process which owns the timer
318 * @now: current time, used to calculate the latency of itimer
320 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0))
321 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
325 TP_PROTO(int which
, struct pid
*pid
, unsigned long long now
),
327 TP_ARGS(which
, pid
, now
),
330 ctf_integer(int , which
, which
)
331 ctf_integer(pid_t
, pid
, pid_nr(pid
))
332 ctf_integer(unsigned long long, now
, now
)
335 #else /* if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
336 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire
,
340 TP_PROTO(int which
, struct pid
*pid
, cputime_t now
),
342 TP_ARGS(which
, pid
, now
),
345 ctf_integer(int , which
, which
)
346 ctf_integer(pid_t
, pid
, pid_nr(pid
))
347 ctf_integer(cputime_t
, now
, now
)
350 #endif /* #else (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
352 #endif /* LTTNG_TRACE_TIMER_H */
354 /* This part must be outside protection */
355 #include <probes/define_trace.h>