[v3] eal/linux: verify mmu type for DPDK support (ppc64le)

Message ID 20231024174315.318408-1-drc@linux.vnet.ibm.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v3] eal/linux: verify mmu type for DPDK support (ppc64le) |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS

Commit Message

David Christensen Oct. 24, 2023, 5:43 p.m. UTC
  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

--
2.39.1
  

Comments

Thomas Monjalon Nov. 6, 2023, 1:55 p.m. UTC | #1
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.
  

Patch

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;
+}