Signed-off-by: Wangkai <wangka...@huawei.com>
---
 net/tap.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/net/tap.c b/net/tap.c
index a40f7f0..9a59934 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -189,6 +189,7 @@ static void tap_send(void *opaque)
 {
     TAPState *s = opaque;
     int size;
+    int packets = 0;
 
     while (qemu_can_send_packet(&s->nc)) {
         uint8_t *buf = s->buf;
@@ -210,6 +211,19 @@ static void tap_send(void *opaque)
         } else if (size < 0) {
             break;
         }
+
+        /*
+         * When receive packets on tap, QEMU io was locked, if too many
+         * packets was delivered to the guest os via tap interface,
+         * tap_send() would keep looping, if then the VM required a io
+         * operation, would be blocked for a long time.
+         * Here we set the number to limit one tap interface receive time,
+         * keep io events fair and lock time little.
+         */
+        packets++;
+        if (packets >= 50) {
+            break;
+        }
     }
 }
 
-- 
1.7.2.5


Reply via email to