timer.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. /**
  99. * hrtimer_init - called when the hrtimer is initialized
  100. * @hrtimer: pointer to struct hrtimer
  101. * @clockid: the hrtimers clock
  102. * @mode: the hrtimers mode
  103. */
  104. TRACE_EVENT(hrtimer_init,
  105. TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid,
  106. enum hrtimer_mode mode),
  107. TP_ARGS(hrtimer, clockid, mode),
  108. TP_STRUCT__entry(
  109. __field( void *, hrtimer )
  110. __field( clockid_t, clockid )
  111. __field( enum hrtimer_mode, mode )
  112. ),
  113. TP_fast_assign(
  114. __entry->hrtimer = hrtimer;
  115. __entry->clockid = clockid;
  116. __entry->mode = mode;
  117. ),
  118. TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer,
  119. __entry->clockid == CLOCK_REALTIME ?
  120. "CLOCK_REALTIME" : "CLOCK_MONOTONIC",
  121. __entry->mode == HRTIMER_MODE_ABS ?
  122. "HRTIMER_MODE_ABS" : "HRTIMER_MODE_REL")
  123. );
  124. /**
  125. * hrtimer_start - called when the hrtimer is started
  126. * @hrtimer: pointer to struct hrtimer
  127. */
  128. TRACE_EVENT(hrtimer_start,
  129. TP_PROTO(struct hrtimer *hrtimer),
  130. TP_ARGS(hrtimer),
  131. TP_STRUCT__entry(
  132. __field( void *, hrtimer )
  133. __field( void *, function )
  134. __field( s64, expires )
  135. __field( s64, softexpires )
  136. ),
  137. TP_fast_assign(
  138. __entry->hrtimer = hrtimer;
  139. __entry->function = hrtimer->function;
  140. __entry->expires = hrtimer_get_expires(hrtimer).tv64;
  141. __entry->softexpires = hrtimer_get_softexpires(hrtimer).tv64;
  142. ),
  143. TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu",
  144. __entry->hrtimer, __entry->function,
  145. (unsigned long long)ktime_to_ns((ktime_t) {
  146. .tv64 = __entry->expires }),
  147. (unsigned long long)ktime_to_ns((ktime_t) {
  148. .tv64 = __entry->softexpires }))
  149. );
  150. /**
  151. * hrtimer_expire_entry - called immediately before the hrtimer callback
  152. * @hrtimer: pointer to struct hrtimer
  153. * @now: pointer to variable which contains current time of the
  154. * timers base.
  155. *
  156. * Allows to determine the timer latency.
  157. */
  158. TRACE_EVENT(hrtimer_expire_entry,
  159. TP_PROTO(struct hrtimer *hrtimer, ktime_t *now),
  160. TP_ARGS(hrtimer, now),
  161. TP_STRUCT__entry(
  162. __field( void *, hrtimer )
  163. __field( s64, now )
  164. __field( void *, function)
  165. ),
  166. TP_fast_assign(
  167. __entry->hrtimer = hrtimer;
  168. __entry->now = now->tv64;
  169. __entry->function = hrtimer->function;
  170. ),
  171. TP_printk("hrtimer=%p function=%pf now=%llu", __entry->hrtimer, __entry->function,
  172. (unsigned long long)ktime_to_ns((ktime_t) { .tv64 = __entry->now }))
  173. );
  174. DECLARE_EVENT_CLASS(hrtimer_class,
  175. TP_PROTO(struct hrtimer *hrtimer),
  176. TP_ARGS(hrtimer),
  177. TP_STRUCT__entry(
  178. __field( void *, hrtimer )
  179. ),
  180. TP_fast_assign(
  181. __entry->hrtimer = hrtimer;
  182. ),
  183. TP_printk("hrtimer=%p", __entry->hrtimer)
  184. );
  185. /**
  186. * hrtimer_expire_exit - called immediately after the hrtimer callback returns
  187. * @hrtimer: pointer to struct hrtimer
  188. *
  189. * When used in combination with the hrtimer_expire_entry tracepoint we can
  190. * determine the runtime of the callback function.
  191. */
  192. DEFINE_EVENT(hrtimer_class, hrtimer_expire_exit,
  193. TP_PROTO(struct hrtimer *hrtimer),
  194. TP_ARGS(hrtimer)
  195. );
  196. /**
  197. * hrtimer_cancel - called when the hrtimer is canceled
  198. * @hrtimer: pointer to struct hrtimer
  199. */
  200. DEFINE_EVENT(hrtimer_class, hrtimer_cancel,
  201. TP_PROTO(struct hrtimer *hrtimer),
  202. TP_ARGS(hrtimer)
  203. );
  204. /**
  205. * itimer_state - called when itimer is started or canceled
  206. * @which: name of the interval timer
  207. * @value: the itimers value, itimer is canceled if value->it_value is
  208. * zero, otherwise it is started
  209. * @expires: the itimers expiry time
  210. */
  211. TRACE_EVENT(itimer_state,
  212. TP_PROTO(int which, const struct itimerval *const value,
  213. cputime_t expires),
  214. TP_ARGS(which, value, expires),
  215. TP_STRUCT__entry(
  216. __field( int, which )
  217. __field( cputime_t, expires )
  218. __field( long, value_sec )
  219. __field( long, value_usec )
  220. __field( long, interval_sec )
  221. __field( long, interval_usec )
  222. ),
  223. TP_fast_assign(
  224. __entry->which = which;
  225. __entry->expires = expires;
  226. __entry->value_sec = value->it_value.tv_sec;
  227. __entry->value_usec = value->it_value.tv_usec;
  228. __entry->interval_sec = value->it_interval.tv_sec;
  229. __entry->interval_usec = value->it_interval.tv_usec;
  230. ),
  231. TP_printk("which=%d expires=%llu it_value=%ld.%ld it_interval=%ld.%ld",
  232. __entry->which, (unsigned long long)__entry->expires,
  233. __entry->value_sec, __entry->value_usec,
  234. __entry->interval_sec, __entry->interval_usec)
  235. );
  236. /**
  237. * itimer_expire - called when itimer expires
  238. * @which: type of the interval timer
  239. * @pid: pid of the process which owns the timer
  240. * @now: current time, used to calculate the latency of itimer
  241. */
  242. TRACE_EVENT(itimer_expire,
  243. TP_PROTO(int which, struct pid *pid, cputime_t now),
  244. TP_ARGS(which, pid, now),
  245. TP_STRUCT__entry(
  246. __field( int , which )
  247. __field( pid_t, pid )
  248. __field( cputime_t, now )
  249. ),
  250. TP_fast_assign(
  251. __entry->which = which;
  252. __entry->now = now;
  253. __entry->pid = pid_nr(pid);
  254. ),
  255. TP_printk("which=%d pid=%d now=%llu", __entry->which,
  256. (int) __entry->pid, (unsigned long long)__entry->now)
  257. );
  258. #ifdef CONFIG_NO_HZ_COMMON
  259. #define TICK_DEP_NAMES \
  260. tick_dep_mask_name(NONE) \
  261. tick_dep_name(POSIX_TIMER) \
  262. tick_dep_name(PERF_EVENTS) \
  263. tick_dep_name(SCHED) \
  264. tick_dep_name_end(CLOCK_UNSTABLE)
  265. #undef tick_dep_name
  266. #undef tick_dep_mask_name
  267. #undef tick_dep_name_end
  268. /* The MASK will convert to their bits and they need to be processed too */
  269. #define tick_dep_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
  270. TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
  271. #define tick_dep_name_end(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
  272. TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
  273. /* NONE only has a mask defined for it */
  274. #define tick_dep_mask_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
  275. TICK_DEP_NAMES
  276. #undef tick_dep_name
  277. #undef tick_dep_mask_name
  278. #undef tick_dep_name_end
  279. #define tick_dep_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
  280. #define tick_dep_mask_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
  281. #define tick_dep_name_end(sdep) { TICK_DEP_MASK_##sdep, #sdep }
  282. #define show_tick_dep_name(val) \
  283. __print_symbolic(val, TICK_DEP_NAMES)
  284. TRACE_EVENT(tick_stop,
  285. TP_PROTO(int success, int dependency),
  286. TP_ARGS(success, dependency),
  287. TP_STRUCT__entry(
  288. __field( int , success )
  289. __field( int , dependency )
  290. ),
  291. TP_fast_assign(
  292. __entry->success = success;
  293. __entry->dependency = dependency;
  294. ),
  295. TP_printk("success=%d dependency=%s", __entry->success, \
  296. show_tick_dep_name(__entry->dependency))
  297. );
  298. #endif
  299. #endif /* _TRACE_TIMER_H */
  300. /* This part must be outside protection */
  301. #include <trace/define_trace.h>