Re: Question: One-jiffy latency from the checking in run_local_timers()

From: Thomas Gleixner
Date: Tue May 21 2024 - 11:03:00 EST


On Mon, May 20 2024 at 21:20, zhuqiuer1@xxxxxxxxxx wrote:
> Hi there, the function "kernel/time/timer.c:run_local_timers" avoids
> raising a softirq when there are no timers set to expire at the
> current time. It achieves this by comparing the current "jiffies"
> with "base->next_expiry". However, when working with SMP, it is
> possible that a few CPUs are reading the jiffies while it is being
> incremented. These CPUs may read the old-jiffies value in
> "run_local_timers" and fail to invoke expired timers at this jiffy.
> This results in a one-jiffy latency for the timers.

Sure, but one tick latency is not the end of the world. What is the real
world problem caused by that?

> Can we simply add 1 to the "jiffies" value when we compare it with
> next_expiry? This may result in an unnecessary softirq being raised
> if a timer expires in the next jiffy, but can remove the one-jiffy
> latency. Not sure if this is a positive trade-off.

What guarantees that the jiffies increment has happened when the soft
interrupt is invoked at the end of the tick interrupt?

Nothing, especially not in virtualized environments.

So I rather keep it simple unless there is a real world problem to be
solved.

Thanks,

tglx