[RFC,2/2] test/power: fix power library with --lcores

Message ID 20240724130336.1076462-2-sivaprasad.tummala@amd.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series [RFC,1/2] power: fix power library with --lcores |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Tummala, Sivaprasad July 24, 2024, 1:03 p.m. UTC
When user request to use lcores mapped to different physical
cores using --lcores eal option, power application accesses
incorrect cpu sysfs attribute for checking current frequency

The patch fixes the cpu_id based on the lcore and cpu mappings.

Signed-off-by: Sivaprasad Tummala <sivaprasad.tummala@amd.com>
---
 app/test/test_power_cpufreq.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
  

Patch

diff --git a/app/test/test_power_cpufreq.c b/app/test/test_power_cpufreq.c
index 619b2811c6..63d13614df 100644
--- a/app/test/test_power_cpufreq.c
+++ b/app/test/test_power_cpufreq.c
@@ -9,6 +9,7 @@ 
 #include <string.h>
 #include <inttypes.h>
 #include <rte_cycles.h>
+#include <rte_lcore.h>
 
 #include "test.h"
 
@@ -46,9 +47,10 @@  test_power_caps(void)
 
 static uint32_t total_freq_num;
 static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX];
+static uint32_t cpu_id;
 
 static int
-check_cur_freq(unsigned int lcore_id, uint32_t idx, bool turbo)
+check_cur_freq(__rte_unused unsigned int lcore_id, uint32_t idx, bool turbo)
 {
 #define TEST_POWER_CONVERT_TO_DECIMAL 10
 #define MAX_LOOP 100
@@ -62,13 +64,13 @@  check_cur_freq(unsigned int lcore_id, uint32_t idx, bool turbo)
 	int i;
 
 	if (snprintf(fullpath, sizeof(fullpath),
-		TEST_POWER_SYSFILE_CPUINFO_FREQ, lcore_id) < 0) {
+		TEST_POWER_SYSFILE_CPUINFO_FREQ, cpu_id) < 0) {
 		return 0;
 	}
 	f = fopen(fullpath, "r");
 	if (f == NULL) {
 		if (snprintf(fullpath, sizeof(fullpath),
-			TEST_POWER_SYSFILE_SCALING_FREQ, lcore_id) < 0) {
+			TEST_POWER_SYSFILE_SCALING_FREQ, cpu_id) < 0) {
 			return 0;
 		}
 		f = fopen(fullpath, "r");
@@ -497,6 +499,20 @@  test_power_cpufreq(void)
 {
 	int ret = -1;
 	enum power_management_env env;
+	rte_cpuset_t lcore_cpus;
+
+	lcore_cpus = rte_lcore_cpuset(TEST_POWER_LCORE_ID);
+	if (CPU_COUNT(&lcore_cpus) != 1) {
+		printf("Power management doesn't support "
+				"lcore %u mapping to %u cpus\n",
+				TEST_POWER_LCORE_ID,
+				CPU_COUNT(&lcore_cpus));
+		return TEST_SKIPPED;
+	}
+	for (cpu_id = 0; cpu_id < CPU_SETSIZE; cpu_id++) {
+		if (CPU_ISSET(cpu_id, &lcore_cpus))
+			break;
+	}
 
 	/* Test initialisation of a valid lcore */
 	ret = rte_power_init(TEST_POWER_LCORE_ID);