From patchwork Mon Jan 25 22:24:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Xu X-Patchwork-Id: 572956 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 03BBB140297 for ; Tue, 26 Jan 2016 10:04:30 +1100 (AEDT) Received: from localhost ([::1]:41179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNqBP-0004dp-R1 for incoming@patchwork.ozlabs.org; Mon, 25 Jan 2016 18:04:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNpa3-0003mB-V0 for qemu-devel@nongnu.org; Mon, 25 Jan 2016 17:25:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNpZz-0008D4-SK for qemu-devel@nongnu.org; Mon, 25 Jan 2016 17:25:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51554) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNpZz-0008D0-Mn for qemu-devel@nongnu.org; Mon, 25 Jan 2016 17:25:47 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 6290AC075655 for ; Mon, 25 Jan 2016 22:25:47 +0000 (UTC) Received: from wei-thinkpad.nay.redhat.com (vpn1-5-80.pek2.redhat.com [10.72.5.80]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0PMOxvr001754; Mon, 25 Jan 2016 17:25:40 -0500 From: wexu@redhat.com To: qemu-devel@nongnu.org Date: Tue, 26 Jan 2016 06:24:45 +0800 Message-Id: <1453760690-21221-6-git-send-email-wexu@redhat.com> In-Reply-To: <1453760690-21221-1-git-send-email-wexu@redhat.com> References: <1453760690-21221-1-git-send-email-wexu@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 X-Mailman-Approved-At: Mon, 25 Jan 2016 18:03:51 -0500 Cc: victork@redhat.com, mst@redhat.com, jasowang@redhat.com, yvugenfi@redhat.com, Wei Xu , marcel@redhat.com, dfleytma@redhat.com Subject: [Qemu-devel] [RFC Patch 05/10] The draining timer, create a timer to purge the packets from the cached pool. 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: Wei Xu --- hw/net/virtio-net.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index d005a56..8da2815 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -48,12 +48,17 @@ #define MAX_VIRTIO_IP_PAYLOAD (65535 + IP_OFFSET) +/* Purge coalesced packets timer interval */ +#define RSC_TIMER_INTERVAL 500000 + /* Global statistics */ static uint32_t rsc_chain_no_mem; /* Switcher to enable/disable rsc */ static bool virtio_net_rsc_bypass; +static uint32_t rsc_timeout = RSC_TIMER_INTERVAL; + /* Coalesce callback for ipv4/6 */ typedef int32_t (VirtioNetCoalesce) (NetRscChain *chain, NetRscSeg *seg, const uint8_t *buf, size_t size); @@ -1625,6 +1630,35 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f, return 0; } +static void virtio_net_rsc_purge(void *opq) +{ + int ret = 0; + NetRscChain *chain = (NetRscChain *)opq; + NetRscSeg *seg, *rn; + + QTAILQ_FOREACH_SAFE(seg, &chain->buffers, next, rn) { + if (!qemu_can_send_packet(seg->nc)) { + /* Should quit or continue? not sure if one or some + * of the queues fail would happen, try continue here */ + continue; + } + + ret = virtio_net_do_receive(seg->nc, seg->buf, seg->size); + QTAILQ_REMOVE(&chain->buffers, seg, next); + g_free(seg->buf); + g_free(seg); + + if (ret == 0) { + /* Try next queue */ + continue; + } + } + + if (!QTAILQ_EMPTY(&chain->buffers)) { + timer_mod(chain->drain_timer, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + rsc_timeout); + } +} static void virtio_net_rsc_cleanup(VirtIONet *n) { @@ -1810,6 +1844,8 @@ static size_t virtio_net_rsc_callback(NetRscChain *chain, NetClientState *nc, if (!virtio_net_rsc_cache_buf(chain, nc, buf, size)) { return 0; } else { + timer_mod(chain->drain_timer, + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + rsc_timeout); return size; } } @@ -1877,6 +1913,8 @@ static NetRscChain *virtio_net_rsc_lookup_chain(NetClientState *nc, } chain->proto = proto; + chain->drain_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, + virtio_net_rsc_purge, chain); chain->do_receive = virtio_net_rsc_receive4; QTAILQ_INIT(&chain->buffers);