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