powerpc-utils/ppc64_cpu-Support-partial-SMT-level-through-SYS-FS-s.patch

72 lines
2.0 KiB
Diff

From 46c524be975a108d2b8d1cadb95003b9c2670c8e Mon Sep 17 00:00:00 2001
From: Laurent Dufour <ldufour@linux.ibm.com>
Date: Thu, 29 Jun 2023 16:41:37 +0200
Subject: [PATCH] ppc64_cpu: Support partial SMT level through SYS FS
smt/control files
The next kernel release will support partial SMT level [1] though the SYS
FS file "devices/system/cpu/smt/control". This allows the SMT level to be
recorded in the kernel. With the current SMT level stored in the kernel,
when a new CPU is added, only the necessary threads are brought online.
The legacy way to active threads through the SYS FS files
'devices/system/cpu/cpu<n>/online', is still used in the case the new SYS
FS API is not available. This allows compatibility with the previous kernel
versions.
[1] https://lore.kernel.org/linuxppc-dev/20230705145143.40545-1-ldufour@linux.ibm.com/
Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com>
---
src/ppc64_cpu.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/ppc64_cpu.c b/src/ppc64_cpu.c
index 5fdf86a..c33a293 100644
--- a/src/ppc64_cpu.c
+++ b/src/ppc64_cpu.c
@@ -56,6 +56,8 @@
#define DIAGNOSTICS_RUN_MODE 42
#define CPU_OFFLINE -1
+#define SYS_SMT_CONTROL "/sys/devices/system/cpu/smt/control"
+
#ifdef HAVE_LINUX_PERF_EVENT_H
struct cpu_freq {
int offline;
@@ -360,6 +362,20 @@ static int is_dscr_capable(void)
return 0;
}
+/*
+ * Depends on kernel's CONFIG_HOTPLUG_CPU
+ */
+static int set_smt_control(int smt_state)
+{
+ if (set_attribute(SYS_SMT_CONTROL, "%d", smt_state)) {
+ /* Silently ignore kernel not supporting this feature */
+ if (errno != ENODEV)
+ perror(SYS_SMT_CONTROL);
+ return -1;
+ }
+ return 0;
+}
+
static int do_smt(char *state, bool numeric)
{
int rc = 0;
@@ -388,7 +404,9 @@ static int do_smt(char *state, bool numeric)
return -1;
}
- rc = set_smt_state(smt_state);
+ /* Try using smt/control if failing, fall back to the legacy way */
+ if (set_smt_control(smt_state))
+ rc = set_smt_state(smt_state);
}
return rc;
--
2.41.0