From patchwork Fri Jul 11 01:05:30 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: 368923 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 6C74D14008D for ; Fri, 11 Jul 2014 11:07:05 +1000 (EST) Received: from localhost ([::1]:41555 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5PIl-00035x-Cb for incoming@patchwork.ozlabs.org; Thu, 10 Jul 2014 21:07:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5PHc-000117-22 for qemu-devel@nongnu.org; Thu, 10 Jul 2014 21:05:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X5PHX-0004EG-2k for qemu-devel@nongnu.org; Thu, 10 Jul 2014 21:05:51 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:2279) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X5PHW-0004CM-D8 for qemu-devel@nongnu.org; Thu, 10 Jul 2014 21:05:47 -0400 Received: from 172.24.2.119 (EHLO nkgeml401-hub.china.huawei.com) ([172.24.2.119]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id ARM33067; Fri, 11 Jul 2014 09:05:37 +0800 (CST) Received: from NKGEML506-MBS.china.huawei.com ([169.254.4.228]) by nkgeml401-hub.china.huawei.com ([10.98.56.32]) with mapi id 14.03.0158.001; Fri, 11 Jul 2014 09:05:31 +0800 From: "Wangkai (Kevin,C)" To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH] Tap: fix vcpu long time io blocking on tap Thread-Index: Ac+cpDL6VMwccMmHQdGigdRcq8qAAQ== Date: Fri, 11 Jul 2014 01:05:30 +0000 Message-ID: <87B246BB5ED53A4C98E4F9A35839EDE128F6F49D@nkgeml506-mbs.china.huawei.com> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.111.75.9] MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.53BF3863.0007,ss=1,re=0.000,fgs=0, ip=169.254.4.228, so=2013-05-26 15:14:31, dmn=2011-05-27 18:58:46 X-Mirapoint-Loop-Id: 61612e98d7637e02f0c857819ec8f775 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.66 Cc: Lee yang , "stefanha@redhat.com" , "aliguori@amazon.com" Subject: [Qemu-devel] [PATCH] Tap: fix vcpu long time io blocking on tap 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 When used a tap as net driver for vm, if too many packets was delivered to the guest os via tap interface, the guest os will be blocked on io events for a long time, while tap driver was busying process packets. kvm vcpu thread block on io lock call trace: __lll_lock_wait _L_lock_1004 __pthread_mutex_lock qemu_mutex_lock kvm_cpu_exec qemu_kvm_cpu_thread_fn start_thread qemu io thread call trace: ... qemu_net_queue_send tap_send qemu_iohandler_poll main_loop_wait main_loop I think the qemu io lock time should be as small as possible, and the io work slice should be limited at a particular ration or time. --- Signed-off-by: Wangkai --- 2.0.0 diff --git a/net/tap.c b/net/tap.c index a40f7f0..df9a0eb 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 pkt = 0; while (qemu_can_send_packet(&s->nc)) { uint8_t *buf = s->buf; @@ -210,6 +211,11 @@ static void tap_send(void *opaque) } else if (size < 0) { break; } + + /* limit io block time slice for 50 packets */ + pkt++; + if (pkt >= 50) + break; } }