timer.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. #undef TRACE_SYSTEM
  2. #define TRACE_SYSTEM timer
  3. #if !defined(_TRACE_TIMER_H) || defined(TRACE_HEADER_MULTI_READ)
  4. #define _TRACE_TIMER_H
  5. #include <linux/tracepoint.h>
  6. #include <linux/hrtimer.h>
  7. #include <linux/timer.h>
  8. DECLARE_EVENT_CLASS(timer_class,
  9. TP_PROTO(struct timer_list *timer),
  10. TP_ARGS(timer),
  11. TP_STRUCT__entry(
  12. __field( void *, timer )
  13. ),
  14. TP_fast_assign(
  15. __entry->timer = timer;
  16. ),
  17. TP_printk("timer=%p", __entry->timer)
  18. );
  19. /**
  20. * timer_init - called when the timer is initialized
  21. * @timer: pointer to struct timer_list
  22. */
  23. DEFINE_EVENT(timer_class, timer_init,
  24. TP_PROTO(struct timer_list *timer),
  25. TP_ARGS(timer)
  26. );
  27. /**
  28. * timer_start - called when the timer is started
  29. * @timer: pointer to struct timer_list
  30. * @expires: the timers expiry time
  31. */
  32. TRACE_EVENT(timer_start,
  33. TP_PROTO(struct timer_list *timer, unsigned long expires),
  34. TP_ARGS(timer, expires),
  35. TP_STRUCT__entry(
  36. __field( void *, timer )
  37. __field( void *, function )
  38. __field( unsigned long, expires )
  39. __field( unsigned long, now )
  40. ),
  41. TP_fast_assign(
  42. __entry->timer = timer;
  43. __entry->function = timer->function;
  44. __entry->expires = expires;
  45. __entry->now = jiffies;
  46. ),
  47. TP_printk("timer=%p function=%pf expires=%lu [timeout=%ld]",
  48. __entry->timer, __entry->function, __entry->expires,
  49. (long)__entry->expires - __entry->now)
  50. );
  51. /**
  52. * timer_expire_entry - called immediately before the timer callback
  53. * @timer: pointer to struct timer_list
  54. *
  55. * Allows to determine the timer latency.
  56. */
  57. TRACE_EVENT(timer_expire_entry,
  58. TP_PROTO(struct timer_list *timer),
  59. TP_ARGS(timer),
  60. TP_STRUCT__entry(
  61. __field( void *, timer )
  62. __field( unsigned long, now )
  63. __field( void *, function)
  64. ),
  65. TP_fast_assign(
  66. __entry->timer = timer;
  67. __entry->now = jiffies;
  68. __entry->function = timer->function;
  69. ),
  70. TP_printk("timer=%p function=%pf now=%lu", __entry->timer, __entry->function,__entry->now)
  71. );
  72. /**
  73. * timer_expire_exit - called immediately after the timer callback returns
  74. * @timer: pointer to struct timer_list
  75. *
  76. * When used in combination with the timer_expire_entry tracepoint we can
  77. * determine the runtime of the timer callback function.
  78. *
  79. * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
  80. * be invalid. We solely track the pointer.
  81. */
  82. DEFINE_EVENT(timer_class, timer_expire_exit,
  83. TP_PROTO(struct timer_list *timer),
  84. TP_ARGS(timer)
  85. );
  86. /**
  87. * timer_cancel - called when the timer is canceled
  88. * @timer: pointer to struct timer_list
  89. */
  90. DEFINE_EVENT(timer_class, timer_cancel,
  91. TP_PROTO(struct timer_list *timer),
  92. TP_ARGS(timer)
  93. );
  94. /**
  95. * hrtimer_init - called when the hrtimer is initialized
  96. * @timer: pointer to struct hrtimer
  97. * @clockid: the hrtimers clock
  98. * @mode: the hrtimers mode
  99. */
  100. TRACE_EVENT(hrtimer_init,
  101. TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid,
  102. enum hrtimer_mode mode),
  103. TP_ARGS(hrtimer, clockid, mode),
  104. TP_STRUCT__entry(
  105. __field( void *, hrtimer )
  106. __field( clockid_t, clockid )
  107. __field( enum hrtimer_mode, mode )
  108. ),
  109. TP_fast_assign(
  110. __entry->hrtimer = hrtimer;
  111. __entry->clockid = clockid;
  112. __entry->mode = mode;
  113. ),
  114. TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer,
  115. __entry->clockid == CLOCK_REALTIME ?
  116. "CLOCK_REALTIME" : "CLOCK_MONOTONIC",
  117. __entry->mode == HRTIMER_MODE_ABS ?
  118. "HRTIMER_MODE_ABS" : "HRTIMER_MODE_REL")
  119. );
  120. /**
  121. * hrtimer_start - called when the hrtimer is started
  122. * @timer: pointer to struct hrtimer
  123. */
  124. TRACE_EVENT(hrtimer_start,
  125. TP_PROTO(struct hrtimer *hrtimer),
  126. TP_ARGS(hrtimer),
  127. TP_STRUCT__entry(
  128. __field( void *, hrtimer )
  129. __field( void *, function )
  130. __field( s64, expires )
  131. __field( s64, softexpires )
  132. ),
  133. TP_fast_assign(
  134. __entry->hrtimer = hrtimer;
  135. __entry->function = hrtimer->function;
  136. __entry->expires = hrtimer_get_expires(hrtimer).tv64;
  137. __entry->softexpires = hrtimer_get_softexpires(hrtimer).tv64;
  138. ),
  139. TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu",
  140. __entry->hrtimer, __entry->function,
  141. (unsigned long long)ktime_to_ns((ktime_t) {
  142. .tv64 = __entry->expires }),
  143. (unsigned long long)ktime_to_ns((ktime_t) {
  144. .tv64 = __entry->softexpires }))
  145. );
  146. /**
  147. * htimmer_expire_entry - called immediately before the hrtimer callback
  148. * @timer: pointer to struct hrtimer
  149. * @now: pointer to variable which contains current time of the
  150. * timers base.
  151. *
  152. * Allows to determine the timer latency.
  153. */
  154. TRACE_EVENT(hrtimer_expire_entry,
  155. TP_PROTO(struct hrtimer *hrtimer, ktime_t *now),
  156. TP_ARGS(hrtimer, now),
  157. TP_STRUCT__entry(
  158. __field( void *, hrtimer )
  159. __field( s64, now )
  160. __field( void *, function)
  161. ),
  162. TP_fast_assign(
  163. __entry->hrtimer = hrtimer;
  164. __entry->now = now->tv64;
  165. __entry->function = hrtimer->function;
  166. ),
  167. TP_printk("hrtimer=%p function=%pf now=%llu", __entry->hrtimer, __entry->function,
  168. (unsigned long long)ktime_to_ns((ktime_t) { .tv64 = __entry->now }))
  169. );
  170. DECLARE_EVENT_CLASS(hrtimer_class,
  171. TP_PROTO(struct hrtimer *hrtimer),
  172. TP_ARGS(hrtimer),
  173. TP_STRUCT__entry(
  174. __field( void *, hrtimer )
  175. ),
  176. TP_fast_assign(
  177. __entry->hrtimer = hrtimer;
  178. ),
  179. TP_printk("hrtimer=%p", __entry->hrtimer)
  180. );
  181. /**
  182. * hrtimer_expire_exit - called immediately after the hrtimer callback returns
  183. * @timer: pointer to struct hrtimer
  184. *
  185. * When used in combination with the hrtimer_expire_entry tracepoint we can
  186. * determine the runtime of the callback function.
  187. */
  188. DEFINE_EVENT(hrtimer_class, hrtimer_expire_exit,
  189. TP_PROTO(struct hrtimer *hrtimer),
  190. TP_ARGS(hrtimer)
  191. );
  192. /**
  193. * hrtimer_cancel - called when the hrtimer is canceled
  194. * @hrtimer: pointer to struct hrtimer
  195. */
  196. DEFINE_EVENT(hrtimer_class, hrtimer_cancel,
  197. TP_PROTO(struct hrtimer *hrtimer),
  198. TP_ARGS(hrtimer)
  199. );
  200. /**
  201. * itimer_state - called when itimer is started or canceled
  202. * @which: name of the interval timer
  203. * @value: the itimers value, itimer is canceled if value->it_value is
  204. * zero, otherwise it is started
  205. * @expires: the itimers expiry time
  206. */
  207. TRACE_EVENT(itimer_state,
  208. TP_PROTO(int which, const struct itimerval *const value,
  209. cputime_t expires),
  210. TP_ARGS(which, value, expires),
  211. TP_STRUCT__entry(
  212. __field( int, which )
  213. __field( cputime_t, expires )
  214. __field( long, value_sec )
  215. __field( long, value_usec )
  216. __field( long, interval_sec )
  217. __field( long, interval_usec )
  218. ),
  219. TP_fast_assign(
  220. __entry->which = which;
  221. __entry->expires = expires;
  222. __entry->value_sec = value->it_value.tv_sec;
  223. __entry->value_usec = value->it_value.tv_usec;
  224. __entry->interval_sec = value->it_interval.tv_sec;
  225. __entry->interval_usec = value->it_interval.tv_usec;
  226. ),
  227. TP_printk("which=%d expires=%llu it_value=%ld.%ld it_interval=%ld.%ld",
  228. __entry->which, (unsigned long long)__entry->expires,
  229. __entry->value_sec, __entry->value_usec,
  230. __entry->interval_sec, __entry->interval_usec)
  231. );
  232. /**
  233. * itimer_expire - called when itimer expires
  234. * @which: type of the interval timer
  235. * @pid: pid of the process which owns the timer
  236. * @now: current time, used to calculate the latency of itimer
  237. */
  238. TRACE_EVENT(itimer_expire,
  239. TP_PROTO(int which, struct pid *pid, cputime_t now),
  240. TP_ARGS(which, pid, now),
  241. TP_STRUCT__entry(
  242. __field( int , which )
  243. __field( pid_t, pid )
  244. __field( cputime_t, now )
  245. ),
  246. TP_fast_assign(
  247. __entry->which = which;
  248. __entry->now = now;
  249. __entry->pid = pid_nr(pid);
  250. ),
  251. TP_printk("which=%d pid=%d now=%llu", __entry->which,
  252. (int) __entry->pid, (unsigned long long)__entry->now)
  253. );
  254. #endif /* _TRACE_TIMER_H */
  255. /* This part must be outside protection */
  256. #include <trace/define_trace.h>