DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] eal/linux: verify mmu type for DPDK support (ppc64le)
@ 2023-10-10 22:51 David Christensen
  2023-10-17 12:39 ` Thomas Monjalon
  2023-10-23 23:19 ` [PATCH v2] eal/linux: " David Christensen
  0 siblings, 2 replies; 9+ messages in thread
From: David Christensen @ 2023-10-10 22:51 UTC (permalink / raw)
  To: thomas; +Cc: dev, David Christensen

IBM POWER systems support more than one type of memory management unit
(MMU).  The Power ISA 3.0 specification, which applies to P9 and later
CPUs, defined a new Radix MMU which, among other things, allows an
anonymous memory page mapping to be converted into a hugepage mapping
at a specific address. This is a required feature in DPDK so we need
to test the MMU type when POWER systems are used and provide a more
useful error message for the user when running on an unsupported
system.

Bugzilla ID: 1221
Suggested-by: Thomas Monjalon <thomas@monjalon.net>
Signed-off-by: David Christensen <drc@linux.vnet.ibm.com>
---
 lib/eal/linux/eal.c | 63 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 5f4b2fb0054a..1c546564fa9c 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -910,6 +910,62 @@ is_iommu_enabled(void)
 	return n > 2;
 }
 
+/*
+ * IBM POWER systems support more than one type of memory management unit (MMU).
+ * The Power ISA 3.0 specification, which applies to P9 and later CPUs, defined
+ * a new Radix MMU which, among other things, allows an anonymous memory page
+ * mapping to be converted into a hugepage mapping at a specific address. This
+ * is a required feature in DPDK so we need to test the MMU type when POWER
+ * systems are used.
+ */
+static bool
+is_mmu_supported(void)
+{
+#ifdef RTE_ARCH_PPC_64
+	static const char proc_cpuinfo[] = "/proc/cpuinfo";
+	static const char str_mmu[] = "MMU";
+	static const char str_radix[] = "Radix";
+	char buf[512];
+	char *ret = NULL;
+	FILE *f = fopen(proc_cpuinfo, "r");
+
+	if (f == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot open %s\n", proc_cpuinfo);
+		return false;
+	}
+
+	/*
+	 * Example "MMU" in /proc/cpuinfo:
+	 * ...
+	 * model	: 8335-GTW
+	 * machine	: PowerNV 8335-GTW
+	 * firmware	: OPAL
+	 * MMU		: Radix
+	 * ... or ...
+	 * model        : IBM,9009-22A
+	 * machine      : CHRP IBM,9009-22A
+	 * MMU          : Hash
+	 */
+	while (fgets(buf, sizeof(buf), f) != NULL) {
+		ret = strstr(buf, str_mmu);
+		if (ret == NULL)
+			continue;
+		ret += sizeof(str_mmu) - 1;
+		ret = strchr(ret, ':');
+		if (ret == NULL)
+			continue;
+		ret = strstr(ret, str_radix);
+		break;
+	}
+	fclose(f);
+	if (ret == NULL)
+		rte_eal_init_alert("DPDK on PPC64 requires radix-mmu.");
+	return (ret != NULL);
+#else
+	return true;
+#endif
+}
+
 static __rte_noreturn void *
 eal_worker_thread_loop(void *arg)
 {
@@ -983,6 +1039,13 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	/* verify if mmu is supported */
+	if (!is_mmu_supported()) {
+		rte_eal_init_alert("unsupported mmu type.");
+		rte_errno = ENOTSUP;
+		return -1;
+	}
+
 	if (!__atomic_compare_exchange_n(&run_once, &has_run, 1, 0,
 					__ATOMIC_RELAXED, __ATOMIC_RELAXED)) {
 		rte_eal_init_alert("already called initialization.");
-- 
2.39.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] eal/linux: verify mmu type for DPDK support (ppc64le)
  2023-10-10 22:51 [PATCH] eal/linux: verify mmu type for DPDK support (ppc64le) David Christensen
@ 2023-10-17 12:39 ` Thomas Monjalon
  2023-10-23 21:59   ` David Christensen
  2023-10-23 23:19 ` [PATCH v2] eal/linux: " David Christensen
  1 sibling, 1 reply; 9+ messages in thread
From: Thomas Monjalon @ 2023-10-17 12:39 UTC (permalink / raw)
  To: David Christensen; +Cc: dev

11/10/2023 00:51, David Christensen:
> IBM POWER systems support more than one type of memory management unit
> (MMU).  The Power ISA 3.0 specification, which applies to P9 and later
> CPUs, defined a new Radix MMU which, among other things, allows an
> anonymous memory page mapping to be converted into a hugepage mapping
> at a specific address. This is a required feature in DPDK so we need
> to test the MMU type when POWER systems are used and provide a more
> useful error message for the user when running on an unsupported
> system.
> 
> Bugzilla ID: 1221
> Suggested-by: Thomas Monjalon <thomas@monjalon.net>
> Signed-off-by: David Christensen <drc@linux.vnet.ibm.com>
> ---
> --- a/lib/eal/linux/eal.c
> +++ b/lib/eal/linux/eal.c
> +/*
> + * IBM POWER systems support more than one type of memory management unit (MMU).
> + * The Power ISA 3.0 specification, which applies to P9 and later CPUs, defined
> + * a new Radix MMU which, among other things, allows an anonymous memory page
> + * mapping to be converted into a hugepage mapping at a specific address. This
> + * is a required feature in DPDK so we need to test the MMU type when POWER
> + * systems are used.
> + */
> +static bool
> +is_mmu_supported(void)
> +{
> +#ifdef RTE_ARCH_PPC_64
> +	static const char proc_cpuinfo[] = "/proc/cpuinfo";
> +	static const char str_mmu[] = "MMU";
> +	static const char str_radix[] = "Radix";
> +	char buf[512];
> +	char *ret = NULL;
> +	FILE *f = fopen(proc_cpuinfo, "r");
> +
> +	if (f == NULL) {
> +		RTE_LOG(ERR, EAL, "Cannot open %s\n", proc_cpuinfo);
> +		return false;
> +	}
> +
> +	/*
> +	 * Example "MMU" in /proc/cpuinfo:
> +	 * ...
> +	 * model	: 8335-GTW
> +	 * machine	: PowerNV 8335-GTW
> +	 * firmware	: OPAL
> +	 * MMU		: Radix
> +	 * ... or ...
> +	 * model        : IBM,9009-22A
> +	 * machine      : CHRP IBM,9009-22A
> +	 * MMU          : Hash
> +	 */
> +	while (fgets(buf, sizeof(buf), f) != NULL) {
> +		ret = strstr(buf, str_mmu);
> +		if (ret == NULL)
> +			continue;
> +		ret += sizeof(str_mmu) - 1;
> +		ret = strchr(ret, ':');
> +		if (ret == NULL)
> +			continue;
> +		ret = strstr(ret, str_radix);
> +		break;
> +	}
> +	fclose(f);
> +	if (ret == NULL)
> +		rte_eal_init_alert("DPDK on PPC64 requires radix-mmu.");
> +	return (ret != NULL);
> +#else
> +	return true;
> +#endif
> +}

I feel this function should not be implemented in the common EAL.
What about adding a new function in lib/eal/ppc/ ?
And add the "return true" for other architectures?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] eal/linux: verify mmu type for DPDK support (ppc64le)
  2023-10-17 12:39 ` Thomas Monjalon
@ 2023-10-23 21:59   ` David Christensen
  2023-11-06 13:54     ` Thomas Monjalon
  0 siblings, 1 reply; 9+ messages in thread
From: David Christensen @ 2023-10-23 21:59 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev



On 10/17/23 5:39 AM, Thomas Monjalon wrote:
> I feel this function should not be implemented in the common EAL.
> What about adding a new function in lib/eal/ppc/ ?
> And add the "return true" for other architectures?

Would it be more appropriate in the lib/eal/common level or 
lib/eal/linux only?  I would expect the MMU requirement should apply to 
FreeBSD on ppc64le as well but IBM doesn't support or test FreeBSD 
internally.

Dave

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2] eal/linux: eal/linux: verify mmu type for DPDK support (ppc64le)
  2023-10-10 22:51 [PATCH] eal/linux: verify mmu type for DPDK support (ppc64le) David Christensen
  2023-10-17 12:39 ` Thomas Monjalon
@ 2023-10-23 23:19 ` David Christensen
  2023-10-24  2:02   ` David Christensen
  2023-10-24 17:43   ` [PATCH v3] " David Christensen
  1 sibling, 2 replies; 9+ messages in thread
