blob: c6f728037c53b234bacdc7babe85e5b705707f54 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/* SPDX-License-Identifier: GPL-2.0 */
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>
9#include <linux/hrtimer.h>
10#include <linux/timer.h>
11
12DECLARE_EVENT_CLASS(timer_class,
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
26 TP_printk("timer=%p", __entry->timer)
27);
28
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
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
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
54 TP_PROTO(struct timer_list *timer,
55 unsigned long expires,
56 unsigned int flags),
57
58 TP_ARGS(timer, expires, flags),
59
60 TP_STRUCT__entry(
61 __field( void *, timer )
62 __field( void *, function )
63 __field( unsigned long, expires )
64 __field( unsigned long, now )
65 __field( unsigned int, flags )
66 ),
67
68 TP_fast_assign(
69 __entry->timer = timer;
70 __entry->function = timer->function;
71 __entry->expires = expires;
72 __entry->now = jiffies;
73 __entry->flags = flags;
74 ),
75
76 TP_printk("timer=%p function=%pf expires=%lu [timeout=%ld] cpu=%u idx=%u flags=%s",
77 __entry->timer, __entry->function, __entry->expires,
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))
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 )
99 __field( void *, function)
100 ),
101
102 TP_fast_assign(
103 __entry->timer = timer;
104 __entry->now = jiffies;
105 __entry->function = timer->function;
106 ),
107
108 TP_printk("timer=%p function=%pf now=%lu", __entry->timer, __entry->function,__entry->now)
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 */
121DEFINE_EVENT(timer_class, timer_expire_exit,
122
123 TP_PROTO(struct timer_list *timer),
124
125 TP_ARGS(timer)
126);
127
128/**
129 * timer_cancel - called when the timer is canceled
130 * @timer: pointer to struct timer_list
131 */
132DEFINE_EVENT(timer_class, timer_cancel,
133
134 TP_PROTO(struct timer_list *timer),
135
136 TP_ARGS(timer)
137);
138
139#define decode_clockid(type) \
140 __print_symbolic(type, \
141 { CLOCK_REALTIME, "CLOCK_REALTIME" }, \
142 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" }, \
143 { CLOCK_BOOTTIME, "CLOCK_BOOTTIME" }, \
144 { CLOCK_TAI, "CLOCK_TAI" })
145
146#define decode_hrtimer_mode(mode) \
147 __print_symbolic(mode, \
148 { HRTIMER_MODE_ABS, "ABS" }, \
149 { HRTIMER_MODE_REL, "REL" }, \
150 { HRTIMER_MODE_ABS_PINNED, "ABS|PINNED" }, \
151 { HRTIMER_MODE_REL_PINNED, "REL|PINNED" })
152
153/**
154 * hrtimer_init - called when the hrtimer is initialized
155 * @hrtimer: pointer to struct hrtimer
156 * @clockid: the hrtimers clock
157 * @mode: the hrtimers mode
158 */
159TRACE_EVENT(hrtimer_init,
160
161 TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid,
162 enum hrtimer_mode mode),
163
164 TP_ARGS(hrtimer, clockid, mode),
165
166 TP_STRUCT__entry(
167 __field( void *, hrtimer )
168 __field( clockid_t, clockid )
169 __field( enum hrtimer_mode, mode )
170 ),
171
172 TP_fast_assign(
173 __entry->hrtimer = hrtimer;
174 __entry->clockid = clockid;
175 __entry->mode = mode;
176 ),
177
178 TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer,
179 decode_clockid(__entry->clockid),
180 decode_hrtimer_mode(__entry->mode))
181);
182
183/**
184 * hrtimer_start - called when the hrtimer is started
185 * @hrtimer: pointer to struct hrtimer
186 */
187TRACE_EVENT(hrtimer_start,
188
189 TP_PROTO(struct hrtimer *hrtimer),
190
191 TP_ARGS(hrtimer),
192
193 TP_STRUCT__entry(
194 __field( void *, hrtimer )
195 __field( void *, function )
196 __field( s64, expires )
197 __field( s64, softexpires )
198 ),
199
200 TP_fast_assign(
201 __entry->hrtimer = hrtimer;
202 __entry->function = hrtimer->function;
203 __entry->expires = hrtimer_get_expires(hrtimer);
204 __entry->softexpires = hrtimer_get_softexpires(hrtimer);
205 ),
206
207 TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu",
208 __entry->hrtimer, __entry->function,
209 (unsigned long long) __entry->expires,
210 (unsigned long long) __entry->softexpires)
211);
212
213/**
214 * hrtimer_expire_entry - called immediately before the hrtimer callback
215 * @hrtimer: pointer to struct hrtimer
216 * @now: pointer to variable which contains current time of the
217 * timers base.
218 *
219 * Allows to determine the timer latency.
220 */
221TRACE_EVENT(hrtimer_expire_entry,
222
223 TP_PROTO(struct hrtimer *hrtimer, ktime_t *now),
224
225 TP_ARGS(hrtimer, now),
226
227 TP_STRUCT__entry(
228 __field( void *, hrtimer )
229 __field( s64, now )
230 __field( void *, function)
231 ),
232
233 TP_fast_assign(
234 __entry->hrtimer = hrtimer;
235 __entry->now = *now;
236 __entry->function = hrtimer->function;
237 ),
238
239 TP_printk("hrtimer=%p function=%pf now=%llu", __entry->hrtimer, __entry->function,
240 (unsigned long long) __entry->now)
241);
242
243DECLARE_EVENT_CLASS(hrtimer_class,
244
245 TP_PROTO(struct hrtimer *hrtimer),
246
247 TP_ARGS(hrtimer),
248
249 TP_STRUCT__entry(
250 __field( void *, hrtimer )
251 ),
252
253 TP_fast_assign(
254 __entry->hrtimer = hrtimer;
255 ),
256
257 TP_printk("hrtimer=%p", __entry->hrtimer)
258);
259
260/**
261 * hrtimer_expire_exit - called immediately after the hrtimer callback returns
262 * @hrtimer: 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 */
267DEFINE_EVENT(hrtimer_class, hrtimer_expire_exit,
268
269 TP_PROTO(struct hrtimer *hrtimer),
270
271 TP_ARGS(hrtimer)
272);
273
274/**
275 * hrtimer_cancel - called when the hrtimer is canceled
276 * @hrtimer: pointer to struct hrtimer
277 */
278DEFINE_EVENT(hrtimer_class, hrtimer_cancel,
279
280 TP_PROTO(struct hrtimer *hrtimer),
281
282 TP_ARGS(hrtimer)
283);
284
285/**
286 * itimer_state - called when itimer is started or canceled
287 * @which: name of the interval timer
288 * @value: the itimers value, itimer is canceled if value->it_value is
289 * zero, otherwise it is started
290 * @expires: the itimers expiry time
291 */
292TRACE_EVENT(itimer_state,
293
294 TP_PROTO(int which, const struct itimerval *const value,
295 unsigned long long expires),
296
297 TP_ARGS(which, value, expires),
298
299 TP_STRUCT__entry(
300 __field( int, which )
301 __field( unsigned long long, expires )
302 __field( long, value_sec )
303 __field( long, value_usec )
304 __field( long, interval_sec )
305 __field( long, interval_usec )
306 ),
307
308 TP_fast_assign(
309 __entry->which = which;
310 __entry->expires = expires;
311 __entry->value_sec = value->it_value.tv_sec;
312 __entry->value_usec = value->it_value.tv_usec;
313 __entry->interval_sec = value->it_interval.tv_sec;
314 __entry->interval_usec = value->it_interval.tv_usec;
315 ),
316
317 TP_printk("which=%d expires=%llu it_value=%ld.%ld it_interval=%ld.%ld",
318 __entry->which, __entry->expires,
319 __entry->value_sec, __entry->value_usec,
320 __entry->interval_sec, __entry->interval_usec)
321);
322
323/**
324 * itimer_expire - called when itimer expires
325 * @which: type of the interval timer
326 * @pid: pid of the process which owns the timer
327 * @now: current time, used to calculate the latency of itimer
328 */
329TRACE_EVENT(itimer_expire,
330
331 TP_PROTO(int which, struct pid *pid, unsigned long long now),
332
333 TP_ARGS(which, pid, now),
334
335 TP_STRUCT__entry(
336 __field( int , which )
337 __field( pid_t, pid )
338 __field( unsigned long long, now )
339 ),
340
341 TP_fast_assign(
342 __entry->which = which;
343 __entry->now = now;
344 __entry->pid = pid_nr(pid);
345 ),
346
347 TP_printk("which=%d pid=%d now=%llu", __entry->which,
348 (int) __entry->pid, __entry->now)
349);
350
351#ifdef CONFIG_NO_HZ_COMMON
352
353#define TICK_DEP_NAMES \
354 tick_dep_mask_name(NONE) \
355 tick_dep_name(POSIX_TIMER) \
356 tick_dep_name(PERF_EVENTS) \
357 tick_dep_name(SCHED) \
358 tick_dep_name_end(CLOCK_UNSTABLE)
359
360#undef tick_dep_name
361#undef tick_dep_mask_name
362#undef tick_dep_name_end
363
364/* The MASK will convert to their bits and they need to be processed too */
365#define tick_dep_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
366 TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
367#define tick_dep_name_end(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
368 TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
369/* NONE only has a mask defined for it */
370#define tick_dep_mask_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
371
372TICK_DEP_NAMES
373
374#undef tick_dep_name
375#undef tick_dep_mask_name
376#undef tick_dep_name_end
377
378#define tick_dep_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
379#define tick_dep_mask_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
380#define tick_dep_name_end(sdep) { TICK_DEP_MASK_##sdep, #sdep }
381
382#define show_tick_dep_name(val) \
383 __print_symbolic(val, TICK_DEP_NAMES)
384
385TRACE_EVENT(tick_stop,
386
387 TP_PROTO(int success, int dependency),
388
389 TP_ARGS(success, dependency),
390
391 TP_STRUCT__entry(
392 __field( int , success )
393 __field( int , dependency )
394 ),
395
396 TP_fast_assign(
397 __entry->success = success;
398 __entry->dependency = dependency;
399 ),
400
401 TP_printk("success=%d dependency=%s", __entry->success, \
402 show_tick_dep_name(__entry->dependency))
403);
404#endif
405
406#endif /* _TRACE_TIMER_H */
407
408/* This part must be outside protection */
409#include <trace/define_trace.h>