timer.h 7.6 KB

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