From nobody Fri Mar 29 02:24:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544116067025175.29945483843244; Thu, 6 Dec 2018 09:07:47 -0800 (PST) Received: from localhost ([::1]:42143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUx7k-0007rV-Ru for importer@patchew.org; Thu, 06 Dec 2018 12:07:40 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 =3D opaque; struct netmap_ring *ring =3D s->rx; + unsigned int tail =3D ring->tail; =20 - /* 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 !=3D tail) { + uint32_t i =3D ring->head; uint32_t idx; bool morefrag; int iovcnt =3D 0; int iovsize; =20 + /* Get a (possibly multi-slot) packet. */ do { - i =3D ring->cur; idx =3D ring->slot[i].buf_idx; morefrag =3D (ring->slot[i].flags & NS_MOREFRAG); - s->iov[iovcnt].iov_base =3D (u_char *)NETMAP_BUF(ring, idx); + s->iov[iovcnt].iov_base =3D (void *)NETMAP_BUF(ring, idx); s->iov[iovcnt].iov_len =3D ring->slot[i].len; iovcnt++; + i =3D nm_ring_next(ring, i); + } while (i !=3D tail && morefrag); =20 - ring->cur =3D ring->head =3D nm_ring_next(ring, i); - } while (!nm_ring_empty(ring) && morefrag); + /* Advance ring->cur to tell the kernel that we have seen the slot= s. */ + ring->cur =3D i; =20 - 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 releasin= g the + * incomplete slots by updating ring->head. We will hopefully + * re-read the complete packet the next time we are called. */ + break; } =20 iovsize =3D qemu_sendv_packet_async(&s->nc, s->iov, iovcnt, netmap_send_completed); =20 + /* Release the slots to the kernel. */ + ring->head =3D i; + if (iovsize =3D=3D 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; } --=20 2.19.2 From nobody Fri Mar 29 02:24:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544115828093972.3977201956068; Thu, 6 Dec 2018 09:03:48 -0800 (PST) Received: from localhost ([::1]:42092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUx3u-0004sI-QX for importer@patchew.org; Thu, 06 Dec 2018 12:03:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUx1e-0003Zn-CB 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 1gUx1Z-0006of-18 for qemu-devel@nongnu.org; Thu, 06 Dec 2018 12:01:21 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:40616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gUx1U-0006k0-Ie for qemu-devel@nongnu.org; Thu, 06 Dec 2018 12:01:15 -0500 Received: by mail-wr1-x444.google.com with SMTP id p4so1203196wrt.7 for ; Thu, 06 Dec 2018 09:01:11 -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.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Dec 2018 09:01:08 -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=YZaWVhK9aZlYPe4Lk3s5yHZyVQRqkzdyzjMy8grX3mw=; b=ij6pIFEyy9FN2doDJcAPAcqAhO13jVm5z/nv59L6hoFBEJnZ4sPWsmxQ6QhxxEaPnH 6la/xate+4iCYXt511EJ6m3hNCkLGtLFL5LDYCqC1P5OSSn1BK//xRpVc2hqBS7lOWxM qZY+5zM+ZyKgzcGKfU8kkseCGFZT7b+oULkSXrCOJ9/S7UOa2INVG13EA0A+GkzeIagB TwqbbHGIlgV6+kdLfF18DjM7+7VOrH1d71AHAZbL4iop8ZI4/QI36buyFR5btIgnRBgY gRjqlNnYG88oOYLjUHeI/Gop6D14vtaGjxbdQyRDLLyGjgy0fJ0/bNzZLnhcF/Z19XxD nMog== 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=YZaWVhK9aZlYPe4Lk3s5yHZyVQRqkzdyzjMy8grX3mw=; b=qwLrk+X14y+EGSv5f5/bIM1he3btJ20imbNij2gcVpqIiBBRKdDhYdnEYua4jXgng9 ck22jOh/e1NkmoiBtsFGuAORLUtB/r3vthlzBhhBA100jhOfiZeQ0fT9lfI+zxQKtWW1 xFR6Mp7Icc5VV6NI0OBB6MsGp3jS8v8dul5lKw96bHxYipF1qaS2E9zh/woEaIF35uga 859VXQTfkCOvNkDflUW2nj+KXOSMnBcw34ea0gSMHaAh+foBc2yv9jr/l0Fwnpjh4BK3 NaB78twPg+G/gMZ2AgItSaNy8kS4LfM4oW3pEqZFT3G8C+PQGGftEyZW2x3gEBRh0f7S jtOw== X-Gm-Message-State: AA+aEWZyAo635eHcTd/s6SkQqr7Zs+ubOBJxao+DN8Th7akCJ5oIwa6J ZqOX6SNKsE8k9FofZ2FY4zlVVN9vZ6E= X-Google-Smtp-Source: AFSGD/VcsSE8bq8nYs6qDFyQVCDuK/n1ASfSPmEYa9M4EIKv2HrYZBUWbSMpiI6GAQHrl0WLkhXqZg== X-Received: by 2002:a5d:4c8a:: with SMTP id z10mr25316378wrs.75.1544115669256; Thu, 06 Dec 2018 09:01:09 -0800 (PST) From: Vincenzo Maffione To: qemu-devel@nongnu.org Date: Thu, 6 Dec 2018 17:59:06 +0100 Message-Id: <20181206165907.23465-3-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 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH v1 2/3] net: netmap: simplify netmap_receive() 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Improve code reuse by implementing netmap_receive() with a call to netmap_receive_iov(). Signed-off-by: Vincenzo Maffione --- net/netmap.c | 50 +++++++++++--------------------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/net/netmap.c b/net/netmap.c index 71a8122bdd..852106af29 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -154,45 +154,6 @@ static void netmap_writable(void *opaque) qemu_flush_queued_packets(&s->nc); } =20 -static ssize_t netmap_receive(NetClientState *nc, - const uint8_t *buf, size_t size) -{ - NetmapState *s =3D DO_UPCAST(NetmapState, nc, nc); - struct netmap_ring *ring =3D s->tx; - uint32_t i; - uint32_t idx; - uint8_t *dst; - - if (unlikely(!ring)) { - /* Drop. */ - return size; - } - - if (unlikely(size > ring->nr_buf_size)) { - RD(5, "[netmap_receive] drop packet of size %d > %d\n", - (int)size, ring->nr_buf_size); - return size; - } - - if (nm_ring_empty(ring)) { - /* No available slots in the netmap TX ring. */ - netmap_write_poll(s, true); - return 0; - } - - i =3D ring->cur; - idx =3D ring->slot[i].buf_idx; - dst =3D (uint8_t *)NETMAP_BUF(ring, idx); - - ring->slot[i].len =3D size; - ring->slot[i].flags =3D 0; - pkt_copy(buf, dst, size); - ring->cur =3D ring->head =3D nm_ring_next(ring, i); - ioctl(s->nmd->fd, NIOCTXSYNC, NULL); - - return size; -} - static ssize_t netmap_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) { @@ -259,6 +220,17 @@ static ssize_t netmap_receive_iov(NetClientState *nc, return iov_size(iov, iovcnt); } =20 +static ssize_t netmap_receive(NetClientState *nc, + const uint8_t *buf, size_t size) +{ + struct iovec iov; + + iov.iov_base =3D (void *)buf; + iov.iov_len =3D size; + + return netmap_receive_iov(nc, &iov, 1); +} + /* Complete a previous send (backend --> guest) and enable the fd_read callback. */ static void netmap_send_completed(NetClientState *nc, ssize_t len) --=20 2.19.2 From nobody Fri Mar 29 02:24:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544116233581477.97076202397363; Thu, 6 Dec 2018 09:10:33 -0800 (PST) Received: from localhost ([::1]:42158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUxAV-0001qu-T7 for importer@patchew.org; Thu, 06 Dec 2018 12:10:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gUx1v-0003mc-C9 for qemu-devel@nongnu.org; Thu, 06 Dec 2018 12:01:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gUx1e-0006t6-ST for qemu-devel@nongnu.org; Thu, 06 Dec 2018 12:01:35 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:34208) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gUx1e-0006kp-99 for qemu-devel@nongnu.org; Thu, 06 Dec 2018 12:01:22 -0500 Received: by mail-wr1-x443.google.com with SMTP id j2so1243119wrw.1 for ; Thu, 06 Dec 2018 09:01:12 -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.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Dec 2018 09:01:09 -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=iUAg6dfrLALQcG1YgGKEexk7hL/v84hmTmLvr6abT14=; b=pZVPGIvsqGb+m6U/u0ubq0peSKp4DW0Hgg8vUt5p+mkkfvctRamudbUayPSsSeK0S0 Gi0mfEWrAxtYKyl/VrPk5U7Deycy0NuFpwwatlc4nqYErcCt0bWwx5N9SxeUrJh5oLpa SO3/CrdECyeEdTK2Rk79wzcHERS4ETrWTtCFaZp9cpL/arT4SApG3Lu+/8BEfgytUtZS 6UPp3UiynmuipOfFe7d9O7Gmf/KV+yZynnptO7w1OwwIXle/QGlktZE4fSlfldjggvml iHHe6muUp2og+28Oia0HRxGuYhG4xqiOTtadNsuy+KEU6Z+JlbstI+8S0cT5RUZGEXKo zgTA== 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=iUAg6dfrLALQcG1YgGKEexk7hL/v84hmTmLvr6abT14=; b=jRUkiLvagqMagcy5p7zAxih15eFowi8lWo5vvz54kwUQMMp5optxRQlJ/X6Z196WN7 /jg/0StwJ2/4sc8xmo518EF6B9l/g2VKUDLUV3fIkuL/3VXBnLEooTjoy4ZdJXeJDKw0 n1F8kUIG4S/quK5I31j1ej+4v2N3ydDQPKrI5vkqwzPpaV8QtZJDKWV1JsSNFExQeVAM 67qfHu09+3NfKP+Zt/paNhcV3wzp7KdmNXiF2mVVJ+QPB4KJYgaM4Ttj+wT2Lyd5XWRi +JENsL/V6TI+5kHQYrhDyGjE2+HHle82eR21UpE0HzygQUF4FH7GemvYmXAp1Q1oK8+H lBaw== X-Gm-Message-State: AA+aEWaCo8wwlosDhUGip9adsT7kmZcHh3/utYMVZQzbJj77UVjzNSZ/ NcqONPvhSwCSsOae9T8XWZjxoYWSiVE= X-Google-Smtp-Source: AFSGD/XYSgEGimH4SjDLyuswwpiYDeR0VqzCaTnaUcm9O4bpIYqqyiJDkahdq1b3pGpD13uA/2d1vQ== X-Received: by 2002:a5d:454f:: with SMTP id p15mr27719537wrr.39.1544115670435; Thu, 06 Dec 2018 09:01:10 -0800 (PST) From: Vincenzo Maffione To: qemu-devel@nongnu.org Date: Thu, 6 Dec 2018 17:59:07 +0100 Message-Id: <20181206165907.23465-4-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 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH v1 3/3] net: netmap: improve netmap_receive_iov() 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Changes: - Save CPU cycles by computing the return value while scanning the input iovec, rather than calling iov_size() at the end. - Remove check for s->tx !=3D NULL, because it cannot happen. - Cache ring->tail in a local variable and use it to check for space in the TX ring. The use of nm_ring_empty() was invalid, because nobody is updating ring->cur and ring->head at that point. - In case we run out of netmap slots in the middle of a packet, move the wake-up point by advancing ring->cur, but do not expose the incomplete packet (i.e., by updating also ring->head). Signed-off-by: Vincenzo Maffione --- net/netmap.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/net/netmap.c b/net/netmap.c index 852106af29..0cc8f545c5 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -159,21 +159,22 @@ static ssize_t netmap_receive_iov(NetClientState *nc, { NetmapState *s =3D DO_UPCAST(NetmapState, nc, nc); struct netmap_ring *ring =3D s->tx; + unsigned int tail =3D ring->tail; + ssize_t totlen =3D 0; uint32_t last; uint32_t idx; uint8_t *dst; int j; uint32_t i; =20 - if (unlikely(!ring)) { - /* Drop the packet. */ - return iov_size(iov, iovcnt); - } - - last =3D i =3D ring->cur; + last =3D i =3D ring->head; =20 if (nm_ring_space(ring) < iovcnt) { - /* Not enough netmap slots. */ + /* Not enough netmap slots. Tell the kernel that we have seen the = new + * available slots (so that it notifies us again when it has more + * ones), but without publishing any new slots to be processed + * (e.g., we don't advance ring->head). */ + ring->cur =3D tail; netmap_write_poll(s, true); return 0; } @@ -183,14 +184,17 @@ static ssize_t netmap_receive_iov(NetClientState *nc, int offset =3D 0; int nm_frag_size; =20 + totlen +=3D iov_frag_size; + /* Split each iovec fragment over more netmap slots, if necessary. */ while (iov_frag_size) { nm_frag_size =3D MIN(iov_frag_size, ring->nr_buf_size); =20 - if (unlikely(nm_ring_empty(ring))) { - /* We run out of netmap slots while splitting the + if (unlikely(i =3D=3D tail)) { + /* We ran out of netmap slots while splitting the iovec fragments. */ + ring->cur =3D tail; netmap_write_poll(s, true); return 0; } @@ -212,12 +216,13 @@ static ssize_t netmap_receive_iov(NetClientState *nc, /* The last slot must not have NS_MOREFRAG set. */ ring->slot[last].flags &=3D ~NS_MOREFRAG; =20 - /* Now update ring->cur and ring->head. */ - ring->cur =3D ring->head =3D i; + /* Now update ring->head and ring->cur to publish the new slots and + * the new wakeup point. */ + ring->head =3D ring->cur =3D i; =20 ioctl(s->nmd->fd, NIOCTXSYNC, NULL); =20 - return iov_size(iov, iovcnt); + return totlen; } =20 static ssize_t netmap_receive(NetClientState *nc, --=20 2.19.2