[PATCH v1 1/2] power: fix power library with --lcores

lihuisong (C) lihuisong at huawei.com
Thu Oct 17 14:05:09 CEST 2024


Good job.
With belows to change,
Acked-by: Huisong Li <lihuisong at 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 at 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 at 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;
> +}
<...>


More information about the dev mailing list