From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B8FF042868; Thu, 30 Mar 2023 01:42:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A665342D82; Thu, 30 Mar 2023 01:41:26 +0200 (CEST) Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by mails.dpdk.org (Postfix) with ESMTP id 0D4F342D4B for ; Thu, 30 Mar 2023 01:41:19 +0200 (CEST) Received: by mail-pj1-f48.google.com with SMTP id q102so15618183pjq.3 for ; Wed, 29 Mar 2023 16:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; t=1680133278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ajNSW0dhTFKFeRoVwFrppElVBjIDjifWwTugDwJNyR8=; b=6QEvGPsmdjjCzjECTQREysoUPrMHugACOH4CkgsIjKGt4U17s600VynGbNEOY71ERA BsZa2Hp+wfmzybBgIUCZxp+/Q6jjcEyTRe74KxCswbelHDFuMD8UPkZjjSkbZJYLXpFv NRSKxfWEZgSyY2QKAzrBs9gxK66B4Vl1Qu8XCUyKDVECIxAvMDtQexUcWXfVHkXM+tzG ZXiPkCYviesCFBxMYCihlFs64hSl7+t0U/VeEaNnUdSLZVK7QOqqH7swqPKv43rswWm5 OOGOat8+S/1ao8F1CglY6no5FV9lBw2AroyZ6yL4BpOvWL5LLEaRcAZF2IdSPpq1qneV I+kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680133278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ajNSW0dhTFKFeRoVwFrppElVBjIDjifWwTugDwJNyR8=; b=0yhdABZLEOB1Lm56l3ymFIoTu4KTCayHIzrAoX7WeEhxMphSTr3e/OEjasY/6uDWaa QV/3nqwNcuvm61K8nI4P1dwEMwYIX1m/ltjGxPwVOHeElBKLGixFW9XwqEW5mSJMLjcN Wtf4QsjJJkEo7Pf/SNsWvJkzv2iWAR2gsRbnM76ZgpnQaE14G+XJVdzM4m35vJQfbMCF Z6cHc6Yq9mFWnV6vEI7R89S2WPPUXVwE6K4K6Er/1AV9D9ydDQ4ULdEkvf2lnJjs5Xgi WaniMp5tdHA3/VLD72vV4oT4q2O/h0Pvsp5Q3VIrMHvlpcq806FB0EvBGKNShw2jIFZz wO7Q== X-Gm-Message-State: AAQBX9fJrzFS6hAFtfnOimLj3YwI7bjVmGudRR0RfRPw98sfctKqvOKS QWEATVlGzN07DgjhNoLjgYF6xRCCcJYXTKVfpxWyFQ== X-Google-Smtp-Source: AKy350Zz1X8kTjXCYIvgSzpYnwDjxBhWGS4cqRQ7+5Y8dTRSK5PCqE/fOwD9GCgu7ySPh1N8YJ5Wig== X-Received: by 2002:a17:902:f985:b0:1a1:d24f:a5f6 with SMTP id ky5-20020a170902f98500b001a1d24fa5f6mr19412830plb.46.1680133278174; Wed, 29 Mar 2023 16:41:18 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id f10-20020a17090274ca00b0019c2b1c4db1sm23360095plt.239.2023.03.29.16.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 16:41:17 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Ruifeng Wang , Yipeng Wang , Sameh Gobriel , Bruce Richardson , Vladimir Medvedkin Subject: [PATCH v12 18/22] hash: move rte_hash_set_alg out header Date: Wed, 29 Mar 2023 16:40:45 -0700 Message-Id: <20230329234049.11071-19-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329234049.11071-1-stephen@networkplumber.org> References: <20230329234049.11071-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The code for setting algorithm for hash is not at all perf sensitive, and doing it inline has a couple of problems. First, it means that if multiple files include the header, then the initialization gets done multiple times. But also, it makes it harder to fix usage of RTE_LOG(). Despite what the checking script say. This is not an ABI change, the previous version inlined the same code; therefore both old and new code will work the same. Signed-off-by: Stephen Hemminger Acked-by: Ruifeng Wang --- lib/hash/meson.build | 1 + lib/hash/rte_crc_arm64.h | 8 ++--- lib/hash/rte_crc_x86.h | 10 +++--- lib/hash/rte_hash_crc.c | 68 ++++++++++++++++++++++++++++++++++++++++ lib/hash/rte_hash_crc.h | 48 ++-------------------------- lib/hash/version.map | 7 +++++ 6 files changed, 88 insertions(+), 54 deletions(-) create mode 100644 lib/hash/rte_hash_crc.c diff --git a/lib/hash/meson.build b/lib/hash/meson.build index e56ee8572564..c345c6f561fc 100644 --- a/lib/hash/meson.build +++ b/lib/hash/meson.build @@ -19,6 +19,7 @@ indirect_headers += files( sources = files( 'rte_cuckoo_hash.c', + 'rte_hash_crc.c', 'rte_fbk_hash.c', 'rte_thash.c', 'rte_thash_gfni.c' diff --git a/lib/hash/rte_crc_arm64.h b/lib/hash/rte_crc_arm64.h index c9f52510871b..414fe065caa8 100644 --- a/lib/hash/rte_crc_arm64.h +++ b/lib/hash/rte_crc_arm64.h @@ -53,7 +53,7 @@ crc32c_arm64_u64(uint64_t data, uint32_t init_val) static inline uint32_t rte_hash_crc_1byte(uint8_t data, uint32_t init_val) { - if (likely(crc32_alg & CRC32_ARM64)) + if (likely(rte_hash_crc32_alg & CRC32_ARM64)) return crc32c_arm64_u8(data, init_val); return crc32c_1byte(data, init_val); @@ -67,7 +67,7 @@ rte_hash_crc_1byte(uint8_t data, uint32_t init_val) static inline uint32_t rte_hash_crc_2byte(uint16_t data, uint32_t init_val) { - if (likely(crc32_alg & CRC32_ARM64)) + if (likely(rte_hash_crc32_alg & CRC32_ARM64)) return crc32c_arm64_u16(data, init_val); return crc32c_2bytes(data, init_val); @@ -81,7 +81,7 @@ rte_hash_crc_2byte(uint16_t data, uint32_t init_val) static inline uint32_t rte_hash_crc_4byte(uint32_t data, uint32_t init_val) { - if (likely(crc32_alg & CRC32_ARM64)) + if (likely(rte_hash_crc32_alg & CRC32_ARM64)) return crc32c_arm64_u32(data, init_val); return crc32c_1word(data, init_val); @@ -95,7 +95,7 @@ rte_hash_crc_4byte(uint32_t data, uint32_t init_val) static inline uint32_t rte_hash_crc_8byte(uint64_t data, uint32_t init_val) { - if (likely(crc32_alg & CRC32_ARM64)) + if (likely(rte_hash_crc32_alg & CRC32_ARM64)) return crc32c_arm64_u64(data, init_val); return crc32c_2words(data, init_val); diff --git a/lib/hash/rte_crc_x86.h b/lib/hash/rte_crc_x86.h index 205bc182be77..3b865e251db2 100644 --- a/lib/hash/rte_crc_x86.h +++ b/lib/hash/rte_crc_x86.h @@ -67,7 +67,7 @@ crc32c_sse42_u64(uint64_t data, uint64_t init_val) static inline uint32_t rte_hash_crc_1byte(uint8_t data, uint32_t init_val) { - if (likely(crc32_alg & CRC32_SSE42)) + if (likely(rte_hash_crc32_alg & CRC32_SSE42)) return crc32c_sse42_u8(data, init_val); return crc32c_1byte(data, init_val); @@ -81,7 +81,7 @@ rte_hash_crc_1byte(uint8_t data, uint32_t init_val) static inline uint32_t rte_hash_crc_2byte(uint16_t data, uint32_t init_val) { - if (likely(crc32_alg & CRC32_SSE42)) + if (likely(rte_hash_crc32_alg & CRC32_SSE42)) return crc32c_sse42_u16(data, init_val); return crc32c_2bytes(data, init_val); @@ -95,7 +95,7 @@ rte_hash_crc_2byte(uint16_t data, uint32_t init_val) static inline uint32_t rte_hash_crc_4byte(uint32_t data, uint32_t init_val) { - if (likely(crc32_alg & CRC32_SSE42)) + if (likely(rte_hash_crc32_alg & CRC32_SSE42)) return crc32c_sse42_u32(data, init_val); return crc32c_1word(data, init_val); @@ -110,11 +110,11 @@ static inline uint32_t rte_hash_crc_8byte(uint64_t data, uint32_t init_val) { #ifdef RTE_ARCH_X86_64 - if (likely(crc32_alg == CRC32_SSE42_x64)) + if (likely(rte_hash_crc32_alg == CRC32_SSE42_x64)) return crc32c_sse42_u64(data, init_val); #endif - if (likely(crc32_alg & CRC32_SSE42)) + if (likely(rte_hash_crc32_alg & CRC32_SSE42)) return crc32c_sse42_u64_mimic(data, init_val); return crc32c_2words(data, init_val); diff --git a/lib/hash/rte_hash_crc.c b/lib/hash/rte_hash_crc.c new file mode 100644 index 000000000000..1439d8a71f6a --- /dev/null +++ b/lib/hash/rte_hash_crc.c @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation + */ + +#include +#include + +#include "rte_hash_crc.h" + +RTE_LOG_REGISTER_SUFFIX(hash_crc_logtype, crc, INFO); +#define RTE_LOGTYPE_HASH_CRC hash_crc_logtype + +uint8_t rte_hash_crc32_alg = CRC32_SW; + +/** + * Allow or disallow use of SSE4.2/ARMv8 intrinsics for CRC32 hash + * calculation. + * + * @param alg + * An OR of following flags: + * - (CRC32_SW) Don't use SSE4.2/ARMv8 intrinsics (default non-[x86/ARMv8]) + * - (CRC32_SSE42) Use SSE4.2 intrinsics if available + * - (CRC32_SSE42_x64) Use 64-bit SSE4.2 intrinsic if available (default x86) + * - (CRC32_ARM64) Use ARMv8 CRC intrinsic if available (default ARMv8) + * + */ +void +rte_hash_crc_set_alg(uint8_t alg) +{ + rte_hash_crc32_alg = CRC32_SW; + + if (alg == CRC32_SW) + return; + +#if defined RTE_ARCH_X86 + if (!(alg & CRC32_SSE42_x64)) + RTE_LOG(WARNING, HASH_CRC, + "Unsupported CRC32 algorithm requested using CRC32_x64/CRC32_SSE42\n"); + if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_EM64T) || alg == CRC32_SSE42) + rte_hash_crc32_alg = CRC32_SSE42; + else + rte_hash_crc32_alg = CRC32_SSE42_x64; +#endif + +#if defined RTE_ARCH_ARM64 + if (!(alg & CRC32_ARM64)) + RTE_LOG(WARNING, HASH_CRC, + "Unsupported CRC32 algorithm requested using CRC32_ARM64\n"); + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32)) + rte_hash_crc32_alg = CRC32_ARM64; +#endif + + if (rte_hash_crc32_alg == CRC32_SW) + RTE_LOG(WARNING, HASH_CRC, + "Unsupported CRC32 algorithm requested using CRC32_SW\n"); +} + +/* Setting the best available algorithm */ +RTE_INIT(rte_hash_crc_init_alg) +{ +#if defined(RTE_ARCH_X86) + rte_hash_crc_set_alg(CRC32_SSE42_x64); +#elif defined(RTE_ARCH_ARM64) && defined(__ARM_FEATURE_CRC32) + rte_hash_crc_set_alg(CRC32_ARM64); +#else + rte_hash_crc_set_alg(CRC32_SW); +#endif +} diff --git a/lib/hash/rte_hash_crc.h b/lib/hash/rte_hash_crc.h index 0249ad16c5b6..e8145ee44204 100644 --- a/lib/hash/rte_hash_crc.h +++ b/lib/hash/rte_hash_crc.h @@ -20,8 +20,6 @@ extern "C" { #include #include #include -#include -#include #include "rte_crc_sw.h" @@ -31,7 +29,7 @@ extern "C" { #define CRC32_SSE42_x64 (CRC32_x64|CRC32_SSE42) #define CRC32_ARM64 (1U << 3) -static uint8_t crc32_alg = CRC32_SW; +extern uint8_t rte_hash_crc32_alg; #if defined(RTE_ARCH_ARM64) && defined(__ARM_FEATURE_CRC32) #include "rte_crc_arm64.h" @@ -53,48 +51,8 @@ static uint8_t crc32_alg = CRC32_SW; * - (CRC32_ARM64) Use ARMv8 CRC intrinsic if available (default ARMv8) * */ -static inline void -rte_hash_crc_set_alg(uint8_t alg) -{ - crc32_alg = CRC32_SW; - - if (alg == CRC32_SW) - return; - -#if defined RTE_ARCH_X86 - if (!(alg & CRC32_SSE42_x64)) - RTE_LOG(WARNING, HASH, - "Unsupported CRC32 algorithm requested using CRC32_x64/CRC32_SSE42\n"); - if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_EM64T) || alg == CRC32_SSE42) - crc32_alg = CRC32_SSE42; - else - crc32_alg = CRC32_SSE42_x64; -#endif - -#if defined RTE_ARCH_ARM64 - if (!(alg & CRC32_ARM64)) - RTE_LOG(WARNING, HASH, - "Unsupported CRC32 algorithm requested using CRC32_ARM64\n"); - if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32)) - crc32_alg = CRC32_ARM64; -#endif - - if (crc32_alg == CRC32_SW) - RTE_LOG(WARNING, HASH, - "Unsupported CRC32 algorithm requested using CRC32_SW\n"); -} - -/* Setting the best available algorithm */ -RTE_INIT(rte_hash_crc_init_alg) -{ -#if defined(RTE_ARCH_X86) - rte_hash_crc_set_alg(CRC32_SSE42_x64); -#elif defined(RTE_ARCH_ARM64) && defined(__ARM_FEATURE_CRC32) - rte_hash_crc_set_alg(CRC32_ARM64); -#else - rte_hash_crc_set_alg(CRC32_SW); -#endif -} +void +rte_hash_crc_set_alg(uint8_t alg); #ifdef __DOXYGEN__ diff --git a/lib/hash/version.map b/lib/hash/version.map index f03b047b2eec..8b22aad5626b 100644 --- a/lib/hash/version.map +++ b/lib/hash/version.map @@ -9,6 +9,7 @@ DPDK_23 { rte_hash_add_key_with_hash; rte_hash_add_key_with_hash_data; rte_hash_count; + rte_hash_crc_set_alg; rte_hash_create; rte_hash_del_key; rte_hash_del_key_with_hash; @@ -56,3 +57,9 @@ EXPERIMENTAL { rte_thash_gfni; rte_thash_gfni_bulk; }; + +INTERNAL { + global: + + rte_hash_crc32_alg; +}; -- 2.39.2