From: "David Matlack" <dmatlack@google.com>
To: "Michal Clapinski" <mclapinski@google.com>,
"Bjorn Helgaas" <bhelgaas@google.com>,
<linux-pci@vger.kernel.org>
Cc: "Lukas Wunner" <lukas@wunner.de>, <linux-kernel@vger.kernel.org>,
"David Matlack" <dmatlack@google.com>
Subject: Re: [PATCH v2 2/2] PCI/DOE: Poll briefly for a response before sleeping
Date: Fri, 04 Dec 2026 15:52:05 -0800 [thread overview]
Message-ID: <DNCCOZQVWA7E.336UCT8YKTMM8@google.com> (raw)
In-Reply-To: <20261103163101.1696520-3-mclapinski@google.com>
On Tue Nov 3, 2026 at 8:31 AM PST, Michal Clapinski wrote:
> +static int pci_doe_wait(struct pci_doe_mb *doe_mb, unsigned int *delay_us)
> {
> + if (test_bit(PCI_DOE_FLAG_CANCEL, &doe_mb->flags))
> + return -EIO;
> +
> + if (*delay_us <= PCI_DOE_POLL_SPIN_MAX_US &&
> + !hrtimer_highres_enabled()) {
> + udelay(*delay_us);
> + *delay_us *= 2;
> + return 0;
> + }
> +
> + if (*delay_us < jiffies_to_usecs(PCI_DOE_POLL_INTERVAL)) {
> + fsleep(*delay_us);
> + *delay_us *= 2;
> + return 0;
> + }
> +
> if (wait_event_timeout(doe_mb->wq,
> test_bit(PCI_DOE_FLAG_CANCEL, &doe_mb->flags),
> - timeout))
> + PCI_DOE_POLL_INTERVAL))
> return -EIO;
> return 0;
> }
I think this could be simplified to a fixed busy-poll followed by the
existing wait_event_timeout():
- Backing off exponentially doesn't buy much while we're spinning,
since the CPU time is spent either way, and it means a response can
sit unnoticed for longer. Instead, re-poll the DOE Status register
every couple of microseconds for a fixed budget (e.g. ~250 us), which
notices a response almost as soon as it's ready.
- Do this unconditionally rather than only until high resolution
timers are enabled. That bounds the wasted CPU time to the same
budget per wait, behaves the same at boot and at runtime (including
with CONFIG_HIGH_RES_TIMERS=n, where hrtimer_highres_enabled() is
always false), and avoids depending on hrtimer_highres_enabled(),
which as far as I can tell has no other users outside of kernel/time.
- After the budget, fall back to the existing wait_event_timeout()
with PCI_DOE_POLL_INTERVAL. Operations that take longer than the
budget behave the same as they do today, so there's no regression
for slower devices, and this keeps the change small. A finer-grained
sleep between the two could always be added later if a device needs
it.
Something like this (untested):
static int pci_doe_wait(struct pci_doe_mb *doe_mb, unsigned int *polls)
{
if (test_bit(PCI_DOE_FLAG_CANCEL, &doe_mb->flags))
return -EIO;
if ((*polls)++ < PCI_DOE_POLL_SPIN_COUNT) {
udelay(PCI_DOE_POLL_SPIN_US);
return 0;
}
if (wait_event_timeout(doe_mb->wq,
test_bit(PCI_DOE_FLAG_CANCEL, &doe_mb->flags),
PCI_DOE_POLL_INTERVAL))
return -EIO;
return 0;
}
where callers start with polls = 0, so they don't need to know about a
minimum delay.
One thing to watch out for is that this does more config reads during
the busy-poll. On devices where the DOE mailbox is handled by the same
firmware that services config requests, polling too aggressively could
slow down the response. Could you measure a couple of step sizes (e.g. 2
us vs 5 us) on the B200 and see if it affects the response time?
next prev parent reply other threads:[~2026-12-04 23:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 16:30 [PATCH v2 0/2] PCI/DOE: Speed up mailbox polling Michal Clapinski
2026-11-03 16:31 ` [PATCH v2 1/2] PCI/DOE: Don't busy-poll the mailbox when HZ < 128 Michal Clapinski
2026-11-03 16:33 ` sashiko-bot
2026-11-03 16:31 ` [PATCH v2 2/2] PCI/DOE: Poll briefly for a response before sleeping Michal Clapinski
2026-11-03 16:35 ` sashiko-bot
2026-12-04 23:52 ` David Matlack [this message]
2026-11-03 21:27 ` [PATCH v2 0/2] PCI/DOE: Speed up mailbox polling Bjorn Helgaas
2026-12-04 23:42 ` David Matlack
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=DNCCOZQVWA7E.336UCT8YKTMM8@google.com \
--to=dmatlack@google.com \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=mclapinski@google.com \
/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