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