* [PATCH] virtio_pci_modern: replace msleep(1) with usleep_range(1000, 2000)
@ 2026-08-16 9:43 Mirza Ishan Beg
2026-08-16 21:38 ` Michael S. Tsirkin
0 siblings, 1 reply; 4+ messages in thread
From: Mirza Ishan Beg @ 2026-08-16 9:43 UTC (permalink / raw)
To: virtualization
Cc: linux-kernel, Michael S . Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Mirza Ishan Beg
Replace msleep(1) with usleep_range(1000, 2000) in the queue reset
loops.
msleep(1) relies on jiffies and can sleep up to 4-10 ms depending on HZ,
whereas usleep_range provides predictable microsecond-level delay.
Signed-off-by: Mirza Ishan Beg <seedandsyntax@gmail.com>
---
drivers/virtio/virtio_pci_modern_dev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
index 413a8c353463..8e74a813ca97 100644
--- a/drivers/virtio/virtio_pci_modern_dev.c
+++ b/drivers/virtio/virtio_pci_modern_dev.c
@@ -535,10 +535,10 @@ void vp_modern_set_queue_reset(struct virtio_pci_modern_device *mdev, u16 index)
vp_iowrite16(1, &cfg->queue_reset);
while (vp_ioread16(&cfg->queue_reset))
- msleep(1);
+ usleep_range(1000, 2000);
while (vp_ioread16(&cfg->cfg.queue_enable))
- msleep(1);
+ usleep_range(1000, 2000);
}
EXPORT_SYMBOL_GPL(vp_modern_set_queue_reset);
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] virtio_pci_modern: replace msleep(1) with usleep_range(1000, 2000)
2026-08-16 9:43 [PATCH] virtio_pci_modern: replace msleep(1) with usleep_range(1000, 2000) Mirza Ishan Beg
@ 2026-08-16 21:38 ` Michael S. Tsirkin
2026-08-17 17:03 ` Mirza Ishan Beg
0 siblings, 1 reply; 4+ messages in thread
From: Michael S. Tsirkin @ 2026-08-16 21:38 UTC (permalink / raw)
To: Mirza Ishan Beg
Cc: virtualization, linux-kernel, Jason Wang, Xuan Zhuo,
Eugenio Pérez
On Sun, Aug 16, 2026 at 03:13:19PM +0530, Mirza Ishan Beg wrote:
> Replace msleep(1) with usleep_range(1000, 2000) in the queue reset
> loops.
> msleep(1) relies on jiffies and can sleep up to 4-10 ms depending on HZ,
> whereas usleep_range provides predictable microsecond-level delay.
>
> Signed-off-by: Mirza Ishan Beg <seedandsyntax@gmail.com>
why do we care?
> ---
> drivers/virtio/virtio_pci_modern_dev.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c
> index 413a8c353463..8e74a813ca97 100644
> --- a/drivers/virtio/virtio_pci_modern_dev.c
> +++ b/drivers/virtio/virtio_pci_modern_dev.c
> @@ -535,10 +535,10 @@ void vp_modern_set_queue_reset(struct virtio_pci_modern_device *mdev, u16 index)
> vp_iowrite16(1, &cfg->queue_reset);
>
> while (vp_ioread16(&cfg->queue_reset))
> - msleep(1);
> + usleep_range(1000, 2000);
>
> while (vp_ioread16(&cfg->cfg.queue_enable))
> - msleep(1);
> + usleep_range(1000, 2000);
> }
> EXPORT_SYMBOL_GPL(vp_modern_set_queue_reset);
>
> --
> 2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] virtio_pci_modern: replace msleep(1) with usleep_range(1000, 2000)
2026-08-16 21:38 ` Michael S. Tsirkin
@ 2026-08-17 17:03 ` Mirza Ishan Beg
2026-08-17 19:55 ` Michael S. Tsirkin
0 siblings, 1 reply; 4+ messages in thread
From: Mirza Ishan Beg @ 2026-08-17 17:03 UTC (permalink / raw)
To: Michael S . Tsirkin
Cc: virtualization, linux-kernel, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Mirza Ishan Beg
On Sun, Aug 16, 2026 at 05:38:06PM -0400, Michael S. Tsirkin wrote:
> why do we care?
Hi Michael,
The motivation originally came from a checkpatch.pl warning, but looking directly at Documentation/timers/timers-howto.rst, there is a practical penalty here.
The documentation explicitly notes for the 1-20ms range: "msleep(1~20) may not do what the caller intends, and will often sleep longer (~20 ms actual sleep for any value given in the 1~20ms range)."
In these queue reset loops, using msleep(1) means each iteration may be extended to 10-20ms depending on HZ and timer slack. The document recommends using usleep_range() to avoid this overhead and provide the intended precision.
Let me know if you'd like this explanation folded into a v2 commit message.
--
Mirza
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] virtio_pci_modern: replace msleep(1) with usleep_range(1000, 2000)
2026-08-17 17:03 ` Mirza Ishan Beg
@ 2026-08-17 19:55 ` Michael S. Tsirkin
0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2026-08-17 19:55 UTC (permalink / raw)
To: Mirza Ishan Beg
Cc: virtualization, linux-kernel, Jason Wang, Xuan Zhuo,
Eugenio Pérez
On Mon, Aug 17, 2026 at 10:33:31PM +0530, Mirza Ishan Beg wrote:
> On Sun, Aug 16, 2026 at 05:38:06PM -0400, Michael S. Tsirkin wrote:
> > why do we care?
>
> Hi Michael,
>
> The motivation originally came from a checkpatch.pl warning, but looking directly at Documentation/timers/timers-howto.rst,
> there is a practical penalty here.
>
> The documentation explicitly notes for the 1-20ms range: "msleep(1~20) may not do what the caller intends, and will often sleep longer (~20 ms actual sleep for any value given in the 1~20ms range)."
>
> In these queue reset loops, using msleep(1) means each iteration may be extended to 10-20ms depending on HZ and timer slack. The document recommends using usleep_range() to avoid this overhead and provide the intended precision.
>
> Let me know if you'd like this explanation folded into a v2 commit message.
>
> --
> Mirza
I don't think we care anyway. We probably just want fsleep?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-17 19:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-16 9:43 [PATCH] virtio_pci_modern: replace msleep(1) with usleep_range(1000, 2000) Mirza Ishan Beg
2026-08-16 21:38 ` Michael S. Tsirkin
2026-08-17 17:03 ` Mirza Ishan Beg
2026-08-17 19:55 ` Michael S. Tsirkin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.