From patchwork Tue Jul 29 11:20:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wangkai (Kevin,C)" X-Patchwork-Id: 374431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A50F4140196 for ; Tue, 29 Jul 2014 21:27:12 +1000 (EST) Received: from localhost ([::1]:44884 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XC5Yk-0002BV-NV for incoming@patchwork.ozlabs.org; Tue, 29 Jul 2014 07:27:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55544) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XC5YO-0001jp-3r for qemu-devel@nongnu.org; Tue, 29 Jul 2014 07:26:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XC5YH-00055M-Pe for qemu-devel@nongnu.org; Tue, 29 Jul 2014 07:26:48 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:57882) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XC5YG-0004jt-SC for qemu-devel@nongnu.org; Tue, 29 Jul 2014 07:26:41 -0400 Received: from 172.24.2.119 (EHLO szxeml417-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BXH62118; Tue, 29 Jul 2014 19:26:21 +0800 (CST) Received: from localhost.localdomain (10.107.51.151) by smtpscn.huawei.com (10.82.67.156) with Microsoft SMTP Server (TLS) id 14.3.158.1; Tue, 29 Jul 2014 19:26:10 +0800 From: Wangkai To: Date: Tue, 29 Jul 2014 19:20:16 +0800 Message-ID: <1406632816-15932-1-git-send-email-wangkai86@huawei.com> X-Mailer: git-send-email 1.7.2.5 MIME-Version: 1.0 X-Originating-IP: [10.107.51.151] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: lee.yang@huawei.com, aliguori@amazon.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH] fix vcpu long time io blocking on tap, when too many packets was delivered to the guest os via tap interface. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Wangkai --- 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; + } } }