From: Wangkai (Kevin,C) Date: Fri, 18 Jul 2014 09:33:42 +0000 (+0000) Subject: tap: fix vcpu long time io blocking on tap X-Git-Tag: v2.3.0-rc0~127^2~4 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=756ae78b275a0625b4559a8fc448df4c6eb331a8;p=users%2Fdwmw2%2Fqemu.git tap: fix vcpu long time io blocking on tap [Adjusted doc comment for grammar. --Stefan] Signed-off-by: Wangkai Signed-off-by: Stefan Hajnoczi --- diff --git a/net/tap.c b/net/tap.c index bde6b58b17..1fe0edfdf7 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,17 @@ static void tap_send(void *opaque) } else if (size < 0) { break; } + + /* + * When the host keeps receiving more packets while tap_send() is + * running we can hog the QEMU global mutex. Limit the number of + * packets that are processed per tap_send() callback to prevent + * stalling the guest. + */ + packets++; + if (packets >= 50) { + break; + } } }