diff mbox

[RFC,26/34] hv-scsi: limit the number of requests per notification

Message ID 20180206203048.11096-27-rkagan@virtuozzo.com (mailing list archive)
State New, archived
Headers show

Commit Message

Roman Kagan Feb. 6, 2018, 8:30 p.m. UTC
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 <rkagan@virtuozzo.com>
---
 hw/scsi/hv-scsi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox

Patch

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)