virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] virtio-net: add cond_resched() to the command waiting loop
@ 2022-09-05  4:53 Jason Wang
  2022-09-05  7:15 ` Michael S. Tsirkin
  2022-10-17 20:09 ` Michael S. Tsirkin
  0 siblings, 2 replies; 14+ messages in thread
From: Jason Wang @ 2022-09-05  4:53 UTC (permalink / raw)
  To: mst, jasowang, davem, edumazet, kuba, pabeni
  Cc: netdev, gautam.dawar, linux-kernel, virtualization

Adding cond_resched() to the command waiting loop for a better
co-operation with the scheduler. This allows to give CPU a breath to
run other task(workqueue) instead of busy looping when preemption is
not allowed.

What's more important. This is a must for some vDPA parent to work
since control virtqueue is emulated via a workqueue for those parents.

Fixes: bda324fd037a ("vdpasim: control virtqueue support")
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/net/virtio_net.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index ece00b84e3a7..169368365d6a 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2000,8 +2000,10 @@ static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd,
 	 * into the hypervisor, so the request should be handled immediately.
 	 */
 	while (!virtqueue_get_buf(vi->cvq, &tmp) &&
-	       !virtqueue_is_broken(vi->cvq))
+	       !virtqueue_is_broken(vi->cvq)) {
+		cond_resched();
 		cpu_relax();
+	}
 
 	return vi->ctrl->status == VIRTIO_NET_OK;
 }
-- 
2.25.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-10-17 20:10 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-05  4:53 [PATCH net] virtio-net: add cond_resched() to the command waiting loop Jason Wang
2022-09-05  7:15 ` Michael S. Tsirkin
2022-09-05  7:49   ` Jason Wang
2022-09-06 10:55     ` Paolo Abeni
2022-09-07  2:09       ` Jason Wang
2022-09-07  7:07         ` Paolo Abeni
2022-09-07  7:46           ` Michael S. Tsirkin
2022-09-08  2:21             ` Jason Wang
2022-09-08  5:19               ` Michael S. Tsirkin
2022-10-09  5:58                 ` Jason Wang
2022-10-10 17:11                   ` Michael S. Tsirkin
2022-10-12  3:19                     ` Jason Wang
2022-10-17  7:15                       ` Jason Wang
2022-10-17 20:09 ` Michael S. Tsirkin

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 NNTP newsgroup(s).