From patchwork Wed Sep 30 13:04:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Power, Ciara" X-Patchwork-Id: 79354 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5EB48A04B5; Wed, 30 Sep 2020 15:13:57 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B32841DBA0; Wed, 30 Sep 2020 15:08:46 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id DA35C1DB61 for ; Wed, 30 Sep 2020 15:08:30 +0200 (CEST) IronPort-SDR: 50UPfOZPYLWnL5dyXt1qUB1CfTRiHx0jMSbajXuPBWNStzVLlKEh+kQtw3eCpyP8t5QiFsq3uw H4uZhTtJMvsg== X-IronPort-AV: E=McAfee;i="6000,8403,9759"; a="150223510" X-IronPort-AV: E=Sophos;i="5.77,322,1596524400"; d="scan'208";a="150223510" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2020 06:08:29 -0700 IronPort-SDR: tINi71Xq7teoX9BflM9n5VZTHSGVUbiSKUgi1gPqXC3NaqXZ50LFZI+SgMcFEgY9HwA+eShBQh hKya+17l160w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,322,1596524400"; d="scan'208";a="294603281" Received: from silpixa00399953.ir.intel.com (HELO silpixa00399953.ger.corp.intel.com) ([10.237.222.53]) by fmsmga008.fm.intel.com with ESMTP; 30 Sep 2020 06:08:27 -0700 From: Ciara Power To: dev@dpdk.org Cc: Ciara Power , Jasvinder Singh , Olivier Matz Date: Wed, 30 Sep 2020 14:04:13 +0100 Message-Id: <20200930130415.11211-18-ciara.power@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200930130415.11211-1-ciara.power@intel.com> References: <20200807155859.63888-1-ciara.power@intel.com> <20200930130415.11211-1-ciara.power@intel.com> Subject: [dpdk-dev] [PATCH v3 17/18] net: add checks for max SIMD bitwidth X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" When choosing a vector path to take, an extra condition must be satisfied to ensure the max SIMD bitwidth allows for the CPU enabled path. The vector path was initially chosen in RTE_INIT, however this is no longer suitable as we cannot check the max SIMD bitwidth at that time. The default chosen in RTE_INIT is now scalar. For best performance and to use vector paths, apps must explicitly call the set algorithm function before using other functions from this library, as this is where vector handlers are now chosen. Suggested-by: Jasvinder Singh Signed-off-by: Ciara Power --- v3: - Moved choosing vector paths out of RTE_INIT. - Moved checking max_simd_bitwidth into the set_alg function. --- lib/librte_net/rte_net_crc.c | 26 +++++++++++++++++--------- lib/librte_net/rte_net_crc.h | 3 ++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/librte_net/rte_net_crc.c b/lib/librte_net/rte_net_crc.c index 9fd4794a9d..241eb16399 100644 --- a/lib/librte_net/rte_net_crc.c +++ b/lib/librte_net/rte_net_crc.c @@ -9,6 +9,7 @@ #include #include #include +#include #if defined(RTE_ARCH_X86_64) && defined(RTE_MACHINE_CPUFLAG_PCLMULQDQ) #define X86_64_SSE42_PCLMULQDQ 1 @@ -60,6 +61,9 @@ static rte_net_crc_handler handlers_neon[] = { }; #endif +static uint16_t max_simd_bitwidth; +#define RTE_LOGTYPE_NET RTE_LOGTYPE_USER1 + /** * Reflect the bits about the middle * @@ -145,18 +149,26 @@ rte_crc32_eth_handler(const uint8_t *data, uint32_t data_len) void rte_net_crc_set_alg(enum rte_net_crc_alg alg) { + if (max_simd_bitwidth == 0) + max_simd_bitwidth = rte_get_max_simd_bitwidth(); + switch (alg) { #ifdef X86_64_SSE42_PCLMULQDQ case RTE_NET_CRC_SSE42: - handlers = handlers_sse42; - break; + if (max_simd_bitwidth >= RTE_MAX_128_SIMD) { + handlers = handlers_sse42; + return; + } + RTE_LOG(INFO, NET, "Max SIMD Bitwidth too low, using scalar\n"); #elif defined ARM64_NEON_PMULL /* fall-through */ case RTE_NET_CRC_NEON: - if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_PMULL)) { + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_PMULL) && + max_simd_bitwidth >= RTE_MAX_128_SIMD) { handlers = handlers_neon; - break; + return; } + RTE_LOG(INFO, NET, "Max SIMD Bitwidth too low or CPU flag not enabled, using scalar\n"); #endif /* fall-through */ case RTE_NET_CRC_SCALAR: @@ -184,19 +196,15 @@ rte_net_crc_calc(const void *data, /* Select highest available crc algorithm as default one */ RTE_INIT(rte_net_crc_init) { - enum rte_net_crc_alg alg = RTE_NET_CRC_SCALAR; - rte_net_crc_scalar_init(); #ifdef X86_64_SSE42_PCLMULQDQ - alg = RTE_NET_CRC_SSE42; rte_net_crc_sse42_init(); #elif defined ARM64_NEON_PMULL if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_PMULL)) { - alg = RTE_NET_CRC_NEON; rte_net_crc_neon_init(); } #endif - rte_net_crc_set_alg(alg); + rte_net_crc_set_alg(RTE_NET_CRC_SCALAR); } diff --git a/lib/librte_net/rte_net_crc.h b/lib/librte_net/rte_net_crc.h index 16e85ca970..7a45ebe193 100644 --- a/lib/librte_net/rte_net_crc.h +++ b/lib/librte_net/rte_net_crc.h @@ -28,7 +28,8 @@ enum rte_net_crc_alg { /** * This API set the CRC computation algorithm (i.e. scalar version, * x86 64-bit sse4.2 intrinsic version, etc.) and internal data - * structure. + * structure. This should be called before any other functions, to + * choose the algorithm for best performance. * * @param alg * This parameter is used to select the CRC implementation version.