[PATCH] ppc64_cpu: Support partial SMT level through SYS FS smt/control files

0 views
Skip to first unread message

Tyrel Datwyler

<tyreld@linux.ibm.com>
unread,
Jan 31, 2024, 7:53:46 PMJan 31
to powerpc-utils-devel@googlegroups.com, Laurent Dufour
From: Laurent Dufour <ldu...@linux.ibm.com>

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....@linux.ibm.com/

Signed-off-by: Laurent Dufour <ldu...@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 5fdf86a14312..c33a293fef57 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.43.0

Reply all
Reply to author
Forward
0 new messages