Skip to content

Commit f28d3d5

Browse files
anna-marialxKAGA-KOKO
authored andcommitted
timer/trace: Improve timer tracing
Timers are added to the timer wheel off by one. This is required in case a timer is queued directly before incrementing jiffies to prevent early timer expiry. When reading a timer trace and relying only on the expiry time of the timer in the timer_start trace point and on the now in the timer_expiry_entry trace point, it seems that the timer fires late. With the current timer_expiry_entry trace point information only now=jiffies is printed but not the value of base->clk. This makes it impossible to draw a conclusion to the index of base->clk and makes it impossible to examine timer problems without additional trace points. Therefore add the base->clk value to the timer_expire_entry trace point, to be able to calculate the index the timer base is located at during collecting expired timers. Signed-off-by: Anna-Maria Gleixner <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Steven Rostedt <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 6849cbb commit f28d3d5

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

include/trace/events/timer.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,27 @@ TRACE_EVENT(timer_start,
8989
*/
9090
TRACE_EVENT(timer_expire_entry,
9191

92-
TP_PROTO(struct timer_list *timer),
92+
TP_PROTO(struct timer_list *timer, unsigned long baseclk),
9393

94-
TP_ARGS(timer),
94+
TP_ARGS(timer, baseclk),
9595

9696
TP_STRUCT__entry(
9797
__field( void *, timer )
9898
__field( unsigned long, now )
9999
__field( void *, function)
100+
__field( unsigned long, baseclk )
100101
),
101102

102103
TP_fast_assign(
103104
__entry->timer = timer;
104105
__entry->now = jiffies;
105106
__entry->function = timer->function;
107+
__entry->baseclk = baseclk;
106108
),
107109

108-
TP_printk("timer=%p function=%ps now=%lu",
109-
__entry->timer, __entry->function, __entry->now)
110+
TP_printk("timer=%p function=%ps now=%lu baseclk=%lu",
111+
__entry->timer, __entry->function, __entry->now,
112+
__entry->baseclk)
110113
);
111114

112115
/**

kernel/time/timer.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,9 @@ int del_timer_sync(struct timer_list *timer)
12931293
EXPORT_SYMBOL(del_timer_sync);
12941294
#endif
12951295

1296-
static void call_timer_fn(struct timer_list *timer, void (*fn)(struct timer_list *))
1296+
static void call_timer_fn(struct timer_list *timer,
1297+
void (*fn)(struct timer_list *),
1298+
unsigned long baseclk)
12971299
{
12981300
int count = preempt_count();
12991301

@@ -1316,7 +1318,7 @@ static void call_timer_fn(struct timer_list *timer, void (*fn)(struct timer_list
13161318
*/
13171319
lock_map_acquire(&lockdep_map);
13181320

1319-
trace_timer_expire_entry(timer);
1321+
trace_timer_expire_entry(timer, baseclk);
13201322
fn(timer);
13211323
trace_timer_expire_exit(timer);
13221324

@@ -1337,6 +1339,13 @@ static void call_timer_fn(struct timer_list *timer, void (*fn)(struct timer_list
13371339

13381340
static void expire_timers(struct timer_base *base, struct hlist_head *head)
13391341
{
1342+
/*
1343+
* This value is required only for tracing. base->clk was
1344+
* incremented directly before expire_timers was called. But expiry
1345+
* is related to the old base->clk value.
1346+
*/
1347+
unsigned long baseclk = base->clk - 1;
1348+
13401349
while (!hlist_empty(head)) {
13411350
struct timer_list *timer;
13421351
void (*fn)(struct timer_list *);
@@ -1350,11 +1359,11 @@ static void expire_timers(struct timer_base *base, struct hlist_head *head)
13501359

13511360
if (timer->flags & TIMER_IRQSAFE) {
13521361
raw_spin_unlock(&base->lock);
1353-
call_timer_fn(timer, fn);
1362+
call_timer_fn(timer, fn, baseclk);
13541363
raw_spin_lock(&base->lock);
13551364
} else {
13561365
raw_spin_unlock_irq(&base->lock);
1357-
call_timer_fn(timer, fn);
1366+
call_timer_fn(timer, fn, baseclk);
13581367
raw_spin_lock_irq(&base->lock);
13591368
}
13601369
}

0 commit comments

Comments
 (0)