From patchwork Tue Jun 2 07:10:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanqin Wei X-Patchwork-Id: 1302111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bjqY6JLNz9sPF for ; Tue, 2 Jun 2020 17:10:33 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id EEBCB86099; Tue, 2 Jun 2020 07:10:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KzMG07Bk--Zw; Tue, 2 Jun 2020 07:10:26 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id A8906851CC; Tue, 2 Jun 2020 07:10:26 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 82C0DC0178; Tue, 2 Jun 2020 07:10:26 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id D604CC016E for ; Tue, 2 Jun 2020 07:10:25 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id B9ED1881E9 for ; Tue, 2 Jun 2020 07:10:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3TxGJTX207mY for ; Tue, 2 Jun 2020 07:10:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by hemlock.osuosl.org (Postfix) with ESMTP id BF2BB8820A for ; Tue, 2 Jun 2020 07:10:24 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6CEDF1FB; Tue, 2 Jun 2020 00:10:24 -0700 (PDT) Received: from net-arm-n1sdp.shanghai.arm.com (net-arm-n1sdp.shanghai.arm.com [10.169.40.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 926823F305; Tue, 2 Jun 2020 00:10:21 -0700 (PDT) From: Yanqin Wei To: dev@openvswitch.org Date: Tue, 2 Jun 2020 02:10:00 -0500 Message-Id: <20200602071005.29925-2-Yanqin.Wei@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200602071005.29925-1-Yanqin.Wei@arm.com> References: <20200602071005.29925-1-Yanqin.Wei@arm.com> Cc: Ruifeng.Wang@arm.com, Lijian.Zhang@arm.com, i.maximets@ovn.org, nd@arm.com Subject: [ovs-dev] [PATCH v1 1/6] netdev: avoid unnecessary packet batch refilling in netdev feature check X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Before sending packets on netdev, feature compatibility is always checked and incompatible traffic should be dropped. But, packet batch is refilled even when no packet needs to be dropped. This patch improves it by keeping the original batch if no packet should be dropped. Reviewed-by: Lijian Zhang Reviewed-by: Malvika Gupta Signed-off-by: Yanqin Wei --- lib/dp-packet.h | 12 ++++++++---- lib/netdev.c | 13 ++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/dp-packet.h b/lib/dp-packet.h index 0430cca8e..1345f46e7 100644 --- a/lib/dp-packet.h +++ b/lib/dp-packet.h @@ -762,12 +762,12 @@ dp_packet_batch_size(const struct dp_packet_batch *batch) return batch->count; } -/* Clear 'batch' for refill. Use dp_packet_batch_refill() to add +/* Clear 'batch' from 'offset' for refill. Use dp_packet_batch_refill() to add * packets back into the 'batch'. */ static inline void -dp_packet_batch_refill_init(struct dp_packet_batch *batch) +dp_packet_batch_refill_prepare(struct dp_packet_batch *batch, size_t offset) { - batch->count = 0; + batch->count = offset; }; static inline void @@ -801,6 +801,10 @@ dp_packet_batch_is_full(const struct dp_packet_batch *batch) for (size_t IDX = 0; IDX < dp_packet_batch_size(BATCH); IDX++) \ if (PACKET = BATCH->packets[IDX], true) +#define DP_PACKET_BATCH_FOR_EACH_WITH_SIZE(IDX, SIZE, PACKET, BATCH) \ + for (size_t IDX = 0; IDX < SIZE; IDX++) \ + if (PACKET = BATCH->packets[IDX], true) + /* Use this macro for cases where some packets in the 'BATCH' may be * dropped after going through each packet in the 'BATCH'. * @@ -813,7 +817,7 @@ dp_packet_batch_is_full(const struct dp_packet_batch *batch) * the 'const' modifier since it should not be modified by * the iterator. */ #define DP_PACKET_BATCH_REFILL_FOR_EACH(IDX, SIZE, PACKET, BATCH) \ - for (dp_packet_batch_refill_init(BATCH), IDX=0; IDX < SIZE; IDX++) \ + for (dp_packet_batch_refill_prepare(BATCH, 0), IDX=0; IDX < SIZE; IDX++) \ if (PACKET = BATCH->packets[IDX], true) static inline void diff --git a/lib/netdev.c b/lib/netdev.c index 90962eec6..7934a00d4 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -838,15 +838,22 @@ netdev_send_prepare_batch(const struct netdev *netdev, struct dp_packet_batch *batch) { struct dp_packet *packet; - size_t i, size = dp_packet_batch_size(batch); + size_t batch_cnt = dp_packet_batch_size(batch);; + bool refill = false; - DP_PACKET_BATCH_REFILL_FOR_EACH (i, size, packet, batch) { + DP_PACKET_BATCH_FOR_EACH_WITH_SIZE (i, batch_cnt, packet, batch) { char *errormsg = NULL; if (netdev_send_prepare_packet(netdev->ol_flags, packet, &errormsg)) { - dp_packet_batch_refill(batch, packet, i); + if ( OVS_UNLIKELY(refill) ) { + dp_packet_batch_refill(batch, packet, i); + } } else { dp_packet_delete(packet); + if( !refill ) { + dp_packet_batch_refill_prepare(batch, i); + refill = true; + } COVERAGE_INC(netdev_send_prepare_drops); VLOG_WARN_RL(&rl, "%s: Packet dropped: %s", netdev_get_name(netdev), errormsg);