timer.h 8.3 KB

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