[LTP] [PATCH v4 09/31] testcases: sysfs: Add sys_cpu_smt01
Cyril Hrubis
chrubis@suse.cz
Thu Aug 27 13:21:35 CEST 2026
A test for /sys/devices/system/cpu/smt/* files.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
include/tst_path_defs.h | 1 +
runtest/sysfs | 1 +
.../sysfs/devices/system/cpu/.gitignore | 1 +
.../sysfs/devices/system/cpu/sys_cpu_smt01.c | 98 +++++++++++++++++++
4 files changed, 101 insertions(+)
create mode 100644 testcases/kernel/sysfs/devices/system/cpu/sys_cpu_smt01.c
diff --git a/include/tst_path_defs.h b/include/tst_path_defs.h
index 31581482d..6bc0d65e1 100644
--- a/include/tst_path_defs.h
+++ b/include/tst_path_defs.h
@@ -95,6 +95,7 @@
/* SYSFS DEVICES */
#define PATH_SYS_CLOCKSOURCE "/sys/devices/system/clocksource"
#define PATH_SYS_CPU "/sys/devices/system/cpu"
+#define PATH_SYS_CPU_SMT "/sys/devices/system/cpu/smt"
#define PATH_SYS_CPU_VULN "/sys/devices/system/cpu/vulnerabilities"
#define PATH_SYS_NODE "/sys/devices/system/node"
diff --git a/runtest/sysfs b/runtest/sysfs
index 663c1d203..4cc2360c6 100644
--- a/runtest/sysfs
+++ b/runtest/sysfs
@@ -5,3 +5,4 @@ sys_node01 sys_node01
sys_cpu_topology01 sys_cpu_topology01
sys_cpu_topology02 sys_cpu_topology02
sys_cpu_vulnerabilities01 sys_cpu_vulnerabilities01
+sys_cpu_smt01 sys_cpu_smt01
diff --git a/testcases/kernel/sysfs/devices/system/cpu/.gitignore b/testcases/kernel/sysfs/devices/system/cpu/.gitignore
index 3ae5f494f..d0f8a6dab 100644
--- a/testcases/kernel/sysfs/devices/system/cpu/.gitignore
+++ b/testcases/kernel/sysfs/devices/system/cpu/.gitignore
@@ -1,3 +1,4 @@
/sys_cpu_topology01
/sys_cpu_topology02
/sys_cpu_vulnerabilities01
+/sys_cpu_smt01
diff --git a/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_smt01.c b/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_smt01.c
new file mode 100644
index 000000000..6b753a911
--- /dev/null
+++ b/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_smt01.c
@@ -0,0 +1,98 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * Sanity checks for the PATH_SYS_CPU_SMT (simultaneous multithreading) control exported
+ * under /sys/devices/system/cpu/smt/.
+ *
+ * The test verifies that:
+ *
+ * - active is a boolean (0 or 1)
+ * - control is one of the known states (on, off, forceoff, notsupported,
+ * notimplemented) or, on architectures that support a partial PATH_SYS_CPU_SMT level
+ * (CONFIG_SMT_NUM_THREADS_DYNAMIC), a positive integer greater than one
+ * that denotes the number of active threads per core
+ * - when PATH_SYS_CPU_SMT is not usable (control is notsupported or notimplemented) active
+ * reads back as 0
+ *
+ * The test skips with TCONF when the smt directory is not present.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include "tst_sysfs_assert.h"
+#include "tst_path_defs.h"
+
+static const char *const control_allowed[] = {
+ "on", "off", "forceoff", "notsupported", "notimplemented", NULL
+};
+
+static int is_number(const char *str)
+{
+ if (!*str)
+ return 0;
+
+ for (; *str; str++) {
+ if (!isdigit(*str))
+ return 0;
+ }
+
+ return 1;
+}
+
+static void do_test(void)
+{
+ char control[32];
+ long active;
+
+ if (access(PATH_SYS_CPU_SMT, F_OK)) {
+ tst_res(TCONF, PATH_SYS_CPU_SMT " is not available");
+ return;
+ }
+
+ TST_SYSFS_ASSERT_BOOL(PATH_SYS_CPU_SMT "/active");
+
+ if (!TST_SYSFS_READ_STR(control, sizeof(control), PATH_SYS_CPU_SMT "/control")) {
+ tst_res(TCONF, PATH_SYS_CPU_SMT "/control file not present");
+ return;
+ }
+
+ if (is_number(control)) {
+ long threads = SAFE_STRTOL(control, 1, LONG_MAX);
+
+ if (threads > 1) {
+ tst_res(TPASS,
+ PATH_SYS_CPU_SMT "/control = '%s' (%ld threads per core)",
+ control, threads);
+ } else {
+ tst_res(TFAIL,
+ PATH_SYS_CPU_SMT "/control = '%s' is not a valid thread count",
+ control);
+ }
+ } else {
+ TST_SYSFS_ASSERT_ONEOF(control_allowed, PATH_SYS_CPU_SMT "/control");
+ }
+
+ active = TST_SYSFS_READ_LI(PATH_SYS_CPU_SMT "/active");
+
+ if (!strcmp(control, "notsupported") ||
+ !strcmp(control, "notimplemented")) {
+ if (active == 0) {
+ tst_res(TPASS,
+ "active is 0 while PATH_SYS_CPU_SMT control is '%s'", control);
+ } else {
+ tst_res(TFAIL,
+ "active is %ld while PATH_SYS_CPU_SMT control is '%s'",
+ active, control);
+ }
+ }
+}
+
+static struct tst_test test = {
+ .test_all = do_test,
+};
--
2.54.0
More information about the ltp
mailing list