xref: /openbmc/linux/include/trace/events/timer.h (revision 4e413e8526aa53393d0b3d9ecbdb0436203586ee)
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 
11363d0f64SLi 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 /**
29363d0f64SLi Zefan  * timer_init - called when the timer is initialized
30363d0f64SLi Zefan  * @timer:	pointer to struct timer_list
31363d0f64SLi Zefan  */
32363d0f64SLi Zefan DEFINE_EVENT(timer_class, timer_init,
33363d0f64SLi Zefan 
34363d0f64SLi Zefan 	TP_PROTO(struct timer_list *timer),
35363d0f64SLi Zefan 
36363d0f64SLi Zefan 	TP_ARGS(timer)
37363d0f64SLi Zefan );
38363d0f64SLi Zefan 
39363d0f64SLi 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 
46*4e413e85SBadhri Jagan Sridharan 	TP_PROTO(struct timer_list *timer,
47*4e413e85SBadhri Jagan Sridharan 		unsigned long expires,
48*4e413e85SBadhri Jagan Sridharan 		unsigned int deferrable),
492b022e3dSXiao Guangrong 
50*4e413e85SBadhri Jagan Sridharan 	TP_ARGS(timer, expires, deferrable),
512b022e3dSXiao Guangrong 
522b022e3dSXiao Guangrong 	TP_STRUCT__entry(
532b022e3dSXiao Guangrong 		__field( void *,	timer		)
542b022e3dSXiao Guangrong 		__field( void *,	function	)
552b022e3dSXiao Guangrong 		__field( unsigned long,	expires		)
562b022e3dSXiao Guangrong 		__field( unsigned long,	now		)
57*4e413e85SBadhri Jagan Sridharan 		__field( unsigned int,	deferrable	)
582b022e3dSXiao Guangrong 	),
592b022e3dSXiao Guangrong 
602b022e3dSXiao Guangrong 	TP_fast_assign(
612b022e3dSXiao Guangrong 		__entry->timer		= timer;
622b022e3dSXiao Guangrong 		__entry->function	= timer->function;
632b022e3dSXiao Guangrong 		__entry->expires	= expires;
642b022e3dSXiao Guangrong 		__entry->now		= jiffies;
65*4e413e85SBadhri Jagan Sridharan 		__entry->deferrable     = deferrable;
662b022e3dSXiao Guangrong 	),
672b022e3dSXiao Guangrong 
68*4e413e85SBadhri Jagan Sridharan 	TP_printk("timer=%p function=%pf expires=%lu [timeout=%ld] defer=%c",
692b022e3dSXiao Guangrong 		  __entry->timer, __entry->function, __entry->expires,
70*4e413e85SBadhri Jagan Sridharan 		  (long)__entry->expires - __entry->now,
71*4e413e85SBadhri Jagan Sridharan 		  __entry->deferrable > 0 ? 'y':'n')
722b022e3dSXiao Guangrong );
732b022e3dSXiao Guangrong 
742b022e3dSXiao Guangrong /**
752b022e3dSXiao Guangrong  * timer_expire_entry - called immediately before the timer callback
762b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
772b022e3dSXiao Guangrong  *
782b022e3dSXiao Guangrong  * Allows to determine the timer latency.
792b022e3dSXiao Guangrong  */
802b022e3dSXiao Guangrong TRACE_EVENT(timer_expire_entry,
812b022e3dSXiao Guangrong 
822b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer),
832b022e3dSXiao Guangrong 
842b022e3dSXiao Guangrong 	TP_ARGS(timer),
852b022e3dSXiao Guangrong 
862b022e3dSXiao Guangrong 	TP_STRUCT__entry(
872b022e3dSXiao Guangrong 		__field( void *,	timer	)
882b022e3dSXiao Guangrong 		__field( unsigned long,	now	)
89ede1b429SArjan van de Ven 		__field( void *,	function)
902b022e3dSXiao Guangrong 	),
912b022e3dSXiao Guangrong 
922b022e3dSXiao Guangrong 	TP_fast_assign(
932b022e3dSXiao Guangrong 		__entry->timer		= timer;
942b022e3dSXiao Guangrong 		__entry->now		= jiffies;
95ede1b429SArjan van de Ven 		__entry->function	= timer->function;
962b022e3dSXiao Guangrong 	),
972b022e3dSXiao Guangrong 
98ede1b429SArjan van de Ven 	TP_printk("timer=%p function=%pf now=%lu", __entry->timer, __entry->function,__entry->now)
992b022e3dSXiao Guangrong );
1002b022e3dSXiao Guangrong 
1012b022e3dSXiao Guangrong /**
1022b022e3dSXiao Guangrong  * timer_expire_exit - called immediately after the timer callback returns
1032b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
1042b022e3dSXiao Guangrong  *
1052b022e3dSXiao Guangrong  * When used in combination with the timer_expire_entry tracepoint we can
1062b022e3dSXiao Guangrong  * determine the runtime of the timer callback function.
1072b022e3dSXiao Guangrong  *
1082b022e3dSXiao Guangrong  * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
1092b022e3dSXiao Guangrong  * be invalid. We solely track the pointer.
1102b022e3dSXiao Guangrong  */
111363d0f64SLi Zefan DEFINE_EVENT(timer_class, timer_expire_exit,
1122b022e3dSXiao Guangrong 
1132b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer),
1142b022e3dSXiao Guangrong 
115363d0f64SLi Zefan 	TP_ARGS(timer)
1162b022e3dSXiao Guangrong );
1172b022e3dSXiao Guangrong 
1182b022e3dSXiao Guangrong /**
1192b022e3dSXiao Guangrong  * timer_cancel - called when the timer is canceled
1202b022e3dSXiao Guangrong  * @timer:	pointer to struct timer_list
1212b022e3dSXiao Guangrong  */
122363d0f64SLi Zefan DEFINE_EVENT(timer_class, timer_cancel,
1232b022e3dSXiao Guangrong 
1242b022e3dSXiao Guangrong 	TP_PROTO(struct timer_list *timer),
1252b022e3dSXiao Guangrong 
126363d0f64SLi Zefan 	TP_ARGS(timer)
1272b022e3dSXiao Guangrong );
1282b022e3dSXiao Guangrong 
129c6a2a177SXiao Guangrong /**
130c6a2a177SXiao Guangrong  * hrtimer_init - called when the hrtimer is initialized
131cf2fbdd2SMasanari Iida  * @hrtimer:	pointer to struct hrtimer
132c6a2a177SXiao Guangrong  * @clockid:	the hrtimers clock
133c6a2a177SXiao Guangrong  * @mode:	the hrtimers mode
134c6a2a177SXiao Guangrong  */
135c6a2a177SXiao Guangrong TRACE_EVENT(hrtimer_init,
136c6a2a177SXiao Guangrong 
137434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid,
138c6a2a177SXiao Guangrong 		 enum hrtimer_mode mode),
139c6a2a177SXiao Guangrong 
140434a83c3SIngo Molnar 	TP_ARGS(hrtimer, clockid, mode),
141c6a2a177SXiao Guangrong 
142c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
143434a83c3SIngo Molnar 		__field( void *,		hrtimer		)
144c6a2a177SXiao Guangrong 		__field( clockid_t,		clockid		)
145c6a2a177SXiao Guangrong 		__field( enum hrtimer_mode,	mode		)
146c6a2a177SXiao Guangrong 	),
147c6a2a177SXiao Guangrong 
148c6a2a177SXiao Guangrong 	TP_fast_assign(
149434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
150c6a2a177SXiao Guangrong 		__entry->clockid	= clockid;
151c6a2a177SXiao Guangrong 		__entry->mode		= mode;
152c6a2a177SXiao Guangrong 	),
153c6a2a177SXiao Guangrong 
154434a83c3SIngo Molnar 	TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer,
155c6a2a177SXiao Guangrong 		  __entry->clockid == CLOCK_REALTIME ?
156c6a2a177SXiao Guangrong 			"CLOCK_REALTIME" : "CLOCK_MONOTONIC",
157c6a2a177SXiao Guangrong 		  __entry->mode == HRTIMER_MODE_ABS ?
158c6a2a177SXiao Guangrong 			"HRTIMER_MODE_ABS" : "HRTIMER_MODE_REL")
159c6a2a177SXiao Guangrong );
160c6a2a177SXiao Guangrong 
161c6a2a177SXiao Guangrong /**
162c6a2a177SXiao Guangrong  * hrtimer_start - called when the hrtimer is started
163cf2fbdd2SMasanari Iida  * @hrtimer: pointer to struct hrtimer
164c6a2a177SXiao Guangrong  */
165c6a2a177SXiao Guangrong TRACE_EVENT(hrtimer_start,
166c6a2a177SXiao Guangrong 
167434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer),
168c6a2a177SXiao Guangrong 
169434a83c3SIngo Molnar 	TP_ARGS(hrtimer),
170c6a2a177SXiao Guangrong 
171c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
172434a83c3SIngo Molnar 		__field( void *,	hrtimer		)
173c6a2a177SXiao Guangrong 		__field( void *,	function	)
174c6a2a177SXiao Guangrong 		__field( s64,		expires		)
175c6a2a177SXiao Guangrong 		__field( s64,		softexpires	)
176c6a2a177SXiao Guangrong 	),
177c6a2a177SXiao Guangrong 
178c6a2a177SXiao Guangrong 	TP_fast_assign(
179434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
180434a83c3SIngo Molnar 		__entry->function	= hrtimer->function;
181434a83c3SIngo Molnar 		__entry->expires	= hrtimer_get_expires(hrtimer).tv64;
182434a83c3SIngo Molnar 		__entry->softexpires	= hrtimer_get_softexpires(hrtimer).tv64;
183c6a2a177SXiao Guangrong 	),
184c6a2a177SXiao Guangrong 
185434a83c3SIngo Molnar 	TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu",
186434a83c3SIngo Molnar 		  __entry->hrtimer, __entry->function,
187c6a2a177SXiao Guangrong 		  (unsigned long long)ktime_to_ns((ktime_t) {
188c6a2a177SXiao Guangrong 				  .tv64 = __entry->expires }),
189c6a2a177SXiao Guangrong 		  (unsigned long long)ktime_to_ns((ktime_t) {
190c6a2a177SXiao Guangrong 				  .tv64 = __entry->softexpires }))
191c6a2a177SXiao Guangrong );
192c6a2a177SXiao Guangrong 
193c6a2a177SXiao Guangrong /**
194cf2fbdd2SMasanari Iida  * hrtimer_expire_entry - called immediately before the hrtimer callback
195cf2fbdd2SMasanari Iida  * @hrtimer:	pointer to struct hrtimer
196c6a2a177SXiao Guangrong  * @now:	pointer to variable which contains current time of the
197c6a2a177SXiao Guangrong  *		timers base.
198c6a2a177SXiao Guangrong  *
199c6a2a177SXiao Guangrong  * Allows to determine the timer latency.
200c6a2a177SXiao Guangrong  */
201c6a2a177SXiao Guangrong TRACE_EVENT(hrtimer_expire_entry,
202c6a2a177SXiao Guangrong 
203434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer, ktime_t *now),
204c6a2a177SXiao Guangrong 
205434a83c3SIngo Molnar 	TP_ARGS(hrtimer, now),
206c6a2a177SXiao Guangrong 
207c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
208434a83c3SIngo Molnar 		__field( void *,	hrtimer	)
209c6a2a177SXiao Guangrong 		__field( s64,		now	)
210ede1b429SArjan van de Ven 		__field( void *,	function)
211c6a2a177SXiao Guangrong 	),
212c6a2a177SXiao Guangrong 
213c6a2a177SXiao Guangrong 	TP_fast_assign(
214434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
215c6a2a177SXiao Guangrong 		__entry->now		= now->tv64;
216ede1b429SArjan van de Ven 		__entry->function	= hrtimer->function;
217c6a2a177SXiao Guangrong 	),
218c6a2a177SXiao Guangrong 
219ede1b429SArjan van de Ven 	TP_printk("hrtimer=%p function=%pf now=%llu", __entry->hrtimer, __entry->function,
220434a83c3SIngo Molnar 		  (unsigned long long)ktime_to_ns((ktime_t) { .tv64 = __entry->now }))
221c6a2a177SXiao Guangrong  );
222c6a2a177SXiao Guangrong 
223363d0f64SLi Zefan DECLARE_EVENT_CLASS(hrtimer_class,
224c6a2a177SXiao Guangrong 
225434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer),
226c6a2a177SXiao Guangrong 
227434a83c3SIngo Molnar 	TP_ARGS(hrtimer),
228c6a2a177SXiao Guangrong 
229c6a2a177SXiao Guangrong 	TP_STRUCT__entry(
230434a83c3SIngo Molnar 		__field( void *,	hrtimer	)
231c6a2a177SXiao Guangrong 	),
232c6a2a177SXiao Guangrong 
233c6a2a177SXiao Guangrong 	TP_fast_assign(
234434a83c3SIngo Molnar 		__entry->hrtimer	= hrtimer;
235c6a2a177SXiao Guangrong 	),
236c6a2a177SXiao Guangrong 
237434a83c3SIngo Molnar 	TP_printk("hrtimer=%p", __entry->hrtimer)
238c6a2a177SXiao Guangrong );
239c6a2a177SXiao Guangrong 
240c6a2a177SXiao Guangrong /**
241363d0f64SLi Zefan  * hrtimer_expire_exit - called immediately after the hrtimer callback returns
242cf2fbdd2SMasanari Iida  * @hrtimer:	pointer to struct hrtimer
243363d0f64SLi Zefan  *
244363d0f64SLi Zefan  * When used in combination with the hrtimer_expire_entry tracepoint we can
245363d0f64SLi Zefan  * determine the runtime of the callback function.
246c6a2a177SXiao Guangrong  */
247363d0f64SLi Zefan DEFINE_EVENT(hrtimer_class, hrtimer_expire_exit,
248c6a2a177SXiao Guangrong 
249434a83c3SIngo Molnar 	TP_PROTO(struct hrtimer *hrtimer),
250c6a2a177SXiao Guangrong 
251363d0f64SLi Zefan 	TP_ARGS(hrtimer)
252363d0f64SLi Zefan );
253c6a2a177SXiao Guangrong 
254363d0f64SLi Zefan /**
255363d0f64SLi Zefan  * hrtimer_cancel - called when the hrtimer is canceled
256363d0f64SLi Zefan  * @hrtimer:	pointer to struct hrtimer
257363d0f64SLi Zefan  */
258363d0f64SLi Zefan DEFINE_EVENT(hrtimer_class, hrtimer_cancel,
259c6a2a177SXiao Guangrong 
260363d0f64SLi Zefan 	TP_PROTO(struct hrtimer *hrtimer),
261c6a2a177SXiao Guangrong 
262363d0f64SLi Zefan 	TP_ARGS(hrtimer)
263c6a2a177SXiao Guangrong );
264c6a2a177SXiao Guangrong 
2653f0a525eSXiao Guangrong /**
2663f0a525eSXiao Guangrong  * itimer_state - called when itimer is started or canceled
2673f0a525eSXiao Guangrong  * @which:	name of the interval timer
2683f0a525eSXiao Guangrong  * @value:	the itimers value, itimer is canceled if value->it_value is
2693f0a525eSXiao Guangrong  *		zero, otherwise it is started
2703f0a525eSXiao Guangrong  * @expires:	the itimers expiry time
2713f0a525eSXiao Guangrong  */
2723f0a525eSXiao Guangrong TRACE_EVENT(itimer_state,
2733f0a525eSXiao Guangrong 
2743f0a525eSXiao Guangrong 	TP_PROTO(int which, const struct itimerval *const value,
2753f0a525eSXiao Guangrong 		 cputime_t expires),
2763f0a525eSXiao Guangrong 
2773f0a525eSXiao Guangrong 	TP_ARGS(which, value, expires),
2783f0a525eSXiao Guangrong 
2793f0a525eSXiao Guangrong 	TP_STRUCT__entry(
2803f0a525eSXiao Guangrong 		__field(	int,		which		)
2813f0a525eSXiao Guangrong 		__field(	cputime_t,	expires		)
2823f0a525eSXiao Guangrong 		__field(	long,		value_sec	)
2833f0a525eSXiao Guangrong 		__field(	long,		value_usec	)
2843f0a525eSXiao Guangrong 		__field(	long,		interval_sec	)
2853f0a525eSXiao Guangrong 		__field(	long,		interval_usec	)
2863f0a525eSXiao Guangrong 	),
2873f0a525eSXiao Guangrong 
2883f0a525eSXiao Guangrong 	TP_fast_assign(
2893f0a525eSXiao Guangrong 		__entry->which		= which;
2903f0a525eSXiao Guangrong 		__entry->expires	= expires;
2913f0a525eSXiao Guangrong 		__entry->value_sec	= value->it_value.tv_sec;
2923f0a525eSXiao Guangrong 		__entry->value_usec	= value->it_value.tv_usec;
2933f0a525eSXiao Guangrong 		__entry->interval_sec	= value->it_interval.tv_sec;
2943f0a525eSXiao Guangrong 		__entry->interval_usec	= value->it_interval.tv_usec;
2953f0a525eSXiao Guangrong 	),
2963f0a525eSXiao Guangrong 
297e9c0748bSThomas Gleixner 	TP_printk("which=%d expires=%llu it_value=%ld.%ld it_interval=%ld.%ld",
298e9c0748bSThomas Gleixner 		  __entry->which, (unsigned long long)__entry->expires,
2993f0a525eSXiao Guangrong 		  __entry->value_sec, __entry->value_usec,
3003f0a525eSXiao Guangrong 		  __entry->interval_sec, __entry->interval_usec)
3013f0a525eSXiao Guangrong );
3023f0a525eSXiao Guangrong 
3033f0a525eSXiao Guangrong /**
3043f0a525eSXiao Guangrong  * itimer_expire - called when itimer expires
3053f0a525eSXiao Guangrong  * @which:	type of the interval timer
3063f0a525eSXiao Guangrong  * @pid:	pid of the process which owns the timer
3073f0a525eSXiao Guangrong  * @now:	current time, used to calculate the latency of itimer
3083f0a525eSXiao Guangrong  */
3093f0a525eSXiao Guangrong TRACE_EVENT(itimer_expire,
3103f0a525eSXiao Guangrong 
3113f0a525eSXiao Guangrong 	TP_PROTO(int which, struct pid *pid, cputime_t now),
3123f0a525eSXiao Guangrong 
3133f0a525eSXiao Guangrong 	TP_ARGS(which, pid, now),
3143f0a525eSXiao Guangrong 
3153f0a525eSXiao Guangrong 	TP_STRUCT__entry(
3163f0a525eSXiao Guangrong 		__field( int ,		which	)
3173f0a525eSXiao Guangrong 		__field( pid_t,		pid	)
3183f0a525eSXiao Guangrong 		__field( cputime_t,	now	)
3193f0a525eSXiao Guangrong 	),
3203f0a525eSXiao Guangrong 
3213f0a525eSXiao Guangrong 	TP_fast_assign(
3223f0a525eSXiao Guangrong 		__entry->which	= which;
3233f0a525eSXiao Guangrong 		__entry->now	= now;
3243f0a525eSXiao Guangrong 		__entry->pid	= pid_nr(pid);
3253f0a525eSXiao Guangrong 	),
3263f0a525eSXiao Guangrong 
327e9c0748bSThomas Gleixner 	TP_printk("which=%d pid=%d now=%llu", __entry->which,
328e9c0748bSThomas Gleixner 		  (int) __entry->pid, (unsigned long long)__entry->now)
3293f0a525eSXiao Guangrong );
3303f0a525eSXiao Guangrong 
3312c82d1beSFrederic Weisbecker #ifdef CONFIG_NO_HZ_COMMON
332cb41a290SFrederic Weisbecker TRACE_EVENT(tick_stop,
333cb41a290SFrederic Weisbecker 
334cb41a290SFrederic Weisbecker 	TP_PROTO(int success, char *error_msg),
335cb41a290SFrederic Weisbecker 
336cb41a290SFrederic Weisbecker 	TP_ARGS(success, error_msg),
337cb41a290SFrederic Weisbecker 
338cb41a290SFrederic Weisbecker 	TP_STRUCT__entry(
339cb41a290SFrederic Weisbecker 		__field( int ,		success	)
340cb41a290SFrederic Weisbecker 		__string( msg, 		error_msg )
341cb41a290SFrederic Weisbecker 	),
342cb41a290SFrederic Weisbecker 
343cb41a290SFrederic Weisbecker 	TP_fast_assign(
344cb41a290SFrederic Weisbecker 		__entry->success	= success;
345cb41a290SFrederic Weisbecker 		__assign_str(msg, error_msg);
346cb41a290SFrederic Weisbecker 	),
347cb41a290SFrederic Weisbecker 
348cb41a290SFrederic Weisbecker 	TP_printk("success=%s msg=%s",  __entry->success ? "yes" : "no", __get_str(msg))
349cb41a290SFrederic Weisbecker );
350cb41a290SFrederic Weisbecker #endif
351cb41a290SFrederic Weisbecker 
3522b022e3dSXiao Guangrong #endif /*  _TRACE_TIMER_H */
3532b022e3dSXiao Guangrong 
3542b022e3dSXiao Guangrong /* This part must be outside protection */
3552b022e3dSXiao Guangrong #include <trace/define_trace.h>
356