From: Bjorn Helgaas <helgaas@kernel.org>
To: Hans Zhang <18255117159@163.com>
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] PCI: Replace msleep(2) with usleep_range() for precise delay
Date: Wed, 20 Aug 2025 13:06:51 -0500 [thread overview]
Message-ID: <20250820180651.GA631082@bhelgaas> (raw)
In-Reply-To: <20250820160944.489061-1-18255117159@163.com>
On Thu, Aug 21, 2025 at 12:09:44AM +0800, Hans Zhang wrote:
> The msleep(2) may sleep up to 20ms due to timer granularity, which can
> cause unnecessary delays. According to PCI spec v3.0 7.6.4.2, the minimum
> Trst is 1ms and we doubled that to 2ms to meet the requirement. Using
> usleep_range(2000, 2001) provides a more precise delay of exactly 2ms.
> ...
Please cite a recent spec version, i.e., r7.0. I see this probably
came from the comment at the change; I wouldn't object to updating
the comment, too.
> WARNING:MSLEEP: msleep < 20ms can sleep for up to 20ms; see function description of msleep().
> #4630: FILE: drivers/pci/pci.c:4630:
> + msleep(1);
> ...
> WARNING:MSLEEP: msleep < 20ms can sleep for up to 20ms; see function description of msleep().
> #3970: FILE: drivers/pci/quirks.c:3970:
> + msleep(10);
> +++ b/drivers/pci/pci.c
> @@ -4967,7 +4967,7 @@ void pci_reset_secondary_bus(struct pci_dev *dev)
> * PCI spec v3.0 7.6.4.2 requires minimum Trst of 1ms. Double
> * this to 2ms to ensure that we meet the minimum requirement.
> */
> - msleep(2);
> + usleep_range(2000, 2001);
IMO the most valuable thing here would be to replace the hard-coded
"2" with some kind of #define explicitly tied to the spec. Similarly
for the other cases.
There is some concern [1] about places that say "msleep(1)" but
actually rely on the current behavior of a longer sleep.
Apart from that concern, I think fsleep() would be my first choice.
usleep_range(x, x+1) defeats the purpose of the range, which is to
reduce interrupts; see 5e7f5a178bba ("timer: Added usleep_range
timer").
Bjorn
[1] https://lore.kernel.org/all/20070809001640.ec2f3bfb.akpm@linux-foundation.org/
next prev parent reply other threads:[~2025-08-20 18:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-20 16:09 [PATCH] PCI: Replace msleep(2) with usleep_range() for precise delay Hans Zhang
2025-08-20 18:06 ` Bjorn Helgaas [this message]
2025-08-22 15:53 ` Hans Zhang
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=20250820180651.GA631082@bhelgaas \
--to=helgaas@kernel.org \
--cc=18255117159@163.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
/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