From: David Christensen @ 2023-10-23 23:19 UTC (permalink / raw)
  To: thomas, Ruifeng Wang, Min Zhou, David Christensen,
	Stanislaw Kardach, Bruce Richardson, Konstantin Ananyev
  Cc: dev

IBM POWER systems support more than one type of memory management unit
(MMU).  The Power ISA 3.0 specification, which applies to P9 and later
CPUs, defined a new Radix MMU which, among other things, allows an
anonymous memory page mapping to be converted into a hugepage mapping
at a specific address. This is a required feature in DPDK so we need
to test the MMU type when POWER systems are used and provide a more
useful error message for the user when running on an unsupported
system.

Bugzilla ID: 1221

Suggested-by: Thomas Monjalon <thomas@monjalon.net>
Signed-off-by: David Christensen <drc@linux.vnet.ibm.com>
---
v2:
 * Replace ifdef with arch specific functions

 lib/eal/arm/meson.build       |  1 +
 lib/eal/arm/rte_mmu.c         | 11 ++++++++
 lib/eal/common/eal_private.h  |  7 +++++
 lib/eal/linux/eal.c           |  7 +++++
 lib/eal/loongarch/meson.build |  1 +
 lib/eal/loongarch/rte_mmu.c   | 11 ++++++++
 lib/eal/ppc/meson.build       |  1 +
 lib/eal/ppc/rte_mmu.c         | 53 +++++++++++++++++++++++++++++++++++
 lib/eal/riscv/meson.build     |  1 +
 lib/eal/riscv/rte_mmu.c       | 11 ++++++++
 lib/eal/x86/meson.build       |  1 +
 lib/eal/x86/rte_mmu.c         | 11 ++++++++
 12 files changed, 116 insertions(+)
 create mode 100644 lib/eal/arm/rte_mmu.c
 create mode 100644 lib/eal/loongarch/rte_mmu.c
 create mode 100644 lib/eal/ppc/rte_mmu.c
 create mode 100644 lib/eal/riscv/rte_mmu.c
 create mode 100644 lib/eal/x86/rte_mmu.c

