From: Owen Hilyard <ohilyard@iol.unh.edu>
Sent: Wednesday, November 16, 2022 2:48 PM
To: Juraj Linkeš <juraj.linkes@pantheon.tech>
Cc: thomas@monjalon.net; Honnappa.Nagarahalli@arm.com; lijuan.tu@intel.com; bruce.richardson@intel.com; dev@dpdk.org
Subject: Re: [RFC PATCH v2 05/10] dts: add node memory setup

 

 

 

On Mon, Nov 14, 2022 at 11:54 AM Juraj Linkeš <juraj.linkes@pantheon.tech> wrote:

Setup hugepages on nodes. This is useful not only on SUT nodes, but
also on TG nodes which use TGs that utilize hugepages.

Signed-off-by: Juraj Linkeš <juraj.linkes@pantheon.tech>
---
 dts/framework/remote_session/__init__.py      |  1 +
 dts/framework/remote_session/arch/__init__.py | 20 +++++
 dts/framework/remote_session/arch/arch.py     | 57 +++++++++++++
 .../remote_session/os/linux_session.py        | 85 +++++++++++++++++++
 dts/framework/remote_session/os/os_session.py | 10 +++
 dts/framework/testbed_model/node/node.py      | 15 +++-
 6 files changed, 187 insertions(+), 1 deletion(-)
 create mode 100644 dts/framework/remote_session/arch/__init__.py
 create mode 100644 dts/framework/remote_session/arch/arch.py

diff --git a/dts/framework/remote_session/__init__.py b/dts/framework/remote_session/__init__.py
index f2339b20bd..f0deeadac6 100644
--- a/dts/framework/remote_session/__init__.py
+++ b/dts/framework/remote_session/__init__.py
@@ -11,4 +11,5 @@

 # pylama:ignore=W0611

+from .arch import Arch, create_arch
 from .os import OSSession, create_session
diff --git a/dts/framework/remote_session/arch/__init__.py b/dts/framework/remote_session/arch/__init__.py
new file mode 100644
index 0000000000..d78ad42ac5
--- /dev/null
+++ b/dts/framework/remote_session/arch/__init__.py
@@ -0,0 +1,20 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2022 PANTHEON.tech s.r.o.
+
+from framework.config import Architecture, NodeConfiguration
+
+from .arch import PPC64, Arch, Arm64, i686, x86_32, x86_64
+
+
+def create_arch(node_config: NodeConfiguration) -> Arch:
+    match node_config.arch:
+        case Architecture.x86_64:
+            return x86_64()
+        case Architecture.x86_32:
+            return x86_32()
+        case Architecture.i686:
+            return i686()
+        case Architecture.ppc64le:
+            return PPC64()
+        case Architecture.arm64:
+            return Arm64()
diff --git a/dts/framework/remote_session/arch/arch.py b/dts/framework/remote_session/arch/arch.py
new file mode 100644
index 0000000000..05c7602def
--- /dev/null
+++ b/dts/framework/remote_session/arch/arch.py
@@ -0,0 +1,57 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2022 PANTHEON.tech s.r.o.
+
+
+class Arch(object):
+    """
+    Stores architecture-specific information.
+    """
+
+    @property
+    def default_hugepage_memory(self) -> int:
+        """
+        Return the default amount of memory allocated for hugepages DPDK will use.
+        The default is an amount equal to 256 2MB hugepages (512MB memory).
+        """
+        return 256 * 2048
+
+    @property
+    def hugepage_force_first_numa(self) -> bool:
+        """
+        An architecture may need to force configuration of hugepages to first socket.
+        """
+        return False
+
+
+class x86_64(Arch):
+    @property
+    def default_hugepage_memory(self) -> int:
+        return 4096 * 2048
+
+
+class x86_32(Arch):
+    @property
+    def hugepage_force_first_numa(self) -> bool:
+        return True
+
+
+class i686(Arch):
+    @property
+    def default_hugepage_memory(self) -> int:
+        return 512 * 2048
+
+    @property
+    def hugepage_force_first_numa(self) -> bool:
+        return True
+
+
+class PPC64(Arch):
+    @property
+    def default_hugepage_memory(self) -> int:
+        return 512 * 2048
+
+
+class Arm64(Arch):
+    @property
+    def default_hugepage_memory(self) -> int:
+        return 2048 * 2048
diff --git a/dts/framework/remote_session/os/linux_session.py b/dts/framework/remote_session/os/linux_session.py
index 21f117b714..fad33d7613 100644
--- a/dts/framework/remote_session/os/linux_session.py
+++ b/dts/framework/remote_session/os/linux_session.py
@@ -3,6 +3,8 @@
 # Copyright(c) 2022 University of New Hampshire

 from framework.config import CPU
+from framework.exception import RemoteCommandExecutionError
+from framework.utils import expand_range

 from .posix_session import PosixSession

@@ -24,3 +26,86 @@ def get_remote_cpus(self, bypass_core0: bool) -> list[CPU]:
                 continue
             cpus.append(CPU(int(cpu), int(core), int(socket), int(node)))
         return cpus
+
+    def setup_hugepages(
+        self, hugepage_amount: int = -1, force_first_numa: bool = False

 

I think that hugepage_amount: int | None = None is better, since it expresses it is an optional argument and the type checker will force anyone using the value to check if it is none, whereas that will not happen with -1. 

 

This is actually a remnant from original DTS, where -1 meant use per-arch default. I've addressed this default elsewhere in the code, so I'll remove the default for this argument (making it mandatory).