* [RFC PATCH 1/2] power: fix power library with --lcores
@ 2024-07-24 13:03 Sivaprasad Tummala
2024-07-24 13:03 ` [RFC PATCH 2/2] test/power: " Sivaprasad Tummala
` (3 more replies)
0 siblings, 4 replies; 14+ messages in thread
From: Sivaprasad Tummala @ 2024-07-24 13:03 UTC (permalink / raw)
To: david.hunt, anatoly.burakov, thomas, ferruh.yigit, david.marchand; +Cc: dev
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.
Signed-off-by: Sivaprasad Tummala <sivaprasad.tummala@amd.com>
---
lib/power/power_acpi_cpufreq.c | 16 ++++++++++++++--
lib/power/power_amd_pstate_cpufreq.c | 16 ++++++++++++++--
lib/power/power_cppc_cpufreq.c | 16 ++++++++++++++--
lib/power/power_pstate_cpufreq.c | 16 ++++++++++++++--
4 files changed, 56 insertions(+), 8 deletions(-)
diff --git a/lib/power/power_acpi_cpufreq.c b/lib/power/power_acpi_cpufreq.c
index 81996e1c13..97a27e09a0 100644
--- a/lib/power/power_acpi_cpufreq.c
+++ b/lib/power/power_acpi_cpufreq.c
@@ -9,6 +9,7 @@
#include <rte_memcpy.h>
#include <rte_stdatomic.h>
#include <rte_string_fns.h>
+#include <rte_lcore.h>
#include "power_acpi_cpufreq.h"
#include "power_common.h"
@@ -234,7 +235,8 @@ int
power_acpi_cpufreq_init(unsigned int lcore_id)
{
struct acpi_power_info *pi;
- uint32_t exp_state;
+ uint32_t exp_state, cpu;
+ rte_cpuset_t lcore_cpus;
if (lcore_id >= RTE_MAX_LCORE) {
POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
@@ -258,7 +260,17 @@ power_acpi_cpufreq_init(unsigned int lcore_id)
return -1;
}
- pi->lcore_id = lcore_id;
+ lcore_cpus = rte_lcore_cpuset(lcore_id);
+ if (CPU_COUNT(&lcore_cpus) != 1) {
+ POWER_LOG(ERR, "Power library doesn't 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;
+ }
+ pi->lcore_id = cpu;
/* 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 090a0d96cb..8a3930eac7 100644
--- a/lib/power/power_amd_pstate_cpufreq.c
+++ b/lib/power/power_amd_pstate_cpufreq.c
@@ -8,6 +8,7 @@
#include <rte_memcpy.h>
#include <rte_stdatomic.h>
+#include <rte_lcore.h>
#include "power_amd_pstate_cpufreq.h"
#include "power_common.h"
@@ -352,7 +353,8 @@ int
power_amd_pstate_cpufreq_init(unsigned int lcore_id)
{
struct amd_pstate_power_info *pi;
- uint32_t exp_state;
+ uint32_t exp_state, cpu;
+ rte_cpuset_t lcore_cpus;
if (lcore_id >= RTE_MAX_LCORE) {
POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
@@ -376,7 +378,17 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id)
return -1;
}
- pi->lcore_id = lcore_id;
+ lcore_cpus = rte_lcore_cpuset(lcore_id);
+ if (CPU_COUNT(&lcore_cpus) != 1) {
+ POWER_LOG(ERR, "Power library doesn't 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;
+ }
+ pi->lcore_id = cpu;
/* 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_cppc_cpufreq.c b/lib/power/power_cppc_cpufreq.c
index 32aaacb948..d51118820b 100644
--- a/lib/power/power_cppc_cpufreq.c
+++ b/lib/power/power_cppc_cpufreq.c
@@ -7,6 +7,7 @@
#include <rte_memcpy.h>
#include <rte_stdatomic.h>
+#include <rte_lcore.h>
#include "power_cppc_cpufreq.h"
#include "power_common.h"
@@ -338,7 +339,8 @@ int
power_cppc_cpufreq_init(unsigned int lcore_id)
{
struct cppc_power_info *pi;
- uint32_t exp_state;
+ uint32_t exp_state, cpu;
+ rte_cpuset_t lcore_cpus;
if (lcore_id >= RTE_MAX_LCORE) {
POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
@@ -362,7 +364,17 @@ power_cppc_cpufreq_init(unsigned int lcore_id)
return -1;
}
- pi->lcore_id = lcore_id;
+ lcore_cpus = rte_lcore_cpuset(lcore_id);
+ if (CPU_COUNT(&lcore_cpus) != 1) {
+ POWER_LOG(ERR, "Power library doesn't 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;
+ }
+ pi->lcore_id = cpu;
/* 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 2343121621..cd7dfb5468 100644
--- a/lib/power/power_pstate_cpufreq.c
+++ b/lib/power/power_pstate_cpufreq.c
@@ -13,6 +13,7 @@
#include <rte_memcpy.h>
#include <rte_stdatomic.h>
+#include <rte_lcore.h>
#include "rte_power_pmd_mgmt.h"
#include "power_pstate_cpufreq.h"
@@ -540,7 +541,8 @@ int
power_pstate_cpufreq_init(unsigned int lcore_id)
{
struct pstate_power_info *pi;
- uint32_t exp_state;
+ uint32_t exp_state, cpu;
+ rte_cpuset_t lcore_cpus;
if (lcore_id >= RTE_MAX_LCORE) {
POWER_LOG(ERR, "Lcore id %u can not exceed %u",
@@ -564,7 +566,17 @@ power_pstate_cpufreq_init(unsigned int lcore_id)
return -1;
}
- pi->lcore_id = lcore_id;
+ lcore_cpus = rte_lcore_cpuset(lcore_id);
+ if (CPU_COUNT(&lcore_cpus) != 1) {
+ POWER_LOG(ERR, "Power library doesn't 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;
+ }
+ pi->lcore_id = cpu;
/* 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
^ permalink raw reply [flat|nested] 14+ messages in thread
* [RFC PATCH 2/2] test/power: fix power library with --lcores
2024-07-24 13:03 [RFC PATCH 1/2] power: fix power library with --lcores Sivaprasad Tummala
@ 2024-07-24 13:03 ` Sivaprasad Tummala
2024-07-24 14:38 ` [RFC PATCH 1/2] power: " Stephen Hemminger
` (2 subsequent siblings)
3 siblings, 0 replies; 14+ messages in thread
From: Sivaprasad Tummala @ 2024-07-24 13:03 UTC (permalink / raw)
To: david.hunt, anatoly.burakov, thomas, ferruh.yigit, david.marchand; +Cc: dev
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(-)
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);
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC PATCH 1/2] power: fix power library with --lcores
2024-07-24 13:03 [RFC PATCH 1/2] power: fix power library with --lcores Sivaprasad Tummala
2024-07-24 13:03 ` [RFC PATCH 2/2] test/power: " Sivaprasad Tummala
@ 2024-07-24 14:38 ` Stephen Hemminger
2024-07-24 14:39 ` Stephen Hemminger
2024-10-17 11:02 ` [PATCH v1 " Sivaprasad Tummala
3 siblings, 0 replies; 14+ messages in thread
From: Stephen Hemminger @ 2024-07-24 14:38 UTC (permalink / raw)
To: Sivaprasad Tummala
Cc: david.hunt, anatoly.burakov, thomas, ferruh.yigit, david.marchand, dev
On Wed, 24 Jul 2024 13:03:35 +0000
Sivaprasad Tummala <sivaprasad.tummala@amd.com> wrote:
> + POWER_LOG(ERR, "Power library doesn't support lcore %u mapping "
> + "to %u cpus", lcore_id, CPU_COUNT(&lcore_cpus));
Please don't break single format error string across lines. It makes it harder
for users to find the error in the source. Instead wrap after Er,,
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC PATCH 1/2] power: fix power library with --lcores
2024-07-24 13:03 [RFC PATCH 1/2] power: fix power library with --lcores 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
3 siblings, 1 reply; 14+ messages in thread
From: Stephen Hemminger @ 2024-07-24 14:39 UTC (permalink / raw)
To: Sivaprasad Tummala
Cc: david.hunt, anatoly.burakov, thomas, ferruh.yigit, david.marchand, dev
On Wed, 24 Jul 2024 13:03:35 +0000
Sivaprasad Tummala <sivaprasad.tummala@amd.com> wrote:
> + lcore_cpus = rte_lcore_cpuset(lcore_id);
> + if (CPU_COUNT(&lcore_cpus) != 1) {
> + POWER_LOG(ERR, "Power library doesn't 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;
> + }
You are copy and pasting the same code into multiple places which
indicates it should be an API function.
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [RFC PATCH 1/2] power: fix power library with --lcores
2024-07-24 14:39 ` Stephen Hemminger
@ 2024-08-26 13:43 ` Tummala, Sivaprasad
0 siblings, 0 replies; 14+ messages in thread
From: Tummala, Sivaprasad @ 2024-08-26 13:43 UTC (permalink / raw)
To: Stephen Hemminger
Cc: david.hunt, anatoly.burakov, thomas, Yigit, Ferruh, david.marchand, dev
[-- Attachment #1: Type: text/plain, Size: 1456 bytes --]
[AMD Official Use Only - AMD Internal Distribution Only]
Hi Stephen,
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Wednesday, July 24, 2024 8:10 PM
> To: Tummala, Sivaprasad <Sivaprasad.Tummala@amd.com>
> Cc: david.hunt@intel.com; anatoly.burakov@intel.com;
> thomas@monjalon.net; Yigit, Ferruh <Ferruh.Yigit@amd.com>;
> david.marchand@redhat.com; dev@dpdk.org
> Subject: Re: [RFC PATCH 1/2] power: fix power library with --lcores
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> On Wed, 24 Jul 2024 13:03:35 +0000
> Sivaprasad Tummala <sivaprasad.tummala@amd.com<mailto:sivaprasad.tummala@amd.com>> wrote:
>
> > + lcore_cpus = rte_lcore_cpuset(lcore_id);
> > + if (CPU_COUNT(&lcore_cpus) != 1) {
> > + POWER_LOG(ERR, "Power library doesn't 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;
> > + }
>
> You are copy and pasting the same code into multiple places which indicates it
> should be an API function.
ACK! Will fix this in next version.
[-- Attachment #2: Type: text/html, Size: 5010 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v1 1/2] power: fix power library with --lcores
2024-07-24 13:03 [RFC PATCH 1/2] power: fix power library with --lcores Sivaprasad Tummala
` (2 preceding siblings ...)
2024-07-24 14:39 ` Stephen Hemminger
@ 2024-10-17 11:02 ` Sivaprasad Tummala
2024-10-17 11:02 ` [PATCH v1 2/2] test/power: " Sivaprasad Tummala
` (3 more replies)
3 siblings, 4 replies; 14+ messages in thread
From: Sivaprasad Tummala @ 2024-10-17 11:02 UTC (permalink / raw)
To: david.hunt, anatoly.burakov, jerinj, radu.nicolau, gakhil,
cristian.dumitrescu, ferruh.yigit, konstantin.ananyev
Cc: dev
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.
Signed-off-by: Sivaprasad Tummala <sivaprasad.tummala@amd.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 81996e1c13..259bc8a263 100644
--- a/lib/power/power_acpi_cpufreq.c
+++ b/lib/power/power_acpi_cpufreq.c
@@ -258,7 +258,12 @@ power_acpi_cpufreq_init(unsigned int lcore_id)
return -1;
}
- pi->lcore_id = lcore_id;
+ if (check_lcore_and_set_cpu(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 090a0d96cb..9bfb271bb7 100644
--- a/lib/power/power_amd_pstate_cpufreq.c
+++ b/lib/power/power_amd_pstate_cpufreq.c
@@ -376,7 +376,12 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id)
return -1;
}
- pi->lcore_id = lcore_id;
+ if (check_lcore_and_set_cpu(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..a8d5cd1c50 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 check_lcore_and_set_cpu(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..c5034104d0 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 check_lcore_and_set_cpu(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 32aaacb948..0a1d723bae 100644
--- a/lib/power/power_cppc_cpufreq.c
+++ b/lib/power/power_cppc_cpufreq.c
@@ -362,7 +362,12 @@ power_cppc_cpufreq_init(unsigned int lcore_id)
return -1;
}
- pi->lcore_id = lcore_id;
+ if (check_lcore_and_set_cpu(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 2343121621..116b130be2 100644
--- a/lib/power/power_pstate_cpufreq.c
+++ b/lib/power/power_pstate_cpufreq.c
@@ -564,7 +564,12 @@ power_pstate_cpufreq_init(unsigned int lcore_id)
return -1;
}
- pi->lcore_id = lcore_id;
+ if (check_lcore_and_set_cpu(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
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v1 2/2] test/power: fix power library with --lcores
2024-10-17 11:02 ` [PATCH v1 " Sivaprasad Tummala
@ 2024-10-17 11:02 ` Sivaprasad Tummala
2024-10-17 12:10 ` lihuisong (C)
2024-10-17 11:57 ` [PATCH v1 1/2] power: " Konstantin Ananyev
` (2 subsequent siblings)
3 siblings, 1 reply; 14+ messages in thread
From: Sivaprasad Tummala @ 2024-10-17 11:02 UTC (permalink / raw)
To: david.hunt, anatoly.burakov, jerinj, radu.nicolau, gakhil,
cristian.dumitrescu, ferruh.yigit, konstantin.ananyev
Cc: dev
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(-)
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);
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [PATCH v1 1/2] power: fix power library with --lcores
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 11:57 ` Konstantin Ananyev
2024-10-17 12:05 ` lihuisong (C)
2024-10-18 3:34 ` [PATCH v2 " Sivaprasad Tummala
3 siblings, 0 replies; 14+ messages in thread
From: Konstantin Ananyev @ 2024-10-17 11:57 UTC (permalink / raw)
To: Sivaprasad Tummala, david.hunt, anatoly.burakov, jerinj,
radu.nicolau, gakhil, cristian.dumitrescu, ferruh.yigit
Cc: dev
> 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.
>
> Signed-off-by: Sivaprasad Tummala <sivaprasad.tummala@amd.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 81996e1c13..259bc8a263 100644
> --- a/lib/power/power_acpi_cpufreq.c
> +++ b/lib/power/power_acpi_cpufreq.c
> @@ -258,7 +258,12 @@ power_acpi_cpufreq_init(unsigned int lcore_id)
> return -1;
> }
>
> - pi->lcore_id = lcore_id;
> + if (check_lcore_and_set_cpu(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 090a0d96cb..9bfb271bb7 100644
> --- a/lib/power/power_amd_pstate_cpufreq.c
> +++ b/lib/power/power_amd_pstate_cpufreq.c
> @@ -376,7 +376,12 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id)
> return -1;
> }
>
> - pi->lcore_id = lcore_id;
> + if (check_lcore_and_set_cpu(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..a8d5cd1c50 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 check_lcore_and_set_cpu(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..c5034104d0 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 check_lcore_and_set_cpu(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 32aaacb948..0a1d723bae 100644
> --- a/lib/power/power_cppc_cpufreq.c
> +++ b/lib/power/power_cppc_cpufreq.c
> @@ -362,7 +362,12 @@ power_cppc_cpufreq_init(unsigned int lcore_id)
> return -1;
> }
>
> - pi->lcore_id = lcore_id;
> + if (check_lcore_and_set_cpu(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 2343121621..116b130be2 100644
> --- a/lib/power/power_pstate_cpufreq.c
> +++ b/lib/power/power_pstate_cpufreq.c
> @@ -564,7 +564,12 @@ power_pstate_cpufreq_init(unsigned int lcore_id)
> return -1;
> }
>
> - pi->lcore_id = lcore_id;
> + if (check_lcore_and_set_cpu(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 "
> --
Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
> 2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v1 1/2] power: fix power library with --lcores
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 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 ` [PATCH v2 " Sivaprasad Tummala
3 siblings, 1 reply; 14+ messages in thread
From: lihuisong (C) @ 2024-10-17 12:05 UTC (permalink / raw)
To: Sivaprasad Tummala, david.hunt, anatoly.burakov, jerinj,
radu.nicolau, gakhil, cristian.dumitrescu, ferruh.yigit,
konstantin.ananyev
Cc: dev
Good job.
With belows to change,
Acked-by: Huisong Li <lihuisong@huawei.com>
在 2024/10/17 19:02, Sivaprasad Tummala 写道:
> 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.
>
> Signed-off-by: Sivaprasad Tummala <sivaprasad.tummala@amd.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 81996e1c13..259bc8a263 100644
> --- a/lib/power/power_acpi_cpufreq.c
> +++ b/lib/power/power_acpi_cpufreq.c
> @@ -258,7 +258,12 @@ power_acpi_cpufreq_init(unsigned int lcore_id)
> return -1;
> }
>
> - pi->lcore_id = lcore_id;
> + if (check_lcore_and_set_cpu(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 090a0d96cb..9bfb271bb7 100644
> --- a/lib/power/power_amd_pstate_cpufreq.c
> +++ b/lib/power/power_amd_pstate_cpufreq.c
> @@ -376,7 +376,12 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id)
> return -1;
> }
>
> - pi->lcore_id = lcore_id;
> + if (check_lcore_and_set_cpu(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..a8d5cd1c50 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 check_lcore_and_set_cpu(uint32_t lcore_id, uint32_t *cpu_id)
How about the following function name? It is probably more common for
other power library like PM QoS which is upstreaming.
-->
int power_get_lcore_mapped_cpu_id(lcore_id)
negative on failure
>=0 on success
> +{
> + 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;
> +}
<...>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v1 2/2] test/power: fix power library with --lcores
2024-10-17 11:02 ` [PATCH v1 2/2] test/power: " Sivaprasad Tummala
@ 2024-10-17 12:10 ` lihuisong (C)
0 siblings, 0 replies; 14+ messages in thread
From: lihuisong (C) @ 2024-10-17 12:10 UTC (permalink / raw)
To: Sivaprasad Tummala, david.hunt, anatoly.burakov, jerinj,
radu.nicolau, gakhil, cristian.dumitrescu, ferruh.yigit,
konstantin.ananyev
Cc: dev
在 2024/10/17 19:02, Sivaprasad Tummala 写道:
> 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(-)
Acked-by: Huisong Li <lihuisong@huawei.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [PATCH v1 1/2] power: fix power library with --lcores
2024-10-17 12:05 ` lihuisong (C)
@ 2024-10-18 2:52 ` Tummala, Sivaprasad
0 siblings, 0 replies; 14+ messages in thread
From: Tummala, Sivaprasad @ 2024-10-18 2:52 UTC (permalink / raw)
To: lihuisong (C),
david.hunt, anatoly.burakov, jerinj, radu.nicolau, gakhil,
cristian.dumitrescu, Yigit, Ferruh, konstantin.ananyev
Cc: dev
[AMD Official Use Only - AMD Internal Distribution Only]
Hi Lihuisong,
> -----Original Message-----
> From: lihuisong (C) <lihuisong@huawei.com>
> Sent: Thursday, October 17, 2024 5:35 PM
> To: Tummala, Sivaprasad <Sivaprasad.Tummala@amd.com>;
> david.hunt@intel.com; anatoly.burakov@intel.com; jerinj@marvell.com;
> radu.nicolau@intel.com; gakhil@marvell.com; cristian.dumitrescu@intel.com; Yigit,
> Ferruh <Ferruh.Yigit@amd.com>; konstantin.ananyev@huawei.com
> Cc: dev@dpdk.org
> Subject: Re: [PATCH v1 1/2] power: fix power library with --lcores
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> Good job.
> With belows to change,
> Acked-by: Huisong Li <lihuisong@huawei.com>
>
>
> 在 2024/10/17 19:02, Sivaprasad Tummala 写道:
> > 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.
> >
> > Signed-off-by: Sivaprasad Tummala <sivaprasad.tummala@amd.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 81996e1c13..259bc8a263 100644
> > --- a/lib/power/power_acpi_cpufreq.c
> > +++ b/lib/power/power_acpi_cpufreq.c
> > @@ -258,7 +258,12 @@ power_acpi_cpufreq_init(unsigned int lcore_id)
> > return -1;
> > }
> >
> > - pi->lcore_id = lcore_id;
> > + if (check_lcore_and_set_cpu(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 090a0d96cb..9bfb271bb7 100644
> > --- a/lib/power/power_amd_pstate_cpufreq.c
> > +++ b/lib/power/power_amd_pstate_cpufreq.c
> > @@ -376,7 +376,12 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id)
> > return -1;
> > }
> >
> > - pi->lcore_id = lcore_id;
> > + if (check_lcore_and_set_cpu(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..a8d5cd1c50 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 check_lcore_and_set_cpu(uint32_t lcore_id, uint32_t *cpu_id)
> How about the following function name? It is probably more common for other power
> library like PM QoS which is upstreaming.
> -->
> int power_get_lcore_mapped_cpu_id(lcore_id)
> negative on failure
ACK!
> >=0 on success
> > +{
> > + 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;
> > +}
> <...>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 1/2] power: fix power library with --lcores
2024-10-17 11:02 ` [PATCH v1 " Sivaprasad Tummala
` (2 preceding siblings ...)
2024-10-17 12:05 ` lihuisong (C)
@ 2024-10-18 3:34 ` Sivaprasad Tummala
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
3 siblings, 2 replies; 14+ messages in thread
From: Sivaprasad Tummala @ 2024-10-18 3:34 UTC (permalink / raw)
To: david.hunt, anatoly.burakov, jerinj, radu.nicolau, gakhil,
cristian.dumitrescu, ferruh.yigit, konstantin.ananyev
Cc: dev, Huisong Li
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v2 2/2] test/power: fix power library with --lcores
2024-10-18 3:34 ` [PATCH v2 " Sivaprasad Tummala
@ 2024-10-18 3:34 ` Sivaprasad Tummala
2024-10-18 10:15 ` [PATCH v2 1/2] power: " Thomas Monjalon
1 sibling, 0 replies; 14+ messages in thread
From: Sivaprasad Tummala @ 2024-10-18 3:34 UTC (permalink / raw)
To: david.hunt, anatoly.burakov, jerinj, radu.nicolau, gakhil,
cristian.dumitrescu, ferruh.yigit, konstantin.ananyev
Cc: dev, Huisong Li
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>
Acked-by: Huisong Li <lihuisong@huawei.com>
---
app/test/test_power_cpufreq.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
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);
--
2.34.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 1/2] power: fix power library with --lcores
2024-10-18 3:34 ` [PATCH v2 " Sivaprasad Tummala
2024-10-18 3:34 ` [PATCH v2 2/2] test/power: " Sivaprasad Tummala
@ 2024-10-18 10:15 ` Thomas Monjalon
1 sibling, 0 replies; 14+ messages in thread
From: Thomas Monjalon @ 2024-10-18 10:15 UTC (permalink / raw)
To: Sivaprasad Tummala
Cc: david.hunt, anatoly.burakov, jerinj, radu.nicolau, gakhil,
cristian.dumitrescu, ferruh.yigit, konstantin.ananyev, dev,
Huisong Li
18/10/2024 05:34, Sivaprasad Tummala:
> 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>
Applied with style edits and Fixes/Cc, thanks.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2024-10-18 10:16 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-24 13:03 [RFC PATCH 1/2] power: fix power library with --lcores 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 ` [PATCH v2 " Sivaprasad Tummala
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
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).