Skip to contentSkip to conversation

Introduce x86 specific identification API

PATCH In review David Marchand 3 participants 10 messages Sep 22, 2023 – Sep 25, 2023 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover Introduce x86 specific identification API

Rather than have every driver implement their own set of cpuid() ugly stuff, provide an abstracted (gcc/clang vs MSVC) API for querying about x86 processor details.

Note:
- coming up with a cross arch API seems a difficult task, hence a arch specific API has been preferred. If other arches have ideas how to abstract I am open to suggestions though I won't have the time to implement it for this release,
- usage of this arch specific API must not become the common practice and maintainers will have to be wary that drivers are still working fine with generic/common processor/arch features,

Signature · 21 lines
David Marchand

David Marchand (2):
  eal: introduce x86 processor identification
  common/mlx5: use EAL x86 processor identification

 MAINTAINERS                       |   1 +
 app/test/meson.build              |   1 +
 app/test/test_cpu.c               |  37 ++++++++
 drivers/common/mlx5/mlx5_common.c |  81 +++++------------
 lib/eal/common/eal_common_cpu.c   | 141 ++++++++++++++++++++++++++++++
 lib/eal/common/eal_cpu.h          |  77 ++++++++++++++++
 lib/eal/common/meson.build        |   1 +
 lib/eal/version.map               |   6 ++
 8 files changed, 285 insertions(+), 60 deletions(-)
 create mode 100644 app/test/test_cpu.c
 create mode 100644 lib/eal/common/eal_common_cpu.c
 create mode 100644 lib/eal/common/eal_cpu.h

-- 
2.41.0
#1 lore raw

PATCH 1/2 eal: introduce x86 processor identification

In some really specific cases, it may be needed to get a detailed information on the processor running a DPDK application for drivers to achieve better performance, or for matters that concern only them.

Those information are highly arch-specific and require a specific API.

Introduce a set of functions to get brand, family and model of a x86 processor.
Those functions do not make sense on other arches and a driver must first check rte_cpu_is_x86() before anything else.

---
 MAINTAINERS                     |   1 +
 app/test/meson.build            |   1 +
 app/test/test_cpu.c             |  37 +++++++++
 lib/eal/common/eal_common_cpu.c | 141 ++++++++++++++++++++++++++++++++
 lib/eal/common/eal_cpu.h        |  77 +++++++++++++++++
 lib/eal/common/meson.build      |   1 +
 lib/eal/version.map             |   6 ++
 7 files changed, 264 insertions(+)
 create mode 100644 app/test/test_cpu.c
 create mode 100644 lib/eal/common/eal_common_cpu.c
 create mode 100644 lib/eal/common/eal_cpu.h
MAINTAINERS +1 -0
index 698608cdb2..b87d47a1e4 100644
@@ -158,6 +158,7 @@ F: app/test/test_barrier.c
 F: app/test/test_bitcount.c
 F: app/test/test_byteorder.c
 F: app/test/test_common.c
+F: app/test/test_cpu.c
 F: app/test/test_cpuflags.c
 F: app/test/test_cycles.c
 F: app/test/test_debug.c
