From: Mamatha I. <mam...@li...> - 2014-12-22 16:31:57
|
Problem: ppc64_cpu --threads-per-core gives wrong data when --smt value set This patch will resolve the above issue and display the correct values of threads-per-core for the ppc64_cpu command when --smt value is set. I have used the following equation to calculate threads_per_core as per lscpu command. threads_per_core = nthreads / ncores *********************************************** Test results: CASE 1: ./src/ppc64_cpu --smt=on [root@llmjuno03b powerpc-utils]# ./src/ppc64_cpu --threads-per-core Threads per core: 4 lscpu output: Thread(s) per core: 4 ------------------------------------------ CASE 2: ./src/ppc64_cpu --smt=2 [root@llmjuno03b powerpc-utils]# ./src/ppc64_cpu --threads-per-core Threads per core: 2 lscpu output: Thread(s) per core: 2 -------------------------------------------------- CASE 3: ./src/ppc64_cpu --smt=1 [root@llmjuno03b powerpc-utils]# ./src/ppc64_cpu --threads-per-core Threads per core: 1 lscpu output: Thread(s) per core: 1 ------------------------------------------------- Signed-off-by: Mamatha Inamdar <mam...@li...> --- src/ppc64_cpu.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ppc64_cpu.c b/src/ppc64_cpu.c index 4df4cdc..a3cfed0 100644 --- a/src/ppc64_cpu.c +++ b/src/ppc64_cpu.c @@ -56,6 +56,7 @@ static int counters[MAX_NR_CPUS]; static int threads_per_cpu = 0; static int cpus_in_system = 0; static int threads_in_system = 0; +static int threads_per_core = 0; static int do_info(void); @@ -529,9 +530,21 @@ static int do_smt(char *state) return rc; } +/* Threads per core */ static inline void do_threads_per_core() { - printf("Threads per core: %d\n", threads_per_cpu); + int i, j; + int nthreads; /* number of threads online */ + + /* Calculate number of threads present on the system */ + for (j = 0; j < threads_in_system; j += threads_per_cpu) { + for (i = 0; i < threads_per_cpu; i++) + nthreads += cpu_online(j + i); + } + + /* Calculate threads per core = nthreads / ncores */ + threads_per_core = nthreads / cpus_in_system; + printf("Threads per core: %d\n", threads_per_core); } static int do_subcores_per_core(char *state) |