xref: /openbmc/linux/include/trace/events/timer.h (revision 363d0f6490f319d0dd69b7ec7503c5f6cbab36d9)
12b022e3dSXiao Guangrong #undef TRACE_SYSTEM
22b022e3dSXiao Guangrong #define TRACE_SYSTEM timer
32b022e3dSXiao Guangrong 
42b022e3dSXiao Guangrong #if !defined(_TRACE_TIMER_H) || defined(TRACE_HEADER_MULTI_READ)
52b022e3dSXiao Guangrong #define _TRACE_TIMER_H
62b022e3dSXiao Guangrong 
72b022e3dSXiao Guangrong #include <linux/tracepoint.h>
8c6a2a177SXiao Guangrong #include <linux/hrtimer.h>
92b022e3dSXiao Guangrong #include <linux/timer.h>
102b022e3dSXiao Guangrong 
11*363d0f64SLi Zefan DECLARE_EVENT_CLASS(timer_class,
122b022e3dSXiao Guangrong 
132b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer),
142b022e3dSXiao Guangrong 
152b022e3dSXiao Guangrong 	TP_ARGS(timer),
162b022e3dSXiao Guangrong 
172b022e3dSXiao Guangrong 	TP_STRUCT__entry(
182b022e3dSXiao Guangrong 		__field( void *,	timer	)
192b022e3dSXiao Guangrong 	),
202b022e3dSXiao Guangrong 
212b022e3dSXiao Guangrong 	TP_fast_assign(
222b022e3dSXiao Guangrong 		__entry->timer	= timer;
232b022e3dSXiao Guangrong 	),
242b022e3dSXiao Guangrong 
25434a83c3SIngo Molnar 	TP_printk("timer=%p", __entry->timer)
262b022e3dSXiao Guangrong );
272b022e3dSXiao Guangrong 
282b022e3dSXiao Guangrong /**
29*363d0f64SLi Zefan  * timer_init - called when the timer is initialized
30*363d0f64SLi Zefan  * @timer:	pointer to struct timer_list
31*363d0f64SLi Zefan  */
32*363d0f64SLi Zefan DEFINE_EVENT(timer_class, timer_init,
33*363d0f64SLi Zefan 
34*363d0f64SLi Zefan 	TP_PROTO(struct timer_list *timer),
35*363d0f64SLi Zefan 
36*363d0f64SLi Zefan 	TP_ARGS(timer)
37*363d0f64SLi Zefan );
38*363d0f64SLi Zefan 
39*363d0f64SLi Zefan /**
402b022e3dSXiao Guangrong  * timer_start - called when the timer is started
412b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
422b022e3dSXiao Guangrong  * @expires:	the timers expiry time
432b022e3dSXiao Guangrong  */
442b022e3dSXiao Guangrong TRACE_EVENT(timer_start,
452b022e3dSXiao Guangrong 
462b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer, unsigned long expires),
472b022e3dSXiao Guangrong 
482b022e3dSXiao Guangrong 	TP_ARGS(timer, expires),
492b022e3dSXiao Guangrong 
502b022e3dSXiao Guangrong 	TP_STRUCT__entry(
512b022e3dSXiao Guangrong 		__field( void *,	timer		)
522b022e3dSXiao Guangrong 		__field( void *,	function	)
532b022e3dSXiao Guangrong 		__field( unsigned long,	expires		)
542b022e3dSXiao Guangrong 		__field( unsigned long,	now		)
552b022e3dSXiao Guangrong 	),
562b022e3dSXiao Guangrong 
572b022e3dSXiao Guangrong 	TP_fast_assign(
582b022e3dSXiao Guangrong 		__entry->timer		= timer;
592b022e3dSXiao Guangrong 		__entry->function	= timer->function;
602b022e3dSXiao Guangrong 		__entry->expires	= expires;
612b022e3dSXiao Guangrong 		__entry->now		= jiffies;
622b022e3dSXiao Guangrong 	),
632b022e3dSXiao Guangrong 
64434a83c3SIngo Molnar 	TP_printk("timer=%p function=%pf expires=%lu [timeout=%ld]",
652b022e3dSXiao Guangrong 		  __entry->timer, __entry->function, __entry->expires,
662b022e3dSXiao Guangrong 		  (long)__entry->expires - __entry->now)
672b022e3dSXiao Guangrong );
682b022e3dSXiao Guangrong 
692b022e3dSXiao Guangrong /**
702b022e3dSXiao Guangrong  * timer_expire_entry - called immediately before the timer callback
712b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
722b022e3dSXiao Guangrong  *
732b022e3dSXiao Guangrong  * Allows to determine the timer latency.
742b022e3dSXiao Guangrong  */
752b022e3dSXiao Guangrong TRACE_EVENT(timer_expire_entry,
762b022e3dSXiao Guangrong 
772b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer),
782b022e3dSXiao Guangrong 
792b022e3dSXiao Guangrong 	TP_ARGS(timer),
802b022e3dSXiao Guangrong 
812b022e3dSXiao Guangrong 	TP_STRUCT__entry(
822b022e3dSXiao Guangrong 		__field( void *,	timer	)
832b022e3dSXiao Guangrong 		__field( unsigned long,	now	)
842b022e3dSXiao Guangrong 	),
852b022e3dSXiao Guangrong 
862b022e3dSXiao Guangrong 	TP_fast_assign(
872b022e3dSXiao Guangrong 		__entry->timer		= timer;
882b022e3dSXiao Guangrong 		__entry->now		= jiffies;
892b022e3dSXiao Guangrong 	),
902b022e3dSXiao Guangrong 
91434a83c3SIngo Molnar 	TP_printk("timer=%p now=%lu", __entry->timer, __entry->now)
922b022e3dSXiao Guangrong );
932b022e3dSXiao Guangrong 
942b022e3dSXiao Guangrong /**
952b022e3dSXiao Guangrong  * timer_expire_exit - called immediately after the timer callback returns
962b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
972b022e3dSXiao Guangrong  *
982b022e3dSXiao Guangrong  * When used in combination with the timer_expire_entry tracepoint we can
992b022e3dSXiao Guangrong  * determine the runtime of the timer callback function.
1002b022e3dSXiao Guangrong  *
1012b022e3dSXiao Guangrong  * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
1022b022e3dSXiao Guangrong  * be invalid. We solely track the pointer.
1032b022e3dSXiao Guangrong  */
104*363d0f64SLi Zefan DEFINE_EVENT(timer_class, timer_expire_exit,
1052b022e3dSXiao Guangrong 
1062b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer),
1072b022e3dSXiao Guangrong 
108*363d0f64SLi Zefan 	TP_ARGS(timer)
1092b022e3dSXiao Guangrong );
1102b022e3dSXiao Guangrong 
1112b022e3dSXiao Guangrong /**
1122b022e3dSXiao Guangrong  * timer_cancel - called when the timer is canceled
1132b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
1142b022e3dSXiao Guangrong  */
115*363d0f64SLi Zefan DEFINE_EVENT(timer_class, timer_cancel,
1162b022e3dSXiao Guangrong 
1172b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer),
1182b022e3dSXiao Guangrong 
119*363d0f64SLi Zefan 	TP_ARGS(timer)
1202b022e3dSXiao Guangrong );
1212b022e3dSXiao Guangrong 
122c6a2a177SXiao Guangrong /**
123c6a2a177SXiao Guangrong  * hrtimer_init - called when the hrtimer is initialized
124c6a2a177SXiao Guangrong  * @timer:	pointer to struct hrtimer
125c6a2a177SXiao Guangrong  * @clockid:	the hrtimers clock
126c6a2a177SXiao Guangrong  * @mode:	the hrtimers mode
127c6a2a177SXiao Guangrong  */
128c6a2a177SXiao Guangrong TRACE_EVENT(hrtimer_init,
129c6a2a177SXiao Guangrong 
130434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid,
131c6a2a177SXiao Guangrong 		 enum hrtimer_mode mode),
132c6a2a177SXiao Guangrong 
133434a83c3SIngo Molnar 	TP_ARGS(hrtimer, clockid, mode),
134c6a2a177SXiao Guangrong 
135c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
136434a83c3SIngo Molnar 		__field( void *,		hrtimer		)
137c6a2a177SXiao Guangrong 		__field( clockid_t,		clockid		)
138c6a2a177SXiao Guangrong 		__field( enum hrtimer_mode,	mode		)
139c6a2a177SXiao Guangrong 	),
140c6a2a177SXiao Guangrong 
141c6a2a177SXiao Guangrong 	TP_fast_assign(
142434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
143c6a2a177SXiao Guangrong 		__entry->clockid	= clockid;
144c6a2a177SXiao Guangrong 		__entry->mode		= mode;
145c6a2a177SXiao Guangrong 	),
146c6a2a177SXiao Guangrong 
147434a83c3SIngo Molnar 	TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer,
148c6a2a177SXiao Guangrong 		  __entry->clockid == CLOCK_REALTIME ?
149c6a2a177SXiao Guangrong 			"CLOCK_REALTIME" : "CLOCK_MONOTONIC",
150c6a2a177SXiao Guangrong 		  __entry->mode == HRTIMER_MODE_ABS ?
151c6a2a177SXiao Guangrong 			"HRTIMER_MODE_ABS" : "HRTIMER_MODE_REL")
152c6a2a177SXiao Guangrong );
153c6a2a177SXiao Guangrong 
154c6a2a177SXiao Guangrong /**
155c6a2a177SXiao Guangrong  * hrtimer_start - called when the hrtimer is started
156c6a2a177SXiao Guangrong  * @timer: pointer to struct hrtimer
157c6a2a177SXiao Guangrong  */
158c6a2a177SXiao Guangrong TRACE_EVENT(hrtimer_start,
159c6a2a177SXiao Guangrong 
160434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer),
161c6a2a177SXiao Guangrong 
162434a83c3SIngo Molnar 	TP_ARGS(hrtimer),
163c6a2a177SXiao Guangrong 
164c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
165434a83c3SIngo Molnar 		__field( void *,	hrtimer		)
166c6a2a177SXiao Guangrong 		__field( void *,	function	)
167c6a2a177SXiao Guangrong 		__field( s64,		expires		)
168c6a2a177SXiao Guangrong 		__field( s64,		softexpires	)
169c6a2a177SXiao Guangrong 	),
170c6a2a177SXiao Guangrong 
171c6a2a177SXiao Guangrong 	TP_fast_assign(
172434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
173434a83c3SIngo Molnar 		__entry->function	= hrtimer->function;
174434a83c3SIngo Molnar 		__entry->expires	= hrtimer_get_expires(hrtimer).tv64;
175434a83c3SIngo Molnar 		__entry->softexpires	= hrtimer_get_softexpires(hrtimer).tv64;
176c6a2a177SXiao Guangrong 	),
177c6a2a177SXiao Guangrong 
178434a83c3SIngo Molnar 	TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu",
179434a83c3SIngo Molnar 		  __entry->hrtimer, __entry->function,
180c6a2a177SXiao Guangrong 		  (unsigned long long)ktime_to_ns((ktime_t) {
181c6a2a177SXiao Guangrong 				  .tv64 = __entry->expires }),
182c6a2a177SXiao Guangrong 		  (unsigned long long)ktime_to_ns((ktime_t) {
183c6a2a177SXiao Guangrong 				  .tv64 = __entry->softexpires }))
184c6a2a177SXiao Guangrong );
185c6a2a177SXiao Guangrong 
186c6a2a177SXiao Guangrong /**
187c6a2a177SXiao Guangrong  * htimmer_expire_entry - called immediately before the hrtimer callback
188c6a2a177SXiao Guangrong  * @timer:	pointer to struct hrtimer
189c6a2a177SXiao Guangrong  * @now:	pointer to variable which contains current time of the
190c6a2a177SXiao Guangrong  *		timers base.
191c6a2a177SXiao Guangrong  *
192c6a2a177SXiao Guangrong  * Allows to determine the timer latency.
193c6a2a177SXiao Guangrong  */
194c6a2a177SXiao Guangrong TRACE_EVENT(hrtimer_expire_entry,
195c6a2a177SXiao Guangrong 
196434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer, ktime_t *now),
197c6a2a177SXiao Guangrong 
198434a83c3SIngo Molnar 	TP_ARGS(hrtimer, now),
199c6a2a177SXiao Guangrong 
200c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
201434a83c3SIngo Molnar 		__field( void *,	hrtimer	)
202c6a2a177SXiao Guangrong 		__field( s64,		now	)
203c6a2a177SXiao Guangrong 	),
204c6a2a177SXiao Guangrong 
205c6a2a177SXiao Guangrong 	TP_fast_assign(
206434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
207c6a2a177SXiao Guangrong 		__entry->now		= now->tv64;
208c6a2a177SXiao Guangrong 	),
209c6a2a177SXiao Guangrong 
210434a83c3SIngo Molnar 	TP_printk("hrtimer=%p now=%llu", __entry->hrtimer,
211434a83c3SIngo Molnar 		  (unsigned long long)ktime_to_ns((ktime_t) { .tv64 = __entry->now }))
212c6a2a177SXiao Guangrong  );
213c6a2a177SXiao Guangrong 
214*363d0f64SLi Zefan DECLARE_EVENT_CLASS(hrtimer_class,
215c6a2a177SXiao Guangrong 
216434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer),
217c6a2a177SXiao Guangrong 
218434a83c3SIngo Molnar 	TP_ARGS(hrtimer),
219c6a2a177SXiao Guangrong 
220c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
221434a83c3SIngo Molnar 		__field( void *,	hrtimer	)
222c6a2a177SXiao Guangrong 	),
223c6a2a177SXiao Guangrong 
224c6a2a177SXiao Guangrong 	TP_fast_assign(
225434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
226c6a2a177SXiao Guangrong 	),
227c6a2a177SXiao Guangrong 
228434a83c3SIngo Molnar 	TP_printk("hrtimer=%p", __entry->hrtimer)
229c6a2a177SXiao Guangrong );
230c6a2a177SXiao Guangrong 
231c6a2a177SXiao Guangrong /**
232*363d0f64SLi Zefan  * hrtimer_expire_exit - called immediately after the hrtimer callback returns
233*363d0f64SLi Zefan  * @timer:	pointer to struct hrtimer
234*363d0f64SLi Zefan  *
235*363d0f64SLi Zefan  * When used in combination with the hrtimer_expire_entry tracepoint we can
236*363d0f64SLi Zefan  * determine the runtime of the callback function.
237c6a2a177SXiao Guangrong  */
238*363d0f64SLi Zefan DEFINE_EVENT(hrtimer_class, hrtimer_expire_exit,
239c6a2a177SXiao Guangrong 
240434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer),
241c6a2a177SXiao Guangrong 
242*363d0f64SLi Zefan 	TP_ARGS(hrtimer)
243*363d0f64SLi Zefan );
244c6a2a177SXiao Guangrong 
245*363d0f64SLi Zefan /**
246*363d0f64SLi Zefan  * hrtimer_cancel - called when the hrtimer is canceled
247*363d0f64SLi Zefan  * @hrtimer:	pointer to struct hrtimer
248*363d0f64SLi Zefan  */
249*363d0f64SLi Zefan DEFINE_EVENT(hrtimer_class, hrtimer_cancel,
250c6a2a177SXiao Guangrong 
251*363d0f64SLi Zefan 	TP_PROTO(struct hrtimer *hrtimer),
252c6a2a177SXiao Guangrong 
253*363d0f64SLi Zefan 	TP_ARGS(hrtimer)
254c6a2a177SXiao Guangrong );
255c6a2a177SXiao Guangrong 
2563f0a525eSXiao Guangrong /**
2573f0a525eSXiao Guangrong  * itimer_state - called when itimer is started or canceled
2583f0a525eSXiao Guangrong  * @which:	name of the interval timer
2593f0a525eSXiao Guangrong  * @value:	the itimers value, itimer is canceled if value->it_value is
2603f0a525eSXiao Guangrong  *		zero, otherwise it is started
2613f0a525eSXiao Guangrong  * @expires:	the itimers expiry time
2623f0a525eSXiao Guangrong  */
2633f0a525eSXiao Guangrong TRACE_EVENT(itimer_state,
2643f0a525eSXiao Guangrong 
2653f0a525eSXiao Guangrong 	TP_PROTO(int which, const struct itimerval *const value,
2663f0a525eSXiao Guangrong 		 cputime_t expires),
2673f0a525eSXiao Guangrong 
2683f0a525eSXiao Guangrong 	TP_ARGS(which, value, expires),
2693f0a525eSXiao Guangrong 
2703f0a525eSXiao Guangrong 	TP_STRUCT__entry(
2713f0a525eSXiao Guangrong 		__field(	int,		which		)
2723f0a525eSXiao Guangrong 		__field(	cputime_t,	expires		)
2733f0a525eSXiao Guangrong 		__field(	long,		value_sec	)
2743f0a525eSXiao Guangrong 		__field(	long,		value_usec	)
2753f0a525eSXiao Guangrong 		__field(	long,		interval_sec	)
2763f0a525eSXiao Guangrong 		__field(	long,		interval_usec	)
2773f0a525eSXiao Guangrong 	),
2783f0a525eSXiao Guangrong 
2793f0a525eSXiao Guangrong 	TP_fast_assign(
2803f0a525eSXiao Guangrong 		__entry->which		= which;
2813f0a525eSXiao Guangrong 		__entry->expires	= expires;
2823f0a525eSXiao Guangrong 		__entry->value_sec	= value->it_value.tv_sec;
2833f0a525eSXiao Guangrong 		__entry->value_usec	= value->it_value.tv_usec;
2843f0a525eSXiao Guangrong 		__entry->interval_sec	= value->it_interval.tv_sec;
2853f0a525eSXiao Guangrong 		__entry->interval_usec	= value->it_interval.tv_usec;
2863f0a525eSXiao Guangrong 	),
2873f0a525eSXiao Guangrong 
288e9c0748bSThomas Gleixner 	TP_printk("which=%d expires=%llu it_value=%ld.%ld it_interval=%ld.%ld",
289e9c0748bSThomas Gleixner 		  __entry->which, (unsigned long long)__entry->expires,
2903f0a525eSXiao Guangrong 		  __entry->value_sec, __entry->value_usec,
2913f0a525eSXiao Guangrong 		  __entry->interval_sec, __entry->interval_usec)
2923f0a525eSXiao Guangrong );
2933f0a525eSXiao Guangrong 
2943f0a525eSXiao Guangrong /**
2953f0a525eSXiao Guangrong  * itimer_expire - called when itimer expires
2963f0a525eSXiao Guangrong  * @which:	type of the interval timer
2973f0a525eSXiao Guangrong  * @pid:	pid of the process which owns the timer
2983f0a525eSXiao Guangrong  * @now:	current time, used to calculate the latency of itimer
2993f0a525eSXiao Guangrong  */
3003f0a525eSXiao Guangrong TRACE_EVENT(itimer_expire,
3013f0a525eSXiao Guangrong 
3023f0a525eSXiao Guangrong 	TP_PROTO(int which, struct pid *pid, cputime_t now),
3033f0a525eSXiao Guangrong 
3043f0a525eSXiao Guangrong 	TP_ARGS(which, pid, now),
3053f0a525eSXiao Guangrong 
3063f0a525eSXiao Guangrong 	TP_STRUCT__entry(
3073f0a525eSXiao Guangrong 		__field( int ,		which	)
3083f0a525eSXiao Guangrong 		__field( pid_t,		pid	)
3093f0a525eSXiao Guangrong 		__field( cputime_t,	now	)
3103f0a525eSXiao Guangrong 	),
3113f0a525eSXiao Guangrong 
3123f0a525eSXiao Guangrong 	TP_fast_assign(
3133f0a525eSXiao Guangrong 		__entry->which	= which;
3143f0a525eSXiao Guangrong 		__entry->now	= now;
3153f0a525eSXiao Guangrong 		__entry->pid	= pid_nr(pid);
3163f0a525eSXiao Guangrong 	),
3173f0a525eSXiao Guangrong 
318e9c0748bSThomas Gleixner 	TP_printk("which=%d pid=%d now=%llu", __entry->which,
319e9c0748bSThomas Gleixner 		  (int) __entry->pid, (unsigned long long)__entry->now)
3203f0a525eSXiao Guangrong );
3213f0a525eSXiao Guangrong 
3222b022e3dSXiao Guangrong #endif /*  _TRACE_TIMER_H */
3232b022e3dSXiao Guangrong 
3242b022e3dSXiao Guangrong /* This part must be outside protection */
3252b022e3dSXiao Guangrong #include <trace/define_trace.h>
326