From patchwork Thu Dec 6 16:59:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincenzo Maffione X-Patchwork-Id: 10716437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F93915A6 for ; Thu, 6 Dec 2018 17:07:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 193002F110 for ; Thu, 6 Dec 2018 17:07:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D4912F174; Thu, 6 Dec 2018 17:07:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A272B2F110 for ; Thu, 6 Dec 2018 17:07:04 +0000 (UTC) Received: from localhost ([::1]:42143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUx79-0007rV-MZ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Dec 2018 12:07:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUx1e-0003Zo-CD for qemu-devel@nongnu.org; Thu, 06 Dec 2018 12:01:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUx1a-0006pQ-6z for qemu-devel@nongnu.org; Thu, 06 Dec 2018 12:01:21 -0500 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:42049) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gUx1W-0006jT-FZ for qemu-devel@nongnu.org; Thu, 06 Dec 2018 12:01:16 -0500 Received: by mail-wr1-x442.google.com with SMTP id q18so1187080wrx.9 for ; Thu, 06 Dec 2018 09:01:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tK2BZqLuzZ+VCr08SBXY+JNTW67/Sq6+s7tBpxJovR4=; b=bjqSFOYAofz5r0ruUn6O+6MTijjM4X0QIvJg2viZWu1Jb3CAl5SsrZk0gnvIcsGN0B JdK/+ZRuws33RMKqFrcnx6WpFL3xNSz4d8rpn8s8CZtFWzm1gcpkrAC6Zs4v746CqLy4 xKLNKXKoOzufcMlHItQZSKHVWBAhv8Va20Bkz6DxcDgvgn7NkBbbVH2hVkc0EoqSXLy9 CmwwdFq1HZpWAA6emE8K/xX5FyXCB3Ea82HJKDMe2Ly2MCkIfh7Z+qWrkybtcQU+VZXW m9AiqjEFrtoS0S7JpdWIJATtJWS/M1NKrYSfJ8ZDbbGy4HiEvYrJiy7F24RKiaLlZxVF 49Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tK2BZqLuzZ+VCr08SBXY+JNTW67/Sq6+s7tBpxJovR4=; b=QCM2bMhozwKV86mkmjxTZ9LvgXtKj7L2NyYpEIWO3TOyGHxITWQx3Cs/Ui/TxE51oM ryTlzDAkO5IF+sqUi3ai++afzQx7l0C8dmv9HrkitM0Vnrrg+GwmvuWt/DX1lIkdRdV1 Sqoiurncp4Jj/ywUFuxwSHTgDiWEKqlSZrq4wpAKQCuiMyvaWBe8DjR+x+XpI9+Z4oFM RK3J4wu5YmGsodEP2SEQAszrYxG7Ra2gwcR9PC5AKXwlVOrgnEb2a78LE87GTgNnmMSG pxxQJQOuzX2OIiXtgRR/E5Ct1zS5rWakoTXvNYGBVYI6/eiqsdEFHGEL6JcSI1gr+H8N E9kw== X-Gm-Message-State: AA+aEWZ6KZjxRFsAstt8fdMczpaWi9TBEwvJkoamD839wqsiVbWfwgoz Jz+y4dEAiUtC0jkT9zuxExQsZmwfLZ4= X-Google-Smtp-Source: AFSGD/WPjiIUNVOGzz8VSXaTv0a0MBHr8enImNafG6Hwq22ZDTwi9+ueOE0Cj2z1Vcif+t7u+As7iw== X-Received: by 2002:a5d:63c3:: with SMTP id c3mr25702469wrw.215.1544115668503; Thu, 06 Dec 2018 09:01:08 -0800 (PST) Received: from localhost.localdomain (prova.iet.unipi.it. [131.114.58.86]) by smtp.gmail.com with ESMTPSA id d4sm467556wrp.89.2018.12.06.09.01.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Dec 2018 09:01:07 -0800 (PST) From: Vincenzo Maffione To: qemu-devel@nongnu.org Date: Thu, 6 Dec 2018 17:59:05 +0100 Message-Id: <20181206165907.23465-2-v.maffione@gmail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181206165907.23465-1-v.maffione@gmail.com> References: <20181206165907.23465-1-v.maffione@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH v1 1/3] net: netmap: small improvements netmap_send() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: g.lettieri@iet.unipi.it, jasowang@redhat.com, Vincenzo Maffione Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This change improves the handling of incomplete multi-slot packets (e.g. with the NS_MOREFRAG set), by advancing ring->head only on complete packets. The ring->cur pointer is advanced in any case in order to acknowledge the kernel and move the wake-up point (thus avoiding repeated wake-ups). Also don't be verbose when incomplete packets are found. Signed-off-by: Vincenzo Maffione --- net/netmap.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/net/netmap.c b/net/netmap.c index 2d11a8f4be..71a8122bdd 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -272,39 +272,46 @@ static void netmap_send(void *opaque) { NetmapState *s = opaque; struct netmap_ring *ring = s->rx; + unsigned int tail = ring->tail; - /* Keep sending while there are available packets into the netmap + /* Keep sending while there are available slots in the netmap RX ring and the forwarding path towards the peer is open. */ - while (!nm_ring_empty(ring)) { - uint32_t i; + while (ring->head != tail) { + uint32_t i = ring->head; uint32_t idx; bool morefrag; int iovcnt = 0; int iovsize; + /* Get a (possibly multi-slot) packet. */ do { - i = ring->cur; idx = ring->slot[i].buf_idx; morefrag = (ring->slot[i].flags & NS_MOREFRAG); - s->iov[iovcnt].iov_base = (u_char *)NETMAP_BUF(ring, idx); + s->iov[iovcnt].iov_base = (void *)NETMAP_BUF(ring, idx); s->iov[iovcnt].iov_len = ring->slot[i].len; iovcnt++; + i = nm_ring_next(ring, i); + } while (i != tail && morefrag); - ring->cur = ring->head = nm_ring_next(ring, i); - } while (!nm_ring_empty(ring) && morefrag); + /* Advance ring->cur to tell the kernel that we have seen the slots. */ + ring->cur = i; - if (unlikely(nm_ring_empty(ring) && morefrag)) { - RD(5, "[netmap_send] ran out of slots, with a pending" - "incomplete packet\n"); + if (unlikely(morefrag)) { + /* This is a truncated packet, so we can stop without releasing the + * incomplete slots by updating ring->head. We will hopefully + * re-read the complete packet the next time we are called. */ + break; } iovsize = qemu_sendv_packet_async(&s->nc, s->iov, iovcnt, netmap_send_completed); + /* Release the slots to the kernel. */ + ring->head = i; + if (iovsize == 0) { /* The peer does not receive anymore. Packet is queued, stop - * reading from the backend until netmap_send_completed() - */ + * reading from the backend until netmap_send_completed(). */ netmap_read_poll(s, false); break; }