timer.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. * @bucket_expiry: the bucket expiry time
  38. */
  39. TRACE_EVENT(timer_start,
  40. TP_PROTO(struct timer_list *timer,
  41. unsigned long bucket_expiry),
  42. TP_ARGS(timer, bucket_expiry),
  43. TP_STRUCT__entry(
  44. __field( void *, timer )
  45. __field( void *, function )
  46. __field( unsigned long, expires )
  47. __field( unsigned long, bucket_expiry )
  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 = timer->expires;
  55. __entry->bucket_expiry = bucket_expiry;
  56. __entry->now = jiffies;
  57. __entry->flags = timer->flags;
  58. ),
  59. TP_printk("timer=%p function=%ps expires=%lu [timeout=%ld] bucket_expiry=%lu cpu=%u idx=%u flags=%s",
  60. __entry->timer, __entry->function, __entry->expires,
  61. (long)__entry->expires - __entry->now,
  62. __entry->bucket_expiry, __entry->flags & TIMER_CPUMASK,
  63. __entry->flags >> TIMER_ARRAYSHIFT,
  64. decode_timer_flags(__entry->flags & TIMER_TRACE_FLAGMASK))
  65. );
  66. /**
  67. * timer_expire_entry - called immediately before the timer callback
  68. * @timer: pointer to struct timer_list
  69. * @baseclk: value of timer_base::clk when timer expires
  70. *
  71. * Allows to determine the timer latency.
  72. */
  73. TRACE_EVENT(timer_expire_entry,
  74. TP_PROTO(struct timer_list *timer, unsigned long baseclk),
  75. TP_ARGS(timer, baseclk),
  76. TP_STRUCT__entry(
  77. __field( void *, timer )
  78. __field( unsigned long, now )
  79. __field( void *, function)
  80. __field( unsigned long, baseclk )
  81. ),
  82. TP_fast_assign(
  83. __entry->timer = timer;
  84. __entry->now = jiffies;
  85. __entry->function = timer->function;
  86. __entry->baseclk = baseclk;
  87. ),
  88. TP_printk("timer=%p function=%ps now=%lu baseclk=%lu",
  89. __entry->timer, __entry->function, __entry->now,
  90. __entry->baseclk)
  91. );
  92. /**
  93. * timer_expire_exit - called immediately after the timer callback returns
  94. * @timer: pointer to struct timer_list
  95. *
  96. * When used in combination with the timer_expire_entry tracepoint we can
  97. * determine the runtime of the timer callback function.
  98. *
  99. * NOTE: Do NOT dereference timer in TP_fast_assign. The pointer might
  100. * be invalid. We solely track the pointer.
  101. */
  102. DEFINE_EVENT(timer_class, timer_expire_exit,
  103. TP_PROTO(struct timer_list *timer),
  104. TP_ARGS(timer)
  105. );
  106. /**
  107. * timer_cancel - called when the timer is canceled
  108. * @timer: pointer to struct timer_list
  109. */
  110. DEFINE_EVENT(timer_class, timer_cancel,
  111. TP_PROTO(struct timer_list *timer),
  112. TP_ARGS(timer)
  113. );
  114. TRACE_EVENT(timer_base_idle,
  115. TP_PROTO(bool is_idle, unsigned int cpu),
  116. TP_ARGS(is_idle, cpu),
  117. TP_STRUCT__entry(
  118. __field( bool, is_idle )
  119. __field( unsigned int, cpu )
  120. ),
  121. TP_fast_assign(
  122. __entry->is_idle = is_idle;
  123. __entry->cpu = cpu;
  124. ),
  125. TP_printk("is_idle=%d cpu=%d",
  126. __entry->is_idle, __entry->cpu)
  127. );
  128. #define decode_clockid(type) \
  129. __print_symbolic(type, \
  130. { CLOCK_REALTIME, "CLOCK_REALTIME" }, \
  131. { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" }, \
  132. { CLOCK_BOOTTIME, "CLOCK_BOOTTIME" }, \
  133. { CLOCK_TAI, "CLOCK_TAI" })
  134. #define decode_hrtimer_mode(mode) \
  135. __print_symbolic(mode, \
  136. { HRTIMER_MODE_ABS, "ABS" }, \
  137. { HRTIMER_MODE_REL, "REL" }, \
  138. { HRTIMER_MODE_ABS_PINNED, "ABS|PINNED" }, \
  139. { HRTIMER_MODE_REL_PINNED, "REL|PINNED" }, \
  140. { HRTIMER_MODE_ABS_SOFT, "ABS|SOFT" }, \
  141. { HRTIMER_MODE_REL_SOFT, "REL|SOFT" }, \
  142. { HRTIMER_MODE_ABS_PINNED_SOFT, "ABS|PINNED|SOFT" }, \
  143. { HRTIMER_MODE_REL_PINNED_SOFT, "REL|PINNED|SOFT" }, \
  144. { HRTIMER_MODE_ABS_HARD, "ABS|HARD" }, \
  145. { HRTIMER_MODE_REL_HARD, "REL|HARD" }, \
  146. { HRTIMER_MODE_ABS_PINNED_HARD, "ABS|PINNED|HARD" }, \
  147. { HRTIMER_MODE_REL_PINNED_HARD, "REL|PINNED|HARD" })
  148. /**
  149. * hrtimer_setup - called when the hrtimer is initialized
  150. * @hrtimer: pointer to struct hrtimer
  151. * @clockid: the hrtimers clock
  152. * @mode: the hrtimers mode
  153. */
  154. TRACE_EVENT(hrtimer_setup,
  155. TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid,
  156. enum hrtimer_mode mode),
  157. TP_ARGS(hrtimer, clockid, mode),
  158. TP_STRUCT__entry(
  159. __field( void *, hrtimer )
  160. __field( clockid_t, clockid )
  161. __field( enum hrtimer_mode, mode )
  162. ),
  163. TP_fast_assign(
  164. __entry->hrtimer = hrtimer;
  165. __entry->clockid = clockid;
  166. __entry->mode = mode;
  167. ),
  168. TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer,
  169. decode_clockid(__entry->clockid),
  170. decode_hrtimer_mode(__entry->mode))
  171. );
  172. /**
  173. * hrtimer_start - called when the hrtimer is started
  174. * @hrtimer: pointer to struct hrtimer
  175. * @mode: the hrtimers mode
  176. */
  177. TRACE_EVENT(hrtimer_start,
  178. TP_PROTO(struct hrtimer *hrtimer, enum hrtimer_mode mode),
  179. TP_ARGS(hrtimer, mode),
  180. TP_STRUCT__entry(
  181. __field( void *, hrtimer )
  182. __field( void *, function )
  183. __field( s64, expires )
  184. __field( s64, softexpires )
  185. __field( enum hrtimer_mode, mode )
  186. ),
  187. TP_fast_assign(
  188. __entry->hrtimer = hrtimer;
  189. __entry->function = ACCESS_PRIVATE(hrtimer, function);
  190. __entry->expires = hrtimer_get_expires(hrtimer);
  191. __entry->softexpires = hrtimer_get_softexpires(hrtimer);
  192. __entry->mode = mode;
  193. ),
  194. TP_printk("hrtimer=%p function=%ps expires=%llu softexpires=%llu "
  195. "mode=%s", __entry->hrtimer, __entry->function,
  196. (unsigned long long) __entry->expires,
  197. (unsigned long long) __entry->softexpires,
  198. decode_hrtimer_mode(__entry->mode))
  199. );
  200. /**
  201. * hrtimer_expire_entry - called immediately before the hrtimer callback
  202. * @hrtimer: pointer to struct hrtimer
  203. * @now: pointer to variable which contains current time of the
  204. * timers base.
  205. *
  206. * Allows to determine the timer latency.
  207. */
  208. TRACE_EVENT(hrtimer_expire_entry,
  209. TP_PROTO(struct hrtimer *hrtimer, ktime_t *now),
  210. TP_ARGS(hrtimer, now),
  211. TP_STRUCT__entry(
  212. __field( void *, hrtimer )
  213. __field( s64, now )
  214. __field( void *, function)
  215. ),
  216. TP_fast_assign(
  217. __entry->hrtimer = hrtimer;
  218. __entry->now = *now;
  219. __entry->function = ACCESS_PRIVATE(hrtimer, function);
  220. ),
  221. TP_printk("hrtimer=%p function=%ps now=%llu",
  222. __entry->hrtimer, __entry->function,
  223. (unsigned long long) __entry->now)
  224. );
  225. DECLARE_EVENT_CLASS(hrtimer_class,
  226. TP_PROTO(struct hrtimer *hrtimer),
  227. TP_ARGS(hrtimer),
  228. TP_STRUCT__entry(
  229. __field( void *, hrtimer )
  230. ),
  231. TP_fast_assign(
  232. __entry->hrtimer = hrtimer;
  233. ),
  234. TP_printk("hrtimer=%p", __entry->hrtimer)
  235. );
  236. /**
  237. * hrtimer_expire_exit - called immediately after the hrtimer callback returns
  238. * @hrtimer: pointer to struct hrtimer
  239. *
  240. * When used in combination with the hrtimer_expire_entry tracepoint we can
  241. * determine the runtime of the callback function.
  242. */
  243. DEFINE_EVENT(hrtimer_class, hrtimer_expire_exit,
  244. TP_PROTO(struct hrtimer *hrtimer),
  245. TP_ARGS(hrtimer)
  246. );
  247. /**
  248. * hrtimer_cancel - called when the hrtimer is canceled
  249. * @hrtimer: pointer to struct hrtimer
  250. */
  251. DEFINE_EVENT(hrtimer_class, hrtimer_cancel,
  252. TP_PROTO(struct hrtimer *hrtimer),
  253. TP_ARGS(hrtimer)
  254. );
  255. /**
  256. * itimer_state - called when itimer is started or canceled
  257. * @which: name of the interval timer
  258. * @value: the itimers value, itimer is canceled if value->it_value is
  259. * zero, otherwise it is started
  260. * @expires: the itimers expiry time
  261. */
  262. TRACE_EVENT(itimer_state,
  263. TP_PROTO(int which, const struct itimerspec64 *const value,
  264. unsigned long long expires),
  265. TP_ARGS(which, value, expires),
  266. TP_STRUCT__entry(
  267. __field( int, which )
  268. __field( unsigned long long, expires )
  269. __field( long, value_sec )
  270. __field( long, value_nsec )
  271. __field( long, interval_sec )
  272. __field( long, interval_nsec )
  273. ),
  274. TP_fast_assign(
  275. __entry->which = which;
  276. __entry->expires = expires;
  277. __entry->value_sec = value->it_value.tv_sec;
  278. __entry->value_nsec = value->it_value.tv_nsec;
  279. __entry->interval_sec = value->it_interval.tv_sec;
  280. __entry->interval_nsec = value->it_interval.tv_nsec;
  281. ),
  282. TP_printk("which=%d expires=%llu it_value=%ld.%06ld it_interval=%ld.%06ld",
  283. __entry->which, __entry->expires,
  284. __entry->value_sec, __entry->value_nsec / NSEC_PER_USEC,
  285. __entry->interval_sec, __entry->interval_nsec / NSEC_PER_USEC)
  286. );
  287. /**
  288. * itimer_expire - called when itimer expires
  289. * @which: type of the interval timer
  290. * @pid: pid of the process which owns the timer
  291. * @now: current time, used to calculate the latency of itimer
  292. */
  293. TRACE_EVENT(itimer_expire,
  294. TP_PROTO(int which, struct pid *pid, unsigned long long now),
  295. TP_ARGS(which, pid, now),
  296. TP_STRUCT__entry(
  297. __field( int , which )
  298. __field( pid_t, pid )
  299. __field( unsigned long long, now )
  300. ),
  301. TP_fast_assign(
  302. __entry->which = which;
  303. __entry->now = now;
  304. __entry->pid = pid_nr(pid);
  305. ),
  306. TP_printk("which=%d pid=%d now=%llu", __entry->which,
  307. (int) __entry->pid, __entry->now)
  308. );
  309. #ifdef CONFIG_NO_HZ_COMMON
  310. #define TICK_DEP_NAMES \
  311. tick_dep_mask_name(NONE) \
  312. tick_dep_name(POSIX_TIMER) \
  313. tick_dep_name(PERF_EVENTS) \
  314. tick_dep_name(SCHED) \
  315. tick_dep_name(CLOCK_UNSTABLE) \
  316. tick_dep_name(RCU) \
  317. tick_dep_name_end(RCU_EXP)
  318. #undef tick_dep_name
  319. #undef tick_dep_mask_name
  320. #undef tick_dep_name_end
  321. /* The MASK will convert to their bits and they need to be processed too */
  322. #define tick_dep_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
  323. TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
  324. #define tick_dep_name_end(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
  325. TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
  326. /* NONE only has a mask defined for it */
  327. #define tick_dep_mask_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
  328. TICK_DEP_NAMES
  329. #undef tick_dep_name
  330. #undef tick_dep_mask_name
  331. #undef tick_dep_name_end
  332. #define tick_dep_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
  333. #define tick_dep_mask_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
  334. #define tick_dep_name_end(sdep) { TICK_DEP_MASK_##sdep, #sdep }
  335. #define show_tick_dep_name(val) \
  336. __print_symbolic(val, TICK_DEP_NAMES)
  337. TRACE_EVENT(tick_stop,
  338. TP_PROTO(int success, int dependency),
  339. TP_ARGS(success, dependency),
  340. TP_STRUCT__entry(
  341. __field( int , success )
  342. __field( int , dependency )
  343. ),
  344. TP_fast_assign(
  345. __entry->success = success;
  346. __entry->dependency = dependency;
  347. ),
  348. TP_printk("success=%d dependency=%s", __entry->success, \
  349. show_tick_dep_name(__entry->dependency))
  350. );
  351. #endif
  352. #endif /* _TRACE_TIMER_H */
  353. /* This part must be outside protection */
  354. #include <trace/define_trace.h>