Skip to content

Commit b573c73

Browse files
anna-marialxKAGA-KOKO
authored andcommitted
tracing/timers: Add tracepoint for tracking timer base is_idle flag
When debugging timer code the timer tracepoints are very important. There is no tracepoint when the is_idle flag of the timer base changes. Instead of always adding manually trace_printk(), add tracepoints which can be easily enabled whenever required. Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Frederic Weisbecker <frederic@kernel.org> Link: https://lore.kernel.org/r/20231201092654.34614-6-anna-maria@linutronix.de
1 parent dbcdcb6 commit b573c73

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

include/trace/events/timer.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,26 @@ DEFINE_EVENT(timer_class, timer_cancel,
142142
TP_ARGS(timer)
143143
);
144144

145+
TRACE_EVENT(timer_base_idle,
146+
147+
TP_PROTO(bool is_idle, unsigned int cpu),
148+
149+
TP_ARGS(is_idle, cpu),
150+
151+
TP_STRUCT__entry(
152+
__field( bool, is_idle )
153+
__field( unsigned int, cpu )
154+
),
155+
156+
TP_fast_assign(
157+
__entry->is_idle = is_idle;
158+
__entry->cpu = cpu;
159+
),
160+
161+
TP_printk("is_idle=%d cpu=%d",
162+
__entry->is_idle, __entry->cpu)
163+
);
164+
145165
#define decode_clockid(type) \
146166
__print_symbolic(type, \
147167
{ CLOCK_REALTIME, "CLOCK_REALTIME" }, \

kernel/time/timer.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,10 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
19501950

19511951
if (time_before_eq(nextevt, basej)) {
19521952
expires = basem;
1953-
base->is_idle = false;
1953+
if (base->is_idle) {
1954+
base->is_idle = false;
1955+
trace_timer_base_idle(false, base->cpu);
1956+
}
19541957
} else {
19551958
if (base->timers_pending)
19561959
expires = basem + (u64)(nextevt - basej) * TICK_NSEC;
@@ -1961,8 +1964,10 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
19611964
* logic is only maintained for the BASE_STD base, deferrable
19621965
* timers may still see large granularity skew (by design).
19631966
*/
1964-
if ((expires - basem) > TICK_NSEC)
1967+
if ((expires - basem) > TICK_NSEC && !base->is_idle) {
19651968
base->is_idle = true;
1969+
trace_timer_base_idle(true, base->cpu);
1970+
}
19661971
}
19671972
raw_spin_unlock(&base->lock);
19681973

@@ -1984,7 +1989,10 @@ void timer_clear_idle(void)
19841989
* sending the IPI a few instructions smaller for the cost of taking
19851990
* the lock in the exit from idle path.
19861991
*/
1987-
base->is_idle = false;
1992+
if (base->is_idle) {
1993+
base->is_idle = false;
1994+
trace_timer_base_idle(false, smp_processor_id());
1995+
}
19881996
}
19891997
#endif
19901998

0 commit comments

Comments
 (0)