timer.h 7.2 KB

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