diff --git a/lib/eal/arm/meson.build b/lib/eal/arm/meson.build
index dca1106aaeec..6fba3d6ba7b8 100644
--- a/lib/eal/arm/meson.build
+++ b/lib/eal/arm/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/arm/rte_mmu.c b/lib/eal/arm/rte_mmu.c
new file mode 100644
index 000000000000..f0002d9f89b1
--- /dev/null
+++ b/lib/eal/arm/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include "eal_private.h"
+
+bool
+eal_mmu_supported_arch(void)
+{
+	return true;
+}
diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h
index ebd496b537cf..7d84adb5b328 100644
--- a/lib/eal/common/eal_private.h
+++ b/lib/eal/common/eal_private.h
@@ -354,6 +354,13 @@ unsigned eal_cpu_core_id(unsigned lcore_id);
  */
 int eal_cpu_detected(unsigned lcore_id);

+/**
+ * Check for architecture supported MMU.
+ *
+ * This function is private to the EAL.
+ */
+bool eal_mmu_supported_arch(void);
+
 /**
  * Set TSC frequency from precise value or estimation
  *
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 5f4b2fb0054a..26333934de0b 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -983,6 +983,13 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}

+	/* verify if DPDK supported on architecture MMU */
+	if (!eal_mmu_supported_arch()) {
+		rte_eal_init_alert("unsupported MMU type.");
+		rte_errno = ENOTSUP;
+		return -1;
+	}
+
 	if (!__atomic_compare_exchange_n(&run_once, &has_run, 1, 0,
 					__ATOMIC_RELAXED, __ATOMIC_RELAXED)) {
 		rte_eal_init_alert("already called initialization.");
diff --git a/lib/eal/loongarch/meson.build b/lib/eal/loongarch/meson.build
index 4dcc27babb9b..3acfe6c3bd77 100644
--- a/lib/eal/loongarch/meson.build
+++ b/lib/eal/loongarch/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/loongarch/rte_mmu.c b/lib/eal/loongarch/rte_mmu.c
new file mode 100644
index 000000000000..f0002d9f89b1
--- /dev/null
+++ b/lib/eal/loongarch/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include "eal_private.h"
+
+bool
+eal_mmu_supported_arch(void)
+{
+	return true;
+}
diff --git a/lib/eal/ppc/meson.build b/lib/eal/ppc/meson.build
index 71c7ac870da6..eeeaeee240b7 100644
--- a/lib/eal/ppc/meson.build
+++ b/lib/eal/ppc/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/ppc/rte_mmu.c b/lib/eal/ppc/rte_mmu.c
new file mode 100644
index 000000000000..017a8768bce3
--- /dev/null
+++ b/lib/eal/ppc/rte_mmu.c
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include "rte_log.h"
+#include "eal_private.h"
+
+bool
+eal_mmu_supported_arch(void)
+{
+	static const char proc_cpuinfo[] = "/proc/cpuinfo";
+	static const char str_mmu[] = "MMU";
+	static const char str_radix[] = "Radix";
+	static const char err_msg[] = "DPDK on PPC64 requires radix-mmu";
+	char buf[512];
+	char *ret = NULL;
+	FILE *f = fopen(proc_cpuinfo, "r");
+
+	if (f == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot open %s\n", proc_cpuinfo);
+		return false;
+	}
+
+	/*
+	 * Example "MMU" in /proc/cpuinfo:
+	 * ...
+	 * model	: 8335-GTW
+	 * machine	: PowerNV 8335-GTW
+	 * firmware	: OPAL
+	 * MMU		: Radix
+	 * ... or ...
+	 * model        : IBM,9009-22A
+	 * machine      : CHRP IBM,9009-22A
+	 * MMU          : Hash
+	 */
+	while (fgets(buf, sizeof(buf), f) != NULL) {
+		ret = strstr(buf, str_mmu);
+		if (ret == NULL)
+			continue;
+		ret += sizeof(str_mmu) - 1;
+		ret = strchr(ret, ':');
+		if (ret == NULL)
+			continue;
+		ret = strstr(ret, str_radix);
+		break;
+	}
+	fclose(f);
+	if (ret == NULL) {
+		fprintf(stderr, "EAL: FATAL: %s\n", err_msg);
+		RTE_LOG(ERR, EAL, "%s\n", err_msg);
+	}
+	return (ret != NULL);
+}
diff --git a/lib/eal/riscv/meson.build b/lib/eal/riscv/meson.build
index dca1106aaeec..6fba3d6ba7b8 100644
--- a/lib/eal/riscv/meson.build
+++ b/lib/eal/riscv/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/riscv/rte_mmu.c b/lib/eal/riscv/rte_mmu.c
new file mode 100644
index 000000000000..f0002d9f89b1
--- /dev/null
+++ b/lib/eal/riscv/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include "eal_private.h"
+
+bool
+eal_mmu_supported_arch(void)
+{
+	return true;
+}
diff --git a/lib/eal/x86/meson.build b/lib/eal/x86/meson.build
index d33a240e1a98..e08dffa13dcc 100644
--- a/lib/eal/x86/meson.build
+++ b/lib/eal/x86/meson.build
@@ -7,6 +7,7 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_spinlock.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/x86/rte_mmu.c b/lib/eal/x86/rte_mmu.c
new file mode 100644
index 000000000000..f0002d9f89b1
--- /dev/null
+++ b/lib/eal/x86/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include "eal_private.h"
+
+bool
+eal_mmu_supported_arch(void)
+{
+	return true;
+}
--
2.39.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2] eal/linux: eal/linux: verify mmu type for DPDK support (ppc64le)
  2023-10-23 23:19 ` [PATCH v2] eal/linux: " David Christensen
@ 2023-10-24  2:02   ` David Christensen
  2023-10-24 17:43   ` [PATCH v3] " David Christensen
  1 sibling, 0 replies; 9+ messages in thread
From: David Christensen @ 2023-10-24  2:02 UTC (permalink / raw)
  To: thomas, Ruifeng Wang, Min Zhou, Stanislaw Kardach,
	Bruce Richardson, Konstantin Ananyev
  Cc: dev



On 10/23/23 4:19 PM, David Christensen wrote:

> diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h
> index ebd496b537cf..7d84adb5b328 100644
> --- a/lib/eal/common/eal_private.h
> +++ b/lib/eal/common/eal_private.h
> @@ -354,6 +354,13 @@ unsigned eal_cpu_core_id(unsigned lcore_id);
>    */
>   int eal_cpu_detected(unsigned lcore_id);
> 
> +/**
> + * Check for architecture supported MMU.
> + *
> + * This function is private to the EAL.
> + */
> +bool eal_mmu_supported_arch(void);
> +
...
> diff --git a/lib/eal/ppc/rte_mmu.c b/lib/eal/ppc/rte_mmu.c
> new file mode 100644
> index 000000000000..017a8768bce3
> --- /dev/null
> +++ b/lib/eal/ppc/rte_mmu.c
> @@ -0,0 +1,53 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright (C) IBM Corporation 2023
> + */
> +
> +#include "rte_log.h"
> +#include "eal_private.h"
> +
> +bool
> +eal_mmu_supported_arch(void)
> +{
> +	static const char proc_cpuinfo[] = "/proc/cpuinfo";

Belatedly recognized that I'd implemented an OS specific detection 
mechanism for a function in the "common" library.  I'll resubmit a v3 
under the "linux" subtree shortly.

Dave

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v3] eal/linux: verify mmu type for DPDK support (ppc64le)
  2023-10-23 23:19 ` [PATCH v2] eal/linux: " David Christensen
  2023-10-24  2:02   ` David Christensen
@ 2023-10-24 17:43   ` David Christensen
  2023-11-06 13:55     ` Thomas Monjalon
  2023-11-30 19:18     ` [PATCH v4] eal: " David Christensen
  1 sibling, 2 replies; 9+ messages in thread
