Skip to content

Commit 8a2c9c7

Browse files
anna-marialxKAGA-KOKO
authored andcommitted
timers: Clarify check in forward_timer_base()
The current check whether a forward of the timer base is required can be simplified by using an already existing comparison function which is easier to read. The related comment is outdated and was not updated when the check changed in commit 36cd28a ("timers: Lower base clock forwarding threshold"). Use time_before_eq() for the check and replace the comment by copying the comment from the same check inside get_next_timer_interrupt(). Move the precious information of the outdated comment to the proper place in __run_timers(). No functional change. 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-9-anna-maria@linutronix.de
1 parent b5e6f59 commit 8a2c9c7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

kernel/time/timer.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -944,11 +944,10 @@ static inline void forward_timer_base(struct timer_base *base)
944944
unsigned long jnow = READ_ONCE(jiffies);
945945

946946
/*
947-
* No need to forward if we are close enough below jiffies.
948-
* Also while executing timers, base->clk is 1 offset ahead
949-
* of jiffies to avoid endless requeuing to current jiffies.
947+
* Check whether we can forward the base. We can only do that when
948+
* @basej is past base->clk otherwise we might rewind base->clk.
950949
*/
951-
if ((long)(jnow - base->clk) < 1)
950+
if (time_before_eq(jnow, base->clk))
952951
return;
953952

954953
/*
@@ -2021,6 +2020,10 @@ static inline void __run_timers(struct timer_base *base)
20212020
*/
20222021
WARN_ON_ONCE(!levels && !base->next_expiry_recalc
20232022
&& base->timers_pending);
2023+
/*
2024+
* While executing timers, base->clk is set 1 offset ahead of
2025+
* jiffies to avoid endless requeuing to current jiffies.
2026+
*/
20242027
base->clk++;
20252028
next_expiry_recalc(base);
20262029

0 commit comments

Comments
 (0)