Skip to contentSkip to conversation

hyperthreading/ht_enabled: Convert to new API

PATCH In review Ricardo B. Marlière via ltp 1 participant 2 messages Mar 19, 2025 – Mar 20, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hyperthreading/ht_enabled: Convert to new API

From: Ricardo B. Marlière <[email protected]>

---
 .../sched/hyperthreading/ht_enabled/ht_enabled.c   | 46 ++++++++++------------
 .../sched/hyperthreading/ht_enabled/ht_utils.h     |  6 +--
 2 files changed, 23 insertions(+), 29 deletions(-)
testcases/kernel/sched/hyperthreading/ht_enabled/ht_enabled.c +21 -25
index 90f37e554f9d1add525498e1964c78bd14f4b16d..88e726d657a4e677a8ede5b71259aadf3da49494 100644
@@ -1,32 +1,28 @@
-/***************************************************************************
-                          HTenabled.c  -  description
-                             -------------------
-    email                : sonic,[email protected]
- ***************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) sonic,[email protected]
+ * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <[email protected]>
+ */
 
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
+/*\
+ * Smoke test that checks if Hyperthreading is enabled by default in the host.
+ */
 
-#include "test.h"
-#include "ht_utils.h"
+#if __i386__ || __x86_64__
 
-char *TCID = "smt_smp_enabled";
-int TST_TOTAL = 1;
+#include "tst_test.h"
+#include "ht_utils.h"
 
-int main(void)
+void run(void)
 {
-	int ret_val = 1;
-#if  (!defined __x86_64__ && !defined __i386__)
-	tst_brkm(TCONF, NULL,
-		 "This test suite can only execute on x86 architecture.");
+	if (check_ht_capability())
+		tst_res(TFAIL, "HT is not enabled by default in this system");
+	else
+		tst_res(TPASS, "HT is enabled by default in this system");
+}
+
+static struct tst_test test = { .test_all = run };
+
 #else
-	ret_val = check_ht_capability();
+TST_TEST_TCONF("This test can only execute on x86 architecture")
 #endif
-	return ret_val;
-}
testcases/kernel/sched/hyperthreading/ht_enabled/ht_utils.h +2 -4
index c03a1242551ce130d3862cbe0db329f7111183ea..61f0ff3d9886afb211d6368665de9f639b2d6654 100644
@@ -1,19 +1,17 @@
-
 #ifndef _HTUTILS_H_
 #define _HTUTILS_H_
 
 #include <sys/types.h>
-#include <stdlib.h>
 
 int is_cmdline_para(const char *para);
 
 // return 0 means Pass,
 // return 1 means ht is not enabled,
-int check_ht_capability();
+int check_ht_capability(void);
 
 extern char buf[];
 
-int get_cpu_count();
+int get_cpu_count(void);
 int get_current_cpu(pid_t pid);
 
 #endif

---
base-commit: ae279276535fc9ca3117a12c4bba0029d792904e
change-id: 20250319-conversions-ht_enabled-d82492a0cbb9

Best regards,

Signature · 5 lines
Ricardo B. Marlière <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Ricardo,

this is not a test but an utility used by smt_smp_affinity.sh , so it needs to be refactored using TST_NO_DEFAULT_MAIN (search it inside the project to understand how to use it). I guess this code should be refactored with the entire hyperthreading testing suite.

Regards,
Andrea

Quoted 98 lines · Ricardo B. Marlière via ltp

From: Ricardo B. Marlière <[email protected]>

---
  .../sched/hyperthreading/ht_enabled/ht_enabled.c   | 46 ++++++++++------------
  .../sched/hyperthreading/ht_enabled/ht_utils.h     |  6 +--
  2 files changed, 23 insertions(+), 29 deletions(-)
testcases/kernel/sched/hyperthreading/ht_enabled/ht_enabled.c +21 -25
index 90f37e554f9d1add525498e1964c78bd14f4b16d..88e726d657a4e677a8ede5b71259aadf3da49494 100644
@@ -1,32 +1,28 @@
-/***************************************************************************
-                          HTenabled.c  -  description
-                             -------------------
-    email                : sonic,[email protected]
- ***************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) sonic,[email protected]
+ * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <[email protected]>
+ */
 
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
+/*\
+ * Smoke test that checks if Hyperthreading is enabled by default in the host.
+ */
 
-#include "test.h"
-#include "ht_utils.h"
+#if __i386__ || __x86_64__
 
-char *TCID = "smt_smp_enabled";
-int TST_TOTAL = 1;
+#include "tst_test.h"
+#include "ht_utils.h"
 
-int main(void)
+void run(void)
  {
-	int ret_val = 1;
-#if  (!defined __x86_64__ && !defined __i386__)
-	tst_brkm(TCONF, NULL,
-		 "This test suite can only execute on x86 architecture.");
+	if (check_ht_capability())
+		tst_res(TFAIL, "HT is not enabled by default in this system");
+	else
+		tst_res(TPASS, "HT is enabled by default in this system");
+}
+
+static struct tst_test test = { .test_all = run };
+
  #else
-	ret_val = check_ht_capability();
+TST_TEST_TCONF("This test can only execute on x86 architecture")
  #endif
-	return ret_val;
-}
testcases/kernel/sched/hyperthreading/ht_enabled/ht_utils.h +2 -5
index c03a1242551ce130d3862cbe0db329f7111183ea..61f0ff3d9886afb211d6368665de9f639b2d6654 100644
@@ -1,19 +1,17 @@
-
  #ifndef _HTUTILS_H_
  #define _HTUTILS_H_
 
  #include <sys/types.h>
-#include <stdlib.h>
 
  int is_cmdline_para(const char *para);
 
  // return 0 means Pass,
  // return 1 means ht is not enabled,
-int check_ht_capability();
+int check_ht_capability(void);
 
  extern char buf[];
 
-int get_cpu_count();
+int get_cpu_count(void);
  int get_current_cpu(pid_t pid);
 
  #endif
 
---

base-commit: ae279276535fc9ca3117a12c4bba0029d792904e
change-id: 20250319-conversions-ht_enabled-d82492a0cbb9

Best regards,

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp