Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #undef TRACE_SYSTEM
0003 #define TRACE_SYSTEM timer
0004 
0005 #if !defined(_TRACE_TIMER_H) || defined(TRACE_HEADER_MULTI_READ)
0006 #define _TRACE_TIMER_H
0007 
0008 #include <linux/tracepoint.h>
0009 #include <linux/hrtimer.h>
0010 #include <linux/timer.h>
0011 
0012 DECLARE_EVENT_CLASS(timer_class,
0013 
0014     TP_PROTO(struct timer_list *timer),
0015 
0016     TP_ARGS(timer),
0017 
0018     TP_STRUCT__entry(
0019         __field( void *,    timer   )
0020     ),
0021 
0022     TP_fast_assign(
0023         __entry->timer  = timer;
0024     ),
0025 
0026     TP_printk("timer=%p", __entry->timer)
0027 );
0028 
0029 /**
0030  * timer_init - called when the timer is initialized
0031  * @timer:  pointer to struct timer_list
0032  */
0033 DEFINE_EVENT(timer_class, timer_init,
0034 
0035     TP_PROTO(struct timer_list *timer),
0036 
0037     TP_ARGS(timer)
0038 );
0039 
0040 #define decode_timer_flags(flags)           \
0041     __print_flags(flags, "|",           \
0042         {  TIMER_MIGRATING, "M" },      \
0043         {  TIMER_DEFERRABLE,    "D" },      \
0044         {  TIMER_PINNED,    "P" },      \
0045         {  TIMER_IRQSAFE,   "I" })
0046 
0047 /**
0048  * timer_start - called when the timer is started
0049  * @timer:  pointer to struct timer_list
0050  * @expires:    the timers expiry time
0051  * @flags:  the timers flags
0052  */
0053 TRACE_EVENT(timer_start,
0054 
0055     TP_PROTO(struct timer_list *timer,
0056         unsigned long expires,
0057         unsigned int flags),
0058 
0059     TP_ARGS(timer, expires, flags),
0060 
0061     TP_STRUCT__entry(
0062         __field( void *,    timer       )
0063         __field( void *,    function    )
0064         __field( unsigned long, expires     )
0065         __field( unsigned long, now     )
0066         __field( unsigned int,  flags       )
0067     ),
0068 
0069     TP_fast_assign(
0070         __entry->timer      = timer;
0071         __entry->function   = timer->function;
0072         __entry->expires    = expires;
0073         __entry->now        = jiffies;
0074         __entry->flags      = flags;
0075     ),
0076 
0077     TP_printk("timer=%p function=%ps expires=%lu [timeout=%ld] cpu=%u idx=%u flags=%s",
0078           __entry->timer, __entry->function, __entry->expires,
0079           (long)__entry->expires - __entry->now,
0080           __entry->flags & TIMER_CPUMASK,
0081           __entry->flags >> TIMER_ARRAYSHIFT,
0082           decode_timer_flags(__entry->flags & TIMER_TRACE_FLAGMASK))
0083 );
0084 
0085 /**
0086  * timer_expire_entry - called immediately before the timer callback
0087  * @timer:  pointer to struct timer_list
0088  * @baseclk:    value of timer_base::clk when timer expires
0089  *
0090  * Allows to determine the timer latency.
0091  */
0092 TRACE_EVENT(timer_expire_entry,
0093 
0094     TP_PROTO(struct timer_list *timer, unsigned long baseclk),
0095 
0096     TP_ARGS(timer, baseclk),
0097 
0098     TP_STRUCT__entry(
0099         __field( void *,    timer   )
0100         __field( unsigned long, now )
0101         __field( void *,    function)
0102         __field( unsigned long, baseclk )
0103     ),
0104 
0105     TP_fast_assign(
0106         __entry->timer      = timer;
0107         __entry->now        = jiffies;
0108         __entry->function   = timer->function;
0109         __entry->baseclk    = baseclk;
0110     ),
0111 
0112     TP_printk("timer=%p function=%ps now=%lu baseclk=%lu",
0113           __entry->timer, __entry->function, __entry->now,
0114           __entry->baseclk)
0115 );
0116 
0117 /**
0118  * timer_expire_exit - called immediately after the timer callback returns
0119  * @timer:  pointer to struct timer_list
0120  *
0121  * When used in combination with the timer_expire_entry tracepoint we can
0122  * determine the runtime of the timer callback function.
0123  *
0124  * NOTE: Do NOT dereference timer in TP_fast_assign. The pointer might
0125  * be invalid. We solely track the pointer.
0126  */
0127 DEFINE_EVENT(timer_class, timer_expire_exit,
0128 
0129     TP_PROTO(struct timer_list *timer),
0130 
0131     TP_ARGS(timer)
0132 );
0133 
0134 /**
0135  * timer_cancel - called when the timer is canceled
0136  * @timer:  pointer to struct timer_list
0137  */
0138 DEFINE_EVENT(timer_class, timer_cancel,
0139 
0140     TP_PROTO(struct timer_list *timer),
0141 
0142     TP_ARGS(timer)
0143 );
0144 
0145 #define decode_clockid(type)                        \
0146     __print_symbolic(type,                      \
0147         { CLOCK_REALTIME,   "CLOCK_REALTIME"    },  \
0148         { CLOCK_MONOTONIC,  "CLOCK_MONOTONIC"   },  \
0149         { CLOCK_BOOTTIME,   "CLOCK_BOOTTIME"    },  \
0150         { CLOCK_TAI,        "CLOCK_TAI"     })
0151 
0152 #define decode_hrtimer_mode(mode)                   \
0153     __print_symbolic(mode,                      \
0154         { HRTIMER_MODE_ABS,     "ABS"       },  \
0155         { HRTIMER_MODE_REL,     "REL"       },  \
0156         { HRTIMER_MODE_ABS_PINNED,  "ABS|PINNED"    },  \
0157         { HRTIMER_MODE_REL_PINNED,  "REL|PINNED"    },  \
0158         { HRTIMER_MODE_ABS_SOFT,    "ABS|SOFT"  },  \
0159         { HRTIMER_MODE_REL_SOFT,    "REL|SOFT"  },  \
0160         { HRTIMER_MODE_ABS_PINNED_SOFT, "ABS|PINNED|SOFT" },    \
0161         { HRTIMER_MODE_REL_PINNED_SOFT, "REL|PINNED|SOFT" })
0162 
0163 /**
0164  * hrtimer_init - called when the hrtimer is initialized
0165  * @hrtimer:    pointer to struct hrtimer
0166  * @clockid:    the hrtimers clock
0167  * @mode:   the hrtimers mode
0168  */
0169 TRACE_EVENT(hrtimer_init,
0170 
0171     TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid,
0172          enum hrtimer_mode mode),
0173 
0174     TP_ARGS(hrtimer, clockid, mode),
0175 
0176     TP_STRUCT__entry(
0177         __field( void *,        hrtimer     )
0178         __field( clockid_t,     clockid     )
0179         __field( enum hrtimer_mode, mode        )
0180     ),
0181 
0182     TP_fast_assign(
0183         __entry->hrtimer    = hrtimer;
0184         __entry->clockid    = clockid;
0185         __entry->mode       = mode;
0186     ),
0187 
0188     TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer,
0189           decode_clockid(__entry->clockid),
0190           decode_hrtimer_mode(__entry->mode))
0191 );
0192 
0193 /**
0194  * hrtimer_start - called when the hrtimer is started
0195  * @hrtimer:    pointer to struct hrtimer
0196  * @mode:   the hrtimers mode
0197  */
0198 TRACE_EVENT(hrtimer_start,
0199 
0200     TP_PROTO(struct hrtimer *hrtimer, enum hrtimer_mode mode),
0201 
0202     TP_ARGS(hrtimer, mode),
0203 
0204     TP_STRUCT__entry(
0205         __field( void *,    hrtimer     )
0206         __field( void *,    function    )
0207         __field( s64,       expires     )
0208         __field( s64,       softexpires )
0209         __field( enum hrtimer_mode, mode    )
0210     ),
0211 
0212     TP_fast_assign(
0213         __entry->hrtimer    = hrtimer;
0214         __entry->function   = hrtimer->function;
0215         __entry->expires    = hrtimer_get_expires(hrtimer);
0216         __entry->softexpires    = hrtimer_get_softexpires(hrtimer);
0217         __entry->mode       = mode;
0218     ),
0219 
0220     TP_printk("hrtimer=%p function=%ps expires=%llu softexpires=%llu "
0221           "mode=%s", __entry->hrtimer, __entry->function,
0222           (unsigned long long) __entry->expires,
0223           (unsigned long long) __entry->softexpires,
0224           decode_hrtimer_mode(__entry->mode))
0225 );
0226 
0227 /**
0228  * hrtimer_expire_entry - called immediately before the hrtimer callback
0229  * @hrtimer:    pointer to struct hrtimer
0230  * @now:    pointer to variable which contains current time of the
0231  *      timers base.
0232  *
0233  * Allows to determine the timer latency.
0234  */
0235 TRACE_EVENT(hrtimer_expire_entry,
0236 
0237     TP_PROTO(struct hrtimer *hrtimer, ktime_t *now),
0238 
0239     TP_ARGS(hrtimer, now),
0240 
0241     TP_STRUCT__entry(
0242         __field( void *,    hrtimer )
0243         __field( s64,       now )
0244         __field( void *,    function)
0245     ),
0246 
0247     TP_fast_assign(
0248         __entry->hrtimer    = hrtimer;
0249         __entry->now        = *now;
0250         __entry->function   = hrtimer->function;
0251     ),
0252 
0253     TP_printk("hrtimer=%p function=%ps now=%llu",
0254           __entry->hrtimer, __entry->function,
0255           (unsigned long long) __entry->now)
0256 );
0257 
0258 DECLARE_EVENT_CLASS(hrtimer_class,
0259 
0260     TP_PROTO(struct hrtimer *hrtimer),
0261 
0262     TP_ARGS(hrtimer),
0263 
0264     TP_STRUCT__entry(
0265         __field( void *,    hrtimer )
0266     ),
0267 
0268     TP_fast_assign(
0269         __entry->hrtimer    = hrtimer;
0270     ),
0271 
0272     TP_printk("hrtimer=%p", __entry->hrtimer)
0273 );
0274 
0275 /**
0276  * hrtimer_expire_exit - called immediately after the hrtimer callback returns
0277  * @hrtimer:    pointer to struct hrtimer
0278  *
0279  * When used in combination with the hrtimer_expire_entry tracepoint we can
0280  * determine the runtime of the callback function.
0281  */
0282 DEFINE_EVENT(hrtimer_class, hrtimer_expire_exit,
0283 
0284     TP_PROTO(struct hrtimer *hrtimer),
0285 
0286     TP_ARGS(hrtimer)
0287 );
0288 
0289 /**
0290  * hrtimer_cancel - called when the hrtimer is canceled
0291  * @hrtimer:    pointer to struct hrtimer
0292  */
0293 DEFINE_EVENT(hrtimer_class, hrtimer_cancel,
0294 
0295     TP_PROTO(struct hrtimer *hrtimer),
0296 
0297     TP_ARGS(hrtimer)
0298 );
0299 
0300 /**
0301  * itimer_state - called when itimer is started or canceled
0302  * @which:  name of the interval timer
0303  * @value:  the itimers value, itimer is canceled if value->it_value is
0304  *      zero, otherwise it is started
0305  * @expires:    the itimers expiry time
0306  */
0307 TRACE_EVENT(itimer_state,
0308 
0309     TP_PROTO(int which, const struct itimerspec64 *const value,
0310          unsigned long long expires),
0311 
0312     TP_ARGS(which, value, expires),
0313 
0314     TP_STRUCT__entry(
0315         __field(    int,            which       )
0316         __field(    unsigned long long, expires     )
0317         __field(    long,           value_sec   )
0318         __field(    long,           value_nsec  )
0319         __field(    long,           interval_sec    )
0320         __field(    long,           interval_nsec   )
0321     ),
0322 
0323     TP_fast_assign(
0324         __entry->which      = which;
0325         __entry->expires    = expires;
0326         __entry->value_sec  = value->it_value.tv_sec;
0327         __entry->value_nsec = value->it_value.tv_nsec;
0328         __entry->interval_sec   = value->it_interval.tv_sec;
0329         __entry->interval_nsec  = value->it_interval.tv_nsec;
0330     ),
0331 
0332     TP_printk("which=%d expires=%llu it_value=%ld.%06ld it_interval=%ld.%06ld",
0333           __entry->which, __entry->expires,
0334           __entry->value_sec, __entry->value_nsec / NSEC_PER_USEC,
0335           __entry->interval_sec, __entry->interval_nsec / NSEC_PER_USEC)
0336 );
0337 
0338 /**
0339  * itimer_expire - called when itimer expires
0340  * @which:  type of the interval timer
0341  * @pid:    pid of the process which owns the timer
0342  * @now:    current time, used to calculate the latency of itimer
0343  */
0344 TRACE_EVENT(itimer_expire,
0345 
0346     TP_PROTO(int which, struct pid *pid, unsigned long long now),
0347 
0348     TP_ARGS(which, pid, now),
0349 
0350     TP_STRUCT__entry(
0351         __field( int ,          which   )
0352         __field( pid_t,         pid )
0353         __field( unsigned long long,    now )
0354     ),
0355 
0356     TP_fast_assign(
0357         __entry->which  = which;
0358         __entry->now    = now;
0359         __entry->pid    = pid_nr(pid);
0360     ),
0361 
0362     TP_printk("which=%d pid=%d now=%llu", __entry->which,
0363           (int) __entry->pid, __entry->now)
0364 );
0365 
0366 #ifdef CONFIG_NO_HZ_COMMON
0367 
0368 #define TICK_DEP_NAMES                  \
0369         tick_dep_mask_name(NONE)        \
0370         tick_dep_name(POSIX_TIMER)      \
0371         tick_dep_name(PERF_EVENTS)      \
0372         tick_dep_name(SCHED)            \
0373         tick_dep_name(CLOCK_UNSTABLE)       \
0374         tick_dep_name_end(RCU)
0375 
0376 #undef tick_dep_name
0377 #undef tick_dep_mask_name
0378 #undef tick_dep_name_end
0379 
0380 /* The MASK will convert to their bits and they need to be processed too */
0381 #define tick_dep_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
0382     TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
0383 #define tick_dep_name_end(sdep)  TRACE_DEFINE_ENUM(TICK_DEP_BIT_##sdep); \
0384     TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
0385 /* NONE only has a mask defined for it */
0386 #define tick_dep_mask_name(sdep) TRACE_DEFINE_ENUM(TICK_DEP_MASK_##sdep);
0387 
0388 TICK_DEP_NAMES
0389 
0390 #undef tick_dep_name
0391 #undef tick_dep_mask_name
0392 #undef tick_dep_name_end
0393 
0394 #define tick_dep_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
0395 #define tick_dep_mask_name(sdep) { TICK_DEP_MASK_##sdep, #sdep },
0396 #define tick_dep_name_end(sdep) { TICK_DEP_MASK_##sdep, #sdep }
0397 
0398 #define show_tick_dep_name(val)             \
0399     __print_symbolic(val, TICK_DEP_NAMES)
0400 
0401 TRACE_EVENT(tick_stop,
0402 
0403     TP_PROTO(int success, int dependency),
0404 
0405     TP_ARGS(success, dependency),
0406 
0407     TP_STRUCT__entry(
0408         __field( int ,      success )
0409         __field( int ,      dependency )
0410     ),
0411 
0412     TP_fast_assign(
0413         __entry->success    = success;
0414         __entry->dependency = dependency;
0415     ),
0416 
0417     TP_printk("success=%d dependency=%s",  __entry->success, \
0418             show_tick_dep_name(__entry->dependency))
0419 );
0420 #endif
0421 
0422 #endif /*  _TRACE_TIMER_H */
0423 
0424 /* This part must be outside protection */
0425 #include <trace/define_trace.h>