From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: ferruh.yigit@amd.com, thomas@monjalon.net,
bruce.richardson@intel.com, konstantin.v.ananyev@yandex.ru,
ruifeng.wang@arm.com, zhoumin@loongson.cn,
drc@linux.vnet.ibm.com, kda@semihalf.com,
roretzla@linux.microsoft.com, Matan Azrad <matan@nvidia.com>,
Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
Ori Kam <orika@nvidia.com>, Suanming Mou <suanmingm@nvidia.com>
Subject: [PATCH 2/2] common/mlx5: use EAL x86 processor identification
Date: Fri, 22 Sep 2023 11:37:21 +0200 [thread overview]
Message-ID: <20230922093722.2057688-3-david.marchand@redhat.com> (raw)
In-Reply-To: <20230922093722.2057688-1-david.marchand@redhat.com>
Rather than use an ugly asm thing, use newly introduced EAL x86 API.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/common/mlx5/mlx5_common.c | 81 ++++++++-----------------------
1 file changed, 21 insertions(+), 60 deletions(-)
diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c
index 0ad14a48c7..99adcd960e 100644
--- a/drivers/common/mlx5/mlx5_common.c
+++ b/drivers/common/mlx5/mlx5_common.c
@@ -6,6 +6,7 @@
#include <string.h>
#include <stdio.h>
+#include <eal_cpu.h>
#include <rte_errno.h>
#include <rte_mempool.h>
#include <rte_class.h>
@@ -52,29 +53,6 @@ uint8_t haswell_broadwell_cpu;
*/
#define MLX5_SQ_DB_NC "sq_db_nc"
-/* In case this is an x86_64 intel processor to check if
- * we should use relaxed ordering.
- */
-#ifdef RTE_ARCH_X86_64
-/**
- * This function returns processor identification and feature information
- * into the registers.
- *
- * @param eax, ebx, ecx, edx
- * Pointers to the registers that will hold cpu information.
- * @param level
- * The main category of information returned.
- */
-static inline void mlx5_cpu_id(unsigned int level,
- unsigned int *eax, unsigned int *ebx,
- unsigned int *ecx, unsigned int *edx)
-{
- __asm__("cpuid\n\t"
- : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
- : "0" (level));
-}
-#endif
-
RTE_LOG_REGISTER_DEFAULT(mlx5_common_logtype, NOTICE)
/* Head of list of drivers. */
@@ -1246,46 +1224,29 @@ mlx5_common_init(void)
RTE_INIT_PRIO(mlx5_is_haswell_broadwell_cpu, LOG)
{
#ifdef RTE_ARCH_X86_64
- unsigned int broadwell_models[4] = {0x3d, 0x47, 0x4F, 0x56};
- unsigned int haswell_models[4] = {0x3c, 0x3f, 0x45, 0x46};
- unsigned int i, model, family, brand_id, vendor;
- unsigned int signature_intel_ebx = 0x756e6547;
- unsigned int extended_model;
- unsigned int eax = 0;
- unsigned int ebx = 0;
- unsigned int ecx = 0;
- unsigned int edx = 0;
- int max_level;
-
- mlx5_cpu_id(0, &eax, &ebx, &ecx, &edx);
- vendor = ebx;
- max_level = eax;
- if (max_level < 1) {
- haswell_broadwell_cpu = 0;
+ uint8_t broadwell_models[] = {0x3d, 0x47, 0x4f, 0x56};
+ uint8_t haswell_models[] = {0x3c, 0x3f, 0x45, 0x46};
+ unsigned int i;
+ uint8_t model;
+
+ if (!rte_cpu_is_x86() || !rte_cpu_x86_is_intel() || rte_cpu_x86_brand() != 0x0 ||
+ rte_cpu_x86_family() != 0x6)
+ goto out;
+
+ model = rte_cpu_x86_model();
+ for (i = 0; i < RTE_DIM(broadwell_models); i++) {
+ if (model != broadwell_models[i])
+ continue;
+ haswell_broadwell_cpu = 1;
return;
}
- mlx5_cpu_id(1, &eax, &ebx, &ecx, &edx);
- model = (eax >> 4) & 0x0f;
- family = (eax >> 8) & 0x0f;
- brand_id = ebx & 0xff;
- extended_model = (eax >> 12) & 0xf0;
- /* Check if the processor is Haswell or Broadwell */
- if (vendor == signature_intel_ebx) {
- if (family == 0x06)
- model += extended_model;
- if (brand_id == 0 && family == 0x6) {
- for (i = 0; i < RTE_DIM(broadwell_models); i++)
- if (model == broadwell_models[i]) {
- haswell_broadwell_cpu = 1;
- return;
- }
- for (i = 0; i < RTE_DIM(haswell_models); i++)
- if (model == haswell_models[i]) {
- haswell_broadwell_cpu = 1;
- return;
- }
- }
+ for (i = 0; i < RTE_DIM(haswell_models); i++) {
+ if (model != haswell_models[i])
+ continue;
+ haswell_broadwell_cpu = 1;
+ return;
}
+out:
#endif
haswell_broadwell_cpu = 0;
}
--
2.41.0
prev parent reply other threads:[~2023-09-22 9:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-22 9:37 [PATCH 0/2] Introduce x86 specific identification API David Marchand
2023-09-22 9:37 ` [PATCH 1/2] eal: introduce x86 processor identification David Marchand
2023-09-22 9:46 ` Bruce Richardson
2023-09-25 9:42 ` David Marchand
2023-09-22 10:38 ` Bruce Richardson
2023-09-22 10:55 ` Bruce Richardson
2023-09-25 9:46 ` David Marchand
2023-09-25 10:16 ` Bruce Richardson
2023-09-25 10:52 ` Morten Brørup
2023-09-22 9:37 ` David Marchand [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230922093722.2057688-3-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=drc@linux.vnet.ibm.com \
--cc=ferruh.yigit@amd.com \
--cc=kda@semihalf.com \
--cc=konstantin.v.ananyev@yandex.ru \
--cc=matan@nvidia.com \
--cc=orika@nvidia.com \
--cc=roretzla@linux.microsoft.com \
--cc=ruifeng.wang@arm.com \
--cc=suanmingm@nvidia.com \
--cc=thomas@monjalon.net \
--cc=viacheslavo@nvidia.com \
--cc=zhoumin@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).