From nobody Mon Feb 9 09:16:26 2026 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