timer.h 9.2 KB

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