From: David Christensen @ 2023-10-24 17:43 UTC (permalink / raw)
  To: thomas, Ruifeng Wang, Min Zhou, David Christensen,
	Stanislaw Kardach, Bruce Richardson, Konstantin Ananyev
  Cc: dev

IBM POWER systems support more than one type of memory management unit
(MMU).  The Power ISA 3.0 specification, which applies to P9 and later
CPUs, defined a new Radix MMU which, among other things, allows an
anonymous memory page mapping to be converted into a hugepage mapping
at a specific address. This is a required feature in DPDK so we need
to test the MMU type when POWER systems are used and provide a more
useful error message for the user when running on an unsupported
system.

Bugzilla ID: 1221

Suggested-by: Thomas Monjalon <thomas@monjalon.net>
Signed-off-by: David Christensen <drc@linux.vnet.ibm.com>
---
v3:
 * Move test function from "common" tree to "linux"
v2:
 * Replace ifdef with arch specific functions
---
 lib/eal/arm/meson.build           |  1 +
 lib/eal/arm/rte_mmu.c             | 11 ++++++
 lib/eal/linux/eal.c               |  8 +++++
 lib/eal/linux/eal_linux_private.h | 17 ++++++++++
 lib/eal/loongarch/meson.build     |  1 +
 lib/eal/loongarch/rte_mmu.c       | 11 ++++++
 lib/eal/ppc/meson.build           |  1 +
 lib/eal/ppc/rte_mmu.c             | 56 +++++++++++++++++++++++++++++++
 lib/eal/riscv/meson.build         |  1 +
 lib/eal/riscv/rte_mmu.c           | 11 ++++++
 lib/eal/x86/meson.build           |  1 +
 lib/eal/x86/rte_mmu.c             | 11 ++++++
 12 files changed, 130 insertions(+)
 create mode 100644 lib/eal/arm/rte_mmu.c
 create mode 100644 lib/eal/linux/eal_linux_private.h
 create mode 100644 lib/eal/loongarch/rte_mmu.c
 create mode 100644 lib/eal/ppc/rte_mmu.c
 create mode 100644 lib/eal/riscv/rte_mmu.c
 create mode 100644 lib/eal/x86/rte_mmu.c

