There's a vague feeling that, if there are too many requests in the
incoming ring buffer, processing and replying to them may usurp the
event loop (main thread) and thus induce lags, soft lockups, etc.

So ensure to yield the event loop at most every 1024 requests.

TODO: do something smarter than this
Signed-off-by: Roman Kagan <rka...@virtuozzo.com>
---
 hw/scsi/hv-scsi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/hw/scsi/hv-scsi.c b/hw/scsi/hv-scsi.c
index bbfc26bf0a..aa055340ef 100644
--- a/hw/scsi/hv-scsi.c
+++ b/hw/scsi/hv-scsi.c
@@ -294,8 +294,9 @@ static void hv_scsi_handle_packet(HvScsiReq *req)
 static void hv_scsi_notify_cb(VMBusChannel *chan)
 {
     HvScsi *scsi = HV_SCSI(vmbus_channel_device(chan));
+    int i;
 
-    for (;;) {
+    for (i = 1024; i; i--) {
         HvScsiReq *req = vmbus_channel_recv(chan, sizeof(*req));
         if (!req) {
             break;
@@ -304,6 +305,10 @@ static void hv_scsi_notify_cb(VMBusChannel *chan)
         hv_scsi_init_req(scsi, req);
         hv_scsi_handle_packet(req);
     }
+
+    if (!i) {
+        vmbus_notify_channel(chan);
+    }
 }
 
 static void hv_scsi_reset(HvScsi *scsi)
-- 
2.14.3


Reply via email to