DPDK patches and discussions
 help / color / mirror / Atom feed
From: Sivaprasad Tummala <sivaprasad.tummala@amd.com>
To: <david.hunt@intel.com>, <anatoly.burakov@intel.com>,
	<jerinj@marvell.com>,  <radu.nicolau@intel.com>,
	<gakhil@marvell.com>, <cristian.dumitrescu@intel.com>,
	<ferruh.yigit@amd.com>, <konstantin.ananyev@huawei.com>
Cc: <dev@dpdk.org>, Huisong Li <lihuisong@huawei.com>
Subject: [PATCH v2 1/2] power: fix power library with --lcores
Date: Fri, 18 Oct 2024 03:34:34 +0000	[thread overview]
Message-ID: <20241018033435.1305782-1-sivaprasad.tummala@amd.com> (raw)
In-Reply-To: <20241017110247.1051770-1-sivaprasad.tummala@amd.com>

This commit fixes an issue in the power library
related to using lcores mapped to different
physical cores (--lcores option in EAL).

Previously, the power library incorrectly accessed
CPU sysfs attributes for power management, treating
lcore IDs as CPU IDs.
e.g. with --lcores '1@128', lcore_id '1' was interpreted
as CPU_id instead of '128'.

This patch corrects the cpu_id based on lcore and CPU
mappings. It also constraints power management support
for lcores mapped to multiple physical cores/threads.

When multiple lcores are mapped to the same physical core,
invoking frequency scaling APIs on any lcore will apply the
changes effectively.

v2:
 - renamed check_lcore_and_set_cpu to power_get_lcore_mapped_cpu_id

Signed-off-by: Sivaprasad Tummala <sivaprasad.tummala@amd.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
---
 lib/power/power_acpi_cpufreq.c       |  7 ++++++-
 lib/power/power_amd_pstate_cpufreq.c |  7 ++++++-
 lib/power/power_common.c             | 23 +++++++++++++++++++++++
 lib/power/power_common.h             |  2 +-
 lib/power/power_cppc_cpufreq.c       |  7 ++++++-
 lib/power/power_pstate_cpufreq.c     |  7 ++++++-
 6 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/lib/power/power_acpi_cpufreq.c b/lib/power/power_acpi_cpufreq.c