diff --git a/lib/eal/arm/meson.build b/lib/eal/arm/meson.build
index dca1106aaeec..6fba3d6ba7b8 100644
--- a/lib/eal/arm/meson.build
+++ b/lib/eal/arm/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/arm/rte_mmu.c b/lib/eal/arm/rte_mmu.c
new file mode 100644
index 000000000000..3c043be10236
--- /dev/null
+++ b/lib/eal/arm/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include <linux/eal_linux_private.h>
+
+bool
+eal_mmu_supported_linux_arch(void)
+{
+	return true;
+}
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 5f4b2fb0054a..6f838265b15b 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -44,6 +44,7 @@

 #include <telemetry_internal.h>
 #include "eal_private.h"
+#include "eal_linux_private.h"
 #include "eal_thread.h"
 #include "eal_internal_cfg.h"
 #include "eal_filesystem.h"
@@ -983,6 +984,13 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}

+	/* verify if DPDK supported on architecture MMU */
+	if (!eal_mmu_supported_linux_arch()) {
+		rte_eal_init_alert("unsupported MMU type.");
+		rte_errno = ENOTSUP;
+		return -1;
+	}
+
 	if (!__atomic_compare_exchange_n(&run_once, &has_run, 1, 0,
 					__ATOMIC_RELAXED, __ATOMIC_RELAXED)) {
 		rte_eal_init_alert("already called initialization.");
diff --git a/lib/eal/linux/eal_linux_private.h b/lib/eal/linux/eal_linux_private.h
new file mode 100644
index 000000000000..b7eaac922849
--- /dev/null
+++ b/lib/eal/linux/eal_linux_private.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 IBM Corporation
+ */
+
+#ifndef _EAL_LINUX_PRIVATE_H_
+#define _EAL_LINUX_PRIVATE_H_
+
+#include <stdbool.h>
+
+/**
+ * Check for architecture supported MMU.
+ *
+ * This function is private to the EAL for Linux.
+ */
+bool eal_mmu_supported_linux_arch(void);
+
+#endif /* _EAL_LINUX_PRIVATE_H_ */
diff --git a/lib/eal/loongarch/meson.build b/lib/eal/loongarch/meson.build
index 4dcc27babb9b..3acfe6c3bd77 100644
--- a/lib/eal/loongarch/meson.build
+++ b/lib/eal/loongarch/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/loongarch/rte_mmu.c b/lib/eal/loongarch/rte_mmu.c
new file mode 100644
index 000000000000..3c043be10236
--- /dev/null
+++ b/lib/eal/loongarch/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include <linux/eal_linux_private.h>
+
+bool
+eal_mmu_supported_linux_arch(void)
+{
+	return true;
+}
diff --git a/lib/eal/ppc/meson.build b/lib/eal/ppc/meson.build
index 71c7ac870da6..eeeaeee240b7 100644
--- a/lib/eal/ppc/meson.build
+++ b/lib/eal/ppc/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/ppc/rte_mmu.c b/lib/eal/ppc/rte_mmu.c
new file mode 100644
index 000000000000..fd762defd72d
--- /dev/null
+++ b/lib/eal/ppc/rte_mmu.c
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include "stdio.h"
+#include "string.h"
+#include "rte_log.h"
+#include <linux/eal_linux_private.h>
+
+bool
+eal_mmu_supported_linux_arch(void)
+{
+	static const char proc_cpuinfo[] = "/proc/cpuinfo";
+	static const char str_mmu[] = "MMU";
+	static const char str_radix[] = "Radix";
+	static const char err_msg[] = "DPDK on PPC64 requires radix-mmu";
+	char buf[512];
+	char *ret = NULL;
+	FILE *f = fopen(proc_cpuinfo, "r");
+
+	if (f == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot open %s\n", proc_cpuinfo);
+		return false;
+	}
+
+	/*
+	 * Example "MMU" in /proc/cpuinfo:
+	 * ...
+	 * model	: 8335-GTW
+	 * machine	: PowerNV 8335-GTW
+	 * firmware	: OPAL
+	 * MMU		: Radix
+	 * ... or ...
+	 * model        : IBM,9009-22A
+	 * machine      : CHRP IBM,9009-22A
+	 * MMU          : Hash
+	 */
+	while (fgets(buf, sizeof(buf), f) != NULL) {
+		ret = strstr(buf, str_mmu);
+		if (ret == NULL)
+			continue;
+		ret += sizeof(str_mmu) - 1;
+		ret = strchr(ret, ':');
+		if (ret == NULL)
+			continue;
+		ret = strstr(ret, str_radix);
+		break;
+	}
+	fclose(f);
+
+	if (ret == NULL) {
+		fprintf(stderr, "EAL: FATAL: %s\n", err_msg);
+		RTE_LOG(ERR, EAL, "%s\n", err_msg);
+	}
+	return (ret != NULL);
+}
diff --git a/lib/eal/riscv/meson.build b/lib/eal/riscv/meson.build
index dca1106aaeec..6fba3d6ba7b8 100644
--- a/lib/eal/riscv/meson.build
+++ b/lib/eal/riscv/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/riscv/rte_mmu.c b/lib/eal/riscv/rte_mmu.c
new file mode 100644
index 000000000000..3c043be10236
--- /dev/null
+++ b/lib/eal/riscv/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include <linux/eal_linux_private.h>
+
+bool
+eal_mmu_supported_linux_arch(void)
+{
+	return true;
+}
diff --git a/lib/eal/x86/meson.build b/lib/eal/x86/meson.build
index d33a240e1a98..e08dffa13dcc 100644
--- a/lib/eal/x86/meson.build
+++ b/lib/eal/x86/meson.build
@@ -7,6 +7,7 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_spinlock.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/x86/rte_mmu.c b/lib/eal/x86/rte_mmu.c
new file mode 100644
index 000000000000..3c043be10236
--- /dev/null
+++ b/lib/eal/x86/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include <linux/eal_linux_private.h>
+
+bool
+eal_mmu_supported_linux_arch(void)
+{
+	return true;
+}
--
2.39.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] eal/linux: verify mmu type for DPDK support (ppc64le)
  2023-10-23 21:59   ` David Christensen
@ 2023-11-06 13:54     ` Thomas Monjalon
  0 siblings, 0 replies; 9+ messages in thread
