From patchwork Tue Oct 6 14:54:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 1377474 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=fail (p=none dis=none) header.from=intel.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 4C5L7g6j8cz9sRk for ; Wed, 7 Oct 2020 01:53:35 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 7B207859D2; Tue, 6 Oct 2020 14:53:33 +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 qHym-G00eJRs; Tue, 6 Oct 2020 14:53:30 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 3E64F8594B; Tue, 6 Oct 2020 14:53:30 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 112F0C1AD7; Tue, 6 Oct 2020 14:53:30 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id A16F9C07FF for ; Tue, 6 Oct 2020 14:53:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 91141858DA for ; Tue, 6 Oct 2020 14:53:27 +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 iXdmekpsHkPm for ; Tue, 6 Oct 2020 14:53:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 27357858F5 for ; Tue, 6 Oct 2020 14:53:27 +0000 (UTC) IronPort-SDR: m13HvTt/d3VvS0QrUFSV54e/m4lTy788Oyyob9XtcmeSC2JTBEXwMvhdVqDNv58UE5V6s58SA8 XKd+YDkD6aXQ== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="249228231" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="249228231" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 07:53:14 -0700 IronPort-SDR: PBh3uH3xd4brjFR4g3By0tU6kF3mM9aK+T45/WmF84SyptVrWKpXC80bHBRtjEW2ZXX1mpWb9N f8pWOIpz62eQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="311246811" Received: from silpixa00399779.ir.intel.com (HELO silpixa00399779.ger.corp.intel.com) ([10.237.222.209]) by orsmga003.jf.intel.com with ESMTP; 06 Oct 2020 07:53:13 -0700 From: Harry van Haaren To: ovs-dev@openvswitch.org Date: Tue, 6 Oct 2020 15:54:30 +0100 Message-Id: <20201006145437.35124-2-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006145437.35124-1-harry.van.haaren@intel.com> References: <20201006145437.35124-1-harry.van.haaren@intel.com> Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 1/8] dpif-netdev: optimize dp output action 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" This commit optimizes the output action, by enabling the compiler to optimize the code better through reducing code complexity. The core concept of this optimization is that the array-length checks have already been performed above the copying code, so can be removed. Removing of the per-packet length checks allows the compiler to auto-vectorize the stores using SIMD registers. Signed-off-by: Harry van Haaren --- Overall performance increase was about 2.5% in simple phy-to-phy testing. There are likely other places in OVS where this technique can be applied. --- lib/dpif-netdev.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 02df8f11e..dbbacfa36 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -7606,12 +7606,25 @@ dp_execute_output_action(struct dp_netdev_pmd_thread *pmd, pmd->n_output_batches++; } - struct dp_packet *packet; - DP_PACKET_BATCH_FOR_EACH (i, packet, packets_) { - p->output_pkts_rxqs[dp_packet_batch_size(&p->output_pkts)] = - pmd->ctx.last_rxq; - dp_packet_batch_add(&p->output_pkts, packet); + /* The above checks ensure that there is enough space in the output batch. + * Using dp_packet_batch_add() has a branch to check if the batch is full. + * This branch reduces the compilers ability to optimize efficiently. The + * below code implements packet movement between batches without checks, + * with the required semantics of output batch perhaps contiaining packets. + */ + int batch_size = dp_packet_batch_size(packets_); + int out_batch_idx = dp_packet_batch_size(&p->output_pkts); + struct dp_netdev_rxq *rxq = pmd->ctx.last_rxq; + struct dp_packet_batch *output_batch = &p->output_pkts; + + for (int i = 0; i < batch_size; i++) { + struct dp_packet *packet = packets_->packets[i]; + p->output_pkts_rxqs[out_batch_idx] = rxq; + output_batch->packets[out_batch_idx] = packet; + out_batch_idx++; } + output_batch->count += batch_size; + return true; } From patchwork Tue Oct 6 14:54:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 1377476 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=fail (p=none dis=none) header.from=intel.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 4C5L7k2Ygfz9sSG for ; Wed, 7 Oct 2020 01:53:38 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id ED42B85CFF; Tue, 6 Oct 2020 14:53:36 +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 yaeDHgjnVUeF; Tue, 6 Oct 2020 14:53:31 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 3B162858DA; Tue, 6 Oct 2020 14:53:31 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 015B6C1AD6; Tue, 6 Oct 2020 14:53:31 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 897BFC0051 for ; Tue, 6 Oct 2020 14:53:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 7757E82346 for ; Tue, 6 Oct 2020 14:53:28 +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 rH06DqDqRBEs for ; Tue, 6 Oct 2020 14:53:27 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 3F13185910 for ; Tue, 6 Oct 2020 14:53:27 +0000 (UTC) IronPort-SDR: tEABpGruERcaJp5LPI3pL+Hz1eFZL3JaKr5Qr1lQoMnYPE5zr8BccuuBaYL8ju6fEDFJFkLtoF e/umwAiszaMg== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="249228240" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="249228240" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 07:53:15 -0700 IronPort-SDR: e5NBXmc90O6D2jUluxYMmR2GueSsSg8s4lXau78ElodL8sXBdW2yAWgJm1hrmArzrsEDGFNGAx eIiG98xVxC/g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="311246822" Received: from silpixa00399779.ir.intel.com (HELO silpixa00399779.ger.corp.intel.com) ([10.237.222.209]) by orsmga003.jf.intel.com with ESMTP; 06 Oct 2020 07:53:14 -0700 From: Harry van Haaren To: ovs-dev@openvswitch.org Date: Tue, 6 Oct 2020 15:54:31 +0100 Message-Id: <20201006145437.35124-3-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006145437.35124-1-harry.van.haaren@intel.com> References: <20201006145437.35124-1-harry.van.haaren@intel.com> Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 2/8] dpif-netdev: refactor emc and smc into dfc header 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" This commit moves the EMC and SMC implementations and data- structures out of the very large dpif-netdev.c file, and into its own header file. No functional changes are made here, only movement of code between files. Signed-off-by: Harry van Haaren --- lib/automake.mk | 1 + lib/dpif-netdev-private-dfc.h | 204 ++++++++++++++++++++++++++++++++++ lib/dpif-netdev.c | 169 +--------------------------- 3 files changed, 206 insertions(+), 168 deletions(-) create mode 100644 lib/dpif-netdev-private-dfc.h diff --git a/lib/automake.mk b/lib/automake.mk index 380a67228..9b0cdeb54 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -111,6 +111,7 @@ lib_libopenvswitch_la_SOURCES = \ lib/dpif-netdev-lookup-generic.c \ lib/dpif-netdev.c \ lib/dpif-netdev.h \ + lib/dpif-netdev-private-dfc.h \ lib/dpif-netdev-private.h \ lib/dpif-netdev-perf.c \ lib/dpif-netdev-perf.h \ diff --git a/lib/dpif-netdev-private-dfc.h b/lib/dpif-netdev-private-dfc.h new file mode 100644 index 000000000..f3c1aa338 --- /dev/null +++ b/lib/dpif-netdev-private-dfc.h @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc. + * Copyright (c) 2019, 2020 Intel Corperation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DPIF_NETDEV_PRIVATE_DFC_H +#define DPIF_NETDEV_PRIVATE_DFC_H 1 + +#include +#include + +#include "dpif.h" +#include "cmap.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* EMC cache and SMC cache compose the datapath flow cache (DFC) + * + * Exact match cache for frequently used flows + * + * The cache uses a 32-bit hash of the packet (which can be the RSS hash) to + * search its entries for a miniflow that matches exactly the miniflow of the + * packet. It stores the 'dpcls_rule' (rule) that matches the miniflow. + * + * A cache entry holds a reference to its 'dp_netdev_flow'. + * + * A miniflow with a given hash can be in one of EM_FLOW_HASH_SEGS different + * entries. The 32-bit hash is split into EM_FLOW_HASH_SEGS values (each of + * them is EM_FLOW_HASH_SHIFT bits wide and the remainder is thrown away). Each + * value is the index of a cache entry where the miniflow could be. + * + * + * Signature match cache (SMC) + * + * This cache stores a 16-bit signature for each flow without storing keys, and + * stores the corresponding 16-bit flow_table index to the 'dp_netdev_flow'. + * Each flow thus occupies 32bit which is much more memory efficient than EMC. + * SMC uses a set-associative design that each bucket contains + * SMC_ENTRY_PER_BUCKET number of entries. + * Since 16-bit flow_table index is used, if there are more than 2^16 + * dp_netdev_flow, SMC will miss them that cannot be indexed by a 16-bit value. + * + * + * Thread-safety + * ============= + * + * Each pmd_thread has its own private exact match cache. + * If dp_netdev_input is not called from a pmd thread, a mutex is used. + */ + +#define EM_FLOW_HASH_SHIFT 13 +#define EM_FLOW_HASH_ENTRIES (1u << EM_FLOW_HASH_SHIFT) +#define EM_FLOW_HASH_MASK (EM_FLOW_HASH_ENTRIES - 1) +#define EM_FLOW_HASH_SEGS 2 + +/* SMC uses a set-associative design. A bucket contains a set of entries that + * a flow item can occupy. For now, it uses one hash function rather than two + * as for the EMC design. */ +#define SMC_ENTRY_PER_BUCKET 4 +#define SMC_ENTRIES (1u << 20) +#define SMC_BUCKET_CNT (SMC_ENTRIES / SMC_ENTRY_PER_BUCKET) +#define SMC_MASK (SMC_BUCKET_CNT - 1) + +/* Default EMC insert probability is 1 / DEFAULT_EM_FLOW_INSERT_INV_PROB */ +#define DEFAULT_EM_FLOW_INSERT_INV_PROB 100 +#define DEFAULT_EM_FLOW_INSERT_MIN (UINT32_MAX / \ + DEFAULT_EM_FLOW_INSERT_INV_PROB) + +struct emc_entry { + struct dp_netdev_flow *flow; + struct netdev_flow_key key; /* key.hash used for emc hash value. */ +}; + +struct emc_cache { + struct emc_entry entries[EM_FLOW_HASH_ENTRIES]; + int sweep_idx; /* For emc_cache_slow_sweep(). */ +}; + +struct smc_bucket { + uint16_t sig[SMC_ENTRY_PER_BUCKET]; + uint16_t flow_idx[SMC_ENTRY_PER_BUCKET]; +}; + +/* Signature match cache, differentiate from EMC cache */ +struct smc_cache { + struct smc_bucket buckets[SMC_BUCKET_CNT]; +}; + +struct dfc_cache { + struct emc_cache emc_cache; + struct smc_cache smc_cache; +}; + +/* Iterate in the exact match cache through every entry that might contain a + * miniflow with hash 'HASH'. */ +#define EMC_FOR_EACH_POS_WITH_HASH(EMC, CURRENT_ENTRY, HASH) \ + for (uint32_t i__ = 0, srch_hash__ = (HASH); \ + (CURRENT_ENTRY) = &(EMC)->entries[srch_hash__ & EM_FLOW_HASH_MASK], \ + i__ < EM_FLOW_HASH_SEGS; \ + i__++, srch_hash__ >>= EM_FLOW_HASH_SHIFT) + +/* These cannot be moved to .h yet as they dereference dp_netdev_flow */ +static inline bool emc_entry_alive(struct emc_entry *ce); +static void emc_clear_entry(struct emc_entry *ce); + +static void +smc_clear_entry(struct smc_bucket *b, int idx) +{ + b->flow_idx[idx] = UINT16_MAX; +} + +static void +emc_cache_init(struct emc_cache *flow_cache) +{ + int i; + + flow_cache->sweep_idx = 0; + for (i = 0; i < ARRAY_SIZE(flow_cache->entries); i++) { + flow_cache->entries[i].flow = NULL; + flow_cache->entries[i].key.hash = 0; + flow_cache->entries[i].key.len = sizeof(struct miniflow); + flowmap_init(&flow_cache->entries[i].key.mf.map); + } +} + +static void +smc_cache_init(struct smc_cache *smc_cache) +{ + int i, j; + for (i = 0; i < SMC_BUCKET_CNT; i++) { + for (j = 0; j < SMC_ENTRY_PER_BUCKET; j++) { + smc_cache->buckets[i].flow_idx[j] = UINT16_MAX; + } + } +} + +static void +dfc_cache_init(struct dfc_cache *flow_cache) +{ + emc_cache_init(&flow_cache->emc_cache); + smc_cache_init(&flow_cache->smc_cache); +} + +static void +emc_cache_uninit(struct emc_cache *flow_cache) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(flow_cache->entries); i++) { + emc_clear_entry(&flow_cache->entries[i]); + } +} + +static void +smc_cache_uninit(struct smc_cache *smc) +{ + int i, j; + + for (i = 0; i < SMC_BUCKET_CNT; i++) { + for (j = 0; j < SMC_ENTRY_PER_BUCKET; j++) { + smc_clear_entry(&(smc->buckets[i]), j); + } + } +} + +static void +dfc_cache_uninit(struct dfc_cache *flow_cache) +{ + smc_cache_uninit(&flow_cache->smc_cache); + emc_cache_uninit(&flow_cache->emc_cache); +} + +/* Check and clear dead flow references slowly (one entry at each + * invocation). */ +static void +emc_cache_slow_sweep(struct emc_cache *flow_cache) +{ + struct emc_entry *entry = &flow_cache->entries[flow_cache->sweep_idx]; + + if (!emc_entry_alive(entry)) { + emc_clear_entry(entry); + } + flow_cache->sweep_idx = (flow_cache->sweep_idx + 1) & EM_FLOW_HASH_MASK; +} + +#ifdef __cplusplus +} +#endif + +#endif /* dpif-netdev-private-dfc.h */ diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index dbbacfa36..c86a98870 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -44,6 +44,7 @@ #include "dpif.h" #include "dpif-netdev-lookup.h" #include "dpif-netdev-perf.h" +#include "dpif-netdev-private-dfc.h" #include "dpif-provider.h" #include "dummy.h" #include "fat-rwlock.h" @@ -142,90 +143,6 @@ static struct odp_support dp_netdev_support = { .ct_orig_tuple6 = true, }; -/* EMC cache and SMC cache compose the datapath flow cache (DFC) - * - * Exact match cache for frequently used flows - * - * The cache uses a 32-bit hash of the packet (which can be the RSS hash) to - * search its entries for a miniflow that matches exactly the miniflow of the - * packet. It stores the 'dpcls_rule' (rule) that matches the miniflow. - * - * A cache entry holds a reference to its 'dp_netdev_flow'. - * - * A miniflow with a given hash can be in one of EM_FLOW_HASH_SEGS different - * entries. The 32-bit hash is split into EM_FLOW_HASH_SEGS values (each of - * them is EM_FLOW_HASH_SHIFT bits wide and the remainder is thrown away). Each - * value is the index of a cache entry where the miniflow could be. - * - * - * Signature match cache (SMC) - * - * This cache stores a 16-bit signature for each flow without storing keys, and - * stores the corresponding 16-bit flow_table index to the 'dp_netdev_flow'. - * Each flow thus occupies 32bit which is much more memory efficient than EMC. - * SMC uses a set-associative design that each bucket contains - * SMC_ENTRY_PER_BUCKET number of entries. - * Since 16-bit flow_table index is used, if there are more than 2^16 - * dp_netdev_flow, SMC will miss them that cannot be indexed by a 16-bit value. - * - * - * Thread-safety - * ============= - * - * Each pmd_thread has its own private exact match cache. - * If dp_netdev_input is not called from a pmd thread, a mutex is used. - */ - -#define EM_FLOW_HASH_SHIFT 13 -#define EM_FLOW_HASH_ENTRIES (1u << EM_FLOW_HASH_SHIFT) -#define EM_FLOW_HASH_MASK (EM_FLOW_HASH_ENTRIES - 1) -#define EM_FLOW_HASH_SEGS 2 - -/* SMC uses a set-associative design. A bucket contains a set of entries that - * a flow item can occupy. For now, it uses one hash function rather than two - * as for the EMC design. */ -#define SMC_ENTRY_PER_BUCKET 4 -#define SMC_ENTRIES (1u << 20) -#define SMC_BUCKET_CNT (SMC_ENTRIES / SMC_ENTRY_PER_BUCKET) -#define SMC_MASK (SMC_BUCKET_CNT - 1) - -/* Default EMC insert probability is 1 / DEFAULT_EM_FLOW_INSERT_INV_PROB */ -#define DEFAULT_EM_FLOW_INSERT_INV_PROB 100 -#define DEFAULT_EM_FLOW_INSERT_MIN (UINT32_MAX / \ - DEFAULT_EM_FLOW_INSERT_INV_PROB) - -struct emc_entry { - struct dp_netdev_flow *flow; - struct netdev_flow_key key; /* key.hash used for emc hash value. */ -}; - -struct emc_cache { - struct emc_entry entries[EM_FLOW_HASH_ENTRIES]; - int sweep_idx; /* For emc_cache_slow_sweep(). */ -}; - -struct smc_bucket { - uint16_t sig[SMC_ENTRY_PER_BUCKET]; - uint16_t flow_idx[SMC_ENTRY_PER_BUCKET]; -}; - -/* Signature match cache, differentiate from EMC cache */ -struct smc_cache { - struct smc_bucket buckets[SMC_BUCKET_CNT]; -}; - -struct dfc_cache { - struct emc_cache emc_cache; - struct smc_cache smc_cache; -}; - -/* Iterate in the exact match cache through every entry that might contain a - * miniflow with hash 'HASH'. */ -#define EMC_FOR_EACH_POS_WITH_HASH(EMC, CURRENT_ENTRY, HASH) \ - for (uint32_t i__ = 0, srch_hash__ = (HASH); \ - (CURRENT_ENTRY) = &(EMC)->entries[srch_hash__ & EM_FLOW_HASH_MASK], \ - i__ < EM_FLOW_HASH_SEGS; \ - i__++, srch_hash__ >>= EM_FLOW_HASH_SHIFT) /* Simple non-wildcarding single-priority classifier. */ @@ -912,90 +829,12 @@ static inline struct dpcls * dp_netdev_pmd_lookup_dpcls(struct dp_netdev_pmd_thread *pmd, odp_port_t in_port); -static inline bool emc_entry_alive(struct emc_entry *ce); -static void emc_clear_entry(struct emc_entry *ce); -static void smc_clear_entry(struct smc_bucket *b, int idx); - static void dp_netdev_request_reconfigure(struct dp_netdev *dp); static inline bool pmd_perf_metrics_enabled(const struct dp_netdev_pmd_thread *pmd); static void queue_netdev_flow_del(struct dp_netdev_pmd_thread *pmd, struct dp_netdev_flow *flow); -static void -emc_cache_init(struct emc_cache *flow_cache) -{ - int i; - - flow_cache->sweep_idx = 0; - for (i = 0; i < ARRAY_SIZE(flow_cache->entries); i++) { - flow_cache->entries[i].flow = NULL; - flow_cache->entries[i].key.hash = 0; - flow_cache->entries[i].key.len = sizeof(struct miniflow); - flowmap_init(&flow_cache->entries[i].key.mf.map); - } -} - -static void -smc_cache_init(struct smc_cache *smc_cache) -{ - int i, j; - for (i = 0; i < SMC_BUCKET_CNT; i++) { - for (j = 0; j < SMC_ENTRY_PER_BUCKET; j++) { - smc_cache->buckets[i].flow_idx[j] = UINT16_MAX; - } - } -} - -static void -dfc_cache_init(struct dfc_cache *flow_cache) -{ - emc_cache_init(&flow_cache->emc_cache); - smc_cache_init(&flow_cache->smc_cache); -} - -static void -emc_cache_uninit(struct emc_cache *flow_cache) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(flow_cache->entries); i++) { - emc_clear_entry(&flow_cache->entries[i]); - } -} - -static void -smc_cache_uninit(struct smc_cache *smc) -{ - int i, j; - - for (i = 0; i < SMC_BUCKET_CNT; i++) { - for (j = 0; j < SMC_ENTRY_PER_BUCKET; j++) { - smc_clear_entry(&(smc->buckets[i]), j); - } - } -} - -static void -dfc_cache_uninit(struct dfc_cache *flow_cache) -{ - smc_cache_uninit(&flow_cache->smc_cache); - emc_cache_uninit(&flow_cache->emc_cache); -} - -/* Check and clear dead flow references slowly (one entry at each - * invocation). */ -static void -emc_cache_slow_sweep(struct emc_cache *flow_cache) -{ - struct emc_entry *entry = &flow_cache->entries[flow_cache->sweep_idx]; - - if (!emc_entry_alive(entry)) { - emc_clear_entry(entry); - } - flow_cache->sweep_idx = (flow_cache->sweep_idx + 1) & EM_FLOW_HASH_MASK; -} - /* Updates the time in PMD threads context and should be called in three cases: * * 1. PMD structure initialization: @@ -3181,12 +3020,6 @@ smc_entry_get(struct dp_netdev_pmd_thread *pmd, const uint32_t hash) return NULL; } -static void -smc_clear_entry(struct smc_bucket *b, int idx) -{ - b->flow_idx[idx] = UINT16_MAX; -} - /* Insert the flow_table index into SMC. Insertion may fail when 1) SMC is * turned off, 2) the flow_table index is larger than uint16_t can handle. * If there is already an SMC entry having same signature, the index will be From patchwork Tue Oct 6 14:54:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 1377475 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=fail (p=none dis=none) header.from=intel.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 4C5L7k04p1z9sRk for ; Wed, 7 Oct 2020 01:53:37 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 8E43B87022; Tue, 6 Oct 2020 14:53:35 +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 KVKpQkAfcfsd; Tue, 6 Oct 2020 14:53:33 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id 0DEF187029; Tue, 6 Oct 2020 14:53:32 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E4628C07FF; Tue, 6 Oct 2020 14:53:31 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7D33FC0051 for ; Tue, 6 Oct 2020 14:53:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 6D9FD843FE for ; Tue, 6 Oct 2020 14:53: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 BSWhXOOEw5xc for ; Tue, 6 Oct 2020 14:53:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 4A737841AC for ; Tue, 6 Oct 2020 14:53:29 +0000 (UTC) IronPort-SDR: gGYVyfxcAD4ENP78Jv6YsvEu9B3HN7Wjih88OvbnPIzXoQed/4s4WAAV61oKvtQOap+lmzoQPo m/kHENNHUrxQ== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="249228253" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="249228253" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 07:53:17 -0700 IronPort-SDR: zmMA1vSUSWSJJcgfPQFSP5SsYCTHUwjhbEYViZW7rnJHrqv0cuz/tnFdL9Mh3vEm7oJbpitM2J ei7rQtOYSTjw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="311246831" Received: from silpixa00399779.ir.intel.com (HELO silpixa00399779.ger.corp.intel.com) ([10.237.222.209]) by orsmga003.jf.intel.com with ESMTP; 06 Oct 2020 07:53:16 -0700 From: Harry van Haaren To: ovs-dev@openvswitch.org Date: Tue, 6 Oct 2020 15:54:32 +0100 Message-Id: <20201006145437.35124-4-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006145437.35124-1-harry.van.haaren@intel.com> References: <20201006145437.35124-1-harry.van.haaren@intel.com> Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 3/8] dpif-netdev: move netdev flow struct to header 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" This commit moves the dp_netdev_flow struct from dpif-netdev.c to the dpif-netdev-private.h file. No code changes are made. Signed-off-by: Harry van Haaren --- lib/dpif-netdev-private.h | 96 +++++++++++++++++++++++++++++++++++++++ lib/dpif-netdev.c | 94 -------------------------------------- 2 files changed, 96 insertions(+), 94 deletions(-) diff --git a/lib/dpif-netdev-private.h b/lib/dpif-netdev-private.h index bdc150d45..db6d11f70 100644 --- a/lib/dpif-netdev-private.h +++ b/lib/dpif-netdev-private.h @@ -105,6 +105,102 @@ netdev_flow_key_gen_masks(const struct netdev_flow_key *tbl, bool dpcls_rule_matches_key(const struct dpcls_rule *rule, const struct netdev_flow_key *target); + + +/* Contained by struct dp_netdev_flow's 'stats' member. */ +struct dp_netdev_flow_stats { + atomic_llong used; /* Last used time, in monotonic msecs. */ + atomic_ullong packet_count; /* Number of packets matched. */ + atomic_ullong byte_count; /* Number of bytes matched. */ + atomic_uint16_t tcp_flags; /* Bitwise-OR of seen tcp_flags values. */ +}; + +/* Contained by struct dp_netdev_flow's 'last_attrs' member. */ +struct dp_netdev_flow_attrs { + atomic_bool offloaded; /* True if flow is offloaded to HW. */ + ATOMIC(const char *) dp_layer; /* DP layer the flow is handled in. */ +}; + +/* A flow in 'dp_netdev_pmd_thread's 'flow_table'. + * + * + * Thread-safety + * ============= + * + * Except near the beginning or ending of its lifespan, rule 'rule' belongs to + * its pmd thread's classifier. The text below calls this classifier 'cls'. + * + * Motivation + * ---------- + * + * The thread safety rules described here for "struct dp_netdev_flow" are + * motivated by two goals: + * + * - Prevent threads that read members of "struct dp_netdev_flow" from + * reading bad data due to changes by some thread concurrently modifying + * those members. + * + * - Prevent two threads making changes to members of a given "struct + * dp_netdev_flow" from interfering with each other. + * + * + * Rules + * ----- + * + * A flow 'flow' may be accessed without a risk of being freed during an RCU + * grace period. Code that needs to hold onto a flow for a while + * should try incrementing 'flow->ref_cnt' with dp_netdev_flow_ref(). + * + * 'flow->ref_cnt' protects 'flow' from being freed. It doesn't protect the + * flow from being deleted from 'cls' and it doesn't protect members of 'flow' + * from modification. + * + * Some members, marked 'const', are immutable. Accessing other members + * requires synchronization, as noted in more detail below. + */ +struct dp_netdev_flow { + const struct flow flow; /* Unmasked flow that created this entry. */ + /* Hash table index by unmasked flow. */ + const struct cmap_node node; /* In owning dp_netdev_pmd_thread's */ + /* 'flow_table'. */ + const struct cmap_node mark_node; /* In owning flow_mark's mark_to_flow */ + const ovs_u128 ufid; /* Unique flow identifier. */ + const ovs_u128 mega_ufid; /* Unique mega flow identifier. */ + const unsigned pmd_id; /* The 'core_id' of pmd thread owning this */ + /* flow. */ + + /* Number of references. + * The classifier owns one reference. + * Any thread trying to keep a rule from being freed should hold its own + * reference. */ + struct ovs_refcount ref_cnt; + + bool dead; + uint32_t mark; /* Unique flow mark assigned to a flow */ + + /* Statistics. */ + struct dp_netdev_flow_stats stats; + + /* Statistics and attributes received from the netdev offload provider. */ + atomic_int netdev_flow_get_result; + struct dp_netdev_flow_stats last_stats; + struct dp_netdev_flow_attrs last_attrs; + + /* Actions. */ + OVSRCU_TYPE(struct dp_netdev_actions *) actions; + + /* While processing a group of input packets, the datapath uses the next + * member to store a pointer to the output batch for the flow. It is + * reset after the batch has been sent out (See dp_netdev_queue_batches(), + * packet_batch_per_flow_init() and packet_batch_per_flow_execute()). */ + struct packet_batch_per_flow *batch; + + /* Packet classification. */ + char *dp_extra_info; /* String to return in a flow dump/get. */ + struct dpcls_rule cr; /* In owning dp_netdev's 'cls'. */ + /* 'cr' must be the last member. */ +}; + #ifdef __cplusplus } #endif diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index c86a98870..350ec13d3 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -401,100 +401,6 @@ struct dp_netdev_port { char *rxq_affinity_list; /* Requested affinity of rx queues. */ }; -/* Contained by struct dp_netdev_flow's 'stats' member. */ -struct dp_netdev_flow_stats { - atomic_llong used; /* Last used time, in monotonic msecs. */ - atomic_ullong packet_count; /* Number of packets matched. */ - atomic_ullong byte_count; /* Number of bytes matched. */ - atomic_uint16_t tcp_flags; /* Bitwise-OR of seen tcp_flags values. */ -}; - -/* Contained by struct dp_netdev_flow's 'last_attrs' member. */ -struct dp_netdev_flow_attrs { - atomic_bool offloaded; /* True if flow is offloaded to HW. */ - ATOMIC(const char *) dp_layer; /* DP layer the flow is handled in. */ -}; - -/* A flow in 'dp_netdev_pmd_thread's 'flow_table'. - * - * - * Thread-safety - * ============= - * - * Except near the beginning or ending of its lifespan, rule 'rule' belongs to - * its pmd thread's classifier. The text below calls this classifier 'cls'. - * - * Motivation - * ---------- - * - * The thread safety rules described here for "struct dp_netdev_flow" are - * motivated by two goals: - * - * - Prevent threads that read members of "struct dp_netdev_flow" from - * reading bad data due to changes by some thread concurrently modifying - * those members. - * - * - Prevent two threads making changes to members of a given "struct - * dp_netdev_flow" from interfering with each other. - * - * - * Rules - * ----- - * - * A flow 'flow' may be accessed without a risk of being freed during an RCU - * grace period. Code that needs to hold onto a flow for a while - * should try incrementing 'flow->ref_cnt' with dp_netdev_flow_ref(). - * - * 'flow->ref_cnt' protects 'flow' from being freed. It doesn't protect the - * flow from being deleted from 'cls' and it doesn't protect members of 'flow' - * from modification. - * - * Some members, marked 'const', are immutable. Accessing other members - * requires synchronization, as noted in more detail below. - */ -struct dp_netdev_flow { - const struct flow flow; /* Unmasked flow that created this entry. */ - /* Hash table index by unmasked flow. */ - const struct cmap_node node; /* In owning dp_netdev_pmd_thread's */ - /* 'flow_table'. */ - const struct cmap_node mark_node; /* In owning flow_mark's mark_to_flow */ - const ovs_u128 ufid; /* Unique flow identifier. */ - const ovs_u128 mega_ufid; /* Unique mega flow identifier. */ - const unsigned pmd_id; /* The 'core_id' of pmd thread owning this */ - /* flow. */ - - /* Number of references. - * The classifier owns one reference. - * Any thread trying to keep a rule from being freed should hold its own - * reference. */ - struct ovs_refcount ref_cnt; - - bool dead; - uint32_t mark; /* Unique flow mark assigned to a flow */ - - /* Statistics. */ - struct dp_netdev_flow_stats stats; - - /* Statistics and attributes received from the netdev offload provider. */ - atomic_int netdev_flow_get_result; - struct dp_netdev_flow_stats last_stats; - struct dp_netdev_flow_attrs last_attrs; - - /* Actions. */ - OVSRCU_TYPE(struct dp_netdev_actions *) actions; - - /* While processing a group of input packets, the datapath uses the next - * member to store a pointer to the output batch for the flow. It is - * reset after the batch has been sent out (See dp_netdev_queue_batches(), - * packet_batch_per_flow_init() and packet_batch_per_flow_execute()). */ - struct packet_batch_per_flow *batch; - - /* Packet classification. */ - char *dp_extra_info; /* String to return in a flow dump/get. */ - struct dpcls_rule cr; /* In owning dp_netdev's 'cls'. */ - /* 'cr' must be the last member. */ -}; - static void dp_netdev_flow_unref(struct dp_netdev_flow *); static bool dp_netdev_flow_ref(struct dp_netdev_flow *); static int dpif_netdev_flow_from_nlattrs(const struct nlattr *, uint32_t, From patchwork Tue Oct 6 14:54:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 1377482 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.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C5LBD42rcz9sSG for ; Wed, 7 Oct 2020 01:55:48 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 822C0207EF; Tue, 6 Oct 2020 14:55:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id D5ImS2HyWwyz; Tue, 6 Oct 2020 14:55:01 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 5467F214EC; Tue, 6 Oct 2020 14:53:58 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3DC81C07FF; Tue, 6 Oct 2020 14:53:58 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 731BFC1AD6 for ; Tue, 6 Oct 2020 14:53:56 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 426BC85C4B for ; Tue, 6 Oct 2020 14:53:56 +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 QF1KzEUZdaAj for ; Tue, 6 Oct 2020 14:53:47 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by fraxinus.osuosl.org (Postfix) with ESMTPS id DD47885C08 for ; Tue, 6 Oct 2020 14:53:43 +0000 (UTC) IronPort-SDR: RXzNkyGCHKknwpQNN5i6uIj6eNCbe9rp8GsH5WSwbAzWNQ0HlgIj74gDwv5yNzSz+B8vy+vIKI yO1nYD5/NVoA== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="249228259" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="249228259" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 07:53:19 -0700 IronPort-SDR: 4RlsD5VvATwkIbzID1hywKrae439aYuVcYWzvxNnotf1kiSDLwoFLn3ReR8TumqiNYph6kAnU2 toAa6IQb1qLg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="311246839" Received: from silpixa00399779.ir.intel.com (HELO silpixa00399779.ger.corp.intel.com) ([10.237.222.209]) by orsmga003.jf.intel.com with ESMTP; 06 Oct 2020 07:53:17 -0700 From: Harry van Haaren To: ovs-dev@openvswitch.org Date: Tue, 6 Oct 2020 15:54:33 +0100 Message-Id: <20201006145437.35124-5-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006145437.35124-1-harry.van.haaren@intel.com> References: <20201006145437.35124-1-harry.van.haaren@intel.com> Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 4/8] dpif-netdev: refactor to multiple header files 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" Split the very large file dpif-netdev.c and the datastructures it contains into multiple header files. Each header file is responsible for the datastructures of that component. This logical split allows better reuse and modularity of the code, and reduces the very large file dpif-netdev.c to be more managable. Due to dependencies between components, it is not possible to move each component in an individual patch. Signed-off-by: Harry van Haaren --- To explain the dependencies better, eg: DPCLS has no deps (from dpif-netdev.c file) FLOW depends on DPCLS (struct dpcls_rule) DFC depends on DPCLS (netdev_flow_key) and FLOW (netdev_flow_key) THREAD depends on DFC (struct dfc_cache) DFC_PROC depends on THREAD (struct pmd_thread) DPCLS lookup.h/c require only DPCLS DPCLS implementations require only dpif-netdev-lookup.h. - This change was made in 2.12 release with function pointers - This commit only refactors the name to "private-dpcls.h" --- lib/automake.mk | 4 + lib/dpif-netdev-lookup-autovalidator.c | 1 - lib/dpif-netdev-lookup-avx512-gather.c | 1 - lib/dpif-netdev-lookup-generic.c | 1 - lib/dpif-netdev-lookup.h | 2 +- lib/dpif-netdev-private-dfc.h | 3 +- lib/dpif-netdev-private-dpcls.h | 113 ++++++++++++++ lib/dpif-netdev-private-flow.h | 131 ++++++++++++++++ lib/dpif-netdev-private-thread.h | 206 +++++++++++++++++++++++++ lib/dpif-netdev-private.h | 196 ++--------------------- lib/dpif-netdev.c | 167 +------------------- 11 files changed, 469 insertions(+), 356 deletions(-) create mode 100644 lib/dpif-netdev-private-dpcls.h create mode 100644 lib/dpif-netdev-private-flow.h create mode 100644 lib/dpif-netdev-private-thread.h diff --git a/lib/automake.mk b/lib/automake.mk index 9b0cdeb54..8ed9878b1 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -112,6 +112,10 @@ lib_libopenvswitch_la_SOURCES = \ lib/dpif-netdev.c \ lib/dpif-netdev.h \ lib/dpif-netdev-private-dfc.h \ + lib/dpif-netdev-private-dpcls.h \ + lib/dpif-netdev-private-flow.h \ + lib/dpif-netdev-private-thread.h \ + lib/dpif-netdev-private-dfc.h \ lib/dpif-netdev-private.h \ lib/dpif-netdev-perf.c \ lib/dpif-netdev-perf.h \ diff --git a/lib/dpif-netdev-lookup-autovalidator.c b/lib/dpif-netdev-lookup-autovalidator.c index 97b59fdd0..475e1ab1e 100644 --- a/lib/dpif-netdev-lookup-autovalidator.c +++ b/lib/dpif-netdev-lookup-autovalidator.c @@ -17,7 +17,6 @@ #include #include "dpif-netdev.h" #include "dpif-netdev-lookup.h" -#include "dpif-netdev-private.h" #include "openvswitch/vlog.h" VLOG_DEFINE_THIS_MODULE(dpif_lookup_autovalidator); diff --git a/lib/dpif-netdev-lookup-avx512-gather.c b/lib/dpif-netdev-lookup-avx512-gather.c index 12a01a34a..b9047d11d 100644 --- a/lib/dpif-netdev-lookup-avx512-gather.c +++ b/lib/dpif-netdev-lookup-avx512-gather.c @@ -21,7 +21,6 @@ #include "dpif-netdev.h" #include "dpif-netdev-lookup.h" -#include "dpif-netdev-private.h" #include "cmap.h" #include "flow.h" #include "pvector.h" diff --git a/lib/dpif-netdev-lookup-generic.c b/lib/dpif-netdev-lookup-generic.c index b1a0cfc36..e3b6be4b6 100644 --- a/lib/dpif-netdev-lookup-generic.c +++ b/lib/dpif-netdev-lookup-generic.c @@ -17,7 +17,6 @@ #include #include "dpif-netdev.h" -#include "dpif-netdev-private.h" #include "dpif-netdev-lookup.h" #include "bitmap.h" diff --git a/lib/dpif-netdev-lookup.h b/lib/dpif-netdev-lookup.h index bd72aa29b..59f51faa0 100644 --- a/lib/dpif-netdev-lookup.h +++ b/lib/dpif-netdev-lookup.h @@ -19,7 +19,7 @@ #include #include "dpif-netdev.h" -#include "dpif-netdev-private.h" +#include "dpif-netdev-private-dpcls.h" /* Function to perform a probe for the subtable bit fingerprint. * Returns NULL if not valid, or a valid function pointer to call for this diff --git a/lib/dpif-netdev-private-dfc.h b/lib/dpif-netdev-private-dfc.h index f3c1aa338..6f618c39f 100644 --- a/lib/dpif-netdev-private-dfc.h +++ b/lib/dpif-netdev-private-dfc.h @@ -22,7 +22,8 @@ #include #include "dpif.h" -#include "cmap.h" +#include "dpif-netdev-private-dpcls.h" +#include "dpif-netdev-private-flow.h" #ifdef __cplusplus extern "C" { diff --git a/lib/dpif-netdev-private-dpcls.h b/lib/dpif-netdev-private-dpcls.h new file mode 100644 index 000000000..e4cac9ba5 --- /dev/null +++ b/lib/dpif-netdev-private-dpcls.h @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc. + * Copyright (c) 2019, 2020 Intel Corperation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DPIF_NETDEV_PRIVATE_DPCLS_H +#define DPIF_NETDEV_PRIVATE_DPCLS_H 1 + +#include +#include + +#include "dpif.h" +#include "cmap.h" +#include "openvswitch/thread.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Forward declaration for lookup_func typedef. */ +struct dpcls_subtable; +struct dpcls_rule; + +/* Must be public as it is instantiated in subtable struct below. */ +struct netdev_flow_key { + uint32_t hash; /* Hash function differs for different users. */ + uint32_t len; /* Length of the following miniflow (incl. map). */ + struct miniflow mf; + uint64_t buf[FLOW_MAX_PACKET_U64S]; +}; + +/* A rule to be inserted to the classifier. */ +struct dpcls_rule { + struct cmap_node cmap_node; /* Within struct dpcls_subtable 'rules'. */ + struct netdev_flow_key *mask; /* Subtable's mask. */ + struct netdev_flow_key flow; /* Matching key. */ + /* 'flow' must be the last field, additional space is allocated here. */ +}; + +/* Lookup function for a subtable in the dpcls. This function is called + * by each subtable with an array of packets, and a bitmask of packets to + * perform the lookup on. Using a function pointer gives flexibility to + * optimize the lookup function based on subtable properties and the + * CPU instruction set available at runtime. + */ +typedef +uint32_t (*dpcls_subtable_lookup_func)(struct dpcls_subtable *subtable, + uint32_t keys_map, + const struct netdev_flow_key *keys[], + struct dpcls_rule **rules); + +/* A set of rules that all have the same fields wildcarded. */ +struct dpcls_subtable { + /* The fields are only used by writers. */ + struct cmap_node cmap_node OVS_GUARDED; /* Within dpcls 'subtables_map'. */ + + /* These fields are accessed by readers. */ + struct cmap rules; /* Contains "struct dpcls_rule"s. */ + uint32_t hit_cnt; /* Number of match hits in subtable in current + optimization interval. */ + + /* Miniflow fingerprint that the subtable matches on. The miniflow "bits" + * are used to select the actual dpcls lookup implementation at subtable + * creation time. + */ + uint8_t mf_bits_set_unit0; + uint8_t mf_bits_set_unit1; + + /* The lookup function to use for this subtable. If there is a known + * property of the subtable (eg: only 3 bits of miniflow metadata is + * used for the lookup) then this can point at an optimized version of + * the lookup function for this particular subtable. */ + dpcls_subtable_lookup_func lookup_func; + + /* Caches the masks to match a packet to, reducing runtime calculations. */ + uint64_t *mf_masks; + + struct netdev_flow_key mask; /* Wildcards for fields (const). */ + /* 'mask' must be the last field, additional space is allocated here. */ +}; + +/* Iterate through netdev_flow_key TNL u64 values specified by 'FLOWMAP'. */ +#define NETDEV_FLOW_KEY_FOR_EACH_IN_FLOWMAP(VALUE, KEY, FLOWMAP) \ + MINIFLOW_FOR_EACH_IN_FLOWMAP (VALUE, &(KEY)->mf, FLOWMAP) + +/* Generates a mask for each bit set in the subtable's miniflow. */ +void +netdev_flow_key_gen_masks(const struct netdev_flow_key *tbl, + uint64_t *mf_masks, + const uint32_t mf_bits_u0, + const uint32_t mf_bits_u1); + +/* Matches a dpcls rule against the incoming packet in 'target' */ +bool dpcls_rule_matches_key(const struct dpcls_rule *rule, + const struct netdev_flow_key *target); + +#ifdef __cplusplus +} +#endif + +#endif /* dpif-netdev-private-dpcls.h */ diff --git a/lib/dpif-netdev-private-flow.h b/lib/dpif-netdev-private-flow.h new file mode 100644 index 000000000..6ba3a3234 --- /dev/null +++ b/lib/dpif-netdev-private-flow.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc. + * Copyright (c) 2019, 2020 Intel Corperation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DPIF_NETDEV_PRIVATE_FLOW_H +#define DPIF_NETDEV_PRIVATE_FLOW_H 1 + +#include +#include + +#include "dpif.h" +#include "dpif-netdev-private-dpcls.h" +#include "cmap.h" +#include "openvswitch/thread.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Contained by struct dp_netdev_flow's 'stats' member. */ +struct dp_netdev_flow_stats { + atomic_llong used; /* Last used time, in monotonic msecs. */ + atomic_ullong packet_count; /* Number of packets matched. */ + atomic_ullong byte_count; /* Number of bytes matched. */ + atomic_uint16_t tcp_flags; /* Bitwise-OR of seen tcp_flags values. */ +}; + +/* Contained by struct dp_netdev_flow's 'last_attrs' member. */ +struct dp_netdev_flow_attrs { + atomic_bool offloaded; /* True if flow is offloaded to HW. */ + ATOMIC(const char *) dp_layer; /* DP layer the flow is handled in. */ +}; + +/* A flow in 'dp_netdev_pmd_thread's 'flow_table'. + * + * + * Thread-safety + * ============= + * + * Except near the beginning or ending of its lifespan, rule 'rule' belongs to + * its pmd thread's classifier. The text below calls this classifier 'cls'. + * + * Motivation + * ---------- + * + * The thread safety rules described here for "struct dp_netdev_flow" are + * motivated by two goals: + * + * - Prevent threads that read members of "struct dp_netdev_flow" from + * reading bad data due to changes by some thread concurrently modifying + * those members. + * + * - Prevent two threads making changes to members of a given "struct + * dp_netdev_flow" from interfering with each other. + * + * + * Rules + * ----- + * + * A flow 'flow' may be accessed without a risk of being freed during an RCU + * grace period. Code that needs to hold onto a flow for a while + * should try incrementing 'flow->ref_cnt' with dp_netdev_flow_ref(). + * + * 'flow->ref_cnt' protects 'flow' from being freed. It doesn't protect the + * flow from being deleted from 'cls' and it doesn't protect members of 'flow' + * from modification. + * + * Some members, marked 'const', are immutable. Accessing other members + * requires synchronization, as noted in more detail below. + */ +struct dp_netdev_flow { + const struct flow flow; /* Unmasked flow that created this entry. */ + /* Hash table index by unmasked flow. */ + const struct cmap_node node; /* In owning dp_netdev_pmd_thread's */ + /* 'flow_table'. */ + const struct cmap_node mark_node; /* In owning flow_mark's mark_to_flow */ + const ovs_u128 ufid; /* Unique flow identifier. */ + const ovs_u128 mega_ufid; /* Unique mega flow identifier. */ + const unsigned pmd_id; /* The 'core_id' of pmd thread owning this */ + /* flow. */ + + /* Number of references. + * The classifier owns one reference. + * Any thread trying to keep a rule from being freed should hold its own + * reference. */ + struct ovs_refcount ref_cnt; + + bool dead; + uint32_t mark; /* Unique flow mark assigned to a flow */ + + /* Statistics. */ + struct dp_netdev_flow_stats stats; + + /* Statistics and attributes received from the netdev offload provider. */ + atomic_int netdev_flow_get_result; + struct dp_netdev_flow_stats last_stats; + struct dp_netdev_flow_attrs last_attrs; + + /* Actions. */ + OVSRCU_TYPE(struct dp_netdev_actions *) actions; + + /* While processing a group of input packets, the datapath uses the next + * member to store a pointer to the output batch for the flow. It is + * reset after the batch has been sent out (See dp_netdev_queue_batches(), + * packet_batch_per_flow_init() and packet_batch_per_flow_execute()). */ + struct packet_batch_per_flow *batch; + + /* Packet classification. */ + char *dp_extra_info; /* String to return in a flow dump/get. */ + struct dpcls_rule cr; /* In owning dp_netdev's 'cls'. */ + /* 'cr' must be the last member. */ +}; + +#ifdef __cplusplus +} +#endif + +#endif /* dpif-netdev-private-flow.h */ diff --git a/lib/dpif-netdev-private-thread.h b/lib/dpif-netdev-private-thread.h new file mode 100644 index 000000000..6d320678d --- /dev/null +++ b/lib/dpif-netdev-private-thread.h @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2015 Nicira, Inc. + * Copyright (c) 2019, 2020 Intel Corperation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DPIF_NETDEV_PRIVATE_THREAD_H +#define DPIF_NETDEV_PRIVATE_THREAD_H 1 + +#include +#include + +#include "dpif.h" +#include "cmap.h" + +#include "dpif-netdev-private-dfc.h" +#include "dpif-netdev-perf.h" +#include "openvswitch/thread.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* PMD Thread Structures */ + +/* A set of properties for the current processing loop that is not directly + * associated with the pmd thread itself, but with the packets being + * processed or the short-term system configuration (for example, time). + * Contained by struct dp_netdev_pmd_thread's 'ctx' member. */ +struct dp_netdev_pmd_thread_ctx { + /* Latest measured time. See 'pmd_thread_ctx_time_update()'. */ + long long now; + /* RX queue from which last packet was received. */ + struct dp_netdev_rxq *last_rxq; + /* EMC insertion probability context for the current processing cycle. */ + uint32_t emc_insert_min; +}; + +/* PMD: Poll modes drivers. PMD accesses devices via polling to eliminate + * the performance overhead of interrupt processing. Therefore netdev can + * not implement rx-wait for these devices. dpif-netdev needs to poll + * these device to check for recv buffer. pmd-thread does polling for + * devices assigned to itself. + * + * DPDK used PMD for accessing NIC. + * + * Note, instance with cpu core id NON_PMD_CORE_ID will be reserved for + * I/O of all non-pmd threads. There will be no actual thread created + * for the instance. + * + * Each struct has its own flow cache and classifier per managed ingress port. + * For packets received on ingress port, a look up is done on corresponding PMD + * thread's flow cache and in case of a miss, lookup is performed in the + * corresponding classifier of port. Packets are executed with the found + * actions in either case. + * */ +struct dp_netdev_pmd_thread { + struct dp_netdev *dp; + struct ovs_refcount ref_cnt; /* Every reference must be refcount'ed. */ + struct cmap_node node; /* In 'dp->poll_threads'. */ + + /* Per thread exact-match cache. Note, the instance for cpu core + * NON_PMD_CORE_ID can be accessed by multiple threads, and thusly + * need to be protected by 'non_pmd_mutex'. Every other instance + * will only be accessed by its own pmd thread. */ + OVS_ALIGNED_VAR(CACHE_LINE_SIZE) struct dfc_cache flow_cache; + + /* Flow-Table and classifiers + * + * Writers of 'flow_table' must take the 'flow_mutex'. Corresponding + * changes to 'classifiers' must be made while still holding the + * 'flow_mutex'. + */ + struct ovs_mutex flow_mutex; + struct cmap flow_table OVS_GUARDED; /* Flow table. */ + + /* One classifier per in_port polled by the pmd */ + struct cmap classifiers; + /* Periodically sort subtable vectors according to hit frequencies */ + long long int next_optimization; + /* End of the next time interval for which processing cycles + are stored for each polled rxq. */ + long long int rxq_next_cycle_store; + + /* Last interval timestamp. */ + uint64_t intrvl_tsc_prev; + /* Last interval cycles. */ + atomic_ullong intrvl_cycles; + + /* Current context of the PMD thread. */ + struct dp_netdev_pmd_thread_ctx ctx; + + struct seq *reload_seq; + uint64_t last_reload_seq; + + /* These are atomic variables used as a synchronization and configuration + * points for thread reload/exit. + * + * 'reload' atomic is the main one and it's used as a memory + * synchronization point for all other knobs and data. + * + * For a thread that requests PMD reload: + * + * * All changes that should be visible to the PMD thread must be made + * before setting the 'reload'. These changes could use any memory + * ordering model including 'relaxed'. + * * Setting the 'reload' atomic should occur in the same thread where + * all other PMD configuration options updated. + * * Setting the 'reload' atomic should be done with 'release' memory + * ordering model or stricter. This will guarantee that all previous + * changes (including non-atomic and 'relaxed') will be visible to + * the PMD thread. + * * To check that reload is done, thread should poll the 'reload' atomic + * to become 'false'. Polling should be done with 'acquire' memory + * ordering model or stricter. This ensures that PMD thread completed + * the reload process. + * + * For the PMD thread: + * + * * PMD thread should read 'reload' atomic with 'acquire' memory + * ordering model or stricter. This will guarantee that all changes + * made before setting the 'reload' in the requesting thread will be + * visible to the PMD thread. + * * All other configuration data could be read with any memory + * ordering model (including non-atomic and 'relaxed') but *only after* + * reading the 'reload' atomic set to 'true'. + * * When the PMD reload done, PMD should (optionally) set all the below + * knobs except the 'reload' to their default ('false') values and + * (mandatory), as the last step, set the 'reload' to 'false' using + * 'release' memory ordering model or stricter. This will inform the + * requesting thread that PMD has completed a reload cycle. + */ + atomic_bool reload; /* Do we need to reload ports? */ + atomic_bool wait_for_reload; /* Can we busy wait for the next reload? */ + atomic_bool reload_tx_qid; /* Do we need to reload static_tx_qid? */ + atomic_bool exit; /* For terminating the pmd thread. */ + + pthread_t thread; + unsigned core_id; /* CPU core id of this pmd thread. */ + int numa_id; /* numa node id of this pmd thread. */ + bool isolated; + + /* Queue id used by this pmd thread to send packets on all netdevs if + * XPS disabled for this netdev. All static_tx_qid's are unique and less + * than 'cmap_count(dp->poll_threads)'. */ + uint32_t static_tx_qid; + + /* Number of filled output batches. */ + int n_output_batches; + + struct ovs_mutex port_mutex; /* Mutex for 'poll_list' and 'tx_ports'. */ + /* List of rx queues to poll. */ + struct hmap poll_list OVS_GUARDED; + /* Map of 'tx_port's used for transmission. Written by the main thread, + * read by the pmd thread. */ + struct hmap tx_ports OVS_GUARDED; + + struct ovs_mutex bond_mutex; /* Protects updates of 'tx_bonds'. */ + /* Map of 'tx_bond's used for transmission. Written by the main thread + * and read by the pmd thread. */ + struct cmap tx_bonds; + + /* These are thread-local copies of 'tx_ports'. One contains only tunnel + * ports (that support push_tunnel/pop_tunnel), the other contains ports + * with at least one txq (that support send). A port can be in both. + * + * There are two separate maps to make sure that we don't try to execute + * OUTPUT on a device which has 0 txqs or PUSH/POP on a non-tunnel device. + * + * The instances for cpu core NON_PMD_CORE_ID can be accessed by multiple + * threads, and thusly need to be protected by 'non_pmd_mutex'. Every + * other instance will only be accessed by its own pmd thread. */ + struct hmap tnl_port_cache; + struct hmap send_port_cache; + + /* Keep track of detailed PMD performance statistics. */ + struct pmd_perf_stats perf_stats; + + /* Stats from previous iteration used by automatic pmd + * load balance logic. */ + uint64_t prev_stats[PMD_N_STATS]; + atomic_count pmd_overloaded; + + /* Set to true if the pmd thread needs to be reloaded. */ + bool need_reload; + + /* Next time when PMD should try RCU quiescing. */ + long long next_rcu_quiesce; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* dpif-netdev-private-thread.h */ diff --git a/lib/dpif-netdev-private.h b/lib/dpif-netdev-private.h index db6d11f70..b5cdcd733 100644 --- a/lib/dpif-netdev-private.h +++ b/lib/dpif-netdev-private.h @@ -18,191 +18,17 @@ #ifndef DPIF_NETDEV_PRIVATE_H #define DPIF_NETDEV_PRIVATE_H 1 -#include -#include - -#include "dpif.h" -#include "cmap.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* Forward declaration for lookup_func typedef. */ -struct dpcls_subtable; -struct dpcls_rule; - -/* Must be public as it is instantiated in subtable struct below. */ -struct netdev_flow_key { - uint32_t hash; /* Hash function differs for different users. */ - uint32_t len; /* Length of the following miniflow (incl. map). */ - struct miniflow mf; - uint64_t buf[FLOW_MAX_PACKET_U64S]; -}; - -/* A rule to be inserted to the classifier. */ -struct dpcls_rule { - struct cmap_node cmap_node; /* Within struct dpcls_subtable 'rules'. */ - struct netdev_flow_key *mask; /* Subtable's mask. */ - struct netdev_flow_key flow; /* Matching key. */ - /* 'flow' must be the last field, additional space is allocated here. */ -}; - -/* Lookup function for a subtable in the dpcls. This function is called - * by each subtable with an array of packets, and a bitmask of packets to - * perform the lookup on. Using a function pointer gives flexibility to - * optimize the lookup function based on subtable properties and the - * CPU instruction set available at runtime. - */ -typedef -uint32_t (*dpcls_subtable_lookup_func)(struct dpcls_subtable *subtable, - uint32_t keys_map, - const struct netdev_flow_key *keys[], - struct dpcls_rule **rules); - -/* A set of rules that all have the same fields wildcarded. */ -struct dpcls_subtable { - /* The fields are only used by writers. */ - struct cmap_node cmap_node OVS_GUARDED; /* Within dpcls 'subtables_map'. */ - - /* These fields are accessed by readers. */ - struct cmap rules; /* Contains "struct dpcls_rule"s. */ - uint32_t hit_cnt; /* Number of match hits in subtable in current - optimization interval. */ - - /* Miniflow fingerprint that the subtable matches on. The miniflow "bits" - * are used to select the actual dpcls lookup implementation at subtable - * creation time. - */ - uint8_t mf_bits_set_unit0; - uint8_t mf_bits_set_unit1; - - /* The lookup function to use for this subtable. If there is a known - * property of the subtable (eg: only 3 bits of miniflow metadata is - * used for the lookup) then this can point at an optimized version of - * the lookup function for this particular subtable. */ - dpcls_subtable_lookup_func lookup_func; - - /* Caches the masks to match a packet to, reducing runtime calculations. */ - uint64_t *mf_masks; - - struct netdev_flow_key mask; /* Wildcards for fields (const). */ - /* 'mask' must be the last field, additional space is allocated here. */ -}; - -/* Iterate through netdev_flow_key TNL u64 values specified by 'FLOWMAP'. */ -#define NETDEV_FLOW_KEY_FOR_EACH_IN_FLOWMAP(VALUE, KEY, FLOWMAP) \ - MINIFLOW_FOR_EACH_IN_FLOWMAP (VALUE, &(KEY)->mf, FLOWMAP) - -/* Generates a mask for each bit set in the subtable's miniflow. */ -void -netdev_flow_key_gen_masks(const struct netdev_flow_key *tbl, - uint64_t *mf_masks, - const uint32_t mf_bits_u0, - const uint32_t mf_bits_u1); - -/* Matches a dpcls rule against the incoming packet in 'target' */ -bool dpcls_rule_matches_key(const struct dpcls_rule *rule, - const struct netdev_flow_key *target); - - - -/* Contained by struct dp_netdev_flow's 'stats' member. */ -struct dp_netdev_flow_stats { - atomic_llong used; /* Last used time, in monotonic msecs. */ - atomic_ullong packet_count; /* Number of packets matched. */ - atomic_ullong byte_count; /* Number of bytes matched. */ - atomic_uint16_t tcp_flags; /* Bitwise-OR of seen tcp_flags values. */ -}; - -/* Contained by struct dp_netdev_flow's 'last_attrs' member. */ -struct dp_netdev_flow_attrs { - atomic_bool offloaded; /* True if flow is offloaded to HW. */ - ATOMIC(const char *) dp_layer; /* DP layer the flow is handled in. */ -}; - -/* A flow in 'dp_netdev_pmd_thread's 'flow_table'. - * - * - * Thread-safety - * ============= - * - * Except near the beginning or ending of its lifespan, rule 'rule' belongs to - * its pmd thread's classifier. The text below calls this classifier 'cls'. - * - * Motivation - * ---------- - * - * The thread safety rules described here for "struct dp_netdev_flow" are - * motivated by two goals: - * - * - Prevent threads that read members of "struct dp_netdev_flow" from - * reading bad data due to changes by some thread concurrently modifying - * those members. - * - * - Prevent two threads making changes to members of a given "struct - * dp_netdev_flow" from interfering with each other. - * - * - * Rules - * ----- - * - * A flow 'flow' may be accessed without a risk of being freed during an RCU - * grace period. Code that needs to hold onto a flow for a while - * should try incrementing 'flow->ref_cnt' with dp_netdev_flow_ref(). - * - * 'flow->ref_cnt' protects 'flow' from being freed. It doesn't protect the - * flow from being deleted from 'cls' and it doesn't protect members of 'flow' - * from modification. - * - * Some members, marked 'const', are immutable. Accessing other members - * requires synchronization, as noted in more detail below. +/* This header includes the various dpif-netdev components' header + * files in the appropriate order. Unfortunately there is a strict + * requirement in the include order due to dependences between components. + * E.g: + * DFC/EMC/SMC requires the netdev_flow_key struct + * PMD thread requires DFC_flow struct + * */ -struct dp_netdev_flow { - const struct flow flow; /* Unmasked flow that created this entry. */ - /* Hash table index by unmasked flow. */ - const struct cmap_node node; /* In owning dp_netdev_pmd_thread's */ - /* 'flow_table'. */ - const struct cmap_node mark_node; /* In owning flow_mark's mark_to_flow */ - const ovs_u128 ufid; /* Unique flow identifier. */ - const ovs_u128 mega_ufid; /* Unique mega flow identifier. */ - const unsigned pmd_id; /* The 'core_id' of pmd thread owning this */ - /* flow. */ - - /* Number of references. - * The classifier owns one reference. - * Any thread trying to keep a rule from being freed should hold its own - * reference. */ - struct ovs_refcount ref_cnt; - - bool dead; - uint32_t mark; /* Unique flow mark assigned to a flow */ - - /* Statistics. */ - struct dp_netdev_flow_stats stats; - - /* Statistics and attributes received from the netdev offload provider. */ - atomic_int netdev_flow_get_result; - struct dp_netdev_flow_stats last_stats; - struct dp_netdev_flow_attrs last_attrs; - - /* Actions. */ - OVSRCU_TYPE(struct dp_netdev_actions *) actions; - - /* While processing a group of input packets, the datapath uses the next - * member to store a pointer to the output batch for the flow. It is - * reset after the batch has been sent out (See dp_netdev_queue_batches(), - * packet_batch_per_flow_init() and packet_batch_per_flow_execute()). */ - struct packet_batch_per_flow *batch; - - /* Packet classification. */ - char *dp_extra_info; /* String to return in a flow dump/get. */ - struct dpcls_rule cr; /* In owning dp_netdev's 'cls'. */ - /* 'cr' must be the last member. */ -}; - -#ifdef __cplusplus -} -#endif +#include "dpif-netdev-private-flow.h" +#include "dpif-netdev-private-dpcls.h" +#include "dpif-netdev-private-dfc.h" +#include "dpif-netdev-private-thread.h" #endif /* netdev-private.h */ diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 350ec13d3..5e222f08c 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -17,6 +17,7 @@ #include #include "dpif-netdev.h" #include "dpif-netdev-private.h" +#include "dpif-netdev-private-dfc.h" #include #include @@ -44,7 +45,6 @@ #include "dpif.h" #include "dpif-netdev-lookup.h" #include "dpif-netdev-perf.h" -#include "dpif-netdev-private-dfc.h" #include "dpif-provider.h" #include "dummy.h" #include "fat-rwlock.h" @@ -466,171 +466,6 @@ struct tx_bond { struct slave_entry slave_buckets[BOND_BUCKETS]; }; -/* A set of properties for the current processing loop that is not directly - * associated with the pmd thread itself, but with the packets being - * processed or the short-term system configuration (for example, time). - * Contained by struct dp_netdev_pmd_thread's 'ctx' member. */ -struct dp_netdev_pmd_thread_ctx { - /* Latest measured time. See 'pmd_thread_ctx_time_update()'. */ - long long now; - /* RX queue from which last packet was received. */ - struct dp_netdev_rxq *last_rxq; - /* EMC insertion probability context for the current processing cycle. */ - uint32_t emc_insert_min; -}; - -/* PMD: Poll modes drivers. PMD accesses devices via polling to eliminate - * the performance overhead of interrupt processing. Therefore netdev can - * not implement rx-wait for these devices. dpif-netdev needs to poll - * these device to check for recv buffer. pmd-thread does polling for - * devices assigned to itself. - * - * DPDK used PMD for accessing NIC. - * - * Note, instance with cpu core id NON_PMD_CORE_ID will be reserved for - * I/O of all non-pmd threads. There will be no actual thread created - * for the instance. - * - * Each struct has its own flow cache and classifier per managed ingress port. - * For packets received on ingress port, a look up is done on corresponding PMD - * thread's flow cache and in case of a miss, lookup is performed in the - * corresponding classifier of port. Packets are executed with the found - * actions in either case. - * */ -struct dp_netdev_pmd_thread { - struct dp_netdev *dp; - struct ovs_refcount ref_cnt; /* Every reference must be refcount'ed. */ - struct cmap_node node; /* In 'dp->poll_threads'. */ - - /* Per thread exact-match cache. Note, the instance for cpu core - * NON_PMD_CORE_ID can be accessed by multiple threads, and thusly - * need to be protected by 'non_pmd_mutex'. Every other instance - * will only be accessed by its own pmd thread. */ - OVS_ALIGNED_VAR(CACHE_LINE_SIZE) struct dfc_cache flow_cache; - - /* Flow-Table and classifiers - * - * Writers of 'flow_table' must take the 'flow_mutex'. Corresponding - * changes to 'classifiers' must be made while still holding the - * 'flow_mutex'. - */ - struct ovs_mutex flow_mutex; - struct cmap flow_table OVS_GUARDED; /* Flow table. */ - - /* One classifier per in_port polled by the pmd */ - struct cmap classifiers; - /* Periodically sort subtable vectors according to hit frequencies */ - long long int next_optimization; - /* End of the next time interval for which processing cycles - are stored for each polled rxq. */ - long long int rxq_next_cycle_store; - - /* Last interval timestamp. */ - uint64_t intrvl_tsc_prev; - /* Last interval cycles. */ - atomic_ullong intrvl_cycles; - - /* Current context of the PMD thread. */ - struct dp_netdev_pmd_thread_ctx ctx; - - struct seq *reload_seq; - uint64_t last_reload_seq; - - /* These are atomic variables used as a synchronization and configuration - * points for thread reload/exit. - * - * 'reload' atomic is the main one and it's used as a memory - * synchronization point for all other knobs and data. - * - * For a thread that requests PMD reload: - * - * * All changes that should be visible to the PMD thread must be made - * before setting the 'reload'. These changes could use any memory - * ordering model including 'relaxed'. - * * Setting the 'reload' atomic should occur in the same thread where - * all other PMD configuration options updated. - * * Setting the 'reload' atomic should be done with 'release' memory - * ordering model or stricter. This will guarantee that all previous - * changes (including non-atomic and 'relaxed') will be visible to - * the PMD thread. - * * To check that reload is done, thread should poll the 'reload' atomic - * to become 'false'. Polling should be done with 'acquire' memory - * ordering model or stricter. This ensures that PMD thread completed - * the reload process. - * - * For the PMD thread: - * - * * PMD thread should read 'reload' atomic with 'acquire' memory - * ordering model or stricter. This will guarantee that all changes - * made before setting the 'reload' in the requesting thread will be - * visible to the PMD thread. - * * All other configuration data could be read with any memory - * ordering model (including non-atomic and 'relaxed') but *only after* - * reading the 'reload' atomic set to 'true'. - * * When the PMD reload done, PMD should (optionally) set all the below - * knobs except the 'reload' to their default ('false') values and - * (mandatory), as the last step, set the 'reload' to 'false' using - * 'release' memory ordering model or stricter. This will inform the - * requesting thread that PMD has completed a reload cycle. - */ - atomic_bool reload; /* Do we need to reload ports? */ - atomic_bool wait_for_reload; /* Can we busy wait for the next reload? */ - atomic_bool reload_tx_qid; /* Do we need to reload static_tx_qid? */ - atomic_bool exit; /* For terminating the pmd thread. */ - - pthread_t thread; - unsigned core_id; /* CPU core id of this pmd thread. */ - int numa_id; /* numa node id of this pmd thread. */ - bool isolated; - - /* Queue id used by this pmd thread to send packets on all netdevs if - * XPS disabled for this netdev. All static_tx_qid's are unique and less - * than 'cmap_count(dp->poll_threads)'. */ - uint32_t static_tx_qid; - - /* Number of filled output batches. */ - int n_output_batches; - - struct ovs_mutex port_mutex; /* Mutex for 'poll_list' and 'tx_ports'. */ - /* List of rx queues to poll. */ - struct hmap poll_list OVS_GUARDED; - /* Map of 'tx_port's used for transmission. Written by the main thread, - * read by the pmd thread. */ - struct hmap tx_ports OVS_GUARDED; - - struct ovs_mutex bond_mutex; /* Protects updates of 'tx_bonds'. */ - /* Map of 'tx_bond's used for transmission. Written by the main thread - * and read by the pmd thread. */ - struct cmap tx_bonds; - - /* These are thread-local copies of 'tx_ports'. One contains only tunnel - * ports (that support push_tunnel/pop_tunnel), the other contains ports - * with at least one txq (that support send). A port can be in both. - * - * There are two separate maps to make sure that we don't try to execute - * OUTPUT on a device which has 0 txqs or PUSH/POP on a non-tunnel device. - * - * The instances for cpu core NON_PMD_CORE_ID can be accessed by multiple - * threads, and thusly need to be protected by 'non_pmd_mutex'. Every - * other instance will only be accessed by its own pmd thread. */ - struct hmap tnl_port_cache; - struct hmap send_port_cache; - - /* Keep track of detailed PMD performance statistics. */ - struct pmd_perf_stats perf_stats; - - /* Stats from previous iteration used by automatic pmd - * load balance logic. */ - uint64_t prev_stats[PMD_N_STATS]; - atomic_count pmd_overloaded; - - /* Set to true if the pmd thread needs to be reloaded. */ - bool need_reload; - - /* Next time when PMD should try RCU quiescing. */ - long long next_rcu_quiesce; -}; - /* Interface to netdev-based datapath. */ struct dpif_netdev { struct dpif dpif; From patchwork Tue Oct 6 14:54:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 1377479 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=fail (p=none dis=none) header.from=intel.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 4C5L892P9Pz9sSG for ; Wed, 7 Oct 2020 01:54:01 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id E2C5185A84; Tue, 6 Oct 2020 14:53:59 +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 ZZS0QsSNG9_m; Tue, 6 Oct 2020 14:53:58 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id EDC4085C28; Tue, 6 Oct 2020 14:53:54 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D9FC3C1AD6; Tue, 6 Oct 2020 14:53:54 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id F18E3C1AD8 for ; Tue, 6 Oct 2020 14:53:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id DC2E685BD1 for ; Tue, 6 Oct 2020 14:53:52 +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 hBEjJTnwXcvT for ; Tue, 6 Oct 2020 14:53:47 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 17BE085886 for ; Tue, 6 Oct 2020 14:53:44 +0000 (UTC) IronPort-SDR: N60eagQyjOBED6jW2dbO9EwEXUfoVPgC5n/ZRSMhBwUr1r1MrQuBtfOwC7K8Mpd0vf1yOIuJmg c5F+ECOYR7DQ== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="249228266" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="249228266" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 07:53:20 -0700 IronPort-SDR: tYpj9u3M+R610tWD4knqgePH/wNO1BBsbcX8oiVPTFnOlOLgDfzW7uRmxfBba/T1Qosx46Q3bO eqetCI/2BNbQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="311246848" Received: from silpixa00399779.ir.intel.com (HELO silpixa00399779.ger.corp.intel.com) ([10.237.222.209]) by orsmga003.jf.intel.com with ESMTP; 06 Oct 2020 07:53:19 -0700 From: Harry van Haaren To: ovs-dev@openvswitch.org Date: Tue, 6 Oct 2020 15:54:34 +0100 Message-Id: <20201006145437.35124-6-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006145437.35124-1-harry.van.haaren@intel.com> References: <20201006145437.35124-1-harry.van.haaren@intel.com> Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 5/8] dpif-netdev: split hwol out to own header file 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" Signed-off-by: Harry van Haaren --- lib/dpif-netdev-private-flow.h | 20 ++++++++++++ lib/dpif-netdev.c | 59 ++-------------------------------- 2 files changed, 23 insertions(+), 56 deletions(-) diff --git a/lib/dpif-netdev-private-flow.h b/lib/dpif-netdev-private-flow.h index 6ba3a3234..ce13632b8 100644 --- a/lib/dpif-netdev-private-flow.h +++ b/lib/dpif-netdev-private-flow.h @@ -124,6 +124,26 @@ struct dp_netdev_flow { /* 'cr' must be the last member. */ }; +static uint32_t +dp_netdev_flow_hash(const ovs_u128 *ufid) +{ + return ufid->u32[0]; +} + +/* A set of datapath actions within a "struct dp_netdev_flow". + * + * + * Thread-safety + * ============= + * + * A struct dp_netdev_actions 'actions' is protected with RCU. */ +struct dp_netdev_actions { + /* These members are immutable: they do not change during the struct's + * lifetime. */ + unsigned int size; /* Size of 'actions', in bytes. */ + struct nlattr actions[]; /* Sequence of OVS_ACTION_ATTR_* attributes. */ +}; + #ifdef __cplusplus } #endif diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 5e222f08c..4b1fc6a33 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -83,6 +83,8 @@ #include "util.h" #include "uuid.h" +#include "dpif-netdev-private-hwol.h" + VLOG_DEFINE_THIS_MODULE(dpif_netdev); /* Auto Load Balancing Defaults */ @@ -406,20 +408,6 @@ static bool dp_netdev_flow_ref(struct dp_netdev_flow *); static int dpif_netdev_flow_from_nlattrs(const struct nlattr *, uint32_t, struct flow *, bool); -/* A set of datapath actions within a "struct dp_netdev_flow". - * - * - * Thread-safety - * ============= - * - * A struct dp_netdev_actions 'actions' is protected with RCU. */ -struct dp_netdev_actions { - /* These members are immutable: they do not change during the struct's - * lifetime. */ - unsigned int size; /* Size of 'actions', in bytes. */ - struct nlattr actions[]; /* Sequence of OVS_ACTION_ATTR_* attributes. */ -}; - struct dp_netdev_actions *dp_netdev_actions_create(const struct nlattr *, size_t); struct dp_netdev_actions *dp_netdev_flow_get_actions( @@ -1929,12 +1917,6 @@ static void dp_netdev_flow_unref(struct dp_netdev_flow *flow) } } -static uint32_t -dp_netdev_flow_hash(const ovs_u128 *ufid) -{ - return ufid->u32[0]; -} - static inline struct dpcls * dp_netdev_pmd_lookup_dpcls(struct dp_netdev_pmd_thread *pmd, odp_port_t in_port) @@ -1969,26 +1951,8 @@ dp_netdev_pmd_find_dpcls(struct dp_netdev_pmd_thread *pmd, return cls; } -#define MAX_FLOW_MARK (UINT32_MAX - 1) -#define INVALID_FLOW_MARK 0 -/* Zero flow mark is used to indicate the HW to remove the mark. A packet - * marked with zero mark is received in SW without a mark at all, so it - * cannot be used as a valid mark. - */ - -struct megaflow_to_mark_data { - const struct cmap_node node; - ovs_u128 mega_ufid; - uint32_t mark; -}; - -struct flow_mark { - struct cmap megaflow_to_mark; - struct cmap mark_to_flow; - struct id_pool *pool; -}; -static struct flow_mark flow_mark = { +struct flow_mark flow_mark = { .megaflow_to_mark = CMAP_INITIALIZER, .mark_to_flow = CMAP_INITIALIZER, }; @@ -2157,23 +2121,6 @@ flow_mark_flush(struct dp_netdev_pmd_thread *pmd) } } -static struct dp_netdev_flow * -mark_to_flow_find(const struct dp_netdev_pmd_thread *pmd, - const uint32_t mark) -{ - struct dp_netdev_flow *flow; - - CMAP_FOR_EACH_WITH_HASH (flow, mark_node, hash_int(mark, 0), - &flow_mark.mark_to_flow) { - if (flow->mark == mark && flow->pmd_id == pmd->core_id && - flow->dead == false) { - return flow; - } - } - - return NULL; -} - static struct dp_flow_offload_item * dp_netdev_alloc_flow_offload(struct dp_netdev_pmd_thread *pmd, struct dp_netdev_flow *flow, From patchwork Tue Oct 6 14:54:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 1377478 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.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=intel.com Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C5L883kFKz9sRk for ; Wed, 7 Oct 2020 01:54:00 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 07CCB866C7; Tue, 6 Oct 2020 14:53:59 +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 skqQktWY0MGh; Tue, 6 Oct 2020 14:53:52 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 055828650E; Tue, 6 Oct 2020 14:53:52 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D686BC07FF; Tue, 6 Oct 2020 14:53:51 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5E14AC07FF for ; Tue, 6 Oct 2020 14:53:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 538B485910 for ; Tue, 6 Oct 2020 14:53:50 +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 xXH6phmteDES for ; Tue, 6 Oct 2020 14:53:47 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 444CD85B3D for ; Tue, 6 Oct 2020 14:53:44 +0000 (UTC) IronPort-SDR: KiFG24dB11RZKlOslV2+KFY+jq3m4EWkuGkmm1ZlNIoKNPSJLIP6fR/A1ElumT2AEAciNmqr+R bH9f/UVUkciA== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="249228278" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="249228278" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 07:53:22 -0700 IronPort-SDR: GVPNQDKsoXeeFRXL/sP6zMzPuoIIAXvcTv37D6VwHQenglQRMpeHpZICqOIZTC2TKkDEVLwn/A XtnAnsNKxq2w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="311246854" Received: from silpixa00399779.ir.intel.com (HELO silpixa00399779.ger.corp.intel.com) ([10.237.222.209]) by orsmga003.jf.intel.com with ESMTP; 06 Oct 2020 07:53:20 -0700 From: Harry van Haaren To: ovs-dev@openvswitch.org Date: Tue, 6 Oct 2020 15:54:35 +0100 Message-Id: <20201006145437.35124-7-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006145437.35124-1-harry.van.haaren@intel.com> References: <20201006145437.35124-1-harry.van.haaren@intel.com> Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 6/8] dpif-netdev/dpcls: refactor function names to dpcls 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" This commit refactors the function names from netdev_* namespace to the dpcls_* namespace, as they are only used by dpcls code. With the name change, it becomes more obvious that the functions belong to dpcls functionality, and in the dpif-netdev-private-dpcls.h header file. Signed-off-by: Harry van Haaren --- lib/dpif-netdev-private-dpcls.h | 6 ++---- lib/dpif-netdev.c | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/dpif-netdev-private-dpcls.h b/lib/dpif-netdev-private-dpcls.h index e4cac9ba5..e4fceaa57 100644 --- a/lib/dpif-netdev-private-dpcls.h +++ b/lib/dpif-netdev-private-dpcls.h @@ -97,10 +97,8 @@ struct dpcls_subtable { /* Generates a mask for each bit set in the subtable's miniflow. */ void -netdev_flow_key_gen_masks(const struct netdev_flow_key *tbl, - uint64_t *mf_masks, - const uint32_t mf_bits_u0, - const uint32_t mf_bits_u1); +dpcls_flow_key_gen_masks(const struct netdev_flow_key *tbl, uint64_t *mf_masks, + const uint32_t mf_bits_u0, const uint32_t mf_bits_u1); /* Matches a dpcls rule against the incoming packet in 'target' */ bool dpcls_rule_matches_key(const struct dpcls_rule *rule, diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 4b1fc6a33..4586a6aa3 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -8163,7 +8163,7 @@ dpcls_create_subtable(struct dpcls *cls, const struct netdev_flow_key *mask) subtable->mf_bits_set_unit0 = unit0; subtable->mf_bits_set_unit1 = unit1; subtable->mf_masks = xmalloc(sizeof(uint64_t) * (unit0 + unit1)); - netdev_flow_key_gen_masks(mask, subtable->mf_masks, unit0, unit1); + dpcls_flow_key_gen_masks(mask, subtable->mf_masks, unit0, unit1); /* Get the preferred subtable search function for this (u0,u1) subtable. * The function is guaranteed to always return a valid implementation, and @@ -8335,11 +8335,10 @@ dpcls_remove(struct dpcls *cls, struct dpcls_rule *rule) } } -/* Inner loop for mask generation of a unit, see netdev_flow_key_gen_masks. */ +/* Inner loop for mask generation of a unit, see dpcls_flow_key_gen_masks. */ static inline void -netdev_flow_key_gen_mask_unit(uint64_t iter, - const uint64_t count, - uint64_t *mf_masks) +dpcls_flow_key_gen_mask_unit(uint64_t iter, const uint64_t count, + uint64_t *mf_masks) { int i; for (i = 0; i < count; i++) { @@ -8360,16 +8359,16 @@ netdev_flow_key_gen_mask_unit(uint64_t iter, * @param mf_bits_unit0 Number of bits set in unit0 of the miniflow */ void -netdev_flow_key_gen_masks(const struct netdev_flow_key *tbl, - uint64_t *mf_masks, - const uint32_t mf_bits_u0, - const uint32_t mf_bits_u1) +dpcls_flow_key_gen_masks(const struct netdev_flow_key *tbl, + uint64_t *mf_masks, + const uint32_t mf_bits_u0, + const uint32_t mf_bits_u1) { uint64_t iter_u0 = tbl->mf.map.bits[0]; uint64_t iter_u1 = tbl->mf.map.bits[1]; - netdev_flow_key_gen_mask_unit(iter_u0, mf_bits_u0, &mf_masks[0]); - netdev_flow_key_gen_mask_unit(iter_u1, mf_bits_u1, &mf_masks[mf_bits_u0]); + dpcls_flow_key_gen_mask_unit(iter_u0, mf_bits_u0, &mf_masks[0]); + dpcls_flow_key_gen_mask_unit(iter_u1, mf_bits_u1, &mf_masks[mf_bits_u0]); } /* Returns true if 'target' satisfies 'key' in 'mask', that is, if each 1-bit From patchwork Tue Oct 6 14:54:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 1377480 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=fail (p=none dis=none) header.from=intel.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 4C5L896VXzz9sRk for ; Wed, 7 Oct 2020 01:54:01 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 491AE87131; Tue, 6 Oct 2020 14:54:00 +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 5OCh3SqQ02E1; Tue, 6 Oct 2020 14:53:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id 3B8A4870C3; Tue, 6 Oct 2020 14:53:56 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id EC9D1C1ADA; Tue, 6 Oct 2020 14:53:55 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 30866C1ADA for ; Tue, 6 Oct 2020 14:53:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2076285886 for ; Tue, 6 Oct 2020 14:53:53 +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 6jtKT0RBzM-q for ; Tue, 6 Oct 2020 14:53:49 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 96E1E85BCF for ; Tue, 6 Oct 2020 14:53:44 +0000 (UTC) IronPort-SDR: gFmH0JHJUuHxInOW9UhWV7bwX/nX8KrEiflxRW+rcmCUvoQPBhSuAtqyxQBhp2v8Sma1IZdMd4 Z+bRcWoqKMEQ== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="249228288" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="249228288" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 07:53:23 -0700 IronPort-SDR: aVJCd4cJHqMMRXv5JwsPPmXlYioiXln6BAJqRqktdS09aWO4RHVMXeWr9mckZBqAoO85FWy2Lt NFGbziWzioew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="311246873" Received: from silpixa00399779.ir.intel.com (HELO silpixa00399779.ger.corp.intel.com) ([10.237.222.209]) by orsmga003.jf.intel.com with ESMTP; 06 Oct 2020 07:53:22 -0700 From: Harry van Haaren To: ovs-dev@openvswitch.org Date: Tue, 6 Oct 2020 15:54:36 +0100 Message-Id: <20201006145437.35124-8-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006145437.35124-1-harry.van.haaren@intel.com> References: <20201006145437.35124-1-harry.van.haaren@intel.com> Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 7/8] dpif-netdev: move pmd_try_optimize function in file 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" This commit moves the pmd_try_optimize function to a more appropriate location in the file - currently it sits in the DPCLS section, which is not its correct home. Signed-off-by: Harry van Haaren --- lib/dpif-netdev.c | 146 +++++++++++++++++++++++----------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 4586a6aa3..cb07a7bdc 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -5585,6 +5585,79 @@ reload: return NULL; } +static inline void +dp_netdev_pmd_try_optimize(struct dp_netdev_pmd_thread *pmd, + struct polled_queue *poll_list, int poll_cnt) +{ + struct dpcls *cls; + uint64_t tot_idle = 0, tot_proc = 0; + unsigned int pmd_load = 0; + + if (pmd->ctx.now > pmd->rxq_next_cycle_store) { + uint64_t curr_tsc; + struct pmd_auto_lb *pmd_alb = &pmd->dp->pmd_alb; + if (pmd_alb->is_enabled && !pmd->isolated + && (pmd->perf_stats.counters.n[PMD_CYCLES_ITER_IDLE] >= + pmd->prev_stats[PMD_CYCLES_ITER_IDLE]) + && (pmd->perf_stats.counters.n[PMD_CYCLES_ITER_BUSY] >= + pmd->prev_stats[PMD_CYCLES_ITER_BUSY])) + { + tot_idle = pmd->perf_stats.counters.n[PMD_CYCLES_ITER_IDLE] - + pmd->prev_stats[PMD_CYCLES_ITER_IDLE]; + tot_proc = pmd->perf_stats.counters.n[PMD_CYCLES_ITER_BUSY] - + pmd->prev_stats[PMD_CYCLES_ITER_BUSY]; + + if (tot_proc) { + pmd_load = ((tot_proc * 100) / (tot_idle + tot_proc)); + } + + if (pmd_load >= ALB_PMD_LOAD_THRESHOLD) { + atomic_count_inc(&pmd->pmd_overloaded); + } else { + atomic_count_set(&pmd->pmd_overloaded, 0); + } + } + + pmd->prev_stats[PMD_CYCLES_ITER_IDLE] = + pmd->perf_stats.counters.n[PMD_CYCLES_ITER_IDLE]; + pmd->prev_stats[PMD_CYCLES_ITER_BUSY] = + pmd->perf_stats.counters.n[PMD_CYCLES_ITER_BUSY]; + + /* Get the cycles that were used to process each queue and store. */ + for (unsigned i = 0; i < poll_cnt; i++) { + uint64_t rxq_cyc_curr = dp_netdev_rxq_get_cycles(poll_list[i].rxq, + RXQ_CYCLES_PROC_CURR); + dp_netdev_rxq_set_intrvl_cycles(poll_list[i].rxq, rxq_cyc_curr); + dp_netdev_rxq_set_cycles(poll_list[i].rxq, RXQ_CYCLES_PROC_CURR, + 0); + } + curr_tsc = cycles_counter_update(&pmd->perf_stats); + if (pmd->intrvl_tsc_prev) { + /* There is a prev timestamp, store a new intrvl cycle count. */ + atomic_store_relaxed(&pmd->intrvl_cycles, + curr_tsc - pmd->intrvl_tsc_prev); + } + pmd->intrvl_tsc_prev = curr_tsc; + /* Start new measuring interval */ + pmd->rxq_next_cycle_store = pmd->ctx.now + PMD_RXQ_INTERVAL_LEN; + } + + if (pmd->ctx.now > pmd->next_optimization) { + /* Try to obtain the flow lock to block out revalidator threads. + * If not possible, just try next time. */ + if (!ovs_mutex_trylock(&pmd->flow_mutex)) { + /* Optimize each classifier */ + CMAP_FOR_EACH (cls, node, &pmd->classifiers) { + dpcls_sort_subtable_vector(cls); + } + ovs_mutex_unlock(&pmd->flow_mutex); + /* Start new measuring interval */ + pmd->next_optimization = pmd->ctx.now + + DPCLS_OPTIMIZATION_INTERVAL; + } + } +} + static void dp_netdev_disable_upcall(struct dp_netdev *dp) OVS_ACQUIRES(dp->upcall_rwlock) @@ -8232,79 +8305,6 @@ dpcls_sort_subtable_vector(struct dpcls *cls) pvector_publish(pvec); } -static inline void -dp_netdev_pmd_try_optimize(struct dp_netdev_pmd_thread *pmd, - struct polled_queue *poll_list, int poll_cnt) -{ - struct dpcls *cls; - uint64_t tot_idle = 0, tot_proc = 0; - unsigned int pmd_load = 0; - - if (pmd->ctx.now > pmd->rxq_next_cycle_store) { - uint64_t curr_tsc; - struct pmd_auto_lb *pmd_alb = &pmd->dp->pmd_alb; - if (pmd_alb->is_enabled && !pmd->isolated - && (pmd->perf_stats.counters.n[PMD_CYCLES_ITER_IDLE] >= - pmd->prev_stats[PMD_CYCLES_ITER_IDLE]) - && (pmd->perf_stats.counters.n[PMD_CYCLES_ITER_BUSY] >= - pmd->prev_stats[PMD_CYCLES_ITER_BUSY])) - { - tot_idle = pmd->perf_stats.counters.n[PMD_CYCLES_ITER_IDLE] - - pmd->prev_stats[PMD_CYCLES_ITER_IDLE]; - tot_proc = pmd->perf_stats.counters.n[PMD_CYCLES_ITER_BUSY] - - pmd->prev_stats[PMD_CYCLES_ITER_BUSY]; - - if (tot_proc) { - pmd_load = ((tot_proc * 100) / (tot_idle + tot_proc)); - } - - if (pmd_load >= ALB_PMD_LOAD_THRESHOLD) { - atomic_count_inc(&pmd->pmd_overloaded); - } else { - atomic_count_set(&pmd->pmd_overloaded, 0); - } - } - - pmd->prev_stats[PMD_CYCLES_ITER_IDLE] = - pmd->perf_stats.counters.n[PMD_CYCLES_ITER_IDLE]; - pmd->prev_stats[PMD_CYCLES_ITER_BUSY] = - pmd->perf_stats.counters.n[PMD_CYCLES_ITER_BUSY]; - - /* Get the cycles that were used to process each queue and store. */ - for (unsigned i = 0; i < poll_cnt; i++) { - uint64_t rxq_cyc_curr = dp_netdev_rxq_get_cycles(poll_list[i].rxq, - RXQ_CYCLES_PROC_CURR); - dp_netdev_rxq_set_intrvl_cycles(poll_list[i].rxq, rxq_cyc_curr); - dp_netdev_rxq_set_cycles(poll_list[i].rxq, RXQ_CYCLES_PROC_CURR, - 0); - } - curr_tsc = cycles_counter_update(&pmd->perf_stats); - if (pmd->intrvl_tsc_prev) { - /* There is a prev timestamp, store a new intrvl cycle count. */ - atomic_store_relaxed(&pmd->intrvl_cycles, - curr_tsc - pmd->intrvl_tsc_prev); - } - pmd->intrvl_tsc_prev = curr_tsc; - /* Start new measuring interval */ - pmd->rxq_next_cycle_store = pmd->ctx.now + PMD_RXQ_INTERVAL_LEN; - } - - if (pmd->ctx.now > pmd->next_optimization) { - /* Try to obtain the flow lock to block out revalidator threads. - * If not possible, just try next time. */ - if (!ovs_mutex_trylock(&pmd->flow_mutex)) { - /* Optimize each classifier */ - CMAP_FOR_EACH (cls, node, &pmd->classifiers) { - dpcls_sort_subtable_vector(cls); - } - ovs_mutex_unlock(&pmd->flow_mutex); - /* Start new measuring interval */ - pmd->next_optimization = pmd->ctx.now - + DPCLS_OPTIMIZATION_INTERVAL; - } - } -} - /* Insert 'rule' into 'cls'. */ static void dpcls_insert(struct dpcls *cls, struct dpcls_rule *rule, From patchwork Tue Oct 6 14:54:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 1377477 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=fail (p=none dis=none) header.from=intel.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 4C5L844X7rz9sSG for ; Wed, 7 Oct 2020 01:53:56 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 05D7987052; Tue, 6 Oct 2020 14:53:55 +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 So-eQzXFLQs9; Tue, 6 Oct 2020 14:53:53 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id EF9538704C; Tue, 6 Oct 2020 14:53:52 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C6676C1AD6; Tue, 6 Oct 2020 14:53:52 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id A35DDC0893 for ; Tue, 6 Oct 2020 14:53:51 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 9499485955 for ; Tue, 6 Oct 2020 14:53:51 +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 m18d0sTiCuBB for ; Tue, 6 Oct 2020 14:53:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by fraxinus.osuosl.org (Postfix) with ESMTPS id E1FB285C9D for ; Tue, 6 Oct 2020 14:53:44 +0000 (UTC) IronPort-SDR: MzGH2WtRx27tYag03Fxggw4jucP8Ylkf394Li8ZfGvjVlBcb01BkQoMq4pFS7qyS088sWkpBnt ddjBylEXJ+5g== X-IronPort-AV: E=McAfee;i="6000,8403,9765"; a="249228297" X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="249228297" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2020 07:53:24 -0700 IronPort-SDR: 6DAwC4HRcJheTJA+2Ufco/d1w2+YcEEsRKnyMYFP4gk+Z2NT929reYSrzDnk2fiyxUFGyhnCxk YINyJsqLXjpA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,343,1596524400"; d="scan'208";a="311246891" Received: from silpixa00399779.ir.intel.com (HELO silpixa00399779.ger.corp.intel.com) ([10.237.222.209]) by orsmga003.jf.intel.com with ESMTP; 06 Oct 2020 07:53:23 -0700 From: Harry van Haaren To: ovs-dev@openvswitch.org Date: Tue, 6 Oct 2020 15:54:37 +0100 Message-Id: <20201006145437.35124-9-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006145437.35124-1-harry.van.haaren@intel.com> References: <20201006145437.35124-1-harry.van.haaren@intel.com> Cc: i.maximets@ovn.org Subject: [ovs-dev] [PATCH 8/8] dpif-netdev: add function pointer for netdev input 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" This commit adds a function pointer to the pmd thread data structure, giving the pmd thread flexibility in its dpif-input function choice. This allows choosing of the implementation based on ISA capabilities of the runtime CPU, leading to optimizations and higher performance. Signed-off-by: Harry van Haaren --- lib/dpif-netdev-private-thread.h | 10 ++++++++++ lib/dpif-netdev.c | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/dpif-netdev-private-thread.h b/lib/dpif-netdev-private-thread.h index 6d320678d..89761eb51 100644 --- a/lib/dpif-netdev-private-thread.h +++ b/lib/dpif-netdev-private-thread.h @@ -47,6 +47,13 @@ struct dp_netdev_pmd_thread_ctx { uint32_t emc_insert_min; }; +/* Foward declaration for typedef */ +struct dp_netdev_pmd_thread; + +typedef void (*dp_netdev_input_func)(struct dp_netdev_pmd_thread *pmd, + struct dp_packet_batch *packets, + odp_port_t port_no); + /* PMD: Poll modes drivers. PMD accesses devices via polling to eliminate * the performance overhead of interrupt processing. Therefore netdev can * not implement rx-wait for these devices. dpif-netdev needs to poll @@ -101,6 +108,9 @@ struct dp_netdev_pmd_thread { /* Current context of the PMD thread. */ struct dp_netdev_pmd_thread_ctx ctx; + /* Function pointer to call for dp_netdev_input() functionality */ + dp_netdev_input_func netdev_input_func; + struct seq *reload_seq; uint64_t last_reload_seq; diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index cb07a7bdc..74a04ab9e 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -4228,8 +4228,9 @@ dp_netdev_process_rxq_port(struct dp_netdev_pmd_thread *pmd, } } } + /* Process packet batch. */ - dp_netdev_input(pmd, &batch, port_no); + pmd->netdev_input_func(pmd, &batch, port_no); /* Assign processing cycles to rx queue. */ cycles = cycle_timer_stop(&pmd->perf_stats, &timer); @@ -5452,6 +5453,12 @@ pmd_thread_main(void *f_) dfc_cache_init(&pmd->flow_cache); pmd_alloc_static_tx_qid(pmd); + /* set dp_netdev_input__ function pointer. This is now flexible, and can + * be modified at runtime just like DPCLS subtable lookup, allowing the + * implementation to be ISA specialized for performance. + */ + pmd->netdev_input_func = dp_netdev_input; + reload: atomic_count_init(&pmd->pmd_overloaded, 0);