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=%pf 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), 93 94 TP_ARGS(timer), 95 96 TP_STRUCT__entry( 97 __field( void *, timer ) 98 __field( unsigned long, now ) 99 __field( void *, function) 100 ), 101 102 TP_fast_assign( 103 __entry->timer = timer; 104 __entry->now = jiffies; 105 __entry->function = timer->function; 106 ), 107 108 TP_printk("timer=%p function=%pf now=%lu", __entry->timer, __entry->function,__entry->now) 109 ); 110 111 /** 112 * timer_expire_exit - called immediately after the timer callback returns 113 * @timer: pointer to struct timer_list 114 * 115 * When used in combination with the timer_expire_entry tracepoint we can 116 * determine the runtime of the timer callback function. 117 * 118 * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might 119 * be invalid. We solely track the pointer. 120 */ 121 DEFINE_EVENT(timer_class, timer_expire_exit, 122 123 TP_PROTO(struct timer_list *timer), 124 125 TP_ARGS(timer) 126 ); 127 128 /** 129 * timer_cancel - called when the timer is canceled 130 * @timer: pointer to struct timer_list 131 */ 132 DEFINE_EVENT(timer_class, timer_cancel, 133 134 TP_PROTO(struct timer_list *timer), 135 136 TP_ARGS(timer) 137 ); 138 139 #define decode_clockid(type) \ 140 __print_symbolic(type, \ 141 { CLOCK_REALTIME, "CLOCK_REALTIME" }, \ 142 { CLOCK_MONOTONIC, "CLOCK_MONOTONIC" }, \ 143 { CLOCK_BOOTTIME, "CLOCK_BOOTTIME" }, \ 144 { CLOCK_TAI, "CLOCK_TAI" }) 145 146 #define decode_hrtimer_mode(mode) \ 147 __print_symbolic(mode, \ 148 { HRTIMER_MODE_ABS, "ABS" }, \ 149 { HRTIMER_MODE_REL, "REL" }, \ 150 { HRTIMER_MODE_ABS_PINNED, "ABS|PINNED" }, \ 151 { HRTIMER_MODE_REL_PINNED, "REL|PINNED" }) 152 153 /** 154 * hrtimer_init - called when the hrtimer is initialized 155 * @hrtimer: pointer to struct hrtimer 156 * @clockid: the hrtimers clock 157 * @mode: the hrtimers mode 158 */ 159 TRACE_EVENT(hrtimer_init, 160 161 TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid, 162 enum hrtimer_mode mode), 163 164 TP_ARGS(hrtimer, clockid, mode), 165 166 TP_STRUCT__entry( 167 __field( void *, hrtimer ) 168 __field( clockid_t, clockid ) 169 __field( enum hrtimer_mode, mode ) 170 ), 171 172 TP_fast_assign( 173 __entry->hrtimer = hrtimer; 174 __entry->clockid = clockid; 175 __entry->mode = mode; 176 ), 177 178 TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer, 179 decode_clockid(__entry->clockid), 180 decode_hrtimer_mode(__entry->mode)) 181 ); 182 183 /** 184 * hrtimer_start - called when the hrtimer is started 185 * @hrtimer: pointer to struct hrtimer 186 */ 187 TRACE_EVENT(hrtimer_start, 188 189 TP_PROTO(struct hrtimer *hrtimer, enum hrtimer_mode mode), 190 191 TP_ARGS(hrtimer, mode), 192 193 TP_STRUCT__entry( 194 __field( void *, hrtimer ) 195 __field( void *, function ) 196 __field( s64, expires ) 197 __field( s64, softexpires ) 198 __field( enum hrtimer_mode, mode ) 199 ), 200 201 TP_fast_assign( 202 __entry->hrtimer = hrtimer; 203 __entry->function = hrtimer->function; 204 __entry->expires = hrtimer_get_expires(hrtimer); 205 __entry->softexpires = hrtimer_get_softexpires(hrtimer); 206 __entry->mode = mode; 207 ), 208 209 TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu " 210 "mode=%s", __entry->hrtimer, __entry->function, 211 (unsigned long long) __entry->expires, 212 (unsigned long long) __entry->softexpires, 213 decode_hrtimer_mode(__entry->mode)) 214 ); 215 216 /** 217 * hrtimer_expire_entry - called immediately before the hrtimer callback 218 * @hrtimer: pointer to struct hrtimer 219 * @now: pointer to variable which contains current time of the 220 * timers base. 221 * 222 * Allows to determine the timer latency. 223 */ 224 TRACE_EVENT(hrtimer_expire_entry, 225 226 TP_PROTO(struct hrtimer *hrtimer, ktime_t *now), 227 228 TP_ARGS(hrtimer, now), 229 230 TP_STRUCT__entry( 231 __field( void *, hrtimer ) 232 __field( s64, now ) 233 __field( void *, function) 234 ), 235 236 TP_fast_assign( 237 __entry->hrtimer = hrtimer; 238 __entry->now = *now; 239 __entry->function = hrtimer->function; 240 ), 241 242 TP_printk("hrtimer=%p function=%pf now=%llu", __entry->hrtimer, __entry->function, 243 (unsigned long long) __entry->now) 244 ); 245 246 DECLARE_EVENT_CLASS(hrtimer_class, 247 248 TP_PROTO(struct hrtimer *hrtimer), 249 250 TP_ARGS(hrtimer), 251 252 TP_STRUCT__entry( 253 __field( void *, hrtimer ) 254 ), 255 256 TP_fast_assign( 257 __entry->hrtimer = hrtimer; 258 ), 259 260 TP_printk("hrtimer=%p", __entry->hrtimer) 261 ); 262 263 /** 264 * hrtimer_expire_exit - called immediately after the hrtimer callback returns 265 * @hrtimer: pointer to struct hrtimer 266 * 267 * When used in combination with the hrtimer_expire_entry tracepoint we can 268 * determine the runtime of the callback function. 269 */ 270 DEFINE_EVENT(hrtimer_class, hrtimer_expire_exit, 271 272 TP_PROTO(struct hrtimer *hrtimer), 273 274 TP_ARGS(hrtimer) 275 ); 276 277 /** 278 * hrtimer_cancel - called when the hrtimer is canceled 279 * @hrtimer: pointer to struct hrtimer 280 */ 281 DEFINE_EVENT(hrtimer_class, hrtimer_cancel, 282 283 TP_PROTO(struct hrtimer *hrtimer), 284 285 TP_ARGS(hrtimer) 286 ); 287 288 /** 289 * itimer_state - called when itimer is started or canceled 290 * @which: name of the interval timer 291 * @value: the itimers value, itimer is canceled if value->it_value is 292 * zero, otherwise it is started 293 * @expires: the itimers expiry time 294 */ 295 TRACE_EVENT(itimer_state, 296 297 TP_PROTO(int which, const struct itimerval *const value, 298 unsigned long long expires), 299 300 TP_ARGS(which, value, expires), 301 302 TP_STRUCT__entry( 303 __field( int, which ) 304 __field( unsigned long long, expires ) 305 __field( long, value_sec ) 306 __field( long, value_usec ) 307 __field( long, interval_sec ) 308 __field( long, interval_usec ) 309 ), 310 311 TP_fast_assign( 312 __entry->which = which; 313 __entry->expires = expires; 314 __entry->value_sec = value->it_value.tv_sec; 315 __entry->value_usec = value->it_value.tv_usec; 316 __entry->interval_sec = value->it_interval.tv_sec; 317 __entry->interval_usec = value->it_interval.tv_usec; 318 ), 319 320 TP_printk("which=%d expires=%llu it_value=%ld.%ld it_interval=%ld.%ld", 321 __entry->which, __entry->expires, 322 __entry->value_sec, __entry->value_usec, 323 __entry->interval_sec, __entry->interval_usec) 324 ); 325 326 /** 327 * itimer_expire - called when itimer expires 328 * @which: type of the interval timer 329 * @pid: pid of the process which owns the timer 330 * @now: current time, used to calculate the latency of itimer 331 */ 332 TRACE_EVENT(itimer_expire, 333 334 TP_PROTO(int which, struct pid *pid, unsigned long long now), 335 336 TP_ARGS(which, pid, now), 337 338 TP_STRUCT__entry( 339 __field( int , which ) 340 __field( pid_t, pid ) 341 __field( unsigned long long, now ) 342 ), 343 344 TP_fast_assign( 345 __entry->which = which; 346 __entry->now = now; 347 __entry->pid = pid_nr(pid); 348 ), 349 350 TP_printk("which=%d pid=%d now=%llu", __entry->which, 351 (int) __entry->pid, __entry->now) 352 ); 353 354 #ifdef CONFIG_NO_HZ_COMMON 355 356 #define TICK_DEP_NAMES \ 357 tick_dep_mask_name(NONE) \ 358 tick_dep_name(POSIX_TIMER) \ 359 tick_dep_name(PERF_EVENTS) \ 360 tick_dep_name(SCHED) \ 361 tick_dep_name_end(CLOCK_UNSTABLE) 362 363 #undef tick_dep_name 364 #undef tick_dep_mask_name 365 #undef tick_dep_name_end 366 367 /* The MASK will convert to their bits and they need to be processed too */ 368 #define tick_dep_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \ 369 TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep); 370 #define tick_dep_name_end(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \ 371 TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep); 372 /* NONE only has a mask defined for it */ 373 #define tick_dep_mask_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep); 374 375 TICK_DEP_NAMES 376 377 #undef tick_dep_name 378 #undef tick_dep_mask_name 379 #undef tick_dep_name_end 380 381 #define tick_dep_name(sdep) { TICK_DEP_MASK_##sdep, #sdep }, 382 #define tick_dep_mask_name(sdep) { TICK_DEP_MASK_##sdep, #sdep }, 383 #define tick_dep_name_end(sdep) { TICK_DEP_MASK_##sdep, #sdep } 384 385 #define show_tick_dep_name(val) \ 386 __print_symbolic(val, TICK_DEP_NAMES) 387 388 TRACE_EVENT(tick_stop, 389 390 TP_PROTO(int success, int dependency), 391 392 TP_ARGS(success, dependency), 393 394 TP_STRUCT__entry( 395 __field( int , success ) 396 __field( int , dependency ) 397 ), 398 399 TP_fast_assign( 400 __entry->success = success; 401 __entry->dependency = dependency; 402 ), 403 404 TP_printk("success=%d dependency=%s", __entry->success, \ 405 show_tick_dep_name(__entry->dependency)) 406 ); 407 #endif 408 409 #endif /* _TRACE_TIMER_H */ 410 411 /* This part must be outside protection */ 412 #include <trace/define_trace.h> 413