fix: timer/trace: Improve timer tracing (v5.2)
[lttng-modules.git] / instrumentation / events / lttng-module / timer.h
1 #undef TRACE_SYSTEM
2 #define TRACE_SYSTEM timer
3
4 #if !defined(LTTNG_TRACE_TIMER_H) || defined(TRACE_HEADER_MULTI_READ)
5 #define LTTNG_TRACE_TIMER_H
6
7 #include <probes/lttng-tracepoint-event.h>
8
9 #ifndef _TRACE_TIMER_DEF_
10 #define _TRACE_TIMER_DEF_
11 #include <linux/hrtimer.h>
12 #include <linux/timer.h>
13 #include <linux/version.h>
14
15 struct timer_list;
16
17 #endif /* _TRACE_TIMER_DEF_ */
18
19 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
20 #define lttng_ktime_get_tv64(kt) (kt)
21 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
22 #define lttng_ktime_get_tv64(kt) ((kt).tv64)
23 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
24
25 LTTNG_TRACEPOINT_EVENT_CLASS(timer_class,
26
27 TP_PROTO(struct timer_list *timer),
28
29 TP_ARGS(timer),
30
31 TP_FIELDS(
32 ctf_integer_hex(void *, timer, timer)
33 )
34 )
35
36 /**
37 * timer_init - called when the timer is initialized
38 * @timer: pointer to struct timer_list
39 */
40 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class, timer_init,
41
42 TP_PROTO(struct timer_list *timer),
43
44 TP_ARGS(timer)
45 )
46
47 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0) || \
48 LTTNG_RHEL_KERNEL_RANGE(3,10,0,957,0,0, 3,11,0,0,0,0))
49 /**
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
54 */
55 LTTNG_TRACEPOINT_EVENT(timer_start,
56
57 TP_PROTO(struct timer_list *timer, unsigned long expires,
58 unsigned int flags),
59
60 TP_ARGS(timer, expires, flags),
61
62 TP_FIELDS(
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)
68 )
69 )
70 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */
71 /**
72 * timer_start - called when the timer is started
73 * @timer: pointer to struct timer_list
74 * @expires: the timers expiry time
75 */
76 LTTNG_TRACEPOINT_EVENT(timer_start,
77
78 TP_PROTO(struct timer_list *timer, unsigned long expires),
79
80 TP_ARGS(timer, expires),
81
82 TP_FIELDS(
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)
87 )
88 )
89 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */
90
91 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,2,0))
92 /**
93 * timer_expire_entry - called immediately before the timer callback
94 * @timer: pointer to struct timer_list
95 *
96 * Allows to determine the timer latency.
97 */
98 LTTNG_TRACEPOINT_EVENT(timer_expire_entry,
99
100 TP_PROTO(struct timer_list *timer, unsigned long baseclk),
101
102 TP_ARGS(timer, baseclk),
103
104 TP_FIELDS(
105 ctf_integer_hex(void *, timer, timer)
106 ctf_integer(unsigned long, now, jiffies)
107 ctf_integer_hex(void *, function, timer->function)
108 ctf_integer(unsigned long, baseclk, baseclk)
109 )
110 )
111 #else
112 /**
113 * timer_expire_entry - called immediately before the timer callback
114 * @timer: pointer to struct timer_list
115 *
116 * Allows to determine the timer latency.
117 */
118 LTTNG_TRACEPOINT_EVENT(timer_expire_entry,
119
120 TP_PROTO(struct timer_list *timer),
121
122 TP_ARGS(timer),
123
124 TP_FIELDS(
125 ctf_integer_hex(void *, timer, timer)
126 ctf_integer(unsigned long, now, jiffies)
127 ctf_integer_hex(void *, function, timer->function)
128 )
129 )
130 #endif
131
132 /**
133 * timer_expire_exit - called immediately after the timer callback returns
134 * @timer: pointer to struct timer_list
135 *
136 * When used in combination with the timer_expire_entry tracepoint we can
137 * determine the runtime of the timer callback function.
138 *
139 * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
140 * be invalid. We solely track the pointer.
141 */
142 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class, timer_expire_exit,
143
144 TP_PROTO(struct timer_list *timer),
145
146 TP_ARGS(timer)
147 )
148
149 /**
150 * timer_cancel - called when the timer is canceled
151 * @timer: pointer to struct timer_list
152 */
153 LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class, timer_cancel,
154
155 TP_PROTO(struct timer_list *timer),
156
157 TP_ARGS(timer)
158 )
159
160 /**
161 * hrtimer_init - called when the hrtimer is initialized
162 * @timer: pointer to struct hrtimer
163 * @clockid: the hrtimers clock
164 * @mode: the hrtimers mode
165 */
166 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_init,
167
168 timer_hrtimer_init,
169
170 TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid,
171 enum hrtimer_mode mode),
172
173 TP_ARGS(hrtimer, clockid, mode),
174
175 TP_FIELDS(
176 ctf_integer_hex(void *, hrtimer, hrtimer)
177 ctf_integer(clockid_t, clockid, clockid)
178 ctf_integer(enum hrtimer_mode, mode, mode)
179 )
180 )
181
182 /**
183 * hrtimer_start - called when the hrtimer is started
184 * @timer: pointer to struct hrtimer
185 */
186 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,16,0) || \
187 LTTNG_RT_KERNEL_RANGE(4,14,0,0, 4,15,0,0))
188 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start,
189
190 timer_hrtimer_start,
191
192 TP_PROTO(struct hrtimer *hrtimer, enum hrtimer_mode mode),
193
194 TP_ARGS(hrtimer, mode),
195
196 TP_FIELDS(
197 ctf_integer_hex(void *, hrtimer, hrtimer)
198 ctf_integer_hex(void *, function, hrtimer->function)
199 ctf_integer(s64, expires,
200 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer)))
201 ctf_integer(s64, softexpires,
202 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer)))
203 ctf_integer(enum hrtimer_mode, mode, mode)
204 )
205 )
206 #else
207 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_start,
208
209 timer_hrtimer_start,
210
211 TP_PROTO(struct hrtimer *hrtimer),
212
213 TP_ARGS(hrtimer),
214
215 TP_FIELDS(
216 ctf_integer_hex(void *, hrtimer, hrtimer)
217 ctf_integer_hex(void *, function, hrtimer->function)
218 ctf_integer(s64, expires,
219 lttng_ktime_get_tv64(hrtimer_get_expires(hrtimer)))
220 ctf_integer(s64, softexpires,
221 lttng_ktime_get_tv64(hrtimer_get_softexpires(hrtimer)))
222 )
223 )
224 #endif
225
226 /**
227 * htimmer_expire_entry - called immediately before the hrtimer callback
228 * @timer: pointer to struct hrtimer
229 * @now: pointer to variable which contains current time of the
230 * timers base.
231 *
232 * Allows to determine the timer latency.
233 */
234 LTTNG_TRACEPOINT_EVENT_MAP(hrtimer_expire_entry,
235
236 timer_hrtimer_expire_entry,
237
238 TP_PROTO(struct hrtimer *hrtimer, ktime_t *now),
239
240 TP_ARGS(hrtimer, now),
241
242 TP_FIELDS(
243 ctf_integer_hex(void *, hrtimer, hrtimer)
244 ctf_integer(s64, now, lttng_ktime_get_tv64(*now))
245 ctf_integer_hex(void *, function, hrtimer->function)
246 )
247 )
248
249 LTTNG_TRACEPOINT_EVENT_CLASS(timer_hrtimer_class,
250
251 TP_PROTO(struct hrtimer *hrtimer),
252
253 TP_ARGS(hrtimer),
254
255 TP_FIELDS(
256 ctf_integer_hex(void *, hrtimer, hrtimer)
257 )
258 )
259
260 /**
261 * hrtimer_expire_exit - called immediately after the hrtimer callback returns
262 * @timer: pointer to struct hrtimer
263 *
264 * When used in combination with the hrtimer_expire_entry tracepoint we can
265 * determine the runtime of the callback function.
266 */
267 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class, hrtimer_expire_exit,
268
269 timer_hrtimer_expire_exit,
270
271 TP_PROTO(struct hrtimer *hrtimer),
272
273 TP_ARGS(hrtimer)
274 )
275
276 /**
277 * hrtimer_cancel - called when the hrtimer is canceled
278 * @hrtimer: pointer to struct hrtimer
279 */
280 LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(timer_hrtimer_class, hrtimer_cancel,
281
282 timer_hrtimer_cancel,
283
284 TP_PROTO(struct hrtimer *hrtimer),
285
286 TP_ARGS(hrtimer)
287 )
288
289 /**
290 * itimer_state - called when itimer is started or canceled
291 * @which: name of the interval timer
292 * @value: the itimers value, itimer is canceled if value->it_value is
293 * zero, otherwise it is started
294 * @expires: the itimers expiry time
295 */
296 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0))
297 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state,
298
299 timer_itimer_state,
300
301 TP_PROTO(int which, const struct itimerval *const value,
302 unsigned long long expires),
303
304 TP_ARGS(which, value, expires),
305
306 TP_FIELDS(
307 ctf_integer(int, which, which)
308 ctf_integer(unsigned long long, expires, expires)
309 ctf_integer(long, value_sec, value->it_value.tv_sec)
310 ctf_integer(long, value_usec, value->it_value.tv_usec)
311 ctf_integer(long, interval_sec, value->it_interval.tv_sec)
312 ctf_integer(long, interval_usec, value->it_interval.tv_usec)
313 )
314 )
315 #else /* if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
316 LTTNG_TRACEPOINT_EVENT_MAP(itimer_state,
317
318 timer_itimer_state,
319
320 TP_PROTO(int which, const struct itimerval *const value,
321 cputime_t expires),
322
323 TP_ARGS(which, value, expires),
324
325 TP_FIELDS(
326 ctf_integer(int, which, which)
327 ctf_integer(cputime_t, expires, expires)
328 ctf_integer(long, value_sec, value->it_value.tv_sec)
329 ctf_integer(long, value_usec, value->it_value.tv_usec)
330 ctf_integer(long, interval_sec, value->it_interval.tv_sec)
331 ctf_integer(long, interval_usec, value->it_interval.tv_usec)
332 )
333 )
334 #endif /* #else (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
335
336 /**
337 * itimer_expire - called when itimer expires
338 * @which: type of the interval timer
339 * @pid: pid of the process which owns the timer
340 * @now: current time, used to calculate the latency of itimer
341 */
342 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0))
343 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire,
344
345 timer_itimer_expire,
346
347 TP_PROTO(int which, struct pid *pid, unsigned long long now),
348
349 TP_ARGS(which, pid, now),
350
351 TP_FIELDS(
352 ctf_integer(int , which, which)
353 ctf_integer(pid_t, pid, pid_nr(pid))
354 ctf_integer(unsigned long long, now, now)
355 )
356 )
357 #else /* if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
358 LTTNG_TRACEPOINT_EVENT_MAP(itimer_expire,
359
360 timer_itimer_expire,
361
362 TP_PROTO(int which, struct pid *pid, cputime_t now),
363
364 TP_ARGS(which, pid, now),
365
366 TP_FIELDS(
367 ctf_integer(int , which, which)
368 ctf_integer(pid_t, pid, pid_nr(pid))
369 ctf_integer(cputime_t, now, now)
370 )
371 )
372 #endif /* #else (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
373
374 #endif /* LTTNG_TRACE_TIMER_H */
375
376 /* This part must be outside protection */
377 #include <probes/define_trace.h>
This page took 0.037315 seconds and 4 git commands to generate.