[LTP] [PATCH] hyperthreading/ht_enabled: Convert to new API

Andrea Cervesato andrea.cervesato@suse.com
Thu Mar 20 08:44:51 CET 2025


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

On 3/19/25 20:37, Ricardo B. Marlière via ltp wrote:
> From: Ricardo B. Marlière <rbm@suse.com>
>
> Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
> ---
>   .../sched/hyperthreading/ht_enabled/ht_enabled.c   | 46 ++++++++++------------
>   .../sched/hyperthreading/ht_enabled/ht_utils.h     |  6 +--
>   2 files changed, 23 insertions(+), 29 deletions(-)
>
> diff --git a/testcases/kernel/sched/hyperthreading/ht_enabled/ht_enabled.c b/testcases/kernel/sched/hyperthreading/ht_enabled/ht_enabled.c
> index 90f37e554f9d1add525498e1964c78bd14f4b16d..88e726d657a4e677a8ede5b71259aadf3da49494 100644
> --- a/testcases/kernel/sched/hyperthreading/ht_enabled/ht_enabled.c
> +++ b/testcases/kernel/sched/hyperthreading/ht_enabled/ht_enabled.c
> @@ -1,32 +1,28 @@
> -/***************************************************************************
> -                          HTenabled.c  -  description
> -                             -------------------
> -    email                : sonic,zhang@intel.com
> - ***************************************************************************/
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) sonic,zhang@intel.com
> + * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <rbm@suse.com>
> + */
>   
> -/***************************************************************************
> - *                                                                         *
> - *   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;
> -}
> diff --git a/testcases/kernel/sched/hyperthreading/ht_enabled/ht_utils.h b/testcases/kernel/sched/hyperthreading/ht_enabled/ht_utils.h
> index c03a1242551ce130d3862cbe0db329f7111183ea..61f0ff3d9886afb211d6368665de9f639b2d6654 100644
> --- a/testcases/kernel/sched/hyperthreading/ht_enabled/ht_utils.h
> +++ b/testcases/kernel/sched/hyperthreading/ht_enabled/ht_utils.h
> @@ -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,


More information about the ltp mailing list