LKML Archive mirror
 help / color / mirror / Atom feed
From: <zhuqiuer1@huawei.com>
To: <anna-maria@linutronix.de>, <frederic@kernel.org>,
	<tglx@linutronix.de>, <linux-kernel@vger.kernel.org>
Cc: <zhuqiuer1@huawei.com>
Subject: Question: One-jiffy latency from the checking in run_local_timers()
Date: Mon, 20 May 2024 21:20:40 +0800	[thread overview]
Message-ID: <20240520132040.259477-1-zhuqiuer1@huawei.com> (raw)

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. 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.

Below is the example that we found to
have a few cpus reading the old-jiffies value while cpu-0 is updating the jiffies:

<idle>-0       [000] d.h.   133.492480: do_timer: updated_jiffies: 4294950645
<idle>-0       [010] d.h.   133.492480: run_local_timers: base->next_expiry: 5368691712, jiffies: 4294950644
<idle>-0       [001] d.h.   133.492480: run_local_timers: base->next_expiry: 4294950645, jiffies: 4294950644
....
<idle>-0       [006] d.h.   133.492481: run_local_timers: base->next_expiry: 4294967808, jiffies: 4294950645
....

We found that in this case the timer on cpu-1 was invoked in next jiffy but not the one it is expected to.

             reply	other threads:[~2024-05-20 13:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-20 13:20 zhuqiuer1 [this message]
2024-05-21 15:02 ` Question: One-jiffy latency from the checking in run_local_timers() Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240520132040.259477-1-zhuqiuer1@huawei.com \
    --to=zhuqiuer1@huawei.com \
    --cc=anna-maria@linutronix.de \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).