From patchwork Mon Feb 20 23:35:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 124244 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2CC4F41CF1; Tue, 21 Feb 2023 00:38:03 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 67AC54317F; Tue, 21 Feb 2023 00:36:37 +0100 (CET) Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mails.dpdk.org (Postfix) with ESMTP id 358B443141 for ; Tue, 21 Feb 2023 00:36:18 +0100 (CET) Received: by mail-pf1-f171.google.com with SMTP id e24so1532745pfn.3 for ; Mon, 20 Feb 2023 15:36:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; 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=Dfb1E0xn1XyQ4s+b+w1zmOSAvjvFm4bNTCC6e3Z0zDw=; b=GGRi1otNPAc7h1++LqtNU6XsSU/OVPmuf9TYgiyqm+PZYLI3rKKXQskHRhyWUMVnVt 5cqZavlrboKIu+6BaaQJa+BvCIY0jDVGAhfdHQa19HxHDJ1+2SzrhOs3dPNl2sYj5tZD PI6Ixqu5cAC4n37LFFg1JyExU/b5/0dnSP6Ozr70DkI+nKgLVjWUlkgGyObSMfQ+3dBD ea9IH9M3VlHSXXuFsGKkFiXzusZN3K41luti7PosQrY3LOdYTB8SxuCzkXnPNOQntY1f /1ywggjThY36gZJgXplSqsanLhrsDoW9y/1nHHeRxZxYA/Q/Hl9QKYRSMnASlEUqocnS LgYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Dfb1E0xn1XyQ4s+b+w1zmOSAvjvFm4bNTCC6e3Z0zDw=; b=wtgLi3MSp7XL8jY09KPY6BaMoxMUK0MQBPcJNNRR1GaLCH+y6v7kWUFOfhSxag9hqM dO5wIHq7Q9R/5BY4KZV4gxrCyCATt9fU/DVbh2yv55h8U+Liconr7EK7h/fgsba+jcfN IYVP8+VSrAH/8cNCvd2C4DS/SCAx0mzbJawXMqft/VpkILnJxuANQyG4reczTIAB4D5r 2uLtRam95GIwDJpROI7HFYJ32aAhpJklo1QcgIlY2sRuoXYplWye3N9BFuHaRQIbkyoV HXNWGbIz2DvYQya+aZOzD5StEgxmSgcFuXkCkUkeNVA+e+J0vAvSR8CkghmYNcoRMGvO boxA== X-Gm-Message-State: AO0yUKVtVv8zkr7zzV46eqmysPpnSuam74ZjmrMTLRtkxZ8ty9TGtZ+i b7YYjiHR/tX67pP/zgVgI8eKPdVnUt7hxYq3aSE= X-Google-Smtp-Source: AK7set9oCxHH+yAcPMAflNxZXRBrprUXps5kvUDd2lnXLWUZ3AASxvQnhJWmhI1yBhqIHIkku2fPBA== X-Received: by 2002:aa7:9691:0:b0:5a8:b911:a264 with SMTP id f17-20020aa79691000000b005a8b911a264mr2413047pfk.28.1676936177294; Mon, 20 Feb 2023 15:36:17 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id q19-20020a62e113000000b005a8dc935ec1sm8215908pfh.62.2023.02.20.15.36.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 15:36:16 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v8 21/22] hash: move rte_hash_set_alg out header Date: Mon, 20 Feb 2023 15:35:55 -0800 Message-Id: <20230220233556.168553-22-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230220233556.168553-1-stephen@networkplumber.org> References: <20230207204151.1503491-1-stephen@networkplumber.org> <20230220233556.168553-1-stephen@networkplumber.org> MIME-Version: 1.0 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 --- lib/hash/meson.build | 1 + lib/hash/rte_hash_crc.c | 63 +++++++++++++++++++++++++++++++++++++++++ lib/hash/rte_hash_crc.h | 46 ++---------------------------- lib/hash/version.map | 1 + 4 files changed, 67 insertions(+), 44 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_hash_crc.c b/lib/hash/rte_hash_crc.c new file mode 100644 index 000000000000..c59eebccb1eb --- /dev/null +++ b/lib/hash/rte_hash_crc.c @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation + */ + +#include +#include + +#include "rte_hash_crc.h" + +/** + * 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) +{ + 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 +} diff --git a/lib/hash/rte_hash_crc.h b/lib/hash/rte_hash_crc.h index 0249ad16c5b6..e4acd99a0c81 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" @@ -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..a1d81835399c 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;