From: Thomas Monjalon @ 2023-11-06 13:54 UTC (permalink / raw)
  To: David Christensen; +Cc: dev

23/10/2023 23:59, David Christensen:
> 
> On 10/17/23 5:39 AM, Thomas Monjalon wrote:
> > I feel this function should not be implemented in the common EAL.
> > What about adding a new function in lib/eal/ppc/ ?
> > And add the "return true" for other architectures?
> 
> Would it be more appropriate in the lib/eal/common level or 
> lib/eal/linux only?  I would expect the MMU requirement should apply to 
> FreeBSD on ppc64le as well but IBM doesn't support or test FreeBSD 
> internally.

Even if you are not testing it, I don't think you should restrict
the code change to Linux.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v3] eal/linux: verify mmu type for DPDK support (ppc64le)
  2023-10-24 17:43   ` [PATCH v3] " David Christensen
@ 2023-11-06 13:55     ` Thomas Monjalon
  2023-11-30 19:18     ` [PATCH v4] eal: " David Christensen
  1 sibling, 0 replies; 9+ messages in thread
From: Thomas Monjalon @ 2023-11-06 13:55 UTC (permalink / raw)
  To: David Christensen
  Cc: Ruifeng Wang, Min Zhou, David Christensen, Stanislaw Kardach,
	Bruce Richardson, Konstantin Ananyev, dev

24/10/2023 19:43, David Christensen:
> IBM POWER systems support more than one type of memory management unit
> (MMU).  The Power ISA 3.0 specification, which applies to P9 and later
> CPUs, defined a new Radix MMU which, among other things, allows an
> anonymous memory page mapping to be converted into a hugepage mapping
> at a specific address. This is a required feature in DPDK so we need
> to test the MMU type when POWER systems are used and provide a more
> useful error message for the user when running on an unsupported
> system.
> 
> Bugzilla ID: 1221
> 
> Suggested-by: Thomas Monjalon <thomas@monjalon.net>
> Signed-off-by: David Christensen <drc@linux.vnet.ibm.com>
> ---
> --- a/lib/eal/linux/eal.c
> +++ b/lib/eal/linux/eal.c
> +	/* verify if DPDK supported on architecture MMU */
> +	if (!eal_mmu_supported_linux_arch()) {
> +		rte_eal_init_alert("unsupported MMU type.");
> +		rte_errno = ENOTSUP;
> +		return -1;
> +	}

I don't think we should restrict the MMU check to Linux.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v4] eal: verify mmu type for DPDK support (ppc64le)
  2023-10-24 17:43   ` [PATCH v3] " David Christensen
  2023-11-06 13:55     ` Thomas Monjalon
@ 2023-11-30 19:18     ` David Christensen
  1 sibling, 0 replies; 9+ messages in thread