index abad53bef1..899d594600 100644
--- a/lib/power/power_acpi_cpufreq.c
+++ b/lib/power/power_acpi_cpufreq.c
@@ -264,7 +264,12 @@ power_acpi_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	pi->lcore_id = lcore_id;
+	if (power_get_lcore_mapped_cpu_id(lcore_id, &pi->lcore_id) < 0) {
+		POWER_LOG(ERR,
+			"Cannot get cpu id mapped for lcore %u", lcore_id);
+		return -1;
+	}
+
 	/* Check and set the governor */
 	if (power_set_governor_userspace(pi) < 0) {
 		POWER_LOG(ERR, "Cannot set governor of lcore %u to "
diff --git a/lib/power/power_amd_pstate_cpufreq.c b/lib/power/power_amd_pstate_cpufreq.c
index 4809d45a22..ada6c14d54 100644
--- a/lib/power/power_amd_pstate_cpufreq.c
+++ b/lib/power/power_amd_pstate_cpufreq.c
@@ -382,7 +382,12 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	pi->lcore_id = lcore_id;
+	if (power_get_lcore_mapped_cpu_id(lcore_id, &pi->lcore_id) < 0) {
+		POWER_LOG(ERR,
+			"Cannot get cpu id mapped for lcore %u", lcore_id);
+		return -1;
+	}
+
 	/* Check and set the governor */
 	if (power_set_governor_userspace(pi) < 0) {
 		POWER_LOG(ERR, "Cannot set governor of lcore %u to "
diff --git a/lib/power/power_common.c b/lib/power/power_common.c
index 590986d5ef..96dc8d8c21 100644
--- a/lib/power/power_common.c
+++ b/lib/power/power_common.c
@@ -9,6 +9,7 @@
 
 #include <rte_log.h>
 #include <rte_string_fns.h>
+#include <rte_lcore.h>
 
 #include "power_common.h"
 
@@ -204,3 +205,25 @@ power_set_governor(unsigned int lcore_id, const char *new_governor,
 
 	return ret;
 }
+
+int power_get_lcore_mapped_cpu_id(uint32_t lcore_id, uint32_t *cpu_id)
+{
+	rte_cpuset_t lcore_cpus;
+	uint32_t cpu;
+
+	lcore_cpus = rte_lcore_cpuset(lcore_id);
+	if (CPU_COUNT(&lcore_cpus) != 1) {
+		POWER_LOG(ERR,
+			"Power library does not support lcore %u mapping to %u cpus",
+			lcore_id, CPU_COUNT(&lcore_cpus));
+		return -1;
+	}
+
+	for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
+		if (CPU_ISSET(cpu, &lcore_cpus))
+			break;
+	}
+	*cpu_id = cpu;
+
+	return 0;
+}
diff --git a/lib/power/power_common.h b/lib/power/power_common.h
index 83f742f42a..92d53c6fe9 100644
--- a/lib/power/power_common.h
+++ b/lib/power/power_common.h
@@ -31,5 +31,5 @@ int open_core_sysfs_file(FILE **f, const char *mode, const char *format, ...)
 int read_core_sysfs_u32(FILE *f, uint32_t *val);
 int read_core_sysfs_s(FILE *f, char *buf, unsigned int len);
 int write_core_sysfs_s(FILE *f, const char *str);
-
+int power_get_lcore_mapped_cpu_id(uint32_t lcore_id, uint32_t *cpu_id);
 #endif /* _POWER_COMMON_H_ */
diff --git a/lib/power/power_cppc_cpufreq.c b/lib/power/power_cppc_cpufreq.c
index e73f4520d0..9910ae85b8 100644
--- a/lib/power/power_cppc_cpufreq.c
+++ b/lib/power/power_cppc_cpufreq.c
@@ -368,7 +368,12 @@ power_cppc_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	pi->lcore_id = lcore_id;
+	if (power_get_lcore_mapped_cpu_id(lcore_id, &pi->lcore_id) < 0) {
+		POWER_LOG(ERR,
+			"Cannot get cpu id mapped for lcore %u", lcore_id);
+		return -1;
+	}
+
 	/* Check and set the governor */
 	if (power_set_governor_userspace(pi) < 0) {
 		POWER_LOG(ERR, "Cannot set governor of lcore %u to "
diff --git a/lib/power/power_pstate_cpufreq.c b/lib/power/power_pstate_cpufreq.c
index 1c2a91a178..cbe14e74ce 100644
--- a/lib/power/power_pstate_cpufreq.c
+++ b/lib/power/power_pstate_cpufreq.c
@@ -570,7 +570,12 @@ power_pstate_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	pi->lcore_id = lcore_id;
+	if (power_get_lcore_mapped_cpu_id(lcore_id, &pi->lcore_id) < 0) {
+		POWER_LOG(ERR,
+			"Cannot get cpu id mapped for lcore %u", lcore_id);
+		return -1;
+	}
+
 	/* Check and set the governor */
 	if (power_set_governor_performance(pi) < 0) {
 		POWER_LOG(ERR, "Cannot set governor of lcore %u to "
-- 
2.34.1


  parent reply	other threads:[~2024-10-18  3:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-24 13:03 [RFC PATCH " Sivaprasad Tummala
2024-07-24 13:03 ` [RFC PATCH 2/2] test/power: " Sivaprasad Tummala
2024-07-24 14:38 ` [RFC PATCH 1/2] power: " Stephen Hemminger
2024-07-24 14:39 ` Stephen Hemminger
2024-08-26 13:43   ` Tummala, Sivaprasad
2024-10-17 11:02 ` [PATCH v1 " Sivaprasad Tummala
2024-10-17 11:02   ` [PATCH v1 2/2] test/power: " Sivaprasad Tummala
2024-10-17 12:10     ` lihuisong (C)
2024-10-17 11:57   ` [PATCH v1 1/2] power: " Konstantin Ananyev
2024-10-17 12:05   ` lihuisong (C)
2024-10-18  2:52     ` Tummala, Sivaprasad
2024-10-18  3:34   ` Sivaprasad Tummala [this message]
2024-10-18  3:34     ` [PATCH v2 2/2] test/power: " Sivaprasad Tummala
2024-10-18 10:15     ` [PATCH v2 1/2] power: " Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241018033435.1305782-1-sivaprasad.tummala@amd.com \
    --to=sivaprasad.tummala@amd.com \
    --cc=anatoly.burakov@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=gakhil@marvell.com \
    --cc=jerinj@marvell.com \
    --cc=konstantin.ananyev@huawei.com \
    --cc=lihuisong@huawei.com \
    --cc=radu.nicolau@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).