| 1 | #undef TRACE_SYSTEM |
| 2 | #define TRACE_SYSTEM timer |
| 3 | |
| 4 | #if !defined(LTTNG_TRACE_TIMER_H) || defined(TRACE_HEADER_MULTI_READ) |
| 5 | #define LTTNG_TRACE_TIMER_H |
| 6 | |
| 7 | #include "../../../probes/lttng-tracepoint-event.h" |
| 8 | |
| 9 | #ifndef _TRACE_TIMER_DEF_ |
| 10 | #define _TRACE_TIMER_DEF_ |
| 11 | #include <linux/hrtimer.h> |
| 12 | #include <linux/timer.h> |
| 13 | #include <linux/version.h> |
| 14 | |
| 15 | struct timer_list; |
| 16 | |
| 17 | #endif /* _TRACE_TIMER_DEF_ */ |
| 18 | |
| 19 | LTTNG_TRACEPOINT_EVENT_CLASS(timer_class, |
| 20 | |
| 21 | TP_PROTO(struct timer_list *timer), |
| 22 | |
| 23 | TP_ARGS(timer), |
| 24 | |
| 25 | TP_STRUCT__entry( |
| 26 | __field( void *, timer ) |
| 27 | ), |
| 28 | |
| 29 | TP_fast_assign( |
| 30 | tp_assign(timer, timer) |
| 31 | ), |
| 32 | |
| 33 | TP_printk("timer=%p", __entry->timer) |
| 34 | ) |
| 35 | |
| 36 | /** |
| 37 | * timer_init - called when the timer is initialized |
| 38 | * @timer: pointer to struct timer_list |
| 39 | */ |
| 40 | LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class, timer_init, |
| 41 | |
| 42 | TP_PROTO(struct timer_list *timer), |
| 43 | |
| 44 | TP_ARGS(timer) |
| 45 | ) |
| 46 | |
| 47 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) |
| 48 | /** |
| 49 | * timer_start - called when the timer is started |
| 50 | * @timer: pointer to struct timer_list |
| 51 | * @expires: the timers expiry time |
| 52 | * @flags: the timers expiry time |
| 53 | */ |
| 54 | LTTNG_TRACEPOINT_EVENT(timer_start, |
| 55 | |
| 56 | TP_PROTO(struct timer_list *timer, unsigned long expires, |
| 57 | unsigned int flags), |
| 58 | |
| 59 | TP_ARGS(timer, expires, flags), |
| 60 | |
| 61 | TP_STRUCT__entry( |
| 62 | __field( void *, timer ) |
| 63 | __field( void *, function ) |
| 64 | __field( unsigned long, expires ) |
| 65 | __field( unsigned long, now ) |
| 66 | __field( unsigned int, flags ) |
| 67 | ), |
| 68 | |
| 69 | TP_fast_assign( |
| 70 | tp_assign(timer, timer) |
| 71 | tp_assign(function, timer->function) |
| 72 | tp_assign(expires, expires) |
| 73 | tp_assign(now, jiffies) |
| 74 | tp_assign(flags, flags) |
| 75 | ), |
| 76 | |
| 77 | TP_printk() |
| 78 | ) |
| 79 | #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */ |
| 80 | /** |
| 81 | * timer_start - called when the timer is started |
| 82 | * @timer: pointer to struct timer_list |
| 83 | * @expires: the timers expiry time |
| 84 | */ |
| 85 | LTTNG_TRACEPOINT_EVENT(timer_start, |
| 86 | |
| 87 | TP_PROTO(struct timer_list *timer, unsigned long expires), |
| 88 | |
| 89 | TP_ARGS(timer, expires), |
| 90 | |
| 91 | TP_STRUCT__entry( |
| 92 | __field( void *, timer ) |
| 93 | __field( void *, function ) |
| 94 | __field( unsigned long, expires ) |
| 95 | __field( unsigned long, now ) |
| 96 | ), |
| 97 | |
| 98 | TP_fast_assign( |
| 99 | tp_assign(timer, timer) |
| 100 | tp_assign(function, timer->function) |
| 101 | tp_assign(expires, expires) |
| 102 | tp_assign(now, jiffies) |
| 103 | ), |
| 104 | |
| 105 | TP_printk("timer=%p function=%pf expires=%lu [timeout=%ld]", |
| 106 | __entry->timer, __entry->function, __entry->expires, |
| 107 | (long)__entry->expires - __entry->now) |
| 108 | ) |
| 109 | #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */ |
| 110 | |
| 111 | /** |
| 112 | * timer_expire_entry - called immediately before the timer callback |
| 113 | * @timer: pointer to struct timer_list |
| 114 | * |
| 115 | * Allows to determine the timer latency. |
| 116 | */ |
| 117 | LTTNG_TRACEPOINT_EVENT(timer_expire_entry, |
| 118 | |
| 119 | TP_PROTO(struct timer_list *timer), |
| 120 | |
| 121 | TP_ARGS(timer), |
| 122 | |
| 123 | TP_STRUCT__entry( |
| 124 | __field( void *, timer ) |
| 125 | __field( unsigned long, now ) |
| 126 | __field( void *, function) |
| 127 | ), |
| 128 | |
| 129 | TP_fast_assign( |
| 130 | tp_assign(timer, timer) |
| 131 | tp_assign(now, jiffies) |
| 132 | tp_assign(function, timer->function) |
| 133 | ), |
| 134 | |
| 135 | TP_printk("timer=%p function=%pf now=%lu", __entry->timer, __entry->function,__entry->now) |
| 136 | ) |
| 137 | |
| 138 | /** |
| 139 | * timer_expire_exit - called immediately after the timer callback returns |
| 140 | * @timer: pointer to struct timer_list |
| 141 | * |
| 142 | * When used in combination with the timer_expire_entry tracepoint we can |
| 143 | * determine the runtime of the timer callback function. |
| 144 | * |
| 145 | * NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might |
| 146 | * be invalid. We solely track the pointer. |
| 147 | */ |
| 148 | LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class, timer_expire_exit, |
| 149 | |
| 150 | TP_PROTO(struct timer_list *timer), |
| 151 | |
| 152 | TP_ARGS(timer) |
| 153 | ) |
| 154 | |
| 155 | /** |
| 156 | * timer_cancel - called when the timer is canceled |
| 157 | * @timer: pointer to struct timer_list |
| 158 | */ |
| 159 | LTTNG_TRACEPOINT_EVENT_INSTANCE(timer_class, timer_cancel, |
| 160 | |
| 161 | TP_PROTO(struct timer_list *timer), |
| 162 | |
| 163 | TP_ARGS(timer) |
| 164 | ) |
| 165 | |
| 166 | /** |
| 167 | * hrtimer_init - called when the hrtimer is initialized |
| 168 | * @timer: pointer to struct hrtimer |
| 169 | * @clockid: the hrtimers clock |
| 170 | * @mode: the hrtimers mode |
| 171 | */ |
| 172 | LTTNG_TRACEPOINT_EVENT(hrtimer_init, |
| 173 | |
| 174 | TP_PROTO(struct hrtimer *hrtimer, clockid_t clockid, |
| 175 | enum hrtimer_mode mode), |
| 176 | |
| 177 | TP_ARGS(hrtimer, clockid, mode), |
| 178 | |
| 179 | TP_STRUCT__entry( |
| 180 | __field( void *, hrtimer ) |
| 181 | __field( clockid_t, clockid ) |
| 182 | __field( enum hrtimer_mode, mode ) |
| 183 | ), |
| 184 | |
| 185 | TP_fast_assign( |
| 186 | tp_assign(hrtimer, hrtimer) |
| 187 | tp_assign(clockid, clockid) |
| 188 | tp_assign(mode, mode) |
| 189 | ), |
| 190 | |
| 191 | TP_printk("hrtimer=%p clockid=%s mode=%s", __entry->hrtimer, |
| 192 | __entry->clockid == CLOCK_REALTIME ? |
| 193 | "CLOCK_REALTIME" : "CLOCK_MONOTONIC", |
| 194 | __entry->mode == HRTIMER_MODE_ABS ? |
| 195 | "HRTIMER_MODE_ABS" : "HRTIMER_MODE_REL") |
| 196 | ) |
| 197 | |
| 198 | /** |
| 199 | * hrtimer_start - called when the hrtimer is started |
| 200 | * @timer: pointer to struct hrtimer |
| 201 | */ |
| 202 | LTTNG_TRACEPOINT_EVENT(hrtimer_start, |
| 203 | |
| 204 | TP_PROTO(struct hrtimer *hrtimer), |
| 205 | |
| 206 | TP_ARGS(hrtimer), |
| 207 | |
| 208 | TP_STRUCT__entry( |
| 209 | __field( void *, hrtimer ) |
| 210 | __field( void *, function ) |
| 211 | __field( s64, expires ) |
| 212 | __field( s64, softexpires ) |
| 213 | ), |
| 214 | |
| 215 | TP_fast_assign( |
| 216 | tp_assign(hrtimer, hrtimer) |
| 217 | tp_assign(function, hrtimer->function) |
| 218 | tp_assign(expires, hrtimer_get_expires(hrtimer).tv64) |
| 219 | tp_assign(softexpires, hrtimer_get_softexpires(hrtimer).tv64) |
| 220 | ), |
| 221 | |
| 222 | TP_printk("hrtimer=%p function=%pf expires=%llu softexpires=%llu", |
| 223 | __entry->hrtimer, __entry->function, |
| 224 | (unsigned long long)ktime_to_ns((ktime_t) { |
| 225 | .tv64 = __entry->expires }), |
| 226 | (unsigned long long)ktime_to_ns((ktime_t) { |
| 227 | .tv64 = __entry->softexpires })) |
| 228 | ) |
| 229 | |
| 230 | /** |
| 231 | * htimmer_expire_entry - called immediately before the hrtimer callback |
| 232 | * @timer: pointer to struct hrtimer |
| 233 | * @now: pointer to variable which contains current time of the |
| 234 | * timers base. |
| 235 | * |
| 236 | * Allows to determine the timer latency. |
| 237 | */ |
| 238 | LTTNG_TRACEPOINT_EVENT(hrtimer_expire_entry, |
| 239 | |
| 240 | TP_PROTO(struct hrtimer *hrtimer, ktime_t *now), |
| 241 | |
| 242 | TP_ARGS(hrtimer, now), |
| 243 | |
| 244 | TP_STRUCT__entry( |
| 245 | __field( void *, hrtimer ) |
| 246 | __field( s64, now ) |
| 247 | __field( void *, function) |
| 248 | ), |
| 249 | |
| 250 | TP_fast_assign( |
| 251 | tp_assign(hrtimer, hrtimer) |
| 252 | tp_assign(now, now->tv64) |
| 253 | tp_assign(function, hrtimer->function) |
| 254 | ), |
| 255 | |
| 256 | TP_printk("hrtimer=%p function=%pf now=%llu", __entry->hrtimer, __entry->function, |
| 257 | (unsigned long long)ktime_to_ns((ktime_t) { .tv64 = __entry->now })) |
| 258 | ) |
| 259 | |
| 260 | LTTNG_TRACEPOINT_EVENT_CLASS(hrtimer_class, |
| 261 | |
| 262 | TP_PROTO(struct hrtimer *hrtimer), |
| 263 | |
| 264 | TP_ARGS(hrtimer), |
| 265 | |
| 266 | TP_STRUCT__entry( |
| 267 | __field( void *, hrtimer ) |
| 268 | ), |
| 269 | |
| 270 | TP_fast_assign( |
| 271 | tp_assign(hrtimer, hrtimer) |
| 272 | ), |
| 273 | |
| 274 | TP_printk("hrtimer=%p", __entry->hrtimer) |
| 275 | ) |
| 276 | |
| 277 | /** |
| 278 | * hrtimer_expire_exit - called immediately after the hrtimer callback returns |
| 279 | * @timer: pointer to struct hrtimer |
| 280 | * |
| 281 | * When used in combination with the hrtimer_expire_entry tracepoint we can |
| 282 | * determine the runtime of the callback function. |
| 283 | */ |
| 284 | LTTNG_TRACEPOINT_EVENT_INSTANCE(hrtimer_class, hrtimer_expire_exit, |
| 285 | |
| 286 | TP_PROTO(struct hrtimer *hrtimer), |
| 287 | |
| 288 | TP_ARGS(hrtimer) |
| 289 | ) |
| 290 | |
| 291 | /** |
| 292 | * hrtimer_cancel - called when the hrtimer is canceled |
| 293 | * @hrtimer: pointer to struct hrtimer |
| 294 | */ |
| 295 | LTTNG_TRACEPOINT_EVENT_INSTANCE(hrtimer_class, hrtimer_cancel, |
| 296 | |
| 297 | TP_PROTO(struct hrtimer *hrtimer), |
| 298 | |
| 299 | TP_ARGS(hrtimer) |
| 300 | ) |
| 301 | |
| 302 | /** |
| 303 | * itimer_state - called when itimer is started or canceled |
| 304 | * @which: name of the interval timer |
| 305 | * @value: the itimers value, itimer is canceled if value->it_value is |
| 306 | * zero, otherwise it is started |
| 307 | * @expires: the itimers expiry time |
| 308 | */ |
| 309 | LTTNG_TRACEPOINT_EVENT(itimer_state, |
| 310 | |
| 311 | TP_PROTO(int which, const struct itimerval *const value, |
| 312 | cputime_t expires), |
| 313 | |
| 314 | TP_ARGS(which, value, expires), |
| 315 | |
| 316 | TP_STRUCT__entry( |
| 317 | __field( int, which ) |
| 318 | __field( cputime_t, expires ) |
| 319 | __field( long, value_sec ) |
| 320 | __field( long, value_usec ) |
| 321 | __field( long, interval_sec ) |
| 322 | __field( long, interval_usec ) |
| 323 | ), |
| 324 | |
| 325 | TP_fast_assign( |
| 326 | tp_assign(which, which) |
| 327 | tp_assign(expires, expires) |
| 328 | tp_assign(value_sec, value->it_value.tv_sec) |
| 329 | tp_assign(value_usec, value->it_value.tv_usec) |
| 330 | tp_assign(interval_sec, value->it_interval.tv_sec) |
| 331 | tp_assign(interval_usec, value->it_interval.tv_usec) |
| 332 | ), |
| 333 | |
| 334 | TP_printk("which=%d expires=%llu it_value=%ld.%ld it_interval=%ld.%ld", |
| 335 | __entry->which, (unsigned long long)__entry->expires, |
| 336 | __entry->value_sec, __entry->value_usec, |
| 337 | __entry->interval_sec, __entry->interval_usec) |
| 338 | ) |
| 339 | |
| 340 | /** |
| 341 | * itimer_expire - called when itimer expires |
| 342 | * @which: type of the interval timer |
| 343 | * @pid: pid of the process which owns the timer |
| 344 | * @now: current time, used to calculate the latency of itimer |
| 345 | */ |
| 346 | LTTNG_TRACEPOINT_EVENT(itimer_expire, |
| 347 | |
| 348 | TP_PROTO(int which, struct pid *pid, cputime_t now), |
| 349 | |
| 350 | TP_ARGS(which, pid, now), |
| 351 | |
| 352 | TP_STRUCT__entry( |
| 353 | __field( int , which ) |
| 354 | __field( pid_t, pid ) |
| 355 | __field( cputime_t, now ) |
| 356 | ), |
| 357 | |
| 358 | TP_fast_assign( |
| 359 | tp_assign(which, which) |
| 360 | tp_assign(now, now) |
| 361 | tp_assign(pid, pid_nr(pid)) |
| 362 | ), |
| 363 | |
| 364 | TP_printk("which=%d pid=%d now=%llu", __entry->which, |
| 365 | (int) __entry->pid, (unsigned long long)__entry->now) |
| 366 | ) |
| 367 | |
| 368 | #endif /* LTTNG_TRACE_TIMER_H */ |
| 369 | |
| 370 | /* This part must be outside protection */ |
| 371 | #include "../../../probes/define_trace.h" |