From: David Christensen @ 2023-11-30 19:18 UTC (permalink / raw)
  To: thomas, Ruifeng Wang, Bruce Richardson, Min Zhou,
	David Christensen, Stanislaw Kardach, Konstantin Ananyev
  Cc: dev

IBM POWER systems support more than one type of memory management unit
(MMU).  The Power ISA 3.0 specification, which applies to P9 and later
CPUs, defined a new Radix MMU which, among other things, allows an
anonymous memory page mapping to be converted into a hugepage mapping
at a specific address. This is a required feature in DPDK so we need
to test the MMU type when POWER systems are used and provide a more
useful error message for the user when running on an unsupported
system.

All architectures other than ppc64le unconditionally report that the
MMU is supported.  When running with ppc64le on Linux, the MMU is
tested and the actual result is returned, while running with ppc64le
on FreeBSD unconditionally reports that the MMU is supported to avoid
unnecessary breakage until an actual test can be implemented for that
environment.

Bugzilla ID: 1221

Suggested-by: Thomas Monjalon <thomas@monjalon.net>
Signed-off-by: David Christensen <drc@linux.vnet.ibm.com>
---
 lib/eal/arm/meson.build       |  1 +
 lib/eal/arm/rte_mmu.c         | 11 ++++++
 lib/eal/common/eal_private.h  |  7 ++++
 lib/eal/freebsd/eal.c         |  7 ++++
 lib/eal/linux/eal.c           |  7 ++++
 lib/eal/loongarch/meson.build |  1 +
 lib/eal/loongarch/rte_mmu.c   | 11 ++++++
 lib/eal/ppc/meson.build       |  1 +
 lib/eal/ppc/rte_mmu.c         | 68 +++++++++++++++++++++++++++++++++++
 lib/eal/riscv/meson.build     |  1 +
 lib/eal/riscv/rte_mmu.c       | 11 ++++++
 lib/eal/x86/meson.build       |  1 +
 lib/eal/x86/rte_mmu.c         | 11 ++++++
 13 files changed, 138 insertions(+)
 create mode 100644 lib/eal/arm/rte_mmu.c
 create mode 100644 lib/eal/loongarch/rte_mmu.c
 create mode 100644 lib/eal/ppc/rte_mmu.c
 create mode 100644 lib/eal/riscv/rte_mmu.c
 create mode 100644 lib/eal/x86/rte_mmu.c

diff --git a/lib/eal/arm/meson.build b/lib/eal/arm/meson.build
index dca1106aaeec..6fba3d6ba7b8 100644
--- a/lib/eal/arm/meson.build
+++ b/lib/eal/arm/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/arm/rte_mmu.c b/lib/eal/arm/rte_mmu.c
new file mode 100644
index 000000000000..3d40bfde386a
--- /dev/null
+++ b/lib/eal/arm/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include "eal_private.h"
+
+bool
+eal_mmu_supported(void)
+{
+	return true;
+}
diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h
index 4d2e80661023..c001c917de1d 100644
--- a/lib/eal/common/eal_private.h
+++ b/lib/eal/common/eal_private.h
@@ -93,6 +93,13 @@ int rte_eal_memzone_init(void);
  */
 int rte_eal_cpu_init(void);
 
