timer.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #undef TRACE_SYSTEM
  3. #define TRACE_SYSTEM timer
  4. #if !defined(_TRACE_TIMER_H) || defined(TRACE_HEADER_MULTI_READ)
  5. #define _TRACE_TIMER_H
  6. #include <linux/tracepoint.h>
  7. #include <linux/hrtimer.h>
  8. #include <linux/timer.h>
  9. DECLARE_EVENT_CLASS(timer_class,
  10. TP_PROTO(struct timer_list *timer),
  11. TP_ARGS(timer),
  12. TP_STRUCT__entry(
  13. __field( void *, timer )
  14. ),
  15. TP_fast_assign(
  16. __entry->timer = timer;
  17. ),
  18. TP_printk("timer=%p", __entry->timer)
  19. );
  20. /**
  21. * timer_init - called when the timer is initialized
  22. * @timer: pointer to struct timer_list
  23. */
  24. DEFINE_EVENT(timer_class, timer_init,
  25. TP_PROTO(struct timer_list *timer),
  26. TP_ARGS(timer)
  27. );
  28. #define decode_timer_flags(flags) \
  29. __print_flags(flags, "|", \
  30. { TIMER_MIGRATING, "M" }, \
  31. { TIMER_DEFERRABLE, "D" }, \
  32. { TIMER_PINNED, "P" }, \
  33. { TIMER_IRQSAFE, "I" })
  34. /**
  35. * timer_start - called when the timer is started
  36. * @timer: pointer to struct timer_list
  37. * @expires: the timers expiry time
  38. */
  39. TRACE_EVENT(timer_start,
  40. TP_PROTO(struct timer_list *timer,
  41. unsigned long expires,
  42. unsigned int flags),
  43. TP_ARGS(timer, expires, flags),
  44. TP_STRUCT__entry(
  45. __field( void *, timer )
  46. __field( void *, function )
  47. __field( unsigned long, expires )
  48. __field( unsigned long, now )
  49. __field( unsigned int, flags )
  50. ),
  51. TP_fast_assign(
  52. __entry->timer = timer;
  53. __entry->function = timer->function;
  54. __entry->expires = expires;
  55. __entry->now = jiffies;
  56. __entry->flags = flags;
  57. ),
  58. TP_printk("timer=%p function=%pf expires=%lu [timeout=%ld] cpu=%u idx=%u flags=%s",
  59. __entry->timer, __entry->function, __entry->expires,
  60. (long)__entry->expires - __entry->now,
  61. __entry->flags & TIMER_CPUMASK,
  62. __entry->flags >> TIMER_ARRAYSHIFT,
  63. decode_timer_flags(__entry->flags & TIMER_TRACE_FLAGMASK))
  64. );
  65. /**
  66. * timer_expire_entry - called immediately before the timer callback
  67. * @timer: pointer to struct timer_list
  68. *
  69. * Allows to determine the timer latency.
  70. */
  71. TRACE_EVENT(timer_expire_entry,
  72. TP_PROTO(struct timer_list *timer),
  73. TP_ARGS(timer),
  74. TP_STRUCT__entry(
  75. __field( void *, timer )
  76. __field( unsigned long, now )
  77. __field( void *, function)
  78. ),
  79. TP_fast_assign(
  80. __entry->timer = timer;
  81. __entry->now = jiffies;
  82. __entry->function = timer->function;
  83. ),
  84. TP_printk("timer=%p function=%pf now=%lu", __entry->timer, __entry->function,__entry->now)
  85. );
  86. /**
  87. * timer_expire_exit - called immediately after the timer callback returns
  88. * @timer: pointer to struct timer_list
  89. *
  90. * When used in combination with the timer_expire_entry tracepoint we can
  91. * determine the runtime of the timer callback function.
  92. *
  93. * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might
  94. * be invalid. We solely track the pointer.
  95. */
  96. DEFINE_EVENT(timer_class, timer_expire_exit,
  97. TP_PROTO(struct timer_list *timer),
  98. TP_ARGS(timer)
  99. );
  100. /**
  101. * timer_cancel - called when the timer is canceled
  102. * @timer: pointer to struct timer_list
  103. */
  104. DEFINE_EVENT(timer_class, timer_cancel,
  105. TP_PROTO(struct timer_list *timer),
  106. TP_ARGS(timer)
  107. );
  108. #define decode_clockid(type) \
  109. __print_symbolic(type, \
  110. { CLOCK_REALTIME, "CLOCK_REALTIME" }, \
  111. { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" }, \
  112. { CLOCK_BOOTTIME, "CLOCK_BOOTTIME" }, \
  113. { CLOCK_TAI, "CLOCK_TAI" })
  114. #define decode_hrtimer_mode(mode) \
  115. __print_symbolic(mode, \
  116. { HRTIMER_MODE_ABS, "ABS" }, \
  117. { HRTIMER_MODE_REL, "REL" }, \
  118. { HRTIMER_MODE_ABS_PINNED, "ABS|PINNED" }, \
  119. { HRTIMER_MODE_REL_PINNED, "REL|PINNED" }, \
  120. { HRTIMER_MODE_ABS_SOFT, "ABS|SOFT" }, \
  121. { HRTIMER_MODE_REL_SOFT, "REL|SOFT" }, \
  122. { HRTIMER_MODE_ABS_PINNED_SOFT, "ABS|PINNED|SOFT" }, \
  123. { HRTIMER_MODE_REL_PINNED_SOFT, "REL|PINNED|SOFT" })
  124. /**
  125. * hrtimer_init - called when the hrtimer is initialized
  126. * @hrtimer: pointer to struct hrtimer
  127. * @clockid: the hrtimers clock
  128. * @mode: the hrtimers mode
  129. */
  130. TRACE_EVENT(hrtimer_init,
  131. TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid,
  132. enum hrtimer_mode mode),
  133. TP_ARGS(hrtimer, clockid, mode),
  134. TP_STRUCT__entry(
  135. __field( void *, hrtimer )
  136. __field( clockid_t, clockid )
  137. __field( enum hrtimer_mode, mode )
  138. ),
  139. TP_fast_assign(
  140. __entry->hrtimer = hrtimer;
  141. __entry->clockid = clockid;
  142. __entry->mode = mode;
  143. ),
  144. TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer,
  145. decode_clockid(__entry->clockid),
  146. decode_hrtimer_mode(__entry->mode))
  147. );
  148. /**
  149. * hrtimer_start - called when the hrtimer is started
  150. * @hrtimer: pointer to struct hrtimer
  151. */
  152. TRACE_EVENT(hrtimer_start,
  153. TP_PROTO(struct hrtimer *hrtimer, enum hrtimer_mode mode),
  154. TP_ARGS(hrtimer, mode),
  155. TP_STRUCT__entry(
  156. __field( void *, hrtimer )
  157. __field( void *, function )
  158. __field( s64, expires )
  159. __field( s64, softexpires )
  160. __field( enum hrtimer_mode, mode )
  161. ),
  162. TP_fast_assign(
  163. __entry->hrtimer = hrtimer;
  164. __entry->function = hrtimer->function;
  165. __entry->expires = hrtimer_get_expires(hrtimer);
  166. __entry->softexpires = hrtimer_get_softexpires(hrtimer);
  167. __entry->mode = mode;
  168. ),
  169. TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu "
  170. "mode=%s", __entry->hrtimer, __entry->function,
  171. (unsigned long long) __entry->expires,
  172. (unsigned long long) __entry->softexpires,
  173. decode_hrtimer_mode(__entry->mode))
  174. );
  175. /**
  176. * hrtimer_expire_entry - called immediately before the hrtimer callback
  177. * @hrtimer: pointer to struct hrtimer
  178. * @now: pointer to variable which contains current time of the
  179. * timers base.
  180. *
  181. * Allows to determine the timer latency.
  182. */
  183. TRACE_EVENT(hrtimer_expire_entry,
  184. TP_PROTO(struct hrtimer *hrtimer, ktime_t *now),
  185. TP_ARGS(hrtimer, now),
  186. TP_STRUCT__entry(
  187. __field( void *, hrtimer )
  188. __field( s64, now )
  189. __field( void *, function)
  190. ),
  191. TP_fast_assign(
  192. __entry->hrtimer = hrtimer;
  193. __entry->now = *now;
  194. __entry->function = hrtimer->function;
  195. ),
  196. TP_printk("hrtimer=%p function=%pf now=%llu", __entry->hrtimer, __entry->function,
  197. (unsigned long long) __entry->now)
  198. );
  199. DECLARE_EVENT_CLASS(hrtimer_class,
  200. TP_PROTO(struct hrtimer *hrtimer),
  201. TP_ARGS(hrtimer),
  202. TP_STRUCT__entry(
  203. __field( void *, hrtimer )
  204. ),
  205. TP_fast_assign(
  206. __entry->hrtimer = hrtimer;
  207. ),
  208. TP_printk("hrtimer=%p", __entry->hrtimer)
  209. );
  210. /**
  211. * hrtimer_expire_exit - called immediately after the hrtimer callback returns
  212. * @hrtimer: pointer to struct hrtimer
  213. *
  214. * When used in combination with the hrtimer_expire_entry tracepoint we can
  215. * determine the runtime of the callback function.
  216. */
  217. DEFINE_EVENT(hrtimer_class, hrtimer_expire_exit,
  218. TP_PROTO(struct hrtimer *hrtimer),
  219. TP_ARGS(hrtimer)
  220. );
  221. /**
  222. * hrtimer_cancel - called when the hrtimer is canceled
  223. * @hrtimer: pointer to struct hrtimer
  224. */
  225. DEFINE_EVENT(hrtimer_class, hrtimer_cancel,
  226. TP_PROTO(struct hrtimer *hrtimer),
  227. TP_ARGS(hrtimer)
  228. );
  229. /**
  230. * itimer_state - called when itimer is started or canceled
  231. * @which: name of the interval timer
  232. * @value: the itimers value, itimer is canceled if value->it_value is
  233. * zero, otherwise it is started
  234. * @expires: the itimers expiry time
  235. */
  236. TRACE_EVENT(itimer_state,
  237. TP_PROTO(int which, const struct itimerval *const value,
  238. unsigned long long expires),
  239. TP_ARGS(which, value, expires),
  240. TP_STRUCT__entry(
  241. __field( int, which )
  242. __field( unsigned long long, expires )
  243. __field( long, value_sec )
  244. __field( long, value_usec )
  245. __field( long, interval_sec )
  246. __field( long, interval_usec )
  247. ),
  248. TP_fast_assign(
  249. __entry->which = which;
  250. __entry->expires = expires;
  251. __entry->value_sec = value->it_value.tv_sec;
  252. __entry->value_usec = value->it_value.tv_usec;
  253. __entry->interval_sec = value->it_interval.tv_sec;
  254. __entry->interval_usec = value->it_interval.tv_usec;
  255. ),
  256. TP_printk("which=%d expires=%llu it_value=%ld.%ld it_interval=%ld.%ld",
  257. __entry->which, __entry->expires,
  258. __entry->value_sec, __entry->value_usec,
  259. __entry->interval_sec, __entry->interval_usec)
  260. );
  261. /**
  262. * itimer_expire - called when itimer expires
  263. * @which: type of the interval timer
  264. * @pid: pid of the process which owns the timer
  265. * @now: current time, used to calculate the latency of itimer
  266. */
  267. TRACE_EVENT(itimer_expire,
  268. TP_PROTO(int which, struct pid *pid, unsigned long long now),
  269. TP_ARGS(which, pid, now),
  270. TP_STRUCT__entry(
  271. __field( int , which )
  272. __field( pid_t, pid )
  273. __field( unsigned long long, now )
  274. ),
  275. TP_fast_assign(
  276. __entry->which = which;
  277. __entry->now = now;
  278. __entry->pid = pid_nr(pid);
  279. ),
  280. TP_printk("which=%d pid=%d now=%llu", __entry->which,
  281. (int) __entry->pid, __entry->now)
  282. );
  283. #ifdef CONFIG_NO_HZ_COMMON
  284. #define TICK_DEP_NAMES \
  285. tick_dep_mask_name(NONE) \
  286. tick_dep_name(POSIX_TIMER) \
  287. tick_dep_name(PERF_EVENTS) \
  288. tick_dep_name(SCHED) \
  289. tick_dep_name_end(CLOCK_UNSTABLE)
  290. #undef tick_dep_name
  291. #undef tick_dep_mask_name
  292. #undef tick_dep_name_end
  293. /* The MASK will convert to their bits and they need to be processed too */
  294. #define tick_dep_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
  295. TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
  296. #define tick_dep_name_end(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
  297. TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
  298. /* NONE only has a mask defined for it */
  299. #define tick_dep_mask_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
  300. TICK_DEP_NAMES
  301. #undef tick_dep_name
  302. #undef tick_dep_mask_name
  303. #undef tick_dep_name_end
  304. #define tick_dep_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
  305. #define tick_dep_mask_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
  306. #define tick_dep_name_end(sdep) { TICK_DEP_MASK_##sdep, #sdep }
  307. #define show_tick_dep_name(val) \
  308. __print_symbolic(val, TICK_DEP_NAMES)
  309. TRACE_EVENT(tick_stop,
  310. TP_PROTO(int success, int dependency),
  311. TP_ARGS(success, dependency),
  312. TP_STRUCT__entry(
  313. __field( int , success )
  314. __field( int , dependency )
  315. ),
  316. TP_fast_assign(
  317. __entry->success = success;
  318. __entry->dependency = dependency;
  319. ),
  320. TP_printk("success=%d dependency=%s", __entry->success, \
  321. show_tick_dep_name(__entry->dependency))
  322. );
  323. #endif
  324. #endif /* _TRACE_TIMER_H */
  325. /* This part must be outside protection */
  326. #include <trace/define_trace.h>