virtio-net: add cond_resched() to the command waiting loop
Subsystems (4)
PATCH 1/1 virtio-net: add cond_resched() to the command waiting loop
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.
--- drivers/net/virtio_net.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/virtio_net.c +3 -1
@@ -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 ; }
Signature · 6 lines
2.25.1 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerQuoted 9 lines · Jason Wang
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")
That's a weird commit to fix. so it fixes the simulator?
Quoted 10 lines
Signed-off-by Jason Wang <[email protected]>--- drivers/net/virtio_net.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/net/virtio_net.c +0
-0
drivers/net/virtio_net.c static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd, · line 2006
Quoted 8 lines
drivers/net/virtio_net.c +3
-1@@ -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 (); + }
with cond_resched do we still need cpu_relax?
Quoted 4 lines
drivers/net/virtio_net.c +0
-0return vi->ctrl->status ==VIRTIO_NET_OK ; }Signature · 1 line
2.25.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Jason Wang
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.
Quoted 6 lines
Quoted 4 lines
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")That's a weird commit to fix. so it fixes the simulator?
Yes, since the simulator is using a workqueue to handle control virtueue.
Quoted 6 lines
Quoted 6 lines
Signed-off-by Jason Wang <[email protected]>--- drivers/net/virtio_net.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 15 lines
drivers/net/virtio_net.c static bool virtnet_send_command(struct virtnet_info *vi, u8 class, u8 cmd, · line 2006
Quoted 13 lines
drivers/net/virtio_net.c +3
-1@@ -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 (); + }with
cond_rescheddo we still needcpu_relax?
I think so, it's possible that cond_sched() just doesn't trigger scheduling.
Thanks
Quoted 6 lines
Quoted 5 lines
drivers/net/virtio_net.c +0
-1return vi->ctrl->status ==VIRTIO_NET_OK ; } --2.25.1
Paolo Abeni
maintainerQuoted 8 lines · Jason Wang
Quoted 7 lines · Michael S. Tsirkin
Quoted 5 lines · Jason Wang
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.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
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")That's a weird commit to fix. so it fixes the simulator?
Yes, since the simulator is using a workqueue to handle control virtueue.
Uhmm... touching a driver for a simulator's sake looks a little weird.
Additionally, if the bug is vdpasim, I think it's better to try to solve it there, if possible.
Looking at vdpasim_net_work() and vdpasim_blk_work() it looks like neither needs a process context, so perhaps you could rework it to run the work_fn() directly from vdpasim_kick_vq(), at least for the control virtqueue?
Thanks!
Paolo
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 13 lines · Paolo Abeni
Quoted 11 lines · Jason Wang
Quoted 10 lines · Michael S. Tsirkin
Quoted 8 lines · Jason Wang
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.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Fixes bda324fd037a ("vdpasim: control virtqueue support")That's a weird commit to fix. so it fixes the simulator?
Yes, since the simulator is using a workqueue to handle control virtueue.
Uhmm... touching a driver for a simulator's sake looks a little weird.
Simulator is not the only one that is using a workqueue (but should be the first).
I can see that the mlx5 vDPA driver is using a workqueue as well (see mlx5_vdpa_kick_vq()).
And in the case of VDUSE, it needs to wait for the response from the userspace, this means cond_resched() is probably a must for the case like UP.
Quoted 8 lines
Additionally, if the bug is vdpasim, I think it's better to try to solve it there, if possible.
Looking at
vdpasim_net_work()andvdpasim_blk_work()it looks like neither needs a process context, so perhaps you could rework it to run thework_fn()directly fromvdpasim_kick_vq(), at least for the control virtqueue?
It's possible (but require some rework on the simulator core). But considering we have other similar use cases, it looks better to solve it in the virtio-net driver.
Additionally, this may have better behaviour when using for the buggy hardware (e.g the control virtqueue takes too long to respond). We may consider switching to use interrupt/sleep in the future (but not suitable for -net).
Thanks
Quoted 5 lines
Thanks!
Paolo
Paolo Abeni
maintainerQuoted 36 lines · Jason Wang
Quoted 13 lines · Paolo Abeni
Quoted 11 lines · Jason Wang
Quoted 10 lines · Michael S. Tsirkin
Quoted 8 lines · Jason Wang
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.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Fixes bda324fd037a ("vdpasim: control virtqueue support")That's a weird commit to fix. so it fixes the simulator?
Yes, since the simulator is using a workqueue to handle control virtueue.
Uhmm... touching a driver for a simulator's sake looks a little weird.
Simulator is not the only one that is using a workqueue (but should be the first).
I can see that the mlx5 vDPA driver is using a workqueue as well (see
mlx5_vdpa_kick_vq()).And in the case of VDUSE, it needs to wait for the response from the userspace, this means
cond_resched()is probably a must for the case like UP.Quoted 4 lines
Additionally, if the bug is vdpasim, I think it's better to try to solve it there, if possible.
Quoted 8 lines
Quoted 4 lines
Looking at
vdpasim_net_work()andvdpasim_blk_work()it looks like neither needs a process context, so perhaps you could rework it to run thework_fn()directly fromvdpasim_kick_vq(), at least for the control virtqueue?It's possible (but require some rework on the simulator core). But considering we have other similar use cases, it looks better to solve it in the virtio-net driver.
I see.
Quoted 4 lines
Additionally, this may have better behaviour when using for the buggy hardware (e.g the control virtqueue takes too long to respond). We may consider switching to use interrupt/sleep in the future (but not suitable for -net).
Agreed. Possibly a timeout could be useful, too.
Cheers,
Paolo
Michael S. Tsirkin
maintainerQuoted 53 lines · Paolo Abeni
Quoted 36 lines · Jason Wang
Quoted 13 lines · Paolo Abeni
Quoted 11 lines · Jason Wang
Quoted 10 lines · Michael S. Tsirkin
Quoted 8 lines · Jason Wang
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.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Fixes bda324fd037a ("vdpasim: control virtqueue support")That's a weird commit to fix. so it fixes the simulator?
Yes, since the simulator is using a workqueue to handle control virtueue.
Uhmm... touching a driver for a simulator's sake looks a little weird.
Simulator is not the only one that is using a workqueue (but should be the first).
I can see that the mlx5 vDPA driver is using a workqueue as well (see
mlx5_vdpa_kick_vq()).And in the case of VDUSE, it needs to wait for the response from the userspace, this means
cond_resched()is probably a must for the case like UP.Quoted 4 lines
Additionally, if the bug is vdpasim, I think it's better to try to solve it there, if possible.
Quoted 8 lines
Quoted 4 lines
Looking at
vdpasim_net_work()andvdpasim_blk_work()it looks like neither needs a process context, so perhaps you could rework it to run thework_fn()directly fromvdpasim_kick_vq(), at least for the control virtqueue?It's possible (but require some rework on the simulator core). But considering we have other similar use cases, it looks better to solve it in the virtio-net driver.
I see.
Quoted 4 lines
Additionally, this may have better behaviour when using for the buggy hardware (e.g the control virtqueue takes too long to respond). We may consider switching to use interrupt/sleep in the future (but not suitable for -net).
Quoted 5 lines
Agreed. Possibly a timeout could be useful, too.
Cheers,
Paolo
Hmm timeouts are kind of arbitrary.
regular drivers basically derive them from hardware behaviour but with a generic driver like virtio it's harder. I guess we could add timeout as a config field, have device make a promise to the driver.
Making the wait interruptible seems more reasonable.
Signature · 6 lines
MST _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 50 lines · Michael S. Tsirkin
Quoted 43 lines · Paolo Abeni
Quoted 29 lines · Jason Wang
Quoted 8 lines · Paolo Abeni
Quoted 7 lines · Jason Wang
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Jason Wang
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.Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
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")That's a weird commit to fix. so it fixes the simulator?
Yes, since the simulator is using a workqueue to handle control virtueue.
Uhmm... touching a driver for a simulator's sake looks a little weird.
Simulator is not the only one that is using a workqueue (but should be the first).
I can see that the mlx5 vDPA driver is using a workqueue as well (see
mlx5_vdpa_kick_vq()).And in the case of VDUSE, it needs to wait for the response from the userspace, this means
cond_resched()is probably a must for the case like UP.Quoted 3 lines
Additionally, if the bug is vdpasim, I think it's better to try to solve it there, if possible.
Quoted 7 lines
Quoted 4 lines
Looking at
vdpasim_net_work()andvdpasim_blk_work()it looks like neither needs a process context, so perhaps you could rework it to run thework_fn()directly fromvdpasim_kick_vq(), at least for the control virtqueue?It's possible (but require some rework on the simulator core). But considering we have other similar use cases, it looks better to solve it in the virtio-net driver.
I see.
Quoted 4 lines
Additionally, this may have better behaviour when using for the buggy hardware (e.g the control virtqueue takes too long to respond). We may consider switching to use interrupt/sleep in the future (but not suitable for -net).
Quoted 5 lines
Agreed. Possibly a timeout could be useful, too.
Cheers,
Paolo
Quoted 7 lines
Hmm timeouts are kind of arbitrary.
regular drivers basically derive them from hardware behaviour but with a generic driver like virtio it's harder. I guess we could add timeout as a config field, have device make a promise to the driver.Making the wait interruptible seems more reasonable.
Yes, but I think we still need this patch for -net and -stable.
Thanks
Quoted 1 line
Michael S. Tsirkin
maintainerQuoted 58 lines · Jason Wang
Quoted 56 lines · Michael S. Tsirkin
Quoted 43 lines · Paolo Abeni
Quoted 29 lines · Jason Wang
Quoted 8 lines · Paolo Abeni
Quoted 7 lines · Jason Wang
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Jason Wang
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.Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
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")That's a weird commit to fix. so it fixes the simulator?
Yes, since the simulator is using a workqueue to handle control virtueue.
Uhmm... touching a driver for a simulator's sake looks a little weird.
Simulator is not the only one that is using a workqueue (but should be the first).
I can see that the mlx5 vDPA driver is using a workqueue as well (see
mlx5_vdpa_kick_vq()).And in the case of VDUSE, it needs to wait for the response from the userspace, this means
cond_resched()is probably a must for the case like UP.Quoted 3 lines
Additionally, if the bug is vdpasim, I think it's better to try to solve it there, if possible.
Quoted 7 lines
Quoted 4 lines
Looking at
vdpasim_net_work()andvdpasim_blk_work()it looks like neither needs a process context, so perhaps you could rework it to run thework_fn()directly fromvdpasim_kick_vq(), at least for the control virtqueue?It's possible (but require some rework on the simulator core). But considering we have other similar use cases, it looks better to solve it in the virtio-net driver.
I see.
Quoted 4 lines
Additionally, this may have better behaviour when using for the buggy hardware (e.g the control virtqueue takes too long to respond). We may consider switching to use interrupt/sleep in the future (but not suitable for -net).
Quoted 5 lines
Agreed. Possibly a timeout could be useful, too.
Cheers,
Paolo
Hmm timeouts are kind of arbitrary.
regular drivers basically derive them from hardware behaviour but with a generic driver like virtio it's harder. I guess we could add timeout as a config field, have device make a promise to the driver.
Quoted 6 lines
Quoted 1 line
Making the wait interruptible seems more reasonable.
Yes, but I think we still need this patch for -net and -stable.
Thanks
I was referring to Paolo's idea of having a timeout.
Signature · 1 line
MST
Quoted 57 lines · Michael S. Tsirkin
Quoted 56 lines · Jason Wang
Quoted 55 lines · Michael S. Tsirkin
Quoted 43 lines · Paolo Abeni
Quoted 29 lines · Jason Wang
Quoted 8 lines · Paolo Abeni
Quoted 7 lines · Jason Wang
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Jason Wang
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.Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
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")That's a weird commit to fix. so it fixes the simulator?
Yes, since the simulator is using a workqueue to handle control virtueue.
Uhmm... touching a driver for a simulator's sake looks a little weird.
Simulator is not the only one that is using a workqueue (but should be the first).
I can see that the mlx5 vDPA driver is using a workqueue as well (see
mlx5_vdpa_kick_vq()).And in the case of VDUSE, it needs to wait for the response from the userspace, this means
cond_resched()is probably a must for the case like UP.Quoted 3 lines
Additionally, if the bug is vdpasim, I think it's better to try to solve it there, if possible.
Quoted 7 lines
Quoted 4 lines
Looking at
vdpasim_net_work()andvdpasim_blk_work()it looks like neither needs a process context, so perhaps you could rework it to run thework_fn()directly fromvdpasim_kick_vq(), at least for the control virtqueue?It's possible (but require some rework on the simulator core). But considering we have other similar use cases, it looks better to solve it in the virtio-net driver.
I see.
Quoted 4 lines
Additionally, this may have better behaviour when using for the buggy hardware (e.g the control virtqueue takes too long to respond). We may consider switching to use interrupt/sleep in the future (but not suitable for -net).
Quoted 5 lines
Agreed. Possibly a timeout could be useful, too.
Cheers,
Paolo
Hmm timeouts are kind of arbitrary.
regular drivers basically derive them from hardware behaviour but with a generic driver like virtio it's harder. I guess we could add timeout as a config field, have device make a promise to the driver.
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Making the wait interruptible seems more reasonable.
Yes, but I think we still need this patch for -net and -stable.
Thanks
I was referring to Paolo's idea of having a timeout.
Ok, I think we're fine with this patch. Any chance to merge this or do I need to resend?
Thanks
Quoted 1 line
Michael S. Tsirkin
maintainerQuoted 63 lines · Jason Wang
Quoted 61 lines · Michael S. Tsirkin
Quoted 60 lines · Jason Wang
Quoted 48 lines · Michael S. Tsirkin
Quoted 47 lines · Paolo Abeni
Quoted 29 lines · Jason Wang
Quoted 8 lines · Paolo Abeni
Quoted 7 lines · Jason Wang
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Jason Wang
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.Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
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")That's a weird commit to fix. so it fixes the simulator?
Yes, since the simulator is using a workqueue to handle control virtueue.
Uhmm... touching a driver for a simulator's sake looks a little weird.
Simulator is not the only one that is using a workqueue (but should be the first).
I can see that the mlx5 vDPA driver is using a workqueue as well (see
mlx5_vdpa_kick_vq()).And in the case of VDUSE, it needs to wait for the response from the userspace, this means
cond_resched()is probably a must for the case like UP.Quoted 3 lines
Additionally, if the bug is vdpasim, I think it's better to try to solve it there, if possible.
Quoted 7 lines
Quoted 4 lines
Looking at
vdpasim_net_work()andvdpasim_blk_work()it looks like neither needs a process context, so perhaps you could rework it to run thework_fn()directly fromvdpasim_kick_vq(), at least for the control virtqueue?It's possible (but require some rework on the simulator core). But considering we have other similar use cases, it looks better to solve it in the virtio-net driver.
I see.
Quoted 4 lines
Additionally, this may have better behaviour when using for the buggy hardware (e.g the control virtqueue takes too long to respond). We may consider switching to use interrupt/sleep in the future (but not suitable for -net).
Agreed. Possibly a timeout could be useful, too.
Cheers,
Quoted 8 lines
Quoted 1 line
Paolo
Hmm timeouts are kind of arbitrary.
regular drivers basically derive them from hardware behaviour but with a generic driver like virtio it's harder. I guess we could add timeout as a config field, have device make a promise to the driver.Making the wait interruptible seems more reasonable.
Yes, but I think we still need this patch for -net and -stable.
Quoted 8 lines
Quoted 2 lines
Quoted 1 line
Thanks
I was referring to Paolo's idea of having a timeout.
Ok, I think we're fine with this patch. Any chance to merge this or do I need to resend?
Thanks
Last question: do we want cpu_relax here now? Or is cond_resched sufficient?
Quoted 2 lines
Quoted 2 lines
Quoted 69 lines · Michael S. Tsirkin
Quoted 67 lines · Jason Wang
Quoted 63 lines · Michael S. Tsirkin
Quoted 56 lines · Jason Wang
Quoted 55 lines · Michael S. Tsirkin
Quoted 43 lines · Paolo Abeni
Quoted 29 lines · Jason Wang
Quoted 8 lines · Paolo Abeni
Quoted 7 lines · Jason Wang
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Jason Wang
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.Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
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")That's a weird commit to fix. so it fixes the simulator?
Yes, since the simulator is using a workqueue to handle control virtueue.
Uhmm... touching a driver for a simulator's sake looks a little weird.
Simulator is not the only one that is using a workqueue (but should be the first).
I can see that the mlx5 vDPA driver is using a workqueue as well (see
mlx5_vdpa_kick_vq()).And in the case of VDUSE, it needs to wait for the response from the userspace, this means
cond_resched()is probably a must for the case like UP.Quoted 3 lines
Additionally, if the bug is vdpasim, I think it's better to try to solve it there, if possible.
Quoted 7 lines
Quoted 4 lines
Looking at
vdpasim_net_work()andvdpasim_blk_work()it looks like neither needs a process context, so perhaps you could rework it to run thework_fn()directly fromvdpasim_kick_vq(), at least for the control virtqueue?It's possible (but require some rework on the simulator core). But considering we have other similar use cases, it looks better to solve it in the virtio-net driver.
I see.
Quoted 4 lines
Additionally, this may have better behaviour when using for the buggy hardware (e.g the control virtqueue takes too long to respond). We may consider switching to use interrupt/sleep in the future (but not suitable for -net).
Quoted 5 lines
Agreed. Possibly a timeout could be useful, too.
Cheers,
Paolo
Hmm timeouts are kind of arbitrary.
regular drivers basically derive them from hardware behaviour but with a generic driver like virtio it's harder. I guess we could add timeout as a config field, have device make a promise to the driver.Quoted 5 lines
Quoted 1 line
Making the wait interruptible seems more reasonable.
Yes, but I think we still need this patch for -net and -stable.
Thanks
I was referring to Paolo's idea of having a timeout.
Quoted 7 lines
Quoted 4 lines
Ok, I think we're fine with this patch. Any chance to merge this or do I need to resend?
Thanks
Last question: do we want
cpu_relaxhere now? Or iscond_reschedsufficient?
(Have answered in another thread)
I think we need cpu_relax() since there could be no high priority task in the current cpu so we still need to relax.
Thanks
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 79 lines · Jason Wang
Quoted 69 lines · Michael S. Tsirkin
Quoted 67 lines · Jason Wang
Quoted 63 lines · Michael S. Tsirkin
Quoted 56 lines · Jason Wang
Quoted 55 lines · Michael S. Tsirkin
Quoted 43 lines · Paolo Abeni
Quoted 29 lines · Jason Wang
Quoted 8 lines · Paolo Abeni
Quoted 7 lines · Jason Wang
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Jason Wang
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.Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
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")That's a weird commit to fix. so it fixes the simulator?
Yes, since the simulator is using a workqueue to handle control virtueue.
Uhmm... touching a driver for a simulator's sake looks a little weird.
Simulator is not the only one that is using a workqueue (but should be the first).
I can see that the mlx5 vDPA driver is using a workqueue as well (see
mlx5_vdpa_kick_vq()).And in the case of VDUSE, it needs to wait for the response from the userspace, this means
cond_resched()is probably a must for the case like UP.Quoted 3 lines
Additionally, if the bug is vdpasim, I think it's better to try to solve it there, if possible.
Quoted 7 lines
Quoted 4 lines
Looking at
vdpasim_net_work()andvdpasim_blk_work()it looks like neither needs a process context, so perhaps you could rework it to run thework_fn()directly fromvdpasim_kick_vq(), at least for the control virtqueue?It's possible (but require some rework on the simulator core). But considering we have other similar use cases, it looks better to solve it in the virtio-net driver.
I see.
Quoted 4 lines
Additionally, this may have better behaviour when using for the buggy hardware (e.g the control virtqueue takes too long to respond). We may consider switching to use interrupt/sleep in the future (but not suitable for -net).
Quoted 5 lines
Agreed. Possibly a timeout could be useful, too.
Cheers,
Paolo
Hmm timeouts are kind of arbitrary.
regular drivers basically derive them from hardware behaviour but with a generic driver like virtio it's harder. I guess we could add timeout as a config field, have device make a promise to the driver.Quoted 5 lines
Quoted 1 line
Making the wait interruptible seems more reasonable.
Yes, but I think we still need this patch for -net and -stable.
Thanks
I was referring to Paolo's idea of having a timeout.
Quoted 7 lines
Quoted 4 lines
Ok, I think we're fine with this patch. Any chance to merge this or do I need to resend?
Thanks
Last question: do we want
cpu_relaxhere now? Or iscond_reschedsufficient?
Quoted 6 lines
(Have answered in another thread)
I think we need
cpu_relax()since there could be no high priority task in the current cpu so we still need to relax.Thanks
Michael, does this answer make sense? If yes, would you like to ack the patch?
Thanks
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 10 lines · Jason Wang
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 <[email protected]>
Quoted 22 lines
--- drivers/net/virtio_net.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/net/virtio_net.c +3
-1@@ -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 ; }Signature · 1 line
2.25.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization