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 D9B1B45AEB; Fri, 11 Oct 2024 15:32:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 91FC0402A1; Fri, 11 Oct 2024 15:32:36 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by mails.dpdk.org (Postfix) with ESMTP id 6C1BD402A1 for ; Fri, 11 Oct 2024 15:32:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728653554; x=1760189554; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1Rs/1EEMXCRDnQUWyY5CZkCTdpOjTMOau6Bhm1f0BoI=; b=GBn9ABfWdGeQ18NWE2GHJLSHH69t63U8Tq9bQYWFQxeqNZDPv8ES9BN+ jnldCfdrX1QwC4SkVYvZyedZPjk/7I+QBm+4uetdplTxUoUVhzF42mUjo N7BvtOfCf9qCIytsuDzsnnLKXwFkkv3FDbEAHOGZYvDd5+bGLuqj+P+n4 2Cq5rwoKoqqq0vZi3NE+Fvn41t+5ZrQzgMWKAStN5xUy0s7zA+moLF0zM 4RxLlbYAcnFaWMwE5SKd5RC+A9f5qoYn6sl3XFGDeaAkPeK2MGS6Nap+P 3rtbR9clwRcbwL4R1FbRY3qm0dTbwxeJWs1/Ef88pzJOk0AmyLDfSTaec g==; X-CSE-ConnectionGUID: NcSCDvrEQWWl3nEOj3PlVQ== X-CSE-MsgGUID: hrQT4AezTJ2fc3e3zIqC5A== X-IronPort-AV: E=McAfee;i="6700,10204,11221"; a="45528747" X-IronPort-AV: E=Sophos;i="6.11,196,1725346800"; d="scan'208";a="45528747" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 06:32:33 -0700 X-CSE-ConnectionGUID: 5rBbUBHzR9WACTU3uAI4EA== X-CSE-MsgGUID: bRkGc0guRC6iLHvwzsCuTg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,196,1725346800"; d="scan'208";a="76539501" Received: from unknown (HELO silpixa00401385.ir.intel.com) ([10.237.214.25]) by fmviesa006.fm.intel.com with ESMTP; 11 Oct 2024 06:32:32 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: david.marchand@redhat.com, wathsala.vithanage@arm.com, konstantin.ananyev@huawei.com, Bruce Richardson Subject: [PATCH] eal/x86: cache queried CPU flags Date: Fri, 11 Oct 2024 14:31:55 +0100 Message-ID: <20241011133219.1495983-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241007110725.377550-1-bruce.richardson@intel.com> References: <20241007110725.377550-1-bruce.richardson@intel.com> 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 Rather than re-querying the HW each time a CPU flag is requested, we can just save the return value in the flags array. This should speed up repeated querying of CPU flags, and provides a workaround for a reported issue where errors are seen with constant querying of the AVX-512 CPU flag from a non-AVX VM. Bugzilla ID: 1501 Signed-off-by: Bruce Richardson --- V2: Add compiler barrier to prevent issues with multi-threaded calls --- lib/eal/x86/rte_cpuflags.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/eal/x86/rte_cpuflags.c b/lib/eal/x86/rte_cpuflags.c index 26163ab746..90389c66fc 100644 --- a/lib/eal/x86/rte_cpuflags.c +++ b/lib/eal/x86/rte_cpuflags.c @@ -8,8 +8,10 @@ #include #include #include +#include #include "rte_cpuid.h" +#include "rte_atomic.h" /** * Struct to hold a processor feature entry @@ -21,12 +23,14 @@ struct feature_entry { uint32_t bit; /**< cpuid register bit */ #define CPU_FLAG_NAME_MAX_LEN 64 char name[CPU_FLAG_NAME_MAX_LEN]; /**< String for printing */ + bool has_value; + bool value; }; #define FEAT_DEF(name, leaf, subleaf, reg, bit) \ [RTE_CPUFLAG_##name] = {leaf, subleaf, reg, bit, #name }, -const struct feature_entry rte_cpu_feature_table[] = { +struct feature_entry rte_cpu_feature_table[] = { FEAT_DEF(SSE3, 0x00000001, 0, RTE_REG_ECX, 0) FEAT_DEF(PCLMULQDQ, 0x00000001, 0, RTE_REG_ECX, 1) FEAT_DEF(DTES64, 0x00000001, 0, RTE_REG_ECX, 2) @@ -147,7 +151,7 @@ const struct feature_entry rte_cpu_feature_table[] = { int rte_cpu_get_flag_enabled(enum rte_cpu_flag_t feature) { - const struct feature_entry *feat; + struct feature_entry *feat; cpuid_registers_t regs; unsigned int maxleaf; @@ -156,6 +160,8 @@ rte_cpu_get_flag_enabled(enum rte_cpu_flag_t feature) return -ENOENT; feat = &rte_cpu_feature_table[feature]; + if (feat->has_value) + return feat->value; if (!feat->leaf) /* This entry in the table wasn't filled out! */ @@ -163,8 +169,10 @@ rte_cpu_get_flag_enabled(enum rte_cpu_flag_t feature) maxleaf = __get_cpuid_max(feat->leaf & 0x80000000, NULL); - if (maxleaf < feat->leaf) - return 0; + if (maxleaf < feat->leaf) { + feat->value = 0; + goto out; + } #ifdef RTE_TOOLCHAIN_MSVC __cpuidex(regs, feat->leaf, feat->subleaf); @@ -175,7 +183,11 @@ rte_cpu_get_flag_enabled(enum rte_cpu_flag_t feature) #endif /* check if the feature is enabled */ - return (regs[feat->reg] >> feat->bit) & 1; + feat->value = (regs[feat->reg] >> feat->bit) & 1; +out: + rte_compiler_barrier(); + feat->has_value = true; + return feat->value; } const char * -- 2.43.0