[LTP] [PATCH v3 09/31] testcases: sysfs: Add sys_cpu_smt01

Cyril Hrubis chrubis@suse.cz
Tue Aug 25 13:36:03 CEST 2026


A test for /sys/devices/system/cpu/smt/* files.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 runtest/sysfs                                 |  1 +
 .../sysfs/devices/system/cpu/.gitignore       |  1 +
 .../sysfs/devices/system/cpu/sys_cpu_smt01.c  | 99 +++++++++++++++++++
 3 files changed, 101 insertions(+)
 create mode 100644 testcases/kernel/sysfs/devices/system/cpu/sys_cpu_smt01.c

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..770b68bb4
--- /dev/null
+++ b/testcases/kernel/sysfs/devices/system/cpu/sys_cpu_smt01.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2026 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * Sanity checks for the 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 SMT level
+ *   (CONFIG_SMT_NUM_THREADS_DYNAMIC), a positive integer greater than one
+ *   that denotes the number of active threads per core
+ * - when 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"
+
+#define SMT "/sys/devices/system/cpu/smt"
+
+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(SMT, F_OK)) {
+		tst_res(TCONF, SMT " is not available");
+		return;
+	}
+
+	TST_SYSFS_ASSERT_BOOL(SMT "/active");
+
+	if (!TST_SYSFS_READ_STR(control, sizeof(control), SMT "/control")) {
+		tst_res(TCONF, SMT "/control file not present");
+		return;
+	}
+
+	if (is_number(control)) {
+		long threads = SAFE_STRTOL(control, 1, LONG_MAX);
+
+		if (threads > 1) {
+			tst_res(TPASS,
+				SMT "/control = '%s' (%ld threads per core)",
+				control, threads);
+		} else {
+			tst_res(TFAIL,
+				SMT "/control = '%s' is not a valid thread count",
+				control);
+		}
+	} else {
+		TST_SYSFS_ASSERT_ONEOF(control_allowed, SMT "/control");
+	}
+
+	active = TST_SYSFS_READ_LI(SMT "/active");
+
+	if (!strcmp(control, "notsupported") ||
+	    !strcmp(control, "notimplemented")) {
+		if (active == 0) {
+			tst_res(TPASS,
+				"active is 0 while SMT control is '%s'", control);
+		} else {
+			tst_res(TFAIL,
+				"active is %ld while SMT control is '%s'",
+				active, control);
+		}
+	}
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+};
-- 
2.51.0



More information about the ltp mailing list