app/test/meson.build +1 -0
index 05bae9216d..4b37ad02fa 100644
@@ -44,6 +44,7 @@ source_file_deps = {
     'test_cmdline_string.c': [],
     'test_common.c': [],
     'test_compressdev.c': ['compressdev'],
+    'test_cpu.c': [],
     'test_cpuflags.c': [],
     'test_crc.c': ['net'],
     'test_cryptodev.c': test_cryptodev_deps,
app/test/test_cpu.c new file +37 -0
new file mode 100644
index 0000000000..40d8bd94eb
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Red Hat, Inc.
+ */
+
+#include <stdio.h>
+#include <inttypes.h>
+
+#include "eal_cpu.h"
+
+#include "test.h"
+
+static int
+test_cpu(void)
+{
+#ifndef RTE_ARCH_X86
+	RTE_TEST_ASSERT(!rte_cpu_is_x86(), "rte_cpu_is_x86() returned true on " RTE_STR(RTE_ARCH));
+#else
+	const char *vendor;
+
+	RTE_TEST_ASSERT(rte_cpu_is_x86(), "rte_cpu_is_x86() returned false");
+
+	if (rte_cpu_x86_is_amd())
+		vendor = "AMD";
+	else if (rte_cpu_x86_is_intel())
+		vendor = "Intel";
+	else
+		vendor = "unknown";
+
+	printf("The processor running this program is a x86 %s processor, brand=0x%"
+		PRIx8", family=0x%"PRIx8", model=0x%"PRIx8"\n", vendor, rte_cpu_x86_brand(),
+		rte_cpu_x86_family(), rte_cpu_x86_model());
+#endif
+
+	return TEST_SUCCESS;
+}
+
+REGISTER_FAST_TEST(cpu_autotest, true, true, test_cpu);
lib/eal/common/eal_common_cpu.c new file +141 -0

141 lines not on this page · raw message

lib/eal/common/eal_cpu.h new file +77 -0

77 lines not on this page · raw message

lib/eal/common/meson.build +1 -0
index 22a626ba6f..bef5b2575b 100644
@@ -9,6 +9,7 @@ sources += files(
         'eal_common_bus.c',
         'eal_common_class.c',
         'eal_common_config.c',
+        'eal_common_cpu.c',
         'eal_common_debug.c',
         'eal_common_dev.c',
         'eal_common_devargs.c',
lib/eal/version.map +6 -0
index 7940431e5a..62632202c5 100644
@@ -424,6 +424,12 @@ INTERNAL {
 
 	rte_bus_register;
 	rte_bus_unregister;
+	rte_cpu_is_x86;
+	rte_cpu_x86_brand;
+	rte_cpu_x86_family;
+	rte_cpu_x86_is_amd;
+	rte_cpu_x86_is_intel;
+	rte_cpu_x86_model;
 	rte_eal_get_baseaddr;
 	rte_eal_parse_coremask;
 	rte_firmware_read;
Signature · 1 line
2.41.0
#2 lore raw

Re: [PATCH 1/2] eal: introduce x86 processor identification

Quoted 119 lines · David Marchand

In some really specific cases, it may be needed to get a detailed information on the processor running a DPDK application for drivers to achieve better performance, or for matters that concern only them.

Those information are highly arch-specific and require a specific API.

Introduce a set of functions to get brand, family and model of a x86 processor.
Those functions do not make sense on other arches and a driver must first check rte_cpu_is_x86() before anything else.

---
 MAINTAINERS                     |   1 +
 app/test/meson.build            |   1 +
 app/test/test_cpu.c             |  37 +++++++++
 lib/eal/common/eal_common_cpu.c | 141 ++++++++++++++++++++++++++++++++
 lib/eal/common/eal_cpu.h        |  77 +++++++++++++++++
 lib/eal/common/meson.build      |   1 +
 lib/eal/version.map             |   6 ++
 7 files changed, 264 insertions(+)
 create mode 100644 app/test/test_cpu.c
 create mode 100644 lib/eal/common/eal_common_cpu.c
 create mode 100644 lib/eal/common/eal_cpu.h
MAINTAINERS +1 -0
index 698608cdb2..b87d47a1e4 100644
@@ -158,6 +158,7 @@ F: app/test/test_barrier.c
 F: app/test/test_bitcount.c
 F: app/test/test_byteorder.c
 F: app/test/test_common.c
+F: app/test/test_cpu.c
 F: app/test/test_cpuflags.c
 F: app/test/test_cycles.c
 F: app/test/test_debug.c
app/test/meson.build +1 -0
index 05bae9216d..4b37ad02fa 100644
@@ -44,6 +44,7 @@ source_file_deps = {
     'test_cmdline_string.c': [],
     'test_common.c': [],
     'test_compressdev.c': ['compressdev'],
+    'test_cpu.c': [],
     'test_cpuflags.c': [],
     'test_crc.c': ['net'],
     'test_cryptodev.c': test_cryptodev_deps,
app/test/test_cpu.c new file +37 -0
new file mode 100644
index 0000000000..40d8bd94eb
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Red Hat, Inc.
+ */
+
+#include <stdio.h>
+#include <inttypes.h>
+
+#include "eal_cpu.h"
+
+#include "test.h"
+
+static int
+test_cpu(void)
+{
+#ifndef RTE_ARCH_X86
+	RTE_TEST_ASSERT(!rte_cpu_is_x86(), "rte_cpu_is_x86() returned true on " RTE_STR(RTE_ARCH));
+#else
+	const char *vendor;
+
+	RTE_TEST_ASSERT(rte_cpu_is_x86(), "rte_cpu_is_x86() returned false");
+
+	if (rte_cpu_x86_is_amd())
+		vendor = "AMD";
+	else if (rte_cpu_x86_is_intel())
+		vendor = "Intel";
+	else
+		vendor = "unknown";
+
+	printf("The processor running this program is a x86 %s processor, brand=0x%"
+		PRIx8", family=0x%"PRIx8", model=0x%"PRIx8"\n", vendor, rte_cpu_x86_brand(),
+		rte_cpu_x86_family(), rte_cpu_x86_model());
+#endif
+
+	return TEST_SUCCESS;
+}
+
+REGISTER_FAST_TEST(cpu_autotest, true, true, test_cpu);
lib/eal/common/eal_common_cpu.c new file +21 -0
new file mode 100644
index 0000000000..18cdb27f75
@@ -0,0 +1,141 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Red Hat, Inc.
+ */
+
+#include <rte_debug.h>
+
+#include "eal_cpu.h"
+
+#ifdef RTE_ARCH_X86
+#ifndef RTE_TOOLCHAIN_MSVC
+#include <cpuid.h>
+#endif
+
+static void
+x86_cpuid(uint32_t leaf, uint32_t subleaf, uint32_t *eax, uint32_t *ebx,
+	uint32_t *ecx, uint32_t *edx)
+{
+	uint32_t regs[4] = { 0 };
+
+#ifdef RTE_TOOLCHAIN_MSVC
+	__cpuidex(regs, leaf, subleaf);

lib/eal/common/eal_common_cpu.c line 31

Quoted 10 lines
lib/eal/common/eal_common_cpu.c new file +10 -0
+#else
+	__cpuid_count(leaf, subleaf, regs[0], regs[1], regs[2], regs[3]);
+#endif
+
+	*eax = regs[0];
+	*ebx = regs[1];
+	*ecx = regs[2];
+	*edx = regs[3];
+}
+#endif /* RTE_ARCH_X86 */

From a readability perspective, I think it would be better to expand the scope of this ifdef and have two copies of each function in the file, rather than a single copy of each with #ifdefs. WDYT?

/Bruce

#3 lore raw

Re: [PATCH 1/2] eal: introduce x86 processor identification

Quoted 127 lines · Bruce Richardson
Quoted 125 lines · David Marchand

In some really specific cases, it may be needed to get a detailed information on the processor running a DPDK application for drivers to achieve better performance, or for matters that concern only them.

Those information are highly arch-specific and require a specific API.

Introduce a set of functions to get brand, family and model of a x86 processor.
Those functions do not make sense on other arches and a driver must first check rte_cpu_is_x86() before anything else.

---
 MAINTAINERS                     |   1 +
 app/test/meson.build            |   1 +
 app/test/test_cpu.c             |  37 +++++++++
 lib/eal/common/eal_common_cpu.c | 141 ++++++++++++++++++++++++++++++++
 lib/eal/common/eal_cpu.h        |  77 +++++++++++++++++
 lib/eal/common/meson.build      |   1 +
 lib/eal/version.map             |   6 ++
 7 files changed, 264 insertions(+)
 create mode 100644 app/test/test_cpu.c
 create mode 100644 lib/eal/common/eal_common_cpu.c
 create mode 100644 lib/eal/common/eal_cpu.h
MAINTAINERS +1 -0
index 698608cdb2..b87d47a1e4 100644
@@ -158,6 +158,7 @@ F: app/test/test_barrier.c
 F: app/test/test_bitcount.c
 F: app/test/test_byteorder.c
 F: app/test/test_common.c
+F: app/test/test_cpu.c
 F: app/test/test_cpuflags.c
 F: app/test/test_cycles.c
 F: app/test/test_debug.c
app/test/meson.build +1 -0
index 05bae9216d..4b37ad02fa 100644
@@ -44,6 +44,7 @@ source_file_deps = {
     'test_cmdline_string.c': [],
     'test_common.c': [],
     'test_compressdev.c': ['compressdev'],
+    'test_cpu.c': [],
     'test_cpuflags.c': [],
     'test_crc.c': ['net'],
     'test_cryptodev.c': test_cryptodev_deps,
app/test/test_cpu.c new file +37 -0
new file mode 100644
index 0000000000..40d8bd94eb
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Red Hat, Inc.
+ */
+
+#include <stdio.h>
+#include <inttypes.h>
+
+#include "eal_cpu.h"
+
+#include "test.h"
+
+static int
+test_cpu(void)
+{
+#ifndef RTE_ARCH_X86
+     RTE_TEST_ASSERT(!rte_cpu_is_x86(), "rte_cpu_is_x86() returned true on " RTE_STR(RTE_ARCH));
+#else
+     const char *vendor;
+
+     RTE_TEST_ASSERT(rte_cpu_is_x86(), "rte_cpu_is_x86() returned false");
+
+     if (rte_cpu_x86_is_amd())
+             vendor = "AMD";
+     else if (rte_cpu_x86_is_intel())
+             vendor = "Intel";
+     else
+             vendor = "unknown";
+
+     printf("The processor running this program is a x86 %s processor, brand=0x%"
+             PRIx8", family=0x%"PRIx8", model=0x%"PRIx8"\n", vendor, rte_cpu_x86_brand(),
+             rte_cpu_x86_family(), rte_cpu_x86_model());
+#endif
+
+     return TEST_SUCCESS;
+}
+
+REGISTER_FAST_TEST(cpu_autotest, true, true, test_cpu);
lib/eal/common/eal_common_cpu.c new file +27 -0
new file mode 100644
index 0000000000..18cdb27f75
@@ -0,0 +1,141 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Red Hat, Inc.
+ */
+
+#include <rte_debug.h>
+
+#include "eal_cpu.h"
+
+#ifdef RTE_ARCH_X86
+#ifndef RTE_TOOLCHAIN_MSVC
+#include <cpuid.h>
+#endif
+
+static void
+x86_cpuid(uint32_t leaf, uint32_t subleaf, uint32_t *eax, uint32_t *ebx,
+     uint32_t *ecx, uint32_t *edx)
+{
+     uint32_t regs[4] = { 0 };
+
+#ifdef RTE_TOOLCHAIN_MSVC
+     __cpuidex(regs, leaf, subleaf);
+#else
+     __cpuid_count(leaf, subleaf, regs[0], regs[1], regs[2], regs[3]);
+#endif
+
+     *eax = regs[0];
+     *ebx = regs[1];
Quoted 8 lines

lib/eal/common/eal_common_cpu.c line 31

Quoted 4 lines
lib/eal/common/eal_common_cpu.c new file +4 -0
+     *ecx = regs[2];
+     *edx = regs[3];
+}
+#endif /* RTE_ARCH_X86 */

From a readability perspective, I think it would be better to expand the scope of this ifdef and have two copies of each function in the file, rather than a single copy of each with #ifdefs. WDYT?

I can have a try later, but if you want to take over the series, I don't mind :-).

Signature · 1 line
David Marchand
#4 lore raw

Re: [PATCH 1/2] eal: introduce x86 processor identification

In reply to David Marchand
Quoted 6 lines · David Marchand

In some really specific cases, it may be needed to get a detailed information on the processor running a DPDK application for drivers to achieve better performance, or for matters that concern only them.

Those information are highly arch-specific and require a specific API.

Quoted 7 lines

Introduce a set of functions to get brand, family and model of a x86 processor.
Those functions do not make sense on other arches and a driver must first check rte_cpu_is_x86() before anything else.

---

Couple of thoughts, having had a few minutes to process this.

* Rather than rte_cpu_is_x86() API, we could go a general API called rte_cpu_arch() which returns either a string, or an enum value. Within that, rather than #ifdefs, the actual return value could just be a define placed by meson in the rte_build_config.h file. The list of families according to meson are [1] - we'd just need to merge the 32 and 64-bit variants into one in the meson file.

* Similarly rather than having is_intel or is_amd functions, we could generalize to a "manufacturer" API, which could be applicable for other architectures too.

/Bruce

[1] https://mesonbuild.com/Reference-tables.html#cpu-families

#5 lore raw

Re: [PATCH 1/2] eal: introduce x86 processor identification

Quoted 15 lines · Bruce Richardson
Quoted 6 lines · David Marchand

In some really specific cases, it may be needed to get a detailed information on the processor running a DPDK application for drivers to achieve better performance, or for matters that concern only them.

Those information are highly arch-specific and require a specific API.

Quoted 7 lines

Introduce a set of functions to get brand, family and model of a x86 processor.
Those functions do not make sense on other arches and a driver must first check rte_cpu_is_x86() before anything else.

---

Quoted 9 lines

Couple of thoughts, having had a few minutes to process this.

* Rather than rte_cpu_is_x86() API, we could go a general API called rte_cpu_arch() which returns either a string, or an enum value. Within that, rather than #ifdefs, the actual return value could just be a define placed by meson in the rte_build_config.h file. The list of families according to meson are [1] - we'd just need to merge the 32 and 64-bit variants into one in the meson file.

We already have the architecture family in meson computed as the "arch_subdir". Exposing that to the C code and wrapping as EAL function might look like below (adding to eal.h for convenience).

Thoughts?
/Bruce

lib/eal/include/rte_eal.h +18 -0
index 53c4a5519e..39f65d0e0c 100644
@@ -517,6 +517,24 @@ __rte_internal
 int
 rte_eal_parse_coremask(const char *coremask, int *cores);
 
+enum rte_arch_family {
+       rte_cpu_arch_arm,
+       rte_cpu_arch_loongarch,
+       rte_cpu_arch_ppc,
+       rte_cpu_arch_riscv,
+       rte_cpu_arch_x86,
+};
+
+/**
+ * Return the architecture family of the current CPU
+ */
+static inline enum rte_arch_family
+rte_eal_get_arch_family(void)
+{
+       /* take value from build config set by meson */
+       return RTE_ARCH_FAMILY;
+}
+
 #ifdef __cplusplus
 }
 #endif
meson.build +1 -0
index 2e6e546d20..45e22daeb1 100644
@@ -63,6 +63,7 @@ elif host_machine.cpu_family().startswith('ppc')
 elif host_machine.cpu_family().startswith('riscv')
     arch_subdir = 'riscv'
 endif
+dpdk_conf.set('RTE_ARCH_FAMILY', 'rte_cpu_arch_' + arch_subdir)
 
 # configure the build, and make sure configs here and in config folder are
 # able to be included in any file. We also store a global array of include dirs
#6 lore raw

Re: [PATCH 1/2] eal: introduce x86 processor identification

In reply to Bruce Richardson
Quoted 16 lines · Bruce Richardson
Quoted 6 lines · David Marchand

In some really specific cases, it may be needed to get a detailed information on the processor running a DPDK application for drivers to achieve better performance, or for matters that concern only them.

Those information are highly arch-specific and require a specific API.

Quoted 7 lines

Introduce a set of functions to get brand, family and model of a x86 processor.
Those functions do not make sense on other arches and a driver must first check rte_cpu_is_x86() before anything else.

---

Quoted 8 lines

Couple of thoughts, having had a few minutes to process this.

* Rather than rte_cpu_is_x86() API, we could go a general API called rte_cpu_arch() which returns either a string, or an enum value. Within that, rather than #ifdefs, the actual return value could just be a define placed by meson in the rte_build_config.h file. The list of families according to meson are [1] - we'd just need to merge the 32 and 64-bit variants into one in the meson file.

Your proposal (in next mail) lgtm.

Quoted 4 lines

* Similarly rather than having is_intel or is_amd functions, we could generalize to a "manufacturer" API, which could be applicable for other architectures too.

Like a rte_cpu_x86_manufacturer() ? which returns an enum too I suppose.

Signature · 1 line
David Marchand
#7 lore raw

Re: [PATCH 1/2] eal: introduce x86 processor identification

Quoted 31 lines · David Marchand
Quoted 16 lines · Bruce Richardson
Quoted 6 lines · David Marchand

In some really specific cases, it may be needed to get a detailed information on the processor running a DPDK application for drivers to achieve better performance, or for matters that concern only them.

Those information are highly arch-specific and require a specific API.

Quoted 7 lines

Introduce a set of functions to get brand, family and model of a x86 processor.
Those functions do not make sense on other arches and a driver must first check rte_cpu_is_x86() before anything else.

---

Quoted 8 lines

Couple of thoughts, having had a few minutes to process this.

* Rather than rte_cpu_is_x86() API, we could go a general API called rte_cpu_arch() which returns either a string, or an enum value. Within that, rather than #ifdefs, the actual return value could just be a define placed by meson in the rte_build_config.h file. The list of families according to meson are [1] - we'd just need to merge the 32 and 64-bit variants into one in the meson file.

Your proposal (in next mail) lgtm.

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

* Similarly rather than having is_intel or is_amd functions, we could generalize to a "manufacturer" API, which could be applicable for other architectures too.

Like a rte_cpu_x86_manufacturer() ? which returns an enum too I suppose.

I was actually thinking a more general "rte_cpu_manufacturer()" which returns string, and therefore could be implemented by all architectures. Could default to NULL or string "unknown" if not implemented.

/Bruce

#8 lore raw

RE: [PATCH 1/2] eal: introduce x86 processor identification

Quoted 40 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 25 September 2023 12.16

Quoted 15 lines · David Marchand
Quoted 13 lines · Bruce Richardson
Quoted 11 lines · David Marchand

In some really specific cases, it may be needed to get a detailed information on the processor running a DPDK application for drivers to achieve better performance, or for matters that concern only them.

Those information are highly arch-specific and require a specific API.

Introduce a set of functions to get brand, family and model of a x86 processor.
Those functions do not make sense on other arches and a driver must first check rte_cpu_is_x86() before anything else.

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

---

Couple of thoughts, having had a few minutes to process this.

* Rather than rte_cpu_is_x86() API, we could go a general API called rte_cpu_arch() which returns either a string, or an enum value. Within that, rather than #ifdefs, the actual return value could just be a

define

Quoted 12 lines
Quoted 3 lines

placed by meson in the rte_build_config.h file. The list of families according to meson are [1] - we'd just need to merge the 32 and 64-bit variants into one in the meson file.

Your proposal (in next mail) lgtm.

Quoted 4 lines

* Similarly rather than having is_intel or is_amd functions, we could generalize to a "manufacturer" API, which could be applicable for other architectures too.

Quoted 7 lines
Quoted 2 lines

Like a rte_cpu_x86_manufacturer() ? which returns an enum too I suppose.

I was actually thinking a more general "rte_cpu_manufacturer()" which returns string, and therefore could be implemented by all architectures. Could default to NULL or string "unknown" if not implemented.

/Bruce

Please stop to think about this!

Nobody cares who manufactured the CPU. E.g. is it Cavium or Marvell... some vendors might have multiple series of CPUs with different features, e.g. from companies they have bought up.

What you are looking for are some sort of "capabilities" APIs, so you can query what the CPU offers. In this context, the CPU is just a device, like any other device. E.g. the ethdev has a bunch of "capabilities" APIs, where you can query for specific features, maximum number of queues, descriptors, and a lot more.

#9 lore raw

PATCH 2/2 common/mlx5: use EAL x86 processor identification

In reply to David Marchand

Rather than use an ugly asm thing, use newly introduced EAL x86 API.

---
 drivers/common/mlx5/mlx5_common.c | 81 ++++++++-----------------------
 1 file changed, 21 insertions(+), 60 deletions(-)
drivers/common/mlx5/mlx5_common.c +21 -60
index 0ad14a48c7..99adcd960e 100644
@@ -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;
 }
Signature · 1 line
2.41.0