+/**
+ * Check for architecture supported MMU.
+ *
+ * This function is private to EAL.
+ */
+bool eal_mmu_supported(void);
+
 /**
  * Create memseg lists
  *
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 568e06e9ed91..0a6a9edc7213 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -597,6 +597,13 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	/* verify if DPDK supported on architecture MMU */
+	if (!eal_mmu_supported()) {
+		rte_eal_init_alert("unsupported MMU type.");
+		rte_errno = ENOTSUP;
+		return -1;
+	}
+
 	if (!rte_atomic_compare_exchange_strong_explicit(&run_once, &has_run, 1,
 					rte_memory_order_relaxed, rte_memory_order_relaxed)) {
 		rte_eal_init_alert("already called initialization.");
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 57da058cec60..b22c19ff0492 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -983,6 +983,13 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
+	/* verify if DPDK supported on architecture MMU */
+	if (!eal_mmu_supported()) {
+		rte_eal_init_alert("unsupported MMU type.");
+		rte_errno = ENOTSUP;
+		return -1;
+	}
+
 	if (!rte_atomic_compare_exchange_strong_explicit(&run_once, &has_run, 1,
 					rte_memory_order_relaxed, rte_memory_order_relaxed)) {
 		rte_eal_init_alert("already called initialization.");
diff --git a/lib/eal/loongarch/meson.build b/lib/eal/loongarch/meson.build
index 4dcc27babb9b..3acfe6c3bd77 100644
--- a/lib/eal/loongarch/meson.build
+++ b/lib/eal/loongarch/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/loongarch/rte_mmu.c b/lib/eal/loongarch/rte_mmu.c
new file mode 100644
index 000000000000..3d40bfde386a
--- /dev/null
+++ b/lib/eal/loongarch/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include "eal_private.h"
+
+bool
+eal_mmu_supported(void)
+{
+	return true;
+}
diff --git a/lib/eal/ppc/meson.build b/lib/eal/ppc/meson.build
index 71c7ac870da6..eeeaeee240b7 100644
--- a/lib/eal/ppc/meson.build
+++ b/lib/eal/ppc/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/ppc/rte_mmu.c b/lib/eal/ppc/rte_mmu.c
new file mode 100644
index 000000000000..2d090362e530
--- /dev/null
+++ b/lib/eal/ppc/rte_mmu.c
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include "stdio.h"
+#include "string.h"
+#include "rte_log.h"
+#include "eal_private.h"
+
+bool
+eal_mmu_supported(void)
+{
+#ifdef RTE_EXEC_ENV_LINUX
+	static const char proc_cpuinfo[] = "/proc/cpuinfo";
+	static const char str_mmu[] = "MMU";
+	static const char str_radix[] = "Radix";
+	static const char err_msg[] = "DPDK on PPC64 requires radix-mmu";
+	char buf[512];
+	char *ret = NULL;
+	FILE *f = fopen(proc_cpuinfo, "r");
+
+	if (f == NULL) {
+		RTE_LOG(ERR, EAL, "Cannot open %s\n", proc_cpuinfo);
+		return false;
+	}
+
+	/*
+	 * Example "MMU" in /proc/cpuinfo:
+	 * ...
+	 * model	: 8335-GTW
+	 * machine	: PowerNV 8335-GTW
+	 * firmware	: OPAL
+	 * MMU		: Radix
+	 * ... or ...
+	 * model        : IBM,9009-22A
+	 * machine      : CHRP IBM,9009-22A
+	 * MMU          : Hash
+	 */
+	while (fgets(buf, sizeof(buf), f) != NULL) {
+		ret = strstr(buf, str_mmu);
+		if (ret == NULL)
+			continue;
+		ret += sizeof(str_mmu) - 1;
+		ret = strchr(ret, ':');
+		if (ret == NULL)
+			continue;
+		ret = strstr(ret, str_radix);
+		break;
+	}
+	fclose(f);
+
+	if (ret == NULL) {
+		fprintf(stderr, "EAL: FATAL: %s\n", err_msg);
+		RTE_LOG(ERR, EAL, "%s\n", err_msg);
+	}
+	return (ret != NULL);
+#elif RTE_EXEC_ENV_FREEBSD
+	/*
+	 * Method to detect MMU type in FreeBSD not known
+	 * by this author.  Return true for now to emulate
+	 * previous behavior and avoid unnecessary failures.
+	 */
+	return true;
+#else
+	/* Force false for other execution environments */
+	return false;
+#endif
+}
diff --git a/lib/eal/riscv/meson.build b/lib/eal/riscv/meson.build
index dca1106aaeec..6fba3d6ba7b8 100644
--- a/lib/eal/riscv/meson.build
+++ b/lib/eal/riscv/meson.build
@@ -7,5 +7,6 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/riscv/rte_mmu.c b/lib/eal/riscv/rte_mmu.c
new file mode 100644
index 000000000000..3d40bfde386a
--- /dev/null
+++ b/lib/eal/riscv/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include "eal_private.h"
+
+bool
+eal_mmu_supported(void)
+{
+	return true;
+}
diff --git a/lib/eal/x86/meson.build b/lib/eal/x86/meson.build
index d33a240e1a98..e08dffa13dcc 100644
--- a/lib/eal/x86/meson.build
+++ b/lib/eal/x86/meson.build
@@ -7,6 +7,7 @@ sources += files(
         'rte_cpuflags.c',
         'rte_cycles.c',
         'rte_hypervisor.c',
+        'rte_mmu.c',
         'rte_spinlock.c',
         'rte_power_intrinsics.c',
 )
diff --git a/lib/eal/x86/rte_mmu.c b/lib/eal/x86/rte_mmu.c
new file mode 100644
index 000000000000..3d40bfde386a
--- /dev/null
+++ b/lib/eal/x86/rte_mmu.c
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C) IBM Corporation 2023
+ */
+
+#include "eal_private.h"
+
+bool
+eal_mmu_supported(void)
+{
+	return true;
+}
-- 
2.39.3


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-11-30 19:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-10 22:51 [PATCH] eal/linux: verify mmu type for DPDK support (ppc64le) David Christensen
2023-10-17 12:39 ` Thomas Monjalon
2023-10-23 21:59   ` David Christensen
2023-11-06 13:54     ` Thomas Monjalon
2023-10-23 23:19 ` [PATCH v2] eal/linux: " David Christensen
2023-10-24  2:02   ` David Christensen
2023-10-24 17:43   ` [PATCH v3] " David Christensen
2023-11-06 13:55     ` Thomas Monjalon
2023-11-30 19:18     ` [PATCH v4] eal: " David Christensen

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).