From patchwork Tue Jun 2 07:10:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanqin Wei X-Patchwork-Id: 1302114 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=none (p=none dis=none) header.from=arm.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 49bjqr3nbmz9sPF for ; Tue, 2 Jun 2020 17:10:48 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 023E787697; Tue, 2 Jun 2020 07:10:47 +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 iSfXvjZSqICs; Tue, 2 Jun 2020 07:10:42 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id DC2A787688; Tue, 2 Jun 2020 07:10:42 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C6533C088D; Tue, 2 Jun 2020 07:10:42 +0000 (UTC) X-Original-To: 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 7F083C016E for ; Tue, 2 Jun 2020 07:10:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 5C8A786151 for ; Tue, 2 Jun 2020 07:10:41 +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 GeAy2COMrAO5 for ; Tue, 2 Jun 2020 07:10:38 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2F397851CC for ; Tue, 2 Jun 2020 07:10:38 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B5CCA1FB; Tue, 2 Jun 2020 00:10:37 -0700 (PDT) Received: from net-arm-n1sdp.shanghai.arm.com (net-arm-n1sdp.shanghai.arm.com [10.169.40.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DAFE33F305; Tue, 2 Jun 2020 00:10:34 -0700 (PDT) From: Yanqin Wei To: dev@openvswitch.org Date: Tue, 2 Jun 2020 02:10:03 -0500 Message-Id: <20200602071005.29925-5-Yanqin.Wei@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200602071005.29925-1-Yanqin.Wei@arm.com> References: <20200602071005.29925-1-Yanqin.Wei@arm.com> Cc: Ruifeng.Wang@arm.com, Lijian.Zhang@arm.com, i.maximets@ovn.org, nd@arm.com Subject: [ovs-dev] [PATCH v1 4/6] dpif-netdev: skip flow hash calculation in case of smc disabled 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" In case of 10k+ flows, emc lookup will usually miss. Flow hash value is always calculated in this case no matter smc is enabled or not. This patch moves it from smc_insert function into fast_path_processing and handle_packet_upcall function to avoid unnecessary hash calculation and memory access(flow->ufid) in smc disabled case. Reviewed-by: Lijian Zhang Reviewed-by: Malvika Gupta Reviewed-by: Lance Yang Signed-off-by: Yanqin Wei --- lib/dpif-netdev.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 3994f41e4..d575edefd 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -2957,14 +2957,8 @@ smc_insert(struct dp_netdev_pmd_thread *pmd, struct smc_bucket *bucket = &smc_cache->buckets[key->hash & SMC_MASK]; uint16_t index; uint32_t cmap_index; - bool smc_enable_db; int i; - atomic_read_relaxed(&pmd->dp->smc_enable_db, &smc_enable_db); - if (!smc_enable_db) { - return; - } - cmap_index = cmap_find_index(&pmd->flow_table, hash); index = (cmap_index >= UINT16_MAX) ? UINT16_MAX : (uint16_t)cmap_index; @@ -6794,8 +6788,13 @@ handle_packet_upcall(struct dp_netdev_pmd_thread *pmd, add_actions->size); } ovs_mutex_unlock(&pmd->flow_mutex); - uint32_t hash = dp_netdev_flow_hash(&netdev_flow->ufid); - smc_insert(pmd, key, hash); + + bool smc_enable_db; + atomic_read_relaxed(&pmd->dp->smc_enable_db, &smc_enable_db); + if (smc_enable_db) { + uint32_t hash = dp_netdev_flow_hash(&netdev_flow->ufid); + smc_insert(pmd, key, hash); + } emc_probabilistic_insert(pmd, key, netdev_flow); } if (pmd_perf_metrics_enabled(pmd)) { @@ -6904,9 +6903,13 @@ fast_path_processing(struct dp_netdev_pmd_thread *pmd, } flow = dp_netdev_flow_cast(rules[i]); - uint32_t hash = dp_netdev_flow_hash(&flow->ufid); - smc_insert(pmd, keys[i], hash); + bool smc_enable_db; + atomic_read_relaxed(&pmd->dp->smc_enable_db, &smc_enable_db); + if (smc_enable_db) { + uint32_t hash = dp_netdev_flow_hash(&flow->ufid); + smc_insert(pmd, keys[i], hash); + } emc_probabilistic_insert(pmd, keys[i], flow); /* Add these packets into the flow map in the same order * as received.