From patchwork Tue Jun 2 07:10:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanqin Wei X-Patchwork-Id: 1302112 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.133; helo=hemlock.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 hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bjqh1n1Hz9sPF for ; Tue, 2 Jun 2020 17:10:40 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id B872D88273; Tue, 2 Jun 2020 07:10:38 +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 65f4ivyNJbhX; Tue, 2 Jun 2020 07:10:38 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id EC4B78826E; Tue, 2 Jun 2020 07:10:37 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B2C16C016E; Tue, 2 Jun 2020 07:10:37 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1D273C016E for ; Tue, 2 Jun 2020 07:10:36 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 0B70587639 for ; Tue, 2 Jun 2020 07:10:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EGxpMORkzIZE for ; Tue, 2 Jun 2020 07:10:32 +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 whitealder.osuosl.org (Postfix) with ESMTP id 7880987686 for ; Tue, 2 Jun 2020 07:10:29 +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 1AB081FB; Tue, 2 Jun 2020 00:10:29 -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 3ED263F305; Tue, 2 Jun 2020 00:10:25 -0700 (PDT) From: Yanqin Wei To: dev@openvswitch.org Date: Tue, 2 Jun 2020 02:10:01 -0500 Message-Id: <20200602071005.29925-3-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 2/6] dpif-netdev: add tunnel_valid flag to skip ip/ipv6 address comparison 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" miniflow_extract checks the validation of tunnel metadata by comparing tunnel destination address, including 16 bytes ipv6 address. This patch introduces a 'tunnel_valid' flag. If it is false, md->cacheline2 will not be touched. This improvement is beneficial to miniflow_extract performance for all kinds of traffic. Reviewed-by: Lijian Zhang Reviewed-by: Malvika Gupta Signed-off-by: Yanqin Wei --- lib/dpif-netdev.c | 14 +++++++++++--- lib/flow.c | 2 +- lib/packets.h | 46 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 51c888501..c94d5e8c7 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -6625,12 +6625,16 @@ dfc_processing(struct dp_netdev_pmd_thread *pmd, if (i != cnt - 1) { struct dp_packet **packets = packets_->packets; /* Prefetch next packet data and metadata. */ - OVS_PREFETCH(dp_packet_data(packets[i+1])); - pkt_metadata_prefetch_init(&packets[i+1]->md); + OVS_PREFETCH(dp_packet_data(packets[i + 1])); + if (md_is_valid) { + pkt_metadata_prefetch(&packets[i + 1]->md); + } else { + pkt_metadata_prefetch_init(&packets[i + 1]->md); + } } if (!md_is_valid) { - pkt_metadata_init(&packet->md, port_no); + pkt_metadata_datapath_init(&packet->md, port_no); } if ((*recirc_depth_get() == 0) && @@ -6730,6 +6734,10 @@ handle_packet_upcall(struct dp_netdev_pmd_thread *pmd, miniflow_expand(&key->mf, &match.flow); memset(&match.wc, 0, sizeof match.wc); + if (!packet->md.tunnel_valid) { + pkt_metadata_tnl_dst_init(&packet->md); + } + ofpbuf_clear(actions); ofpbuf_clear(put_actions); diff --git a/lib/flow.c b/lib/flow.c index cc1b3f2db..1f0b3d4dc 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -747,7 +747,7 @@ miniflow_extract(struct dp_packet *packet, struct miniflow *dst) ovs_be16 ct_tp_src = 0, ct_tp_dst = 0; /* Metadata. */ - if (flow_tnl_dst_is_set(&md->tunnel)) { + if (md->tunnel_valid && flow_tnl_dst_is_set(&md->tunnel)) { miniflow_push_words(mf, tunnel, &md->tunnel, offsetof(struct flow_tnl, metadata) / sizeof(uint64_t)); diff --git a/lib/packets.h b/lib/packets.h index 447e6f6fa..3b507d2a3 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -103,15 +103,16 @@ PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline0, action. */ uint32_t skb_priority; /* Packet priority for QoS. */ uint32_t pkt_mark; /* Packet mark. */ + struct conn *conn; /* Cached conntrack connection. */ uint8_t ct_state; /* Connection state. */ bool ct_orig_tuple_ipv6; uint16_t ct_zone; /* Connection zone. */ uint32_t ct_mark; /* Connection mark. */ ovs_u128 ct_label; /* Connection label. */ union flow_in_port in_port; /* Input port. */ - struct conn *conn; /* Cached conntrack connection. */ bool reply; /* True if reply direction. */ bool icmp_related; /* True if ICMP related. */ + bool tunnel_valid; ); PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline1, @@ -141,6 +142,7 @@ pkt_metadata_init_tnl(struct pkt_metadata *md) * are before this and as long as they are empty, the options won't * be looked at. */ memset(md, 0, offsetof(struct pkt_metadata, tunnel.metadata.opts)); + md->tunnel_valid = true; } static inline void @@ -151,6 +153,25 @@ pkt_metadata_init_conn(struct pkt_metadata *md) static inline void pkt_metadata_init(struct pkt_metadata *md, odp_port_t port) +{ + /* Initialize only till ct_state. Once the ct_state is zeroed out rest + * of ct fields will not be looked at unless ct_state != 0. + */ + memset(md, 0, offsetof(struct pkt_metadata, ct_orig_tuple_ipv6)); + + /* It can be expensive to zero out all of the tunnel metadata. However, + * we can just zero out ip_dst and the rest of the data will never be + * looked at. */ + md->tunnel_valid = true; + md->tunnel.ip_dst = 0; + md->tunnel.ipv6_dst = in6addr_any; + + md->in_port.odp_port = port; +} + +/* This function initializes those members used by userspace datapath */ +static inline void +pkt_metadata_datapath_init(struct pkt_metadata *md, odp_port_t port) { /* This is called for every packet in userspace datapath and affects * performance if all the metadata is initialized. Hence, fields should @@ -162,12 +183,19 @@ pkt_metadata_init(struct pkt_metadata *md, odp_port_t port) memset(md, 0, offsetof(struct pkt_metadata, ct_orig_tuple_ipv6)); /* It can be expensive to zero out all of the tunnel metadata. However, - * we can just zero out ip_dst and the rest of the data will never be - * looked at. */ + * we can just clear tunnel_valid */ + md->tunnel_valid = false; + + md->in_port.odp_port = port; +} + +/* This function initializes tunnel dst for upcall */ +static inline void +pkt_metadata_tnl_dst_init(struct pkt_metadata *md) +{ md->tunnel.ip_dst = 0; md->tunnel.ipv6_dst = in6addr_any; - md->in_port.odp_port = port; - md->conn = NULL; + md->tunnel_valid = true; } /* This function prefetches the cachelines touched by pkt_metadata_init() @@ -184,7 +212,13 @@ pkt_metadata_prefetch_init(struct pkt_metadata *md) * in pkt_metadata_init_tnl(). */ OVS_PREFETCH(md->cacheline1); - /* Prefetch cachline2 as ip_dst & ipv6_dst fields will be initialized. */ +} +/* This function prefetches the cachelines touched by miniflow_extract().*/ +static inline void +pkt_metadata_prefetch(struct pkt_metadata *md) +{ + OVS_PREFETCH(md->cacheline0); + OVS_PREFETCH(md->cacheline1); OVS_PREFETCH(md->cacheline2); }