xref: /openbmc/linux/include/trace/events/timer.h (revision 434a83c3fbb951908a3a52040f7f0e0b8ba00dd0)
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 
112b022e3dSXiao Guangrong /**
122b022e3dSXiao Guangrong  * timer_init - called when the timer is initialized
132b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
142b022e3dSXiao Guangrong  */
152b022e3dSXiao Guangrong TRACE_EVENT(timer_init,
162b022e3dSXiao Guangrong 
172b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer),
182b022e3dSXiao Guangrong 
192b022e3dSXiao Guangrong 	TP_ARGS(timer),
202b022e3dSXiao Guangrong 
212b022e3dSXiao Guangrong 	TP_STRUCT__entry(
222b022e3dSXiao Guangrong 		__field( void *,	timer	)
232b022e3dSXiao Guangrong 	),
242b022e3dSXiao Guangrong 
252b022e3dSXiao Guangrong 	TP_fast_assign(
262b022e3dSXiao Guangrong 		__entry->timer	= timer;
272b022e3dSXiao Guangrong 	),
282b022e3dSXiao Guangrong 
29*434a83c3SIngo Molnar 	TP_printk("timer=%p", __entry->timer)
302b022e3dSXiao Guangrong );
312b022e3dSXiao Guangrong 
322b022e3dSXiao Guangrong /**
332b022e3dSXiao Guangrong  * timer_start - called when the timer is started
342b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
352b022e3dSXiao Guangrong  * @expires:	the timers expiry time
362b022e3dSXiao Guangrong  */
372b022e3dSXiao Guangrong TRACE_EVENT(timer_start,
382b022e3dSXiao Guangrong 
392b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer, unsigned long expires),
402b022e3dSXiao Guangrong 
412b022e3dSXiao Guangrong 	TP_ARGS(timer, expires),
422b022e3dSXiao Guangrong 
432b022e3dSXiao Guangrong 	TP_STRUCT__entry(
442b022e3dSXiao Guangrong 		__field( void *,	timer		)
452b022e3dSXiao Guangrong 		__field( void *,	function	)
462b022e3dSXiao Guangrong 		__field( unsigned long,	expires		)
472b022e3dSXiao Guangrong 		__field( unsigned long,	now		)
482b022e3dSXiao Guangrong 	),
492b022e3dSXiao Guangrong 
502b022e3dSXiao Guangrong 	TP_fast_assign(
512b022e3dSXiao Guangrong 		__entry->timer		= timer;
522b022e3dSXiao Guangrong 		__entry->function	= timer->function;
532b022e3dSXiao Guangrong 		__entry->expires	= expires;
542b022e3dSXiao Guangrong 		__entry->now		= jiffies;
552b022e3dSXiao Guangrong 	),
562b022e3dSXiao Guangrong 
57*434a83c3SIngo Molnar 	TP_printk("timer=%p function=%pf expires=%lu [timeout=%ld]",
582b022e3dSXiao Guangrong 		  __entry->timer, __entry->function, __entry->expires,
592b022e3dSXiao Guangrong 		  (long)__entry->expires - __entry->now)
602b022e3dSXiao Guangrong );
612b022e3dSXiao Guangrong 
622b022e3dSXiao Guangrong /**
632b022e3dSXiao Guangrong  * timer_expire_entry - called immediately before the timer callback
642b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
652b022e3dSXiao Guangrong  *
662b022e3dSXiao Guangrong  * Allows to determine the timer latency.
672b022e3dSXiao Guangrong  */
682b022e3dSXiao Guangrong TRACE_EVENT(timer_expire_entry,
692b022e3dSXiao Guangrong 
702b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer),
712b022e3dSXiao Guangrong 
722b022e3dSXiao Guangrong 	TP_ARGS(timer),
732b022e3dSXiao Guangrong 
742b022e3dSXiao Guangrong 	TP_STRUCT__entry(
752b022e3dSXiao Guangrong 		__field( void *,	timer	)
762b022e3dSXiao Guangrong 		__field( unsigned long,	now	)
772b022e3dSXiao Guangrong 	),
782b022e3dSXiao Guangrong 
792b022e3dSXiao Guangrong 	TP_fast_assign(
802b022e3dSXiao Guangrong 		__entry->timer		= timer;
812b022e3dSXiao Guangrong 		__entry->now		= jiffies;
822b022e3dSXiao Guangrong 	),
832b022e3dSXiao Guangrong 
84*434a83c3SIngo Molnar 	TP_printk("timer=%p now=%lu", __entry->timer, __entry->now)
852b022e3dSXiao Guangrong );
862b022e3dSXiao Guangrong 
872b022e3dSXiao Guangrong /**
882b022e3dSXiao Guangrong  * timer_expire_exit - called immediately after the timer callback returns
892b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
902b022e3dSXiao Guangrong  *
912b022e3dSXiao Guangrong  * When used in combination with the timer_expire_entry tracepoint we can
922b022e3dSXiao Guangrong  * determine the runtime of the timer callback function.
932b022e3dSXiao Guangrong  *
942b022e3dSXiao Guangrong  * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
952b022e3dSXiao Guangrong  * be invalid. We solely track the pointer.
962b022e3dSXiao Guangrong  */
972b022e3dSXiao Guangrong TRACE_EVENT(timer_expire_exit,
982b022e3dSXiao Guangrong 
992b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer),
1002b022e3dSXiao Guangrong 
1012b022e3dSXiao Guangrong 	TP_ARGS(timer),
1022b022e3dSXiao Guangrong 
1032b022e3dSXiao Guangrong 	TP_STRUCT__entry(
1042b022e3dSXiao Guangrong 		__field(void *,	timer	)
1052b022e3dSXiao Guangrong 	),
1062b022e3dSXiao Guangrong 
1072b022e3dSXiao Guangrong 	TP_fast_assign(
1082b022e3dSXiao Guangrong 		__entry->timer	= timer;
1092b022e3dSXiao Guangrong 	),
1102b022e3dSXiao Guangrong 
111*434a83c3SIngo Molnar 	TP_printk("timer=%p", __entry->timer)
1122b022e3dSXiao Guangrong );
1132b022e3dSXiao Guangrong 
1142b022e3dSXiao Guangrong /**
1152b022e3dSXiao Guangrong  * timer_cancel - called when the timer is canceled
1162b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
1172b022e3dSXiao Guangrong  */
1182b022e3dSXiao Guangrong TRACE_EVENT(timer_cancel,
1192b022e3dSXiao Guangrong 
1202b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer),
1212b022e3dSXiao Guangrong 
1222b022e3dSXiao Guangrong 	TP_ARGS(timer),
1232b022e3dSXiao Guangrong 
1242b022e3dSXiao Guangrong 	TP_STRUCT__entry(
1252b022e3dSXiao Guangrong 		__field( void *,	timer	)
1262b022e3dSXiao Guangrong 	),
1272b022e3dSXiao Guangrong 
1282b022e3dSXiao Guangrong 	TP_fast_assign(
1292b022e3dSXiao Guangrong 		__entry->timer	= timer;
1302b022e3dSXiao Guangrong 	),
1312b022e3dSXiao Guangrong 
132*434a83c3SIngo Molnar 	TP_printk("timer=%p", __entry->timer)
1332b022e3dSXiao Guangrong );
1342b022e3dSXiao Guangrong 
135c6a2a177SXiao Guangrong /**
136c6a2a177SXiao Guangrong  * hrtimer_init - called when the hrtimer is initialized
137c6a2a177SXiao Guangrong  * @timer:	pointer to struct hrtimer
138c6a2a177SXiao Guangrong  * @clockid:	the hrtimers clock
139c6a2a177SXiao Guangrong  * @mode:	the hrtimers mode
140c6a2a177SXiao Guangrong  */
141c6a2a177SXiao Guangrong TRACE_EVENT(hrtimer_init,
142c6a2a177SXiao Guangrong 
143*434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid,
144c6a2a177SXiao Guangrong 		 enum hrtimer_mode mode),
145c6a2a177SXiao Guangrong 
146*434a83c3SIngo Molnar 	TP_ARGS(hrtimer, clockid, mode),
147c6a2a177SXiao Guangrong 
148c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
149*434a83c3SIngo Molnar 		__field( void *,		hrtimer		)
150c6a2a177SXiao Guangrong 		__field( clockid_t,		clockid		)
151c6a2a177SXiao Guangrong 		__field( enum hrtimer_mode,	mode		)
152c6a2a177SXiao Guangrong 	),
153c6a2a177SXiao Guangrong 
154c6a2a177SXiao Guangrong 	TP_fast_assign(
155*434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
156c6a2a177SXiao Guangrong 		__entry->clockid	= clockid;
157c6a2a177SXiao Guangrong 		__entry->mode		= mode;
158c6a2a177SXiao Guangrong 	),
159c6a2a177SXiao Guangrong 
160*434a83c3SIngo Molnar 	TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer,
161c6a2a177SXiao Guangrong 		  __entry->clockid == CLOCK_REALTIME ?
162c6a2a177SXiao Guangrong 			"CLOCK_REALTIME" : "CLOCK_MONOTONIC",
163c6a2a177SXiao Guangrong 		  __entry->mode == HRTIMER_MODE_ABS ?
164c6a2a177SXiao Guangrong 			"HRTIMER_MODE_ABS" : "HRTIMER_MODE_REL")
165c6a2a177SXiao Guangrong );
166c6a2a177SXiao Guangrong 
167c6a2a177SXiao Guangrong /**
168c6a2a177SXiao Guangrong  * hrtimer_start - called when the hrtimer is started
169c6a2a177SXiao Guangrong  * @timer: pointer to struct hrtimer
170c6a2a177SXiao Guangrong  */
171c6a2a177SXiao Guangrong TRACE_EVENT(hrtimer_start,
172c6a2a177SXiao Guangrong 
173*434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer),
174c6a2a177SXiao Guangrong 
175*434a83c3SIngo Molnar 	TP_ARGS(hrtimer),
176c6a2a177SXiao Guangrong 
177c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
178*434a83c3SIngo Molnar 		__field( void *,	hrtimer		)
179c6a2a177SXiao Guangrong 		__field( void *,	function	)
180c6a2a177SXiao Guangrong 		__field( s64,		expires		)
181c6a2a177SXiao Guangrong 		__field( s64,		softexpires	)
182c6a2a177SXiao Guangrong 	),
183c6a2a177SXiao Guangrong 
184c6a2a177SXiao Guangrong 	TP_fast_assign(
185*434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
186*434a83c3SIngo Molnar 		__entry->function	= hrtimer->function;
187*434a83c3SIngo Molnar 		__entry->expires	= hrtimer_get_expires(hrtimer).tv64;
188*434a83c3SIngo Molnar 		__entry->softexpires	= hrtimer_get_softexpires(hrtimer).tv64;
189c6a2a177SXiao Guangrong 	),
190c6a2a177SXiao Guangrong 
191*434a83c3SIngo Molnar 	TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu",
192*434a83c3SIngo Molnar 		  __entry->hrtimer, __entry->function,
193c6a2a177SXiao Guangrong 		  (unsigned long long)ktime_to_ns((ktime_t) {
194c6a2a177SXiao Guangrong 				  .tv64 = __entry->expires }),
195c6a2a177SXiao Guangrong 		  (unsigned long long)ktime_to_ns((ktime_t) {
196c6a2a177SXiao Guangrong 				  .tv64 = __entry->softexpires }))
197c6a2a177SXiao Guangrong );
198c6a2a177SXiao Guangrong 
199c6a2a177SXiao Guangrong /**
200c6a2a177SXiao Guangrong  * htimmer_expire_entry - called immediately before the hrtimer callback
201c6a2a177SXiao Guangrong  * @timer:	pointer to struct hrtimer
202c6a2a177SXiao Guangrong  * @now:	pointer to variable which contains current time of the
203c6a2a177SXiao Guangrong  *		timers base.
204c6a2a177SXiao Guangrong  *
205c6a2a177SXiao Guangrong  * Allows to determine the timer latency.
206c6a2a177SXiao Guangrong  */
207c6a2a177SXiao Guangrong TRACE_EVENT(hrtimer_expire_entry,
208c6a2a177SXiao Guangrong 
209*434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer, ktime_t *now),
210c6a2a177SXiao Guangrong 
211*434a83c3SIngo Molnar 	TP_ARGS(hrtimer, now),
212c6a2a177SXiao Guangrong 
213c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
214*434a83c3SIngo Molnar 		__field( void *,	hrtimer	)
215c6a2a177SXiao Guangrong 		__field( s64,		now	)
216c6a2a177SXiao Guangrong 	),
217c6a2a177SXiao Guangrong 
218c6a2a177SXiao Guangrong 	TP_fast_assign(
219*434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
220c6a2a177SXiao Guangrong 		__entry->now		= now->tv64;
221c6a2a177SXiao Guangrong 	),
222c6a2a177SXiao Guangrong 
223*434a83c3SIngo Molnar 	TP_printk("hrtimer=%p now=%llu", __entry->hrtimer,
224*434a83c3SIngo Molnar 		  (unsigned long long)ktime_to_ns((ktime_t) { .tv64 = __entry->now }))
225c6a2a177SXiao Guangrong  );
226c6a2a177SXiao Guangrong 
227c6a2a177SXiao Guangrong /**
228c6a2a177SXiao Guangrong  * hrtimer_expire_exit - called immediately after the hrtimer callback returns
229c6a2a177SXiao Guangrong  * @timer:	pointer to struct hrtimer
230c6a2a177SXiao Guangrong  *
231c6a2a177SXiao Guangrong  * When used in combination with the hrtimer_expire_entry tracepoint we can
232c6a2a177SXiao Guangrong  * determine the runtime of the callback function.
233c6a2a177SXiao Guangrong  */
234c6a2a177SXiao Guangrong TRACE_EVENT(hrtimer_expire_exit,
235c6a2a177SXiao Guangrong 
236*434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer),
237c6a2a177SXiao Guangrong 
238*434a83c3SIngo Molnar 	TP_ARGS(hrtimer),
239c6a2a177SXiao Guangrong 
240c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
241*434a83c3SIngo Molnar 		__field( void *,	hrtimer	)
242c6a2a177SXiao Guangrong 	),
243c6a2a177SXiao Guangrong 
244c6a2a177SXiao Guangrong 	TP_fast_assign(
245*434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
246c6a2a177SXiao Guangrong 	),
247c6a2a177SXiao Guangrong 
248*434a83c3SIngo Molnar 	TP_printk("hrtimer=%p", __entry->hrtimer)
249c6a2a177SXiao Guangrong );
250c6a2a177SXiao Guangrong 
251c6a2a177SXiao Guangrong /**
252c6a2a177SXiao Guangrong  * hrtimer_cancel - called when the hrtimer is canceled
253*434a83c3SIngo Molnar  * @hrtimer:	pointer to struct hrtimer
254c6a2a177SXiao Guangrong  */
255c6a2a177SXiao Guangrong TRACE_EVENT(hrtimer_cancel,
256c6a2a177SXiao Guangrong 
257*434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer),
258c6a2a177SXiao Guangrong 
259*434a83c3SIngo Molnar 	TP_ARGS(hrtimer),
260c6a2a177SXiao Guangrong 
261c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
262*434a83c3SIngo Molnar 		__field( void *,	hrtimer	)
263c6a2a177SXiao Guangrong 	),
264c6a2a177SXiao Guangrong 
265c6a2a177SXiao Guangrong 	TP_fast_assign(
266*434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
267c6a2a177SXiao Guangrong 	),
268c6a2a177SXiao Guangrong 
269*434a83c3SIngo Molnar 	TP_printk("hrtimer=%p", __entry->hrtimer)
270c6a2a177SXiao Guangrong );
271c6a2a177SXiao Guangrong 
2723f0a525eSXiao Guangrong /**
2733f0a525eSXiao Guangrong  * itimer_state - called when itimer is started or canceled
2743f0a525eSXiao Guangrong  * @which:	name of the interval timer
2753f0a525eSXiao Guangrong  * @value:	the itimers value, itimer is canceled if value->it_value is
2763f0a525eSXiao Guangrong  *		zero, otherwise it is started
2773f0a525eSXiao Guangrong  * @expires:	the itimers expiry time
2783f0a525eSXiao Guangrong  */
2793f0a525eSXiao Guangrong TRACE_EVENT(itimer_state,
2803f0a525eSXiao Guangrong 
2813f0a525eSXiao Guangrong 	TP_PROTO(int which, const struct itimerval *const value,
2823f0a525eSXiao Guangrong 		 cputime_t expires),
2833f0a525eSXiao Guangrong 
2843f0a525eSXiao Guangrong 	TP_ARGS(which, value, expires),
2853f0a525eSXiao Guangrong 
2863f0a525eSXiao Guangrong 	TP_STRUCT__entry(
2873f0a525eSXiao Guangrong 		__field(	int,		which		)
2883f0a525eSXiao Guangrong 		__field(	cputime_t,	expires		)
2893f0a525eSXiao Guangrong 		__field(	long,		value_sec	)
2903f0a525eSXiao Guangrong 		__field(	long,		value_usec	)
2913f0a525eSXiao Guangrong 		__field(	long,		interval_sec	)
2923f0a525eSXiao Guangrong 		__field(	long,		interval_usec	)
2933f0a525eSXiao Guangrong 	),
2943f0a525eSXiao Guangrong 
2953f0a525eSXiao Guangrong 	TP_fast_assign(
2963f0a525eSXiao Guangrong 		__entry->which		= which;
2973f0a525eSXiao Guangrong 		__entry->expires	= expires;
2983f0a525eSXiao Guangrong 		__entry->value_sec	= value->it_value.tv_sec;
2993f0a525eSXiao Guangrong 		__entry->value_usec	= value->it_value.tv_usec;
3003f0a525eSXiao Guangrong 		__entry->interval_sec	= value->it_interval.tv_sec;
3013f0a525eSXiao Guangrong 		__entry->interval_usec	= value->it_interval.tv_usec;
3023f0a525eSXiao Guangrong 	),
3033f0a525eSXiao Guangrong 
304*434a83c3SIngo Molnar 	TP_printk("which=%d expires=%lu it_value=%lu.%lu it_interval=%lu.%lu",
3053f0a525eSXiao Guangrong 		  __entry->which, __entry->expires,
3063f0a525eSXiao Guangrong 		  __entry->value_sec, __entry->value_usec,
3073f0a525eSXiao Guangrong 		  __entry->interval_sec, __entry->interval_usec)
3083f0a525eSXiao Guangrong );
3093f0a525eSXiao Guangrong 
3103f0a525eSXiao Guangrong /**
3113f0a525eSXiao Guangrong  * itimer_expire - called when itimer expires
3123f0a525eSXiao Guangrong  * @which:	type of the interval timer
3133f0a525eSXiao Guangrong  * @pid:	pid of the process which owns the timer
3143f0a525eSXiao Guangrong  * @now:	current time, used to calculate the latency of itimer
3153f0a525eSXiao Guangrong  */
3163f0a525eSXiao Guangrong TRACE_EVENT(itimer_expire,
3173f0a525eSXiao Guangrong 
3183f0a525eSXiao Guangrong 	TP_PROTO(int which, struct pid *pid, cputime_t now),
3193f0a525eSXiao Guangrong 
3203f0a525eSXiao Guangrong 	TP_ARGS(which, pid, now),
3213f0a525eSXiao Guangrong 
3223f0a525eSXiao Guangrong 	TP_STRUCT__entry(
3233f0a525eSXiao Guangrong 		__field( int ,		which	)
3243f0a525eSXiao Guangrong 		__field( pid_t,		pid	)
3253f0a525eSXiao Guangrong 		__field( cputime_t,	now	)
3263f0a525eSXiao Guangrong 	),
3273f0a525eSXiao Guangrong 
3283f0a525eSXiao Guangrong 	TP_fast_assign(
3293f0a525eSXiao Guangrong 		__entry->which	= which;
3303f0a525eSXiao Guangrong 		__entry->now	= now;
3313f0a525eSXiao Guangrong 		__entry->pid	= pid_nr(pid);
3323f0a525eSXiao Guangrong 	),
3333f0a525eSXiao Guangrong 
334*434a83c3SIngo Molnar 	    TP_printk("which=%d pid=%d now=%lu", __entry->which,
3353f0a525eSXiao Guangrong 		      (int) __entry->pid, __entry->now)
3363f0a525eSXiao Guangrong );
3373f0a525eSXiao Guangrong 
3382b022e3dSXiao Guangrong #endif /*  _TRACE_TIMER_H */
3392b022e3dSXiao Guangrong 
3402b022e3dSXiao Guangrong /* This part must be outside protection */
3412b022e3dSXiao Guangrong #include <trace/define_trace.h>
342