License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-block.git] / include / trace / events / timer.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
2b022e3d
XG
2#undef TRACE_SYSTEM
3#define TRACE_SYSTEM timer
4
5#if !defined(_TRACE_TIMER_H) || defined(TRACE_HEADER_MULTI_READ)
6#define _TRACE_TIMER_H
7
8#include <linux/tracepoint.h>
c6a2a177 9#include <linux/hrtimer.h>
2b022e3d
XG
10#include <linux/timer.h>
11
363d0f64 12DECLARE_EVENT_CLASS(timer_class,
2b022e3d
XG
13
14 TP_PROTO(struct timer_list *timer),
15
16 TP_ARGS(timer),
17
18 TP_STRUCT__entry(
19 __field( void *, timer )
20 ),
21
22 TP_fast_assign(
23 __entry->timer = timer;
24 ),
25
434a83c3 26 TP_printk("timer=%p", __entry->timer)
2b022e3d
XG
27);
28
363d0f64
LZ
29/**
30 * timer_init - called when the timer is initialized
31 * @timer: pointer to struct timer_list
32 */
33DEFINE_EVENT(timer_class, timer_init,
34
35 TP_PROTO(struct timer_list *timer),
36
37 TP_ARGS(timer)
38);
39
8a58a34b
TG
40#define decode_timer_flags(flags) \
41 __print_flags(flags, "|", \
42 { TIMER_MIGRATING, "M" }, \
43 { TIMER_DEFERRABLE, "D" }, \
44 { TIMER_PINNED, "P" }, \
45 { TIMER_IRQSAFE, "I" })
46
2b022e3d
XG
47/**
48 * timer_start - called when the timer is started
49 * @timer: pointer to struct timer_list
50 * @expires: the timers expiry time
51 */
52TRACE_EVENT(timer_start,
53
4e413e85
BJS
54 TP_PROTO(struct timer_list *timer,
55 unsigned long expires,
0eeda71b 56 unsigned int flags),
2b022e3d 57
0eeda71b 58 TP_ARGS(timer, expires, flags),
2b022e3d
XG
59
60 TP_STRUCT__entry(
61 __field( void *, timer )
62 __field( void *, function )
63 __field( unsigned long, expires )
64 __field( unsigned long, now )
0eeda71b 65 __field( unsigned int, flags )
2b022e3d
XG
66 ),
67
68 TP_fast_assign(
69 __entry->timer = timer;
70 __entry->function = timer->function;
71 __entry->expires = expires;
72 __entry->now = jiffies;
0eeda71b 73 __entry->flags = flags;
2b022e3d
XG
74 ),
75
8a58a34b 76 TP_printk("timer=%p function=%pf expires=%lu [timeout=%ld] cpu=%u idx=%u flags=%s",
2b022e3d 77 __entry->timer, __entry->function, __entry->expires,
8a58a34b
TG
78 (long)__entry->expires - __entry->now,
79 __entry->flags & TIMER_CPUMASK,
80 __entry->flags >> TIMER_ARRAYSHIFT,
81 decode_timer_flags(__entry->flags & TIMER_TRACE_FLAGMASK))
2b022e3d
XG
82);
83
84/**
85 * timer_expire_entry - called immediately before the timer callback
86 * @timer: pointer to struct timer_list
87 *
88 * Allows to determine the timer latency.
89 */
90TRACE_EVENT(timer_expire_entry,
91
92 TP_PROTO(struct timer_list *timer),
93
94 TP_ARGS(timer),
95
96 TP_STRUCT__entry(
97 __field( void *, timer )
98 __field( unsigned long, now )
ede1b429 99 __field( void *, function)
2b022e3d
XG
100 ),
101
102 TP_fast_assign(
103 __entry->timer = timer;
104 __entry->now = jiffies;
ede1b429 105 __entry->function = timer->function;
2b022e3d
XG
106 ),
107
ede1b429 108 TP_printk("timer=%p function=%pf now=%lu", __entry->timer, __entry->function,__entry->now)
2b022e3d
XG
109);
110
111/**
112 * timer_expire_exit - called immediately after the timer callback returns
113 * @timer: pointer to struct timer_list
114 *
115 * When used in combination with the timer_expire_entry tracepoint we can
116 * determine the runtime of the timer callback function.
117 *
118 * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
119 * be invalid. We solely track the pointer.
120 */
363d0f64 121DEFINE_EVENT(timer_class, timer_expire_exit,
2b022e3d
XG
122
123 TP_PROTO(struct timer_list *timer),
124
363d0f64 125 TP_ARGS(timer)
2b022e3d
XG
126);
127
128/**
129 * timer_cancel - called when the timer is canceled
130 * @timer: pointer to struct timer_list
131 */
363d0f64 132DEFINE_EVENT(timer_class, timer_cancel,
2b022e3d
XG
133
134 TP_PROTO(struct timer_list *timer),
135
363d0f64 136 TP_ARGS(timer)
2b022e3d
XG
137);
138
c6a2a177
XG
139/**
140 * hrtimer_init - called when the hrtimer is initialized
cf2fbdd2 141 * @hrtimer: pointer to struct hrtimer
c6a2a177
XG
142 * @clockid: the hrtimers clock
143 * @mode: the hrtimers mode
144 */
145TRACE_EVENT(hrtimer_init,
146
434a83c3 147 TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid,
c6a2a177
XG
148 enum hrtimer_mode mode),
149
434a83c3 150 TP_ARGS(hrtimer, clockid, mode),
c6a2a177
XG
151
152 TP_STRUCT__entry(
434a83c3 153 __field( void *, hrtimer )
c6a2a177
XG
154 __field( clockid_t, clockid )
155 __field( enum hrtimer_mode, mode )
156 ),
157
158 TP_fast_assign(
434a83c3 159 __entry->hrtimer = hrtimer;
c6a2a177
XG
160 __entry->clockid = clockid;
161 __entry->mode = mode;
162 ),
163
434a83c3 164 TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer,
c6a2a177
XG
165 __entry->clockid == CLOCK_REALTIME ?
166 "CLOCK_REALTIME" : "CLOCK_MONOTONIC",
167 __entry->mode == HRTIMER_MODE_ABS ?
168 "HRTIMER_MODE_ABS" : "HRTIMER_MODE_REL")
169);
170
171/**
172 * hrtimer_start - called when the hrtimer is started
cf2fbdd2 173 * @hrtimer: pointer to struct hrtimer
c6a2a177
XG
174 */
175TRACE_EVENT(hrtimer_start,
176
434a83c3 177 TP_PROTO(struct hrtimer *hrtimer),
c6a2a177 178
434a83c3 179 TP_ARGS(hrtimer),
c6a2a177
XG
180
181 TP_STRUCT__entry(
434a83c3 182 __field( void *, hrtimer )
c6a2a177
XG
183 __field( void *, function )
184 __field( s64, expires )
185 __field( s64, softexpires )
186 ),
187
188 TP_fast_assign(
434a83c3
IM
189 __entry->hrtimer = hrtimer;
190 __entry->function = hrtimer->function;
2456e855
TG
191 __entry->expires = hrtimer_get_expires(hrtimer);
192 __entry->softexpires = hrtimer_get_softexpires(hrtimer);
c6a2a177
XG
193 ),
194
434a83c3
IM
195 TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu",
196 __entry->hrtimer, __entry->function,
2456e855
TG
197 (unsigned long long) __entry->expires,
198 (unsigned long long) __entry->softexpires)
c6a2a177
XG
199);
200
201/**
cf2fbdd2
MI
202 * hrtimer_expire_entry - called immediately before the hrtimer callback
203 * @hrtimer: pointer to struct hrtimer
c6a2a177
XG
204 * @now: pointer to variable which contains current time of the
205 * timers base.
206 *
207 * Allows to determine the timer latency.
208 */
209TRACE_EVENT(hrtimer_expire_entry,
210
434a83c3 211 TP_PROTO(struct hrtimer *hrtimer, ktime_t *now),
c6a2a177 212
434a83c3 213 TP_ARGS(hrtimer, now),
c6a2a177
XG
214
215 TP_STRUCT__entry(
434a83c3 216 __field( void *, hrtimer )
c6a2a177 217 __field( s64, now )
ede1b429 218 __field( void *, function)
c6a2a177
XG
219 ),
220
221 TP_fast_assign(
434a83c3 222 __entry->hrtimer = hrtimer;
2456e855 223 __entry->now = *now;
ede1b429 224 __entry->function = hrtimer->function;
c6a2a177
XG
225 ),
226
ede1b429 227 TP_printk("hrtimer=%p function=%pf now=%llu", __entry->hrtimer, __entry->function,
2456e855
TG
228 (unsigned long long) __entry->now)
229);
c6a2a177 230
363d0f64 231DECLARE_EVENT_CLASS(hrtimer_class,
c6a2a177 232
434a83c3 233 TP_PROTO(struct hrtimer *hrtimer),
c6a2a177 234
434a83c3 235 TP_ARGS(hrtimer),
c6a2a177
XG
236
237 TP_STRUCT__entry(
434a83c3 238 __field( void *, hrtimer )
c6a2a177
XG
239 ),
240
241 TP_fast_assign(
434a83c3 242 __entry->hrtimer = hrtimer;
c6a2a177
XG
243 ),
244
434a83c3 245 TP_printk("hrtimer=%p", __entry->hrtimer)
c6a2a177
XG
246);
247
248/**
363d0f64 249 * hrtimer_expire_exit - called immediately after the hrtimer callback returns
cf2fbdd2 250 * @hrtimer: pointer to struct hrtimer
363d0f64
LZ
251 *
252 * When used in combination with the hrtimer_expire_entry tracepoint we can
253 * determine the runtime of the callback function.
c6a2a177 254 */
363d0f64 255DEFINE_EVENT(hrtimer_class, hrtimer_expire_exit,
c6a2a177 256
434a83c3 257 TP_PROTO(struct hrtimer *hrtimer),
c6a2a177 258
363d0f64
LZ
259 TP_ARGS(hrtimer)
260);
c6a2a177 261
363d0f64
LZ
262/**
263 * hrtimer_cancel - called when the hrtimer is canceled
264 * @hrtimer: pointer to struct hrtimer
265 */
266DEFINE_EVENT(hrtimer_class, hrtimer_cancel,
c6a2a177 267
363d0f64 268 TP_PROTO(struct hrtimer *hrtimer),
c6a2a177 269
363d0f64 270 TP_ARGS(hrtimer)
c6a2a177
XG
271);
272
3f0a525e
XG
273/**
274 * itimer_state - called when itimer is started or canceled
275 * @which: name of the interval timer
276 * @value: the itimers value, itimer is canceled if value->it_value is
277 * zero, otherwise it is started
278 * @expires: the itimers expiry time
279 */
280TRACE_EVENT(itimer_state,
281
282 TP_PROTO(int which, const struct itimerval *const value,
858cf3a8 283 unsigned long long expires),
3f0a525e
XG
284
285 TP_ARGS(which, value, expires),
286
287 TP_STRUCT__entry(
858cf3a8
FW
288 __field( int, which )
289 __field( unsigned long long, expires )
290 __field( long, value_sec )
291 __field( long, value_usec )
292 __field( long, interval_sec )
293 __field( long, interval_usec )
3f0a525e
XG
294 ),
295
296 TP_fast_assign(
297 __entry->which = which;
298 __entry->expires = expires;
299 __entry->value_sec = value->it_value.tv_sec;
300 __entry->value_usec = value->it_value.tv_usec;
301 __entry->interval_sec = value->it_interval.tv_sec;
302 __entry->interval_usec = value->it_interval.tv_usec;
303 ),
304
e9c0748b 305 TP_printk("which=%d expires=%llu it_value=%ld.%ld it_interval=%ld.%ld",
858cf3a8 306 __entry->which, __entry->expires,
3f0a525e
XG
307 __entry->value_sec, __entry->value_usec,
308 __entry->interval_sec, __entry->interval_usec)
309);
310
311/**
312 * itimer_expire - called when itimer expires
313 * @which: type of the interval timer
314 * @pid: pid of the process which owns the timer
315 * @now: current time, used to calculate the latency of itimer
316 */
317TRACE_EVENT(itimer_expire,
318
858cf3a8 319 TP_PROTO(int which, struct pid *pid, unsigned long long now),
3f0a525e
XG
320
321 TP_ARGS(which, pid, now),
322
323 TP_STRUCT__entry(
858cf3a8
FW
324 __field( int , which )
325 __field( pid_t, pid )
326 __field( unsigned long long, now )
3f0a525e
XG
327 ),
328
329 TP_fast_assign(
330 __entry->which = which;
331 __entry->now = now;
332 __entry->pid = pid_nr(pid);
333 ),
334
e9c0748b 335 TP_printk("which=%d pid=%d now=%llu", __entry->which,
858cf3a8 336 (int) __entry->pid, __entry->now)
3f0a525e
XG
337);
338
2c82d1be 339#ifdef CONFIG_NO_HZ_COMMON
e6e6cc22
FW
340
341#define TICK_DEP_NAMES \
c87edb36 342 tick_dep_mask_name(NONE) \
e6e6cc22
FW
343 tick_dep_name(POSIX_TIMER) \
344 tick_dep_name(PERF_EVENTS) \
345 tick_dep_name(SCHED) \
346 tick_dep_name_end(CLOCK_UNSTABLE)
347
348#undef tick_dep_name
c87edb36 349#undef tick_dep_mask_name
e6e6cc22
FW
350#undef tick_dep_name_end
351
c87edb36
SRRH
352/* The MASK will convert to their bits and they need to be processed too */
353#define tick_dep_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
354 TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
355#define tick_dep_name_end(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
356 TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
357/* NONE only has a mask defined for it */
358#define tick_dep_mask_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
e6e6cc22
FW
359
360TICK_DEP_NAMES
361
362#undef tick_dep_name
c87edb36 363#undef tick_dep_mask_name
e6e6cc22
FW
364#undef tick_dep_name_end
365
366#define tick_dep_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
c87edb36 367#define tick_dep_mask_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
e6e6cc22
FW
368#define tick_dep_name_end(sdep) { TICK_DEP_MASK_##sdep, #sdep }
369
370#define show_tick_dep_name(val) \
371 __print_symbolic(val, TICK_DEP_NAMES)
372
cb41a290
FW
373TRACE_EVENT(tick_stop,
374
e6e6cc22 375 TP_PROTO(int success, int dependency),
cb41a290 376
e6e6cc22 377 TP_ARGS(success, dependency),
cb41a290
FW
378
379 TP_STRUCT__entry(
380 __field( int , success )
e6e6cc22 381 __field( int , dependency )
cb41a290
FW
382 ),
383
384 TP_fast_assign(
385 __entry->success = success;
e6e6cc22 386 __entry->dependency = dependency;
cb41a290
FW
387 ),
388
e6e6cc22
FW
389 TP_printk("success=%d dependency=%s", __entry->success, \
390 show_tick_dep_name(__entry->dependency))
cb41a290
FW
391);
392#endif
393
2b022e3d
XG
394#endif /* _TRACE_TIMER_H */
395
396/* This part must be outside protection */
397#include <trace/define_trace.h>