Commit 1e490484 authored by Anna-Maria Behnsen's avatar Anna-Maria Behnsen Committed by Thomas Gleixner

timers: Split out forward timer base functionality

Forwarding timer base is done when the next expiry value is calculated and
when a new timer is enqueued. When the next expiry value is calculated the
jiffies value is already available and does not need to be reread a second
time.

Splitting out the forward timer base functionality to make it executable
via both contextes - those where jiffies are already known and those, where
jiffies need to be read.

No functional change.
Signed-off-by: default avatarAnna-Maria Behnsen <anna-maria@linutronix.de>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarFrederic Weisbecker <frederic@kernel.org>
Link: https://lore.kernel.org/r/20231201092654.34614-10-anna-maria@linutronix.de
parent 8a2c9c7e
...@@ -939,30 +939,34 @@ get_target_base(struct timer_base *base, unsigned tflags) ...@@ -939,30 +939,34 @@ get_target_base(struct timer_base *base, unsigned tflags)
return get_timer_this_cpu_base(tflags); return get_timer_this_cpu_base(tflags);
} }
static inline void forward_timer_base(struct timer_base *base) static inline void __forward_timer_base(struct timer_base *base,
unsigned long basej)
{ {
unsigned long jnow = READ_ONCE(jiffies);
/* /*
* Check whether we can forward the base. We can only do that when * Check whether we can forward the base. We can only do that when
* @basej is past base->clk otherwise we might rewind base->clk. * @basej is past base->clk otherwise we might rewind base->clk.
*/ */
if (time_before_eq(jnow, base->clk)) if (time_before_eq(basej, base->clk))
return; return;
/* /*
* If the next expiry value is > jiffies, then we fast forward to * If the next expiry value is > jiffies, then we fast forward to
* jiffies otherwise we forward to the next expiry value. * jiffies otherwise we forward to the next expiry value.
*/ */
if (time_after(base->next_expiry, jnow)) { if (time_after(base->next_expiry, basej)) {
base->clk = jnow; base->clk = basej;
} else { } else {
if (WARN_ON_ONCE(time_before(base->next_expiry, base->clk))) if (WARN_ON_ONCE(time_before(base->next_expiry, base->clk)))
return; return;
base->clk = base->next_expiry; base->clk = base->next_expiry;
} }
} }
static inline void forward_timer_base(struct timer_base *base)
{
__forward_timer_base(base, READ_ONCE(jiffies));
}
/* /*
* We are using hashed locking: Holding per_cpu(timer_bases[x]).lock means * We are using hashed locking: Holding per_cpu(timer_bases[x]).lock means
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment