Re: [PATCH v2 2/2] PCI/DOE: Poll briefly for a response before sleeping

From: David Matlack

Date: Fri Dec 04 2026 - 18:52:22 EST


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?