From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 42D4645B5D; Thu, 17 Oct 2024 13:58:00 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CCE1B40279; Thu, 17 Oct 2024 13:57:59 +0200 (CEST) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by mails.dpdk.org (Postfix) with ESMTP id BB45B4021E for ; Thu, 17 Oct 2024 13:57:58 +0200 (CEST) Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XTmXs26Plz6J9h8; Thu, 17 Oct 2024 19:57:17 +0800 (CST) Received: from frapeml100006.china.huawei.com (unknown [7.182.85.201]) by mail.maildlp.com (Postfix) with ESMTPS id 5FB951400F4; Thu, 17 Oct 2024 19:57:57 +0800 (CST) Received: from frapeml500007.china.huawei.com (7.182.85.172) by frapeml100006.china.huawei.com (7.182.85.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 17 Oct 2024 13:57:57 +0200 Received: from frapeml500007.china.huawei.com ([7.182.85.172]) by frapeml500007.china.huawei.com ([7.182.85.172]) with mapi id 15.01.2507.039; Thu, 17 Oct 2024 13:57:57 +0200 From: Konstantin Ananyev To: Sivaprasad Tummala , "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" CC: "dev@dpdk.org" Subject: RE: [PATCH v1 1/2] power: fix power library with --lcores Thread-Topic: [PATCH v1 1/2] power: fix power library with --lcores Thread-Index: AQHbIIQq7ABRx1eO6ECU/6uK9sP1cbKK1kBA Date: Thu, 17 Oct 2024 11:57:56 +0000 Message-ID: References: <20240724130336.1076462-1-sivaprasad.tummala@amd.com> <20241017110247.1051770-1-sivaprasad.tummala@amd.com> In-Reply-To: <20241017110247.1051770-1-sivaprasad.tummala@amd.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.206.138.42] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > This commit fixes an issue in the power library > related to using lcores mapped to different > physical cores (--lcores option in EAL). >=20 > 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'. >=20 > 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. >=20 > When multiple lcores are mapped to the same physical core, > invoking frequency scaling APIs on any lcore will apply the > changes effectively. >=20 > Signed-off-by: Sivaprasad Tummala > --- > 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(-) >=20 > diff --git a/lib/power/power_acpi_cpufreq.c b/lib/power/power_acpi_cpufre= q.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; > } >=20 > - pi->lcore_id =3D 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_p= state_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; > } >=20 > - pi->lcore_id =3D 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 @@ >=20 > #include > #include > +#include >=20 > #include "power_common.h" >=20 > @@ -204,3 +205,25 @@ power_set_governor(unsigned int lcore_id, const char= *new_governor, >=20 > 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 =3D rte_lcore_cpuset(lcore_id); > + if (CPU_COUNT(&lcore_cpus) !=3D 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 =3D 0; cpu < CPU_SETSIZE; cpu++) { > + if (CPU_ISSET(cpu, &lcore_cpus)) > + break; > + } > + *cpu_id =3D 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, co= nst 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_cpufre= q.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; > } >=20 > - pi->lcore_id =3D 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_cp= ufreq.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; > } >=20 > - pi->lcore_id =3D 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 > 2.34.1