DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 00/15] power: unify and improve lcore ID verification
@ 2026-04-16  3:05 Huisong Li
  2026-04-16  3:05 ` [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check Huisong Li
                   ` (16 more replies)
  0 siblings, 17 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:05 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

This patch series reworks the lcore ID verification logic within the power
library to ensure consistency and improve maintainability. Currently, various
cpufreq drivers implement their own lcore ID checks, often relying on simple
range checks that do not account for whether a core is actually enabled in
the application.

Key Changes:
1. Replaces basic range checks with rte_lcore_is_enabled() across all
   cpufreq drivers (ACPI, AMD P-state, CPPC, Intel P-state, and KVM VM).
   This ensures the power library only operates on lcores assigned to the
   application.
2. Introduces a common macro in the power library's internal headers to
   standardize lcore ID verification.
3. Moves the verification logic from individual driver implementations up
   to the high-level framework API. This reduces duplication code and
   ensures that all drivers benefit from uniform validation.
4. Updates the power QoS and PMD Management libraries to use the new macro.

Huisong Li (15):
  power/kvm_vm: enforce enabled lcore ID check
  power/acpi_cpufreq: enforce enabled lcore ID check
  power/amd_pstate: enforce enabled lcore ID check
  power/cppc_cpufreq: enforce enabled lcore ID check
  power/intel_pstate: enforce enabled lcore ID check
  power: enforce enabled lcore ID check
  power: add a common macro to verify lcore ID
  power/pmd_mgmt: replace lcore ID verification with new macro
  power/qos: replace the lcore ID verification with new macro
  power/cpufreq: add the lcore ID verification to framework
  power/acpi_cpufreq: remove the verification of lcore ID
  power/amd_pstate: remove the verification of lcore ID
  power/cppc_cpufreq: remove the verification of lcore ID
  power/intel_pstate: remove the verification of lcore ID
  power/kvm_vm: remove the verification of lcore ID

 drivers/power/acpi/acpi_cpufreq.c             | 65 -------------------
 drivers/power/amd_pstate/amd_pstate_cpufreq.c | 65 -------------------
 drivers/power/cppc/cppc_cpufreq.c             | 65 -------------------
 .../power/intel_pstate/intel_pstate_cpufreq.c | 65 -------------------
 drivers/power/kvm_vm/kvm_vm.c                 | 10 ---
 lib/power/power_common.h                      |  7 ++
 lib/power/rte_power_cpufreq.c                 | 14 ++++
 lib/power/rte_power_pmd_mgmt.c                | 25 ++-----
 lib/power/rte_power_qos.c                     | 10 +--
 9 files changed, 30 insertions(+), 296 deletions(-)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
@ 2026-04-16  3:05 ` Huisong Li
  2026-04-16 15:48   ` Stephen Hemminger
  2026-04-16  3:05 ` [PATCH v1 02/15] power/acpi_cpufreq: " Huisong Li
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:05 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

The locre ID in cpufreq power must be enabled core in application.
Use rte_lcore_is_enabled to verify lcore_id.

Fixes: 6f987b594fa6 ("power: refactor core power management")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/kvm_vm/kvm_vm.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/power/kvm_vm/kvm_vm.c b/drivers/power/kvm_vm/kvm_vm.c
index 5754a441cd..816863da7a 100644
--- a/drivers/power/kvm_vm/kvm_vm.c
+++ b/drivers/power/kvm_vm/kvm_vm.c
@@ -24,11 +24,11 @@ power_kvm_vm_check_supported(void)
 int
 power_kvm_vm_init(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Core(%u) is out of range 0...%d",
-				lcore_id, RTE_MAX_LCORE-1);
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
+
 	pkt[lcore_id].command = RTE_POWER_CPU_POWER;
 	pkt[lcore_id].resource_id = lcore_id;
 	return guest_channel_host_connect(FD_PATH, lcore_id);
@@ -73,11 +73,11 @@ send_msg(unsigned int lcore_id, uint32_t scale_direction)
 {
 	int ret;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Core(%u) is out of range 0...%d",
-				lcore_id, RTE_MAX_LCORE-1);
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
+
 	pkt[lcore_id].unit = scale_direction;
 	ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);
 	if (ret == 0)
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 02/15] power/acpi_cpufreq: enforce enabled lcore ID check
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
  2026-04-16  3:05 ` [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check Huisong Li
@ 2026-04-16  3:05 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 03/15] power/amd_pstate: " Huisong Li
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:05 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

The locre ID in cpufreq power must be enabled core in application.
Use rte_lcore_is_enabled to verify lcore_id.

Fixes: 6f987b594fa6 ("power: refactor core power management")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/acpi/acpi_cpufreq.c | 56 +++++++++++++++----------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/power/acpi/acpi_cpufreq.c b/drivers/power/acpi/acpi_cpufreq.c
index 81a5e3f6ea..d22e0eb627 100644
--- a/drivers/power/acpi/acpi_cpufreq.c
+++ b/drivers/power/acpi/acpi_cpufreq.c
@@ -242,9 +242,8 @@ power_acpi_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -319,11 +318,11 @@ power_acpi_cpufreq_exit(unsigned int lcore_id)
 	struct acpi_power_info *pi;
 	uint32_t exp_state;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
+
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -373,8 +372,8 @@ power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return 0;
 	}
 
@@ -396,8 +395,8 @@ power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_acpi_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return RTE_POWER_INVALID_FREQ_INDEX;
 	}
 
@@ -407,8 +406,8 @@ power_acpi_cpufreq_get_freq(unsigned int lcore_id)
 int
 power_acpi_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -420,8 +419,8 @@ power_acpi_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -438,8 +437,8 @@ power_acpi_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -455,8 +454,8 @@ power_acpi_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_acpi_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -479,8 +478,8 @@ power_acpi_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -496,8 +495,8 @@ power_acpi_turbo_status(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -512,8 +511,8 @@ power_acpi_enable_turbo(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -545,8 +544,8 @@ power_acpi_disable_turbo(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -572,10 +571,11 @@ int power_acpi_get_capabilities(unsigned int lcore_id,
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
+
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 03/15] power/amd_pstate: enforce enabled lcore ID check
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
  2026-04-16  3:05 ` [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check Huisong Li
  2026-04-16  3:05 ` [PATCH v1 02/15] power/acpi_cpufreq: " Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 04/15] power/cppc_cpufreq: " Huisong Li
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

The locre ID in cpufreq power must be enabled core in application.
Use rte_lcore_is_enabled to verify lcore_id.

Fixes: 6f987b594fa6 ("power: refactor core power management")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/amd_pstate/amd_pstate_cpufreq.c | 56 +++++++++----------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/power/amd_pstate/amd_pstate_cpufreq.c b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
index 95495bff7d..68d4d3472c 100644
--- a/drivers/power/amd_pstate/amd_pstate_cpufreq.c
+++ b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
@@ -360,9 +360,8 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -443,11 +442,11 @@ power_amd_pstate_cpufreq_exit(unsigned int lcore_id)
 	struct amd_pstate_power_info *pi;
 	uint32_t exp_state;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
+
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -493,8 +492,8 @@ power_amd_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return 0;
 	}
 
@@ -516,8 +515,8 @@ power_amd_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t
 uint32_t
 power_amd_pstate_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return RTE_POWER_INVALID_FREQ_INDEX;
 	}
 
@@ -527,8 +526,8 @@ power_amd_pstate_cpufreq_get_freq(unsigned int lcore_id)
 int
 power_amd_pstate_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -540,8 +539,8 @@ power_amd_pstate_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -558,8 +557,8 @@ power_amd_pstate_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -575,8 +574,8 @@ power_amd_pstate_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_amd_pstate_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -600,8 +599,8 @@ power_amd_pstate_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -616,8 +615,8 @@ power_amd_pstate_turbo_status(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -631,8 +630,8 @@ power_amd_pstate_enable_turbo(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -667,8 +666,8 @@ power_amd_pstate_disable_turbo(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -695,10 +694,11 @@ power_amd_pstate_get_capabilities(unsigned int lcore_id,
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
+
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 04/15] power/cppc_cpufreq: enforce enabled lcore ID check
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (2 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 03/15] power/amd_pstate: " Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 05/15] power/intel_pstate: " Huisong Li
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

The locre ID in cpufreq power must be enabled core in application.
Use rte_lcore_is_enabled to verify lcore_id.

Fixes: 6f987b594fa6 ("power: refactor core power management")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/cppc/cppc_cpufreq.c | 56 +++++++++++++++----------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/power/cppc/cppc_cpufreq.c b/drivers/power/cppc/cppc_cpufreq.c
index 3cd4165c83..e63cec7ce5 100644
--- a/drivers/power/cppc/cppc_cpufreq.c
+++ b/drivers/power/cppc/cppc_cpufreq.c
@@ -346,9 +346,8 @@ power_cppc_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -429,11 +428,11 @@ power_cppc_cpufreq_exit(unsigned int lcore_id)
 	struct cppc_power_info *pi;
 	uint32_t exp_state;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
+
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -479,8 +478,8 @@ power_cppc_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return 0;
 	}
 
@@ -502,8 +501,8 @@ power_cppc_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_cppc_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return RTE_POWER_INVALID_FREQ_INDEX;
 	}
 
@@ -513,8 +512,8 @@ power_cppc_cpufreq_get_freq(unsigned int lcore_id)
 int
 power_cppc_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -526,8 +525,8 @@ power_cppc_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -544,8 +543,8 @@ power_cppc_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -561,8 +560,8 @@ power_cppc_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_cppc_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -585,8 +584,8 @@ power_cppc_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -601,8 +600,8 @@ power_cppc_turbo_status(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -616,8 +615,8 @@ power_cppc_enable_turbo(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -652,8 +651,8 @@ power_cppc_disable_turbo(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -680,10 +679,11 @@ power_cppc_get_capabilities(unsigned int lcore_id,
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
+
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 05/15] power/intel_pstate: enforce enabled lcore ID check
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (3 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 04/15] power/cppc_cpufreq: " Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 06/15] power: " Huisong Li
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

The locre ID in cpufreq power must be enabled core in application.
Use rte_lcore_is_enabled to verify it.

Fixes: 6f987b594fa6 ("power: refactor core power management")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 .../power/intel_pstate/intel_pstate_cpufreq.c | 56 +++++++++----------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/power/intel_pstate/intel_pstate_cpufreq.c b/drivers/power/intel_pstate/intel_pstate_cpufreq.c
index 8e27570e3c..fe19802c25 100644
--- a/drivers/power/intel_pstate/intel_pstate_cpufreq.c
+++ b/drivers/power/intel_pstate/intel_pstate_cpufreq.c
@@ -548,9 +548,8 @@ power_pstate_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceed %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -630,11 +629,11 @@ power_pstate_cpufreq_exit(unsigned int lcore_id)
 	struct pstate_power_info *pi;
 	uint32_t exp_state;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
+
 	pi = &lcore_power_info[lcore_id];
 
 	exp_state = POWER_USED;
@@ -688,8 +687,8 @@ power_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return 0;
 	}
 
@@ -711,8 +710,8 @@ power_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_pstate_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return RTE_POWER_INVALID_FREQ_INDEX;
 	}
 
@@ -723,8 +722,8 @@ power_pstate_cpufreq_get_freq(unsigned int lcore_id)
 int
 power_pstate_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -736,8 +735,8 @@ power_pstate_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -755,8 +754,8 @@ power_pstate_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -771,8 +770,8 @@ power_pstate_cpufreq_freq_down(unsigned int lcore_id)
 int
 power_pstate_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -796,8 +795,8 @@ power_pstate_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -813,8 +812,8 @@ power_pstate_turbo_status(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -828,8 +827,8 @@ power_pstate_enable_turbo(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -854,8 +853,8 @@ power_pstate_disable_turbo(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
 
@@ -882,10 +881,11 @@ int power_pstate_get_capabilities(unsigned int lcore_id,
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_enabled(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
 		return -1;
 	}
+
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 06/15] power: enforce enabled lcore ID check
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (4 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 05/15] power/intel_pstate: " Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 07/15] power: add a common macro to verify lcore ID Huisong Li
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

The locre ID in cpufreq power must be enabled core in application.
Use rte_lcore_is_enabled to verify it.

Fixes: 6f987b594fa6 ("power: refactor core power management")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/power/rte_power_pmd_mgmt.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/lib/power/rte_power_pmd_mgmt.c b/lib/power/rte_power_pmd_mgmt.c
index a4d53aac2a..a5fc1c3a94 100644
--- a/lib/power/rte_power_pmd_mgmt.c
+++ b/lib/power/rte_power_pmd_mgmt.c
@@ -511,7 +511,8 @@ rte_power_ethdev_pmgmt_queue_enable(unsigned int lcore_id, uint16_t port_id,
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
 
-	if (queue_id >= RTE_MAX_QUEUES_PER_PORT || lcore_id >= RTE_MAX_LCORE) {
+	if (queue_id >= RTE_MAX_QUEUES_PER_PORT ||
+	    !rte_lcore_is_enabled(lcore_id)) {
 		ret = -EINVAL;
 		goto end;
 	}
@@ -627,7 +628,7 @@ rte_power_ethdev_pmgmt_queue_disable(unsigned int lcore_id,
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
 
-	if (lcore_id >= RTE_MAX_LCORE || queue_id >= RTE_MAX_QUEUES_PER_PORT)
+	if (!rte_lcore_is_enabled(lcore_id) || queue_id >= RTE_MAX_QUEUES_PER_PORT)
 		return -EINVAL;
 
 	/* check if the queue is stopped */
@@ -729,8 +730,8 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_set_scaling_freq_min)
 int
 rte_power_pmd_mgmt_set_scaling_freq_min(unsigned int lcore, unsigned int min)
 {
-	if (lcore >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID: %u", lcore);
+	if (!rte_lcore_is_enabled(lcore)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
 		return -EINVAL;
 	}
 
@@ -747,8 +748,8 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_set_scaling_freq_max)
 int
 rte_power_pmd_mgmt_set_scaling_freq_max(unsigned int lcore, unsigned int max)
 {
-	if (lcore >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID: %u", lcore);
+	if (!rte_lcore_is_enabled(lcore)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
 		return -EINVAL;
 	}
 
@@ -769,8 +770,8 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_get_scaling_freq_min)
 int
 rte_power_pmd_mgmt_get_scaling_freq_min(unsigned int lcore)
 {
-	if (lcore >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID: %u", lcore);
+	if (!rte_lcore_is_enabled(lcore)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
 		return -EINVAL;
 	}
 
@@ -784,8 +785,8 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_get_scaling_freq_max)
 int
 rte_power_pmd_mgmt_get_scaling_freq_max(unsigned int lcore)
 {
-	if (lcore >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID: %u", lcore);
+	if (!rte_lcore_is_enabled(lcore)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
 		return -EINVAL;
 	}
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 07/15] power: add a common macro to verify lcore ID
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (5 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 06/15] power: " Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 08/15] power/pmd_mgmt: replace lcore ID verification with new macro Huisong Li
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

There are many places to verify lcore ID in power lib or driver.
So add a common macro to do this to simplify code.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/power/power_common.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/power/power_common.h b/lib/power/power_common.h
index 3f56b1103d..5f13068ad6 100644
--- a/lib/power/power_common.h
+++ b/lib/power/power_common.h
@@ -23,6 +23,13 @@ extern int rte_power_logtype;
 #define POWER_DEBUG_LOG(...)
 #endif
 
+#define RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, retval) do { \
+	if (!rte_lcore_is_enabled(lcore_id)) { \
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id); \
+		return retval; \
+	} \
+} while (0)
+
 /* check if scaling driver matches one we want */
 __rte_internal
 int cpufreq_check_scaling_driver(const char *driver);
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 08/15] power/pmd_mgmt: replace lcore ID verification with new macro
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (6 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 07/15] power: add a common macro to verify lcore ID Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 09/15] power/qos: replace the " Huisong Li
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Replace the duplicate code for validating the ID with
RTE_POWER_VALID_LCOREID_OR_ERR_RET.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/power/rte_power_pmd_mgmt.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/lib/power/rte_power_pmd_mgmt.c b/lib/power/rte_power_pmd_mgmt.c
index a5fc1c3a94..393adba27f 100644
--- a/lib/power/rte_power_pmd_mgmt.c
+++ b/lib/power/rte_power_pmd_mgmt.c
@@ -730,10 +730,7 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_set_scaling_freq_min)
 int
 rte_power_pmd_mgmt_set_scaling_freq_min(unsigned int lcore, unsigned int min)
 {
-	if (!rte_lcore_is_enabled(lcore)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
-		return -EINVAL;
-	}
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore, -EINVAL);
 
 	if (min > scale_freq_max[lcore]) {
 		POWER_LOG(ERR, "Invalid min frequency: Cannot be greater than max frequency");
@@ -748,10 +745,7 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_set_scaling_freq_max)
 int
 rte_power_pmd_mgmt_set_scaling_freq_max(unsigned int lcore, unsigned int max)
 {
-	if (!rte_lcore_is_enabled(lcore)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
-		return -EINVAL;
-	}
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore, -EINVAL);
 
 	/* Zero means 'not set'. Use UINT32_MAX to enable RTE_MIN/MAX macro use when scaling. */
 	if (max == 0)
@@ -770,10 +764,7 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_get_scaling_freq_min)
 int
 rte_power_pmd_mgmt_get_scaling_freq_min(unsigned int lcore)
 {
-	if (!rte_lcore_is_enabled(lcore)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
-		return -EINVAL;
-	}
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore, -EINVAL);
 
 	if (scale_freq_max[lcore] == 0)
 		POWER_LOG(DEBUG, "Scaling freq min config not set. Using sysfs min freq.");
@@ -785,10 +776,7 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_get_scaling_freq_max)
 int
 rte_power_pmd_mgmt_get_scaling_freq_max(unsigned int lcore)
 {
-	if (!rte_lcore_is_enabled(lcore)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
-		return -EINVAL;
-	}
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore, -EINVAL);
 
 	if (scale_freq_max[lcore] == UINT32_MAX) {
 		POWER_LOG(DEBUG, "Scaling freq max config not set. Using sysfs max freq.");
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 09/15] power/qos: replace the lcore ID verification with new macro
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (7 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 08/15] power/pmd_mgmt: replace lcore ID verification with new macro Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 10/15] power/cpufreq: add the lcore ID verification to framework Huisong Li
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Replace the duplicate code for validating the ID with
RTE_POWER_VALID_LCOREID_OR_ERR_RET.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/power/rte_power_qos.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/lib/power/rte_power_qos.c b/lib/power/rte_power_qos.c
index be230d1c50..f6630b08f7 100644
--- a/lib/power/rte_power_qos.c
+++ b/lib/power/rte_power_qos.c
@@ -27,10 +27,7 @@ rte_power_qos_set_cpu_resume_latency(uint16_t lcore_id, int latency)
 	FILE *f;
 	int ret;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -EINVAL;
-	}
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -EINVAL);
 	ret = power_get_lcore_mapped_cpu_id(lcore_id, &cpu_id);
 	if (ret != 0)
 		return ret;
@@ -82,10 +79,7 @@ rte_power_qos_get_cpu_resume_latency(uint16_t lcore_id)
 	FILE *f;
 	int ret;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -EINVAL;
-	}
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -EINVAL);
 	ret = power_get_lcore_mapped_cpu_id(lcore_id, &cpu_id);
 	if (ret != 0)
 		return ret;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 10/15] power/cpufreq: add the lcore ID verification to framework
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (8 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 09/15] power/qos: replace the " Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 11/15] power/acpi_cpufreq: remove the verification of lcore ID Huisong Li
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

The lcore ID verification is common for each cpufreq driver.
So add this verification to framework.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/power/rte_power_cpufreq.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lib/power/rte_power_cpufreq.c b/lib/power/rte_power_cpufreq.c
index f63e976dc2..c51dc8364e 100644
--- a/lib/power/rte_power_cpufreq.c
+++ b/lib/power/rte_power_cpufreq.c
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2010-2014 Intel Corporation
  */
+#include <errno.h>
 
 #include <eal_export.h>
 #include <rte_spinlock.h>
@@ -116,6 +117,7 @@ rte_power_init(unsigned int lcore_id)
 	struct rte_power_cpufreq_ops *ops;
 	uint8_t env;
 
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	if (global_default_env != PM_ENV_NOT_SET)
 		return global_cpufreq_ops->init(lcore_id);
 
@@ -147,6 +149,7 @@ RTE_EXPORT_SYMBOL(rte_power_exit)
 int
 rte_power_exit(unsigned int lcore_id)
 {
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	if (global_default_env != PM_ENV_NOT_SET)
 		return global_cpufreq_ops->exit(lcore_id);
 
@@ -161,6 +164,7 @@ uint32_t
 rte_power_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t n)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, 0);
 	return global_cpufreq_ops->get_avail_freqs(lcore_id, freqs, n);
 }
 
@@ -169,6 +173,7 @@ uint32_t
 rte_power_get_freq(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, RTE_POWER_INVALID_FREQ_INDEX);
 	return global_cpufreq_ops->get_freq(lcore_id);
 }
 
@@ -177,6 +182,7 @@ uint32_t
 rte_power_set_freq(unsigned int lcore_id, uint32_t index)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->set_freq(lcore_id, index);
 }
 
@@ -185,6 +191,7 @@ int
 rte_power_freq_up(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->freq_up(lcore_id);
 }
 
@@ -193,6 +200,7 @@ int
 rte_power_freq_down(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->freq_down(lcore_id);
 }
 
@@ -201,6 +209,7 @@ int
 rte_power_freq_max(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->freq_max(lcore_id);
 }
 
@@ -209,6 +218,7 @@ int
 rte_power_freq_min(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->freq_min(lcore_id);
 }
 
@@ -217,6 +227,7 @@ int
 rte_power_turbo_status(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->turbo_status(lcore_id);
 }
 
@@ -225,6 +236,7 @@ int
 rte_power_freq_enable_turbo(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->enable_turbo(lcore_id);
 }
 
@@ -233,6 +245,7 @@ int
 rte_power_freq_disable_turbo(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->disable_turbo(lcore_id);
 }
 
@@ -242,5 +255,6 @@ rte_power_get_capabilities(unsigned int lcore_id,
 		struct rte_power_core_capabilities *caps)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->get_caps(lcore_id, caps);
 }
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 11/15] power/acpi_cpufreq: remove the verification of lcore ID
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (9 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 10/15] power/cpufreq: add the lcore ID verification to framework Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 12/15] power/amd_pstate: " Huisong Li
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Now the lcore id has been verified in framework API, so remove
the verification in driver.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/acpi/acpi_cpufreq.c | 65 -------------------------------
 1 file changed, 65 deletions(-)

diff --git a/drivers/power/acpi/acpi_cpufreq.c b/drivers/power/acpi/acpi_cpufreq.c
index d22e0eb627..9c78b4cb1a 100644
--- a/drivers/power/acpi/acpi_cpufreq.c
+++ b/drivers/power/acpi/acpi_cpufreq.c
@@ -242,11 +242,6 @@ power_acpi_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_IDLE;
 	/* The power in use state works as a guard variable between
@@ -318,11 +313,6 @@ power_acpi_cpufreq_exit(unsigned int lcore_id)
 	struct acpi_power_info *pi;
 	uint32_t exp_state;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -372,11 +362,6 @@ power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return 0;
-	}
-
 	if (freqs == NULL) {
 		POWER_LOG(ERR, "NULL buffer supplied");
 		return 0;
@@ -395,22 +380,12 @@ power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_acpi_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return RTE_POWER_INVALID_FREQ_INDEX;
-	}
-
 	return lcore_power_info[lcore_id].curr_idx;
 }
 
 int
 power_acpi_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	return set_freq_internal(&(lcore_power_info[lcore_id]), index);
 }
 
@@ -419,11 +394,6 @@ power_acpi_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx + 1 == pi->nb_freqs)
 		return 0;
@@ -437,11 +407,6 @@ power_acpi_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx == 0 ||
 	    (pi->curr_idx == 1 && pi->turbo_available && !pi->turbo_enable))
@@ -454,11 +419,6 @@ power_acpi_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_acpi_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	/* Frequencies in the array are from high to low. */
 	if (lcore_power_info[lcore_id].turbo_available) {
 		if (lcore_power_info[lcore_id].turbo_enable)
@@ -478,11 +438,6 @@ power_acpi_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	/* Frequencies in the array are from high to low. */
@@ -495,11 +450,6 @@ power_acpi_turbo_status(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	return pi->turbo_enable;
@@ -511,11 +461,6 @@ power_acpi_enable_turbo(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	if (pi->turbo_available)
@@ -544,11 +489,6 @@ power_acpi_disable_turbo(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	 pi->turbo_enable = 0;
@@ -571,11 +511,6 @@ int power_acpi_get_capabilities(unsigned int lcore_id,
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 12/15] power/amd_pstate: remove the verification of lcore ID
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (10 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 11/15] power/acpi_cpufreq: remove the verification of lcore ID Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 13/15] power/cppc_cpufreq: " Huisong Li
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Now the lcore ID has been verified in framework API, so remove
the verification in driver.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/amd_pstate/amd_pstate_cpufreq.c | 65 -------------------
 1 file changed, 65 deletions(-)

diff --git a/drivers/power/amd_pstate/amd_pstate_cpufreq.c b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
index 68d4d3472c..8ca27d689d 100644
--- a/drivers/power/amd_pstate/amd_pstate_cpufreq.c
+++ b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
@@ -360,11 +360,6 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_IDLE;
 	/* The power in use state works as a guard variable between
@@ -442,11 +437,6 @@ power_amd_pstate_cpufreq_exit(unsigned int lcore_id)
 	struct amd_pstate_power_info *pi;
 	uint32_t exp_state;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -492,11 +482,6 @@ power_amd_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return 0;
-	}
-
 	if (freqs == NULL) {
 		POWER_LOG(ERR, "NULL buffer supplied");
 		return 0;
@@ -515,22 +500,12 @@ power_amd_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t
 uint32_t
 power_amd_pstate_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return RTE_POWER_INVALID_FREQ_INDEX;
-	}
-
 	return lcore_power_info[lcore_id].curr_idx;
 }
 
 int
 power_amd_pstate_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	return set_freq_internal(&(lcore_power_info[lcore_id]), index);
 }
 
@@ -539,11 +514,6 @@ power_amd_pstate_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx + 1 == pi->nb_freqs)
 		return 0;
@@ -557,11 +527,6 @@ power_amd_pstate_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx == 0 || (pi->curr_idx == pi->nom_idx &&
 		pi->turbo_available && !pi->turbo_enable))
@@ -574,11 +539,6 @@ power_amd_pstate_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_amd_pstate_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	/* Frequencies in the array are from high to low. */
 	if (lcore_power_info[lcore_id].turbo_available) {
 		if (lcore_power_info[lcore_id].turbo_enable)
@@ -599,11 +559,6 @@ power_amd_pstate_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	/* Frequencies in the array are from high to low. */
@@ -615,11 +570,6 @@ power_amd_pstate_turbo_status(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	return pi->turbo_enable;
@@ -630,11 +580,6 @@ power_amd_pstate_enable_turbo(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	if (pi->turbo_available)
@@ -666,11 +611,6 @@ power_amd_pstate_disable_turbo(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	pi->turbo_enable = 0;
@@ -694,11 +634,6 @@ power_amd_pstate_get_capabilities(unsigned int lcore_id,
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 13/15] power/cppc_cpufreq: remove the verification of lcore ID
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (11 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 12/15] power/amd_pstate: " Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 14/15] power/intel_pstate: " Huisong Li
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Now the lcore ID has been verified in framework API, so remove
the verification in driver.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/cppc/cppc_cpufreq.c | 65 -------------------------------
 1 file changed, 65 deletions(-)

diff --git a/drivers/power/cppc/cppc_cpufreq.c b/drivers/power/cppc/cppc_cpufreq.c
index e63cec7ce5..529f68e574 100644
--- a/drivers/power/cppc/cppc_cpufreq.c
+++ b/drivers/power/cppc/cppc_cpufreq.c
@@ -346,11 +346,6 @@ power_cppc_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_IDLE;
 	/* The power in use state works as a guard variable between
@@ -428,11 +423,6 @@ power_cppc_cpufreq_exit(unsigned int lcore_id)
 	struct cppc_power_info *pi;
 	uint32_t exp_state;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -478,11 +468,6 @@ power_cppc_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return 0;
-	}
-
 	if (freqs == NULL) {
 		POWER_LOG(ERR, "NULL buffer supplied");
 		return 0;
@@ -501,22 +486,12 @@ power_cppc_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_cppc_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return RTE_POWER_INVALID_FREQ_INDEX;
-	}
-
 	return lcore_power_info[lcore_id].curr_idx;
 }
 
 int
 power_cppc_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	return set_freq_internal(&(lcore_power_info[lcore_id]), index);
 }
 
@@ -525,11 +500,6 @@ power_cppc_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx + 1 == pi->nb_freqs)
 		return 0;
@@ -543,11 +513,6 @@ power_cppc_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx == 0 || (pi->curr_idx == 1 &&
 		pi->turbo_available && !pi->turbo_enable))
@@ -560,11 +525,6 @@ power_cppc_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_cppc_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	/* Frequencies in the array are from high to low. */
 	if (lcore_power_info[lcore_id].turbo_available) {
 		if (lcore_power_info[lcore_id].turbo_enable)
@@ -584,11 +544,6 @@ power_cppc_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	/* Frequencies in the array are from high to low. */
@@ -600,11 +555,6 @@ power_cppc_turbo_status(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	return pi->turbo_enable;
@@ -615,11 +565,6 @@ power_cppc_enable_turbo(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	if (pi->turbo_available)
@@ -651,11 +596,6 @@ power_cppc_disable_turbo(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	pi->turbo_enable = 0;
@@ -679,11 +619,6 @@ power_cppc_get_capabilities(unsigned int lcore_id,
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 14/15] power/intel_pstate: remove the verification of lcore ID
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (12 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 13/15] power/cppc_cpufreq: " Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16  3:06 ` [PATCH v1 15/15] power/kvm_vm: " Huisong Li
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Now the lcore ID has been verified in framework API, so remove
the verification in driver.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 .../power/intel_pstate/intel_pstate_cpufreq.c | 65 -------------------
 1 file changed, 65 deletions(-)

diff --git a/drivers/power/intel_pstate/intel_pstate_cpufreq.c b/drivers/power/intel_pstate/intel_pstate_cpufreq.c
index fe19802c25..e7ed9c8260 100644
--- a/drivers/power/intel_pstate/intel_pstate_cpufreq.c
+++ b/drivers/power/intel_pstate/intel_pstate_cpufreq.c
@@ -548,11 +548,6 @@ power_pstate_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_IDLE;
 	/* The power in use state works as a guard variable between
@@ -629,11 +624,6 @@ power_pstate_cpufreq_exit(unsigned int lcore_id)
 	struct pstate_power_info *pi;
 	uint32_t exp_state;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	exp_state = POWER_USED;
@@ -687,11 +677,6 @@ power_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return 0;
-	}
-
 	if (freqs == NULL) {
 		POWER_LOG(ERR, "NULL buffer supplied");
 		return 0;
@@ -710,11 +695,6 @@ power_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_pstate_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return RTE_POWER_INVALID_FREQ_INDEX;
-	}
-
 	return lcore_power_info[lcore_id].curr_idx;
 }
 
@@ -722,11 +702,6 @@ power_pstate_cpufreq_get_freq(unsigned int lcore_id)
 int
 power_pstate_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	return set_freq_internal(&(lcore_power_info[lcore_id]), index);
 }
 
@@ -735,11 +710,6 @@ power_pstate_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx == 0 ||
 	    (pi->curr_idx == 1 && pi->turbo_available && !pi->turbo_enable))
@@ -754,11 +724,6 @@ power_pstate_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx + 1 == pi->nb_freqs)
 		return 0;
@@ -770,11 +735,6 @@ power_pstate_cpufreq_freq_down(unsigned int lcore_id)
 int
 power_pstate_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	/* Frequencies in the array are from high to low. */
 	if (lcore_power_info[lcore_id].turbo_available) {
 		if (lcore_power_info[lcore_id].turbo_enable)
@@ -795,11 +755,6 @@ power_pstate_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	/* Frequencies in the array are from high to low. */
@@ -812,11 +767,6 @@ power_pstate_turbo_status(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	return pi->turbo_enable;
@@ -827,11 +777,6 @@ power_pstate_enable_turbo(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	if (pi->turbo_available)
@@ -853,11 +798,6 @@ power_pstate_disable_turbo(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	pi->turbo_enable = 0;
@@ -881,11 +821,6 @@ int power_pstate_get_capabilities(unsigned int lcore_id,
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v1 15/15] power/kvm_vm: remove the verification of lcore ID
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (13 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 14/15] power/intel_pstate: " Huisong Li
@ 2026-04-16  3:06 ` Huisong Li
  2026-04-16 15:51 ` [PATCH v1 00/15] power: unify and improve lcore ID verification Stephen Hemminger
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
  16 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-04-16  3:06 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Now the lcore ID has been verified in framework API, so remove
the verification in driver.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/kvm_vm/kvm_vm.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/drivers/power/kvm_vm/kvm_vm.c b/drivers/power/kvm_vm/kvm_vm.c
index 816863da7a..e8b454bb55 100644
--- a/drivers/power/kvm_vm/kvm_vm.c
+++ b/drivers/power/kvm_vm/kvm_vm.c
@@ -24,11 +24,6 @@ power_kvm_vm_check_supported(void)
 int
 power_kvm_vm_init(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pkt[lcore_id].command = RTE_POWER_CPU_POWER;
 	pkt[lcore_id].resource_id = lcore_id;
 	return guest_channel_host_connect(FD_PATH, lcore_id);
@@ -73,11 +68,6 @@ send_msg(unsigned int lcore_id, uint32_t scale_direction)
 {
 	int ret;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -1;
-	}
-
 	pkt[lcore_id].unit = scale_direction;
 	ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);
 	if (ret == 0)
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* Re: [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check
  2026-04-16  3:05 ` [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check Huisong Li
@ 2026-04-16 15:48   ` Stephen Hemminger
  2026-04-17  2:51     ` lihuisong (C)
  0 siblings, 1 reply; 39+ messages in thread
From: Stephen Hemminger @ 2026-04-16 15:48 UTC (permalink / raw)
  To: Huisong Li
  Cc: anatoly.burakov, sivaprasad.tummala, dev, thomas, fengchengwen,
	yangxingui, zhanjie9

On Thu, 16 Apr 2026 11:05:58 +0800
Huisong Li <lihuisong@huawei.com> wrote:

> The locre ID in cpufreq power must be enabled core in application.
Spelling error, use checkpatch next time, it runs a spell checker.
Also run devtools/check-git-log there other issues in the commit messages.

> Use rte_lcore_is_enabled to verify lcore_id.
> 
> Fixes: 6f987b594fa6 ("power: refactor core power management")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> ---

The rte_lcore_is_enabled() will return false for service lcores.
Is this a bug or a feature here?

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v1 00/15] power: unify and improve lcore ID verification
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (14 preceding siblings ...)
  2026-04-16  3:06 ` [PATCH v1 15/15] power/kvm_vm: " Huisong Li
@ 2026-04-16 15:51 ` Stephen Hemminger
  2026-04-17  2:53   ` lihuisong (C)
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
  16 siblings, 1 reply; 39+ messages in thread
From: Stephen Hemminger @ 2026-04-16 15:51 UTC (permalink / raw)
  To: Huisong Li
  Cc: anatoly.burakov, sivaprasad.tummala, dev, thomas, fengchengwen,
	yangxingui, zhanjie9

On Thu, 16 Apr 2026 11:05:57 +0800
Huisong Li <lihuisong@huawei.com> wrote:

> This patch series reworks the lcore ID verification logic within the power
> library to ensure consistency and improve maintainability. Currently, various
> cpufreq drivers implement their own lcore ID checks, often relying on simple
> range checks that do not account for whether a core is actually enabled in
> the application.
> 
> Key Changes:
> 1. Replaces basic range checks with rte_lcore_is_enabled() across all
>    cpufreq drivers (ACPI, AMD P-state, CPPC, Intel P-state, and KVM VM).
>    This ensures the power library only operates on lcores assigned to the
>    application.
> 2. Introduces a common macro in the power library's internal headers to
>    standardize lcore ID verification.
> 3. Moves the verification logic from individual driver implementations up
>    to the high-level framework API. This reduces duplication code and
>    ensures that all drivers benefit from uniform validation.
> 4. Updates the power QoS and PMD Management libraries to use the new macro.
> 
> Huisong Li (15):
>   power/kvm_vm: enforce enabled lcore ID check
>   power/acpi_cpufreq: enforce enabled lcore ID check
>   power/amd_pstate: enforce enabled lcore ID check
>   power/cppc_cpufreq: enforce enabled lcore ID check
>   power/intel_pstate: enforce enabled lcore ID check
>   power: enforce enabled lcore ID check
>   power: add a common macro to verify lcore ID
>   power/pmd_mgmt: replace lcore ID verification with new macro
>   power/qos: replace the lcore ID verification with new macro
>   power/cpufreq: add the lcore ID verification to framework
>   power/acpi_cpufreq: remove the verification of lcore ID
>   power/amd_pstate: remove the verification of lcore ID
>   power/cppc_cpufreq: remove the verification of lcore ID
>   power/intel_pstate: remove the verification of lcore ID
>   power/kvm_vm: remove the verification of lcore ID
> 
>  drivers/power/acpi/acpi_cpufreq.c             | 65 -------------------
>  drivers/power/amd_pstate/amd_pstate_cpufreq.c | 65 -------------------
>  drivers/power/cppc/cppc_cpufreq.c             | 65 -------------------
>  .../power/intel_pstate/intel_pstate_cpufreq.c | 65 -------------------
>  drivers/power/kvm_vm/kvm_vm.c                 | 10 ---
>  lib/power/power_common.h                      |  7 ++
>  lib/power/rte_power_cpufreq.c                 | 14 ++++
>  lib/power/rte_power_pmd_mgmt.c                | 25 ++-----
>  lib/power/rte_power_qos.c                     | 10 +--
>  9 files changed, 30 insertions(+), 296 deletions(-)
> 

Patch 3 did not get sent in the series maybe too big or mail issue?

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check
  2026-04-16 15:48   ` Stephen Hemminger
@ 2026-04-17  2:51     ` lihuisong (C)
  2026-04-21 11:07       ` lihuisong (C)
  2026-04-21 14:23       ` Stephen Hemminger
  0 siblings, 2 replies; 39+ messages in thread
From: lihuisong (C) @ 2026-04-17  2:51 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: anatoly.burakov, sivaprasad.tummala, dev, thomas, fengchengwen,
	yangxingui, zhanjie9


On 4/16/2026 11:48 PM, Stephen Hemminger wrote:
> On Thu, 16 Apr 2026 11:05:58 +0800
> Huisong Li <lihuisong@huawei.com> wrote:
>
>> The locre ID in cpufreq power must be enabled core in application.
> Spelling error, use checkpatch next time, it runs a spell checker.
> Also run devtools/check-git-log there other issues in the commit messages.
Sorry for this.
Yeah, I used checkpatch.sh and check-git-log.sh before sent out.
But it didn't found this. I guess that because the "locre" is not a word.
>> Use rte_lcore_is_enabled to verify lcore_id.
>>
>> Fixes: 6f987b594fa6 ("power: refactor core power management")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Huisong Li <lihuisong@huawei.com>
>> ---
> The rte_lcore_is_enabled() will return false for service lcores.
> Is this a bug or a feature here?
My understanding is that the ROLE_RTE core is used to tasks on data 
plane and the ROLE_SERVICE core is used to periodic or control-plane tasks.
Currently, power management in DPDK is mainly processed based on 
services on the data plane, like the usage in pmd_mgmt or l3fwd-power.
However, the tasks on the service cores may also occupy 100% CPU.
Therefore, power library or driver should be able to be work with these 
tasks.
 From this perspective, allowing the ROLE_SERVICE core to set power has 
the least impact on applications in this series.
what do you think, Stephen?

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v1 00/15] power: unify and improve lcore ID verification
  2026-04-16 15:51 ` [PATCH v1 00/15] power: unify and improve lcore ID verification Stephen Hemminger
@ 2026-04-17  2:53   ` lihuisong (C)
  0 siblings, 0 replies; 39+ messages in thread
From: lihuisong (C) @ 2026-04-17  2:53 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: anatoly.burakov, sivaprasad.tummala, dev, thomas, fengchengwen,
	yangxingui, zhanjie9


On 4/16/2026 11:51 PM, Stephen Hemminger wrote:
> On Thu, 16 Apr 2026 11:05:57 +0800
> Huisong Li <lihuisong@huawei.com> wrote:
>
>> This patch series reworks the lcore ID verification logic within the power
>> library to ensure consistency and improve maintainability. Currently, various
>> cpufreq drivers implement their own lcore ID checks, often relying on simple
>> range checks that do not account for whether a core is actually enabled in
>> the application.
>>
>> Key Changes:
>> 1. Replaces basic range checks with rte_lcore_is_enabled() across all
>>     cpufreq drivers (ACPI, AMD P-state, CPPC, Intel P-state, and KVM VM).
>>     This ensures the power library only operates on lcores assigned to the
>>     application.
>> 2. Introduces a common macro in the power library's internal headers to
>>     standardize lcore ID verification.
>> 3. Moves the verification logic from individual driver implementations up
>>     to the high-level framework API. This reduces duplication code and
>>     ensures that all drivers benefit from uniform validation.
>> 4. Updates the power QoS and PMD Management libraries to use the new macro.
>>
>> Huisong Li (15):
>>    power/kvm_vm: enforce enabled lcore ID check
>>    power/acpi_cpufreq: enforce enabled lcore ID check
>>    power/amd_pstate: enforce enabled lcore ID check
>>    power/cppc_cpufreq: enforce enabled lcore ID check
>>    power/intel_pstate: enforce enabled lcore ID check
>>    power: enforce enabled lcore ID check
>>    power: add a common macro to verify lcore ID
>>    power/pmd_mgmt: replace lcore ID verification with new macro
>>    power/qos: replace the lcore ID verification with new macro
>>    power/cpufreq: add the lcore ID verification to framework
>>    power/acpi_cpufreq: remove the verification of lcore ID
>>    power/amd_pstate: remove the verification of lcore ID
>>    power/cppc_cpufreq: remove the verification of lcore ID
>>    power/intel_pstate: remove the verification of lcore ID
>>    power/kvm_vm: remove the verification of lcore ID
>>
>>   drivers/power/acpi/acpi_cpufreq.c             | 65 -------------------
>>   drivers/power/amd_pstate/amd_pstate_cpufreq.c | 65 -------------------
>>   drivers/power/cppc/cppc_cpufreq.c             | 65 -------------------
>>   .../power/intel_pstate/intel_pstate_cpufreq.c | 65 -------------------
>>   drivers/power/kvm_vm/kvm_vm.c                 | 10 ---
>>   lib/power/power_common.h                      |  7 ++
>>   lib/power/rte_power_cpufreq.c                 | 14 ++++
>>   lib/power/rte_power_pmd_mgmt.c                | 25 ++-----
>>   lib/power/rte_power_qos.c                     | 10 +--
>>   9 files changed, 30 insertions(+), 296 deletions(-)
>>
> Patch 3 did not get sent in the series maybe too big or mail issue?
It is in the series. I can see it in dpdk patch list.
https://patches.dpdk.org/project/dpdk/patch/20260416030612.2379407-2-lihuisong@huawei.com/ 


^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check
  2026-04-17  2:51     ` lihuisong (C)
@ 2026-04-21 11:07       ` lihuisong (C)
  2026-04-21 14:23       ` Stephen Hemminger
  1 sibling, 0 replies; 39+ messages in thread
From: lihuisong (C) @ 2026-04-21 11:07 UTC (permalink / raw)
  To: sivaprasad.tummala
  Cc: anatoly.burakov, dev, thomas, fengchengwen, yangxingui, zhanjie9,
	Stephen Hemminger


On 4/17/2026 10:51 AM, lihuisong (C) wrote:
>
> On 4/16/2026 11:48 PM, Stephen Hemminger wrote:
>> On Thu, 16 Apr 2026 11:05:58 +0800
>> Huisong Li <lihuisong@huawei.com> wrote:
>>
>>> The locre ID in cpufreq power must be enabled core in application.
>> Spelling error, use checkpatch next time, it runs a spell checker.
>> Also run devtools/check-git-log there other issues in the commit 
>> messages.
> Sorry for this.
> Yeah, I used checkpatch.sh and check-git-log.sh before sent out.
> But it didn't found this. I guess that because the "locre" is not a word.
>>> Use rte_lcore_is_enabled to verify lcore_id.
>>>
>>> Fixes: 6f987b594fa6 ("power: refactor core power management")
>>> Cc: stable@dpdk.org
>>>
>>> Signed-off-by: Huisong Li <lihuisong@huawei.com>
>>> ---
>> The rte_lcore_is_enabled() will return false for service lcores.
>> Is this a bug or a feature here?
> My understanding is that the ROLE_RTE core is used to tasks on data 
> plane and the ROLE_SERVICE core is used to periodic or control-plane 
> tasks.
> Currently, power management in DPDK is mainly processed based on 
> services on the data plane, like the usage in pmd_mgmt or l3fwd-power.
> However, the tasks on the service cores may also occupy 100% CPU.
> Therefore, power library or driver should be able to be work with 
> these tasks.
> From this perspective, allowing the ROLE_SERVICE core to set power has 
> the least impact on applications in this series.
> what do you think, Stephen?
Hi Sivaprasad,

Do you think we need to allow the role_service core to set cpufreq?

/Huisong

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check
  2026-04-17  2:51     ` lihuisong (C)
  2026-04-21 11:07       ` lihuisong (C)
@ 2026-04-21 14:23       ` Stephen Hemminger
  2026-04-22  9:18         ` lihuisong (C)
  1 sibling, 1 reply; 39+ messages in thread
From: Stephen Hemminger @ 2026-04-21 14:23 UTC (permalink / raw)
  To: lihuisong (C)
  Cc: anatoly.burakov, sivaprasad.tummala, dev, thomas, fengchengwen,
	yangxingui, zhanjie9

On Fri, 17 Apr 2026 10:51:48 +0800
"lihuisong (C)" <lihuisong@huawei.com> wrote:

> On 4/16/2026 11:48 PM, Stephen Hemminger wrote:
> > On Thu, 16 Apr 2026 11:05:58 +0800
> > Huisong Li <lihuisong@huawei.com> wrote:
> >  
> >> The locre ID in cpufreq power must be enabled core in application.  
> > Spelling error, use checkpatch next time, it runs a spell checker.
> > Also run devtools/check-git-log there other issues in the commit messages.  
> Sorry for this.
> Yeah, I used checkpatch.sh and check-git-log.sh before sent out.
> But it didn't found this. I guess that because the "locre" is not a word.
> >> Use rte_lcore_is_enabled to verify lcore_id.
> >>
> >> Fixes: 6f987b594fa6 ("power: refactor core power management")
> >> Cc: stable@dpdk.org
> >>
> >> Signed-off-by: Huisong Li <lihuisong@huawei.com>
> >> ---  
> > The rte_lcore_is_enabled() will return false for service lcores.
> > Is this a bug or a feature here?  
> My understanding is that the ROLE_RTE core is used to tasks on data 
> plane and the ROLE_SERVICE core is used to periodic or control-plane tasks.
> Currently, power management in DPDK is mainly processed based on 
> services on the data plane, like the usage in pmd_mgmt or l3fwd-power.
> However, the tasks on the service cores may also occupy 100% CPU.
> Therefore, power library or driver should be able to be work with these 
> tasks.
>  From this perspective, allowing the ROLE_SERVICE core to set power has 
> the least impact on applications in this series.
> what do you think, Stephen?


Service lcore's are just things doing other work.
They really should not be doing non-blocking poll, that is a mistake.
The service cores are intended for control path things.

The power API should ignore them in general but not break if a user
calls a power API from a service thread.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check
  2026-04-21 14:23       ` Stephen Hemminger
@ 2026-04-22  9:18         ` lihuisong (C)
  0 siblings, 0 replies; 39+ messages in thread
From: lihuisong (C) @ 2026-04-22  9:18 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: anatoly.burakov, sivaprasad.tummala, dev, thomas, fengchengwen,
	yangxingui, zhanjie9


On 4/21/2026 10:23 PM, Stephen Hemminger wrote:
> On Fri, 17 Apr 2026 10:51:48 +0800
> "lihuisong (C)" <lihuisong@huawei.com> wrote:
>
>> On 4/16/2026 11:48 PM, Stephen Hemminger wrote:
>>> On Thu, 16 Apr 2026 11:05:58 +0800
>>> Huisong Li <lihuisong@huawei.com> wrote:
>>>   
>>>> The locre ID in cpufreq power must be enabled core in application.
>>> Spelling error, use checkpatch next time, it runs a spell checker.
>>> Also run devtools/check-git-log there other issues in the commit messages.
>> Sorry for this.
>> Yeah, I used checkpatch.sh and check-git-log.sh before sent out.
>> But it didn't found this. I guess that because the "locre" is not a word.
>>>> Use rte_lcore_is_enabled to verify lcore_id.
>>>>
>>>> Fixes: 6f987b594fa6 ("power: refactor core power management")
>>>> Cc: stable@dpdk.org
>>>>
>>>> Signed-off-by: Huisong Li <lihuisong@huawei.com>
>>>> ---
>>> The rte_lcore_is_enabled() will return false for service lcores.
>>> Is this a bug or a feature here?
>> My understanding is that the ROLE_RTE core is used to tasks on data
>> plane and the ROLE_SERVICE core is used to periodic or control-plane tasks.
>> Currently, power management in DPDK is mainly processed based on
>> services on the data plane, like the usage in pmd_mgmt or l3fwd-power.
>> However, the tasks on the service cores may also occupy 100% CPU.
>> Therefore, power library or driver should be able to be work with these
>> tasks.
>>   From this perspective, allowing the ROLE_SERVICE core to set power has
>> the least impact on applications in this series.
>> what do you think, Stephen?
>
> Service lcore's are just things doing other work.
> They really should not be doing non-blocking poll, that is a mistake.
> The service cores are intended for control path things.
got it.
>
> The power API should ignore them in general but not break if a user
> calls a power API from a service thread.
What you suggest is that we should allow the service core to 
successfully set the power API?
I know this approach has the least impact.

However, pmd_mgmt lib is also used together with the data plane task of 
network devices.
They should only allow the ROLE_RTE core to use them.
I originally wanted to extract a common macro to verify the lcore in 
power lib.
This common macro is not appropriate to pmd_mgmt lib if this common 
macro counts ROLE_SERVICE core as valid.

But we don't know if aplication having the service core thread used 
cpufreq API.
Although they may not be used in general, it seems that we need allow 
the service core to set the cpufreq API.

^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH V2 00/15] power: unify and improve lcore ID verification
  2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
                   ` (15 preceding siblings ...)
  2026-04-16 15:51 ` [PATCH v1 00/15] power: unify and improve lcore ID verification Stephen Hemminger
@ 2026-05-07  2:42 ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 01/15] eal: add interface to check if lcore is EAL managed Huisong Li
                     ` (14 more replies)
  16 siblings, 15 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

This patch series reworks the lcore ID verification logic within the
power library to ensure consistency and improve maintainability.

Currently, various cpufreq drivers implement their own lcore ID checks,
which are limited to simple range validation and involve significant
code duplication. Moreover, these checks do not account for whether the
core is actually managed by the application.

For the verification in cpufreq-related APIs and power QoS APIs, although
service cores do not typically invoke these APIs, they may operate in
polling modes where power management is required. To maintain compatibility
with applications using service cores, the validation logic now explicitly
allows both ROLE_RTE and ROLE_SERVICE.

But the lcore ID in the pmd_mgmt library must be ROLE_RTE because it is
mainly used together with the data plane of ethdev PMD. So use
rte_lcore_is_enabled to verify.

Key Changes:
1. Add lcore role verification to individual cpufreq drivers.
2. Introduces a unified macro in the power library to standardize lcore ID
   checks.
3. Moves verification logic from individualdrivers to the framework level.
   This reduces code duplication.
4. Allow the service cores to configure power QoS.
5. Use rte_lcore_is_enabled to verfify the lcore ID in pmd_mgmt.

---
v2:
 - Allow the service cores to set power API.

---

Huisong Li (15):
  eal: add interface to check if lcore is EAL managed
  power/kvm_vm: validate lcore role in cpufreq API
  power/acpi_cpufreq: validate lcore role in cpufreq API
  power/amd_pstate: validate lcore role in cpufreq API
  power/cppc_cpufreq: validate lcore role in cpufreq API
  power/intel_pstate: validate lcore role in cpufreq API
  power: add a common macro to verify lcore ID
  power/cpufreq: add the lcore ID verification to framework
  power/acpi_cpufreq: remove the verification of lcore ID
  power/amd_pstate: remove the verification of lcore ID
  power/cppc_cpufreq: remove the verification of lcore ID
  power/intel_pstate: remove the verification of lcore ID
  power/kvm_vm: remove the verification of lcore ID
  power: allow the service core to config power QoS
  power: add lcore ID check for PMD mgmt

 drivers/power/acpi/acpi_cpufreq.c             | 65 -------------------
 drivers/power/amd_pstate/amd_pstate_cpufreq.c | 65 -------------------
 drivers/power/cppc/cppc_cpufreq.c             | 65 -------------------
 .../power/intel_pstate/intel_pstate_cpufreq.c | 65 -------------------
 drivers/power/kvm_vm/kvm_vm.c                 | 10 ---
 lib/eal/common/eal_common_lcore.c             | 11 ++++
 lib/eal/include/rte_lcore.h                   | 11 ++++
 lib/power/power_common.h                      |  7 ++
 lib/power/rte_power_cpufreq.c                 | 14 +++-
 lib/power/rte_power_pmd_mgmt.c                | 21 +++---
 lib/power/rte_power_qos.c                     | 10 +--
 11 files changed, 55 insertions(+), 289 deletions(-)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH V2 01/15] eal: add interface to check if lcore is EAL managed
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 02/15] power/kvm_vm: validate lcore role in cpufreq API Huisong Li
                     ` (13 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Add a new helper function rte_lcore_is_eal_managed() to determine
if a logical core is managed by EAL.

This interface returns true if the lcore role is either ROLE_RTE
(standard worker/main cores) or ROLE_SERVICE (service cores).

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/eal/common/eal_common_lcore.c | 11 +++++++++++
 lib/eal/include/rte_lcore.h       | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/lib/eal/common/eal_common_lcore.c b/lib/eal/common/eal_common_lcore.c
index 39411f9370..dfbd96875a 100644
--- a/lib/eal/common/eal_common_lcore.c
+++ b/lib/eal/common/eal_common_lcore.c
@@ -102,6 +102,17 @@ int rte_lcore_is_enabled(unsigned int lcore_id)
 	return cfg->lcore_role[lcore_id] == ROLE_RTE;
 }
 
+RTE_EXPORT_SYMBOL(rte_lcore_is_eal_managed)
+int rte_lcore_is_eal_managed(unsigned int lcore_id)
+{
+	struct rte_config *cfg = rte_eal_get_configuration();
+
+	if (lcore_id >= RTE_MAX_LCORE)
+		return 0;
+	return cfg->lcore_role[lcore_id] == ROLE_RTE ||
+		cfg->lcore_role[lcore_id] == ROLE_SERVICE;
+}
+
 RTE_EXPORT_SYMBOL(rte_get_next_lcore)
 unsigned int rte_get_next_lcore(unsigned int i, int skip_main, int wrap)
 {
diff --git a/lib/eal/include/rte_lcore.h b/lib/eal/include/rte_lcore.h
index 10f965b4f0..cbfd50a936 100644
--- a/lib/eal/include/rte_lcore.h
+++ b/lib/eal/include/rte_lcore.h
@@ -195,6 +195,17 @@ rte_cpuset_t rte_lcore_cpuset(unsigned int lcore_id);
  */
 int rte_lcore_is_enabled(unsigned int lcore_id);
 
+/**
+ * Test if an lcore is ROLE_RTE or ROLE_SERVICE.
+ *
+ * @param lcore_id
+ *   The identifier of the lcore, which MUST be between 0 and
+ *   RTE_MAX_LCORE-1.
+ * @return
+ *   True if the given lcore is ROLE_RTE or ROLE_SERVICE; false otherwise.
+ */
+int rte_lcore_is_eal_managed(unsigned int lcore_id);
+
 /**
  * Get the next enabled lcore ID.
  *
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 02/15] power/kvm_vm: validate lcore role in cpufreq API
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
  2026-05-07  2:42   ` [PATCH V2 01/15] eal: add interface to check if lcore is EAL managed Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 03/15] power/acpi_cpufreq: " Huisong Li
                     ` (12 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Currently, the kvm_vm driver only checks if the lcore_id is within
the RTE_MAX_LCORE range, but fails to verify if the core is actually
active or managed by the application. This lacks sufficient validation.

This patch add a lcore role check to the cpufreq-related APIs.
Although service cores do not typically invoke these APIs, they may
operate in polling states where power management is required.
To maintain compatibility with applications using service cores, the
validation logic now explicitly allows both ROLE_RTE and ROLE_SERVICE.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/kvm_vm/kvm_vm.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/power/kvm_vm/kvm_vm.c b/drivers/power/kvm_vm/kvm_vm.c
index 5754a441cd..133d1f0882 100644
--- a/drivers/power/kvm_vm/kvm_vm.c
+++ b/drivers/power/kvm_vm/kvm_vm.c
@@ -24,11 +24,11 @@ power_kvm_vm_check_supported(void)
 int
 power_kvm_vm_init(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Core(%u) is out of range 0...%d",
-				lcore_id, RTE_MAX_LCORE-1);
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
+
 	pkt[lcore_id].command = RTE_POWER_CPU_POWER;
 	pkt[lcore_id].resource_id = lcore_id;
 	return guest_channel_host_connect(FD_PATH, lcore_id);
@@ -73,11 +73,11 @@ send_msg(unsigned int lcore_id, uint32_t scale_direction)
 {
 	int ret;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Core(%u) is out of range 0...%d",
-				lcore_id, RTE_MAX_LCORE-1);
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
+
 	pkt[lcore_id].unit = scale_direction;
 	ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);
 	if (ret == 0)
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 03/15] power/acpi_cpufreq: validate lcore role in cpufreq API
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
  2026-05-07  2:42   ` [PATCH V2 01/15] eal: add interface to check if lcore is EAL managed Huisong Li
  2026-05-07  2:42   ` [PATCH V2 02/15] power/kvm_vm: validate lcore role in cpufreq API Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 04/15] power/amd_pstate: " Huisong Li
                     ` (11 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Currently, the acpi_cpufreq driver only checks if the lcore_id is
within the RTE_MAX_LCORE range, but fails to verify if the core is
actually active or managed by the application. This lacks sufficient
validation.

This patch add a lcore role check to the cpufreq-related APIs.
Although service cores do not typically invoke these APIs, they may
operate in polling states where power management is required.
To maintain compatibility with applications using service cores, the
validation logic now explicitly allows both ROLE_RTE and ROLE_SERVICE.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/acpi/acpi_cpufreq.c | 56 +++++++++++++++----------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/power/acpi/acpi_cpufreq.c b/drivers/power/acpi/acpi_cpufreq.c
index 81a5e3f6ea..155b30fcf7 100644
--- a/drivers/power/acpi/acpi_cpufreq.c
+++ b/drivers/power/acpi/acpi_cpufreq.c
@@ -242,9 +242,8 @@ power_acpi_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -319,11 +318,11 @@ power_acpi_cpufreq_exit(unsigned int lcore_id)
 	struct acpi_power_info *pi;
 	uint32_t exp_state;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
+
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -373,8 +372,8 @@ power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return 0;
 	}
 
@@ -396,8 +395,8 @@ power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_acpi_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return RTE_POWER_INVALID_FREQ_INDEX;
 	}
 
@@ -407,8 +406,8 @@ power_acpi_cpufreq_get_freq(unsigned int lcore_id)
 int
 power_acpi_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -420,8 +419,8 @@ power_acpi_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -438,8 +437,8 @@ power_acpi_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -455,8 +454,8 @@ power_acpi_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_acpi_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -479,8 +478,8 @@ power_acpi_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -496,8 +495,8 @@ power_acpi_turbo_status(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -512,8 +511,8 @@ power_acpi_enable_turbo(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -545,8 +544,8 @@ power_acpi_disable_turbo(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -572,10 +571,11 @@ int power_acpi_get_capabilities(unsigned int lcore_id,
 {
 	struct acpi_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
+
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 04/15] power/amd_pstate: validate lcore role in cpufreq API
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (2 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 03/15] power/acpi_cpufreq: " Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 05/15] power/cppc_cpufreq: " Huisong Li
                     ` (10 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Currently, the amd_pstate driver only checks if the lcore_id is
within the RTE_MAX_LCORE range, but fails to verify if the core
is actually active or managed by the application. This lacks
sufficient validation.

This patch add a lcore role check to the cpufreq-related APIs.
Although service cores do not typically invoke these APIs, they may
operate in polling states where power management is required.
To maintain compatibility with applications using service cores, the
validation logic now explicitly allows both ROLE_RTE and ROLE_SERVICE.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/amd_pstate/amd_pstate_cpufreq.c | 56 +++++++++----------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/power/amd_pstate/amd_pstate_cpufreq.c b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
index 95495bff7d..bca148dc8d 100644
--- a/drivers/power/amd_pstate/amd_pstate_cpufreq.c
+++ b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
@@ -360,9 +360,8 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -443,11 +442,11 @@ power_amd_pstate_cpufreq_exit(unsigned int lcore_id)
 	struct amd_pstate_power_info *pi;
 	uint32_t exp_state;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
+
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -493,8 +492,8 @@ power_amd_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return 0;
 	}
 
@@ -516,8 +515,8 @@ power_amd_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t
 uint32_t
 power_amd_pstate_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return RTE_POWER_INVALID_FREQ_INDEX;
 	}
 
@@ -527,8 +526,8 @@ power_amd_pstate_cpufreq_get_freq(unsigned int lcore_id)
 int
 power_amd_pstate_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -540,8 +539,8 @@ power_amd_pstate_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -558,8 +557,8 @@ power_amd_pstate_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -575,8 +574,8 @@ power_amd_pstate_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_amd_pstate_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -600,8 +599,8 @@ power_amd_pstate_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -616,8 +615,8 @@ power_amd_pstate_turbo_status(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -631,8 +630,8 @@ power_amd_pstate_enable_turbo(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -667,8 +666,8 @@ power_amd_pstate_disable_turbo(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -695,10 +694,11 @@ power_amd_pstate_get_capabilities(unsigned int lcore_id,
 {
 	struct amd_pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
+
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 05/15] power/cppc_cpufreq: validate lcore role in cpufreq API
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (3 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 04/15] power/amd_pstate: " Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 06/15] power/intel_pstate: " Huisong Li
                     ` (9 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Currently, the cppc_cpufreq driver only checks if the lcore_id is
within the RTE_MAX_LCORE range, but fails to verify if the core is
actually active or managed by the application. This lacks sufficient
validation.

This patch add a lcore role check to the cpufreq-related APIs.
Although service cores do not typically invoke these APIs, they may
operate in polling states where power management is required.
To maintain compatibility with applications using service cores, the
validation logic now explicitly allows both ROLE_RTE and ROLE_SERVICE.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/cppc/cppc_cpufreq.c | 56 +++++++++++++++----------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/power/cppc/cppc_cpufreq.c b/drivers/power/cppc/cppc_cpufreq.c
index 3cd4165c83..7e1298110a 100644
--- a/drivers/power/cppc/cppc_cpufreq.c
+++ b/drivers/power/cppc/cppc_cpufreq.c
@@ -346,9 +346,8 @@ power_cppc_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -429,11 +428,11 @@ power_cppc_cpufreq_exit(unsigned int lcore_id)
 	struct cppc_power_info *pi;
 	uint32_t exp_state;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
+
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -479,8 +478,8 @@ power_cppc_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return 0;
 	}
 
@@ -502,8 +501,8 @@ power_cppc_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_cppc_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return RTE_POWER_INVALID_FREQ_INDEX;
 	}
 
@@ -513,8 +512,8 @@ power_cppc_cpufreq_get_freq(unsigned int lcore_id)
 int
 power_cppc_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -526,8 +525,8 @@ power_cppc_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -544,8 +543,8 @@ power_cppc_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -561,8 +560,8 @@ power_cppc_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_cppc_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -585,8 +584,8 @@ power_cppc_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -601,8 +600,8 @@ power_cppc_turbo_status(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -616,8 +615,8 @@ power_cppc_enable_turbo(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -652,8 +651,8 @@ power_cppc_disable_turbo(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -680,10 +679,11 @@ power_cppc_get_capabilities(unsigned int lcore_id,
 {
 	struct cppc_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
+
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 06/15] power/intel_pstate: validate lcore role in cpufreq API
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (4 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 05/15] power/cppc_cpufreq: " Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 07/15] power: add a common macro to verify lcore ID Huisong Li
                     ` (8 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Currently, the intel_pstate driver only checks if the lcore_id is
within the RTE_MAX_LCORE range, but fails to verify if the core is
actually active or managed by the application. This lacks sufficient
validation.

This patch add a lcore role check to the cpufreq-related APIs.
Although service cores do not typically invoke these APIs, they may
operate in polling states where power management is required.
To maintain compatibility with applications using service cores, the
validation logic now explicitly allows both ROLE_RTE and ROLE_SERVICE.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 .../power/intel_pstate/intel_pstate_cpufreq.c | 56 +++++++++----------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/power/intel_pstate/intel_pstate_cpufreq.c b/drivers/power/intel_pstate/intel_pstate_cpufreq.c
index 8e27570e3c..58be63fecc 100644
--- a/drivers/power/intel_pstate/intel_pstate_cpufreq.c
+++ b/drivers/power/intel_pstate/intel_pstate_cpufreq.c
@@ -548,9 +548,8 @@ power_pstate_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceed %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -630,11 +629,11 @@ power_pstate_cpufreq_exit(unsigned int lcore_id)
 	struct pstate_power_info *pi;
 	uint32_t exp_state;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Lcore id %u can not exceeds %u",
-				lcore_id, RTE_MAX_LCORE - 1U);
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
+
 	pi = &lcore_power_info[lcore_id];
 
 	exp_state = POWER_USED;
@@ -688,8 +687,8 @@ power_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return 0;
 	}
 
@@ -711,8 +710,8 @@ power_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_pstate_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return RTE_POWER_INVALID_FREQ_INDEX;
 	}
 
@@ -723,8 +722,8 @@ power_pstate_cpufreq_get_freq(unsigned int lcore_id)
 int
 power_pstate_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -736,8 +735,8 @@ power_pstate_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -755,8 +754,8 @@ power_pstate_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -771,8 +770,8 @@ power_pstate_cpufreq_freq_down(unsigned int lcore_id)
 int
 power_pstate_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -796,8 +795,8 @@ power_pstate_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -813,8 +812,8 @@ power_pstate_turbo_status(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -828,8 +827,8 @@ power_pstate_enable_turbo(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -854,8 +853,8 @@ power_pstate_disable_turbo(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
 
@@ -882,10 +881,11 @@ int power_pstate_get_capabilities(unsigned int lcore_id,
 {
 	struct pstate_power_info *pi;
 
-	if (lcore_id >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID");
+	if (!rte_lcore_is_eal_managed(lcore_id)) {
+		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
 		return -1;
 	}
+
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 07/15] power: add a common macro to verify lcore ID
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (5 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 06/15] power/intel_pstate: " Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 08/15] power/cpufreq: add the lcore ID verification to framework Huisong Li
                     ` (7 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

There are many places to verify lcore ID in power. So add a common macro
to do this to simplify code.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/power/power_common.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/power/power_common.h b/lib/power/power_common.h
index 3f56b1103d..78cebef59b 100644
--- a/lib/power/power_common.h
+++ b/lib/power/power_common.h
@@ -23,6 +23,13 @@ extern int rte_power_logtype;
 #define POWER_DEBUG_LOG(...)
 #endif
 
+#define RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, retval) do { \
+	if (!rte_lcore_is_eal_managed(lcore_id)) { \
+		POWER_LOG(ERR, "lcore id %u is invalid", lcore_id); \
+		return retval; \
+	} \
+} while (0)
+
 /* check if scaling driver matches one we want */
 __rte_internal
 int cpufreq_check_scaling_driver(const char *driver);
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 08/15] power/cpufreq: add the lcore ID verification to framework
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (6 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 07/15] power: add a common macro to verify lcore ID Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 09/15] power/acpi_cpufreq: remove the verification of lcore ID Huisong Li
                     ` (6 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

The lcore ID verification is common for each cpufreq driver.
So add this verification to framework.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/power/rte_power_cpufreq.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/power/rte_power_cpufreq.c b/lib/power/rte_power_cpufreq.c
index f63e976dc2..54872debfa 100644
--- a/lib/power/rte_power_cpufreq.c
+++ b/lib/power/rte_power_cpufreq.c
@@ -1,7 +1,6 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(c) 2010-2014 Intel Corporation
  */
-
 #include <eal_export.h>
 #include <rte_spinlock.h>
 #include <rte_debug.h>
@@ -116,6 +115,7 @@ rte_power_init(unsigned int lcore_id)
 	struct rte_power_cpufreq_ops *ops;
 	uint8_t env;
 
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	if (global_default_env != PM_ENV_NOT_SET)
 		return global_cpufreq_ops->init(lcore_id);
 
@@ -147,6 +147,7 @@ RTE_EXPORT_SYMBOL(rte_power_exit)
 int
 rte_power_exit(unsigned int lcore_id)
 {
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	if (global_default_env != PM_ENV_NOT_SET)
 		return global_cpufreq_ops->exit(lcore_id);
 
@@ -161,6 +162,7 @@ uint32_t
 rte_power_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t n)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, 0);
 	return global_cpufreq_ops->get_avail_freqs(lcore_id, freqs, n);
 }
 
@@ -169,6 +171,7 @@ uint32_t
 rte_power_get_freq(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, RTE_POWER_INVALID_FREQ_INDEX);
 	return global_cpufreq_ops->get_freq(lcore_id);
 }
 
@@ -177,6 +180,7 @@ uint32_t
 rte_power_set_freq(unsigned int lcore_id, uint32_t index)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->set_freq(lcore_id, index);
 }
 
@@ -185,6 +189,7 @@ int
 rte_power_freq_up(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->freq_up(lcore_id);
 }
 
@@ -193,6 +198,7 @@ int
 rte_power_freq_down(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->freq_down(lcore_id);
 }
 
@@ -201,6 +207,7 @@ int
 rte_power_freq_max(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->freq_max(lcore_id);
 }
 
@@ -209,6 +216,7 @@ int
 rte_power_freq_min(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->freq_min(lcore_id);
 }
 
@@ -217,6 +225,7 @@ int
 rte_power_turbo_status(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->turbo_status(lcore_id);
 }
 
@@ -225,6 +234,7 @@ int
 rte_power_freq_enable_turbo(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->enable_turbo(lcore_id);
 }
 
@@ -233,6 +243,7 @@ int
 rte_power_freq_disable_turbo(unsigned int lcore_id)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->disable_turbo(lcore_id);
 }
 
@@ -242,5 +253,6 @@ rte_power_get_capabilities(unsigned int lcore_id,
 		struct rte_power_core_capabilities *caps)
 {
 	RTE_ASSERT(global_cpufreq_ops != NULL);
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -1);
 	return global_cpufreq_ops->get_caps(lcore_id, caps);
 }
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 09/15] power/acpi_cpufreq: remove the verification of lcore ID
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (7 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 08/15] power/cpufreq: add the lcore ID verification to framework Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 10/15] power/amd_pstate: " Huisong Li
                     ` (5 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Now the lcore id has been verified in framework API, so remove
the verification in driver.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/acpi/acpi_cpufreq.c | 65 -------------------------------
 1 file changed, 65 deletions(-)

diff --git a/drivers/power/acpi/acpi_cpufreq.c b/drivers/power/acpi/acpi_cpufreq.c
index 155b30fcf7..9c78b4cb1a 100644
--- a/drivers/power/acpi/acpi_cpufreq.c
+++ b/drivers/power/acpi/acpi_cpufreq.c
@@ -242,11 +242,6 @@ power_acpi_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_IDLE;
 	/* The power in use state works as a guard variable between
@@ -318,11 +313,6 @@ power_acpi_cpufreq_exit(unsigned int lcore_id)
 	struct acpi_power_info *pi;
 	uint32_t exp_state;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -372,11 +362,6 @@ power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return 0;
-	}
-
 	if (freqs == NULL) {
 		POWER_LOG(ERR, "NULL buffer supplied");
 		return 0;
@@ -395,22 +380,12 @@ power_acpi_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_acpi_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return RTE_POWER_INVALID_FREQ_INDEX;
-	}
-
 	return lcore_power_info[lcore_id].curr_idx;
 }
 
 int
 power_acpi_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	return set_freq_internal(&(lcore_power_info[lcore_id]), index);
 }
 
@@ -419,11 +394,6 @@ power_acpi_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx + 1 == pi->nb_freqs)
 		return 0;
@@ -437,11 +407,6 @@ power_acpi_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx == 0 ||
 	    (pi->curr_idx == 1 && pi->turbo_available && !pi->turbo_enable))
@@ -454,11 +419,6 @@ power_acpi_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_acpi_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	/* Frequencies in the array are from high to low. */
 	if (lcore_power_info[lcore_id].turbo_available) {
 		if (lcore_power_info[lcore_id].turbo_enable)
@@ -478,11 +438,6 @@ power_acpi_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	/* Frequencies in the array are from high to low. */
@@ -495,11 +450,6 @@ power_acpi_turbo_status(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	return pi->turbo_enable;
@@ -511,11 +461,6 @@ power_acpi_enable_turbo(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	if (pi->turbo_available)
@@ -544,11 +489,6 @@ power_acpi_disable_turbo(unsigned int lcore_id)
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	 pi->turbo_enable = 0;
@@ -571,11 +511,6 @@ int power_acpi_get_capabilities(unsigned int lcore_id,
 {
 	struct acpi_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 10/15] power/amd_pstate: remove the verification of lcore ID
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (8 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 09/15] power/acpi_cpufreq: remove the verification of lcore ID Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 11/15] power/cppc_cpufreq: " Huisong Li
                     ` (4 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Now the lcore ID has been verified in framework API, so remove
the verification in driver.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/amd_pstate/amd_pstate_cpufreq.c | 65 -------------------
 1 file changed, 65 deletions(-)

diff --git a/drivers/power/amd_pstate/amd_pstate_cpufreq.c b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
index bca148dc8d..8ca27d689d 100644
--- a/drivers/power/amd_pstate/amd_pstate_cpufreq.c
+++ b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
@@ -360,11 +360,6 @@ power_amd_pstate_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_IDLE;
 	/* The power in use state works as a guard variable between
@@ -442,11 +437,6 @@ power_amd_pstate_cpufreq_exit(unsigned int lcore_id)
 	struct amd_pstate_power_info *pi;
 	uint32_t exp_state;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -492,11 +482,6 @@ power_amd_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return 0;
-	}
-
 	if (freqs == NULL) {
 		POWER_LOG(ERR, "NULL buffer supplied");
 		return 0;
@@ -515,22 +500,12 @@ power_amd_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t
 uint32_t
 power_amd_pstate_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return RTE_POWER_INVALID_FREQ_INDEX;
-	}
-
 	return lcore_power_info[lcore_id].curr_idx;
 }
 
 int
 power_amd_pstate_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	return set_freq_internal(&(lcore_power_info[lcore_id]), index);
 }
 
@@ -539,11 +514,6 @@ power_amd_pstate_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx + 1 == pi->nb_freqs)
 		return 0;
@@ -557,11 +527,6 @@ power_amd_pstate_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx == 0 || (pi->curr_idx == pi->nom_idx &&
 		pi->turbo_available && !pi->turbo_enable))
@@ -574,11 +539,6 @@ power_amd_pstate_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_amd_pstate_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	/* Frequencies in the array are from high to low. */
 	if (lcore_power_info[lcore_id].turbo_available) {
 		if (lcore_power_info[lcore_id].turbo_enable)
@@ -599,11 +559,6 @@ power_amd_pstate_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	/* Frequencies in the array are from high to low. */
@@ -615,11 +570,6 @@ power_amd_pstate_turbo_status(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	return pi->turbo_enable;
@@ -630,11 +580,6 @@ power_amd_pstate_enable_turbo(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	if (pi->turbo_available)
@@ -666,11 +611,6 @@ power_amd_pstate_disable_turbo(unsigned int lcore_id)
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	pi->turbo_enable = 0;
@@ -694,11 +634,6 @@ power_amd_pstate_get_capabilities(unsigned int lcore_id,
 {
 	struct amd_pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 11/15] power/cppc_cpufreq: remove the verification of lcore ID
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (9 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 10/15] power/amd_pstate: " Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 12/15] power/intel_pstate: " Huisong Li
                     ` (3 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Now the lcore ID has been verified in framework API, so remove
the verification in driver.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/cppc/cppc_cpufreq.c | 65 -------------------------------
 1 file changed, 65 deletions(-)

diff --git a/drivers/power/cppc/cppc_cpufreq.c b/drivers/power/cppc/cppc_cpufreq.c
index 7e1298110a..529f68e574 100644
--- a/drivers/power/cppc/cppc_cpufreq.c
+++ b/drivers/power/cppc/cppc_cpufreq.c
@@ -346,11 +346,6 @@ power_cppc_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_IDLE;
 	/* The power in use state works as a guard variable between
@@ -428,11 +423,6 @@ power_cppc_cpufreq_exit(unsigned int lcore_id)
 	struct cppc_power_info *pi;
 	uint32_t exp_state;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_USED;
 	/* The power in use state works as a guard variable between
@@ -478,11 +468,6 @@ power_cppc_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return 0;
-	}
-
 	if (freqs == NULL) {
 		POWER_LOG(ERR, "NULL buffer supplied");
 		return 0;
@@ -501,22 +486,12 @@ power_cppc_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_cppc_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return RTE_POWER_INVALID_FREQ_INDEX;
-	}
-
 	return lcore_power_info[lcore_id].curr_idx;
 }
 
 int
 power_cppc_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	return set_freq_internal(&(lcore_power_info[lcore_id]), index);
 }
 
@@ -525,11 +500,6 @@ power_cppc_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx + 1 == pi->nb_freqs)
 		return 0;
@@ -543,11 +513,6 @@ power_cppc_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx == 0 || (pi->curr_idx == 1 &&
 		pi->turbo_available && !pi->turbo_enable))
@@ -560,11 +525,6 @@ power_cppc_cpufreq_freq_up(unsigned int lcore_id)
 int
 power_cppc_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	/* Frequencies in the array are from high to low. */
 	if (lcore_power_info[lcore_id].turbo_available) {
 		if (lcore_power_info[lcore_id].turbo_enable)
@@ -584,11 +544,6 @@ power_cppc_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	/* Frequencies in the array are from high to low. */
@@ -600,11 +555,6 @@ power_cppc_turbo_status(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	return pi->turbo_enable;
@@ -615,11 +565,6 @@ power_cppc_enable_turbo(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	if (pi->turbo_available)
@@ -651,11 +596,6 @@ power_cppc_disable_turbo(unsigned int lcore_id)
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	pi->turbo_enable = 0;
@@ -679,11 +619,6 @@ power_cppc_get_capabilities(unsigned int lcore_id,
 {
 	struct cppc_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 12/15] power/intel_pstate: remove the verification of lcore ID
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (10 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 11/15] power/cppc_cpufreq: " Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 13/15] power/kvm_vm: " Huisong Li
                     ` (2 subsequent siblings)
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Now the lcore ID has been verified in framework API, so remove
the verification in driver.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 .../power/intel_pstate/intel_pstate_cpufreq.c | 65 -------------------
 1 file changed, 65 deletions(-)

diff --git a/drivers/power/intel_pstate/intel_pstate_cpufreq.c b/drivers/power/intel_pstate/intel_pstate_cpufreq.c
index 58be63fecc..e7ed9c8260 100644
--- a/drivers/power/intel_pstate/intel_pstate_cpufreq.c
+++ b/drivers/power/intel_pstate/intel_pstate_cpufreq.c
@@ -548,11 +548,6 @@ power_pstate_cpufreq_init(unsigned int lcore_id)
 		return -1;
 	}
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	exp_state = POWER_IDLE;
 	/* The power in use state works as a guard variable between
@@ -629,11 +624,6 @@ power_pstate_cpufreq_exit(unsigned int lcore_id)
 	struct pstate_power_info *pi;
 	uint32_t exp_state;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	exp_state = POWER_USED;
@@ -687,11 +677,6 @@ power_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return 0;
-	}
-
 	if (freqs == NULL) {
 		POWER_LOG(ERR, "NULL buffer supplied");
 		return 0;
@@ -710,11 +695,6 @@ power_pstate_cpufreq_freqs(unsigned int lcore_id, uint32_t *freqs, uint32_t num)
 uint32_t
 power_pstate_cpufreq_get_freq(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return RTE_POWER_INVALID_FREQ_INDEX;
-	}
-
 	return lcore_power_info[lcore_id].curr_idx;
 }
 
@@ -722,11 +702,6 @@ power_pstate_cpufreq_get_freq(unsigned int lcore_id)
 int
 power_pstate_cpufreq_set_freq(unsigned int lcore_id, uint32_t index)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	return set_freq_internal(&(lcore_power_info[lcore_id]), index);
 }
 
@@ -735,11 +710,6 @@ power_pstate_cpufreq_freq_up(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx == 0 ||
 	    (pi->curr_idx == 1 && pi->turbo_available && !pi->turbo_enable))
@@ -754,11 +724,6 @@ power_pstate_cpufreq_freq_down(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 	if (pi->curr_idx + 1 == pi->nb_freqs)
 		return 0;
@@ -770,11 +735,6 @@ power_pstate_cpufreq_freq_down(unsigned int lcore_id)
 int
 power_pstate_cpufreq_freq_max(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	/* Frequencies in the array are from high to low. */
 	if (lcore_power_info[lcore_id].turbo_available) {
 		if (lcore_power_info[lcore_id].turbo_enable)
@@ -795,11 +755,6 @@ power_pstate_cpufreq_freq_min(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	/* Frequencies in the array are from high to low. */
@@ -812,11 +767,6 @@ power_pstate_turbo_status(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	return pi->turbo_enable;
@@ -827,11 +777,6 @@ power_pstate_enable_turbo(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	if (pi->turbo_available)
@@ -853,11 +798,6 @@ power_pstate_disable_turbo(unsigned int lcore_id)
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pi = &lcore_power_info[lcore_id];
 
 	pi->turbo_enable = 0;
@@ -881,11 +821,6 @@ int power_pstate_get_capabilities(unsigned int lcore_id,
 {
 	struct pstate_power_info *pi;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	if (caps == NULL) {
 		POWER_LOG(ERR, "Invalid argument");
 		return -1;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 13/15] power/kvm_vm: remove the verification of lcore ID
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (11 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 12/15] power/intel_pstate: " Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 14/15] power: allow the service core to config power QoS Huisong Li
  2026-05-07  2:42   ` [PATCH V2 15/15] power: add lcore ID check for PMD mgmt Huisong Li
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

Now the lcore ID has been verified in framework API, so remove
the verification in driver.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/kvm_vm/kvm_vm.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/drivers/power/kvm_vm/kvm_vm.c b/drivers/power/kvm_vm/kvm_vm.c
index 133d1f0882..e8b454bb55 100644
--- a/drivers/power/kvm_vm/kvm_vm.c
+++ b/drivers/power/kvm_vm/kvm_vm.c
@@ -24,11 +24,6 @@ power_kvm_vm_check_supported(void)
 int
 power_kvm_vm_init(unsigned int lcore_id)
 {
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pkt[lcore_id].command = RTE_POWER_CPU_POWER;
 	pkt[lcore_id].resource_id = lcore_id;
 	return guest_channel_host_connect(FD_PATH, lcore_id);
@@ -73,11 +68,6 @@ send_msg(unsigned int lcore_id, uint32_t scale_direction)
 {
 	int ret;
 
-	if (!rte_lcore_is_eal_managed(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is invalid.", lcore_id);
-		return -1;
-	}
-
 	pkt[lcore_id].unit = scale_direction;
 	ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);
 	if (ret == 0)
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 14/15] power: allow the service core to config power QoS
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (12 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 13/15] power/kvm_vm: " Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  2026-05-07  2:42   ` [PATCH V2 15/15] power: add lcore ID check for PMD mgmt Huisong Li
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

The service core thread can use power QoS API.
So allow these cores to config it.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/power/rte_power_qos.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/lib/power/rte_power_qos.c b/lib/power/rte_power_qos.c
index be230d1c50..f6630b08f7 100644
--- a/lib/power/rte_power_qos.c
+++ b/lib/power/rte_power_qos.c
@@ -27,10 +27,7 @@ rte_power_qos_set_cpu_resume_latency(uint16_t lcore_id, int latency)
 	FILE *f;
 	int ret;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -EINVAL;
-	}
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -EINVAL);
 	ret = power_get_lcore_mapped_cpu_id(lcore_id, &cpu_id);
 	if (ret != 0)
 		return ret;
@@ -82,10 +79,7 @@ rte_power_qos_get_cpu_resume_latency(uint16_t lcore_id)
 	FILE *f;
 	int ret;
 
-	if (!rte_lcore_is_enabled(lcore_id)) {
-		POWER_LOG(ERR, "lcore id %u is not enabled", lcore_id);
-		return -EINVAL;
-	}
+	RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, -EINVAL);
 	ret = power_get_lcore_mapped_cpu_id(lcore_id, &cpu_id);
 	if (ret != 0)
 		return ret;
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH V2 15/15] power: add lcore ID check for PMD mgmt
  2026-05-07  2:42 ` [PATCH V2 " Huisong Li
                     ` (13 preceding siblings ...)
  2026-05-07  2:42   ` [PATCH V2 14/15] power: allow the service core to config power QoS Huisong Li
@ 2026-05-07  2:42   ` Huisong Li
  14 siblings, 0 replies; 39+ messages in thread
From: Huisong Li @ 2026-05-07  2:42 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala, stephen
  Cc: dev, thomas, fengchengwen, yangxingui, zhanjie9, lihuisong

The pmd_mgmt lib is mainly used together with the data plane of ethdev
PMD. The core in data plane is ROLE_RTE. So use rte_lcore_is_enabled
to verify it.

Fixes: 6f987b594fa6 ("power: refactor core power management")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 lib/power/rte_power_pmd_mgmt.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/lib/power/rte_power_pmd_mgmt.c b/lib/power/rte_power_pmd_mgmt.c
index a4d53aac2a..a5fc1c3a94 100644
--- a/lib/power/rte_power_pmd_mgmt.c
+++ b/lib/power/rte_power_pmd_mgmt.c
@@ -511,7 +511,8 @@ rte_power_ethdev_pmgmt_queue_enable(unsigned int lcore_id, uint16_t port_id,
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
 
-	if (queue_id >= RTE_MAX_QUEUES_PER_PORT || lcore_id >= RTE_MAX_LCORE) {
+	if (queue_id >= RTE_MAX_QUEUES_PER_PORT ||
+	    !rte_lcore_is_enabled(lcore_id)) {
 		ret = -EINVAL;
 		goto end;
 	}
@@ -627,7 +628,7 @@ rte_power_ethdev_pmgmt_queue_disable(unsigned int lcore_id,
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
 
-	if (lcore_id >= RTE_MAX_LCORE || queue_id >= RTE_MAX_QUEUES_PER_PORT)
+	if (!rte_lcore_is_enabled(lcore_id) || queue_id >= RTE_MAX_QUEUES_PER_PORT)
 		return -EINVAL;
 
 	/* check if the queue is stopped */
@@ -729,8 +730,8 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_set_scaling_freq_min)
 int
 rte_power_pmd_mgmt_set_scaling_freq_min(unsigned int lcore, unsigned int min)
 {
-	if (lcore >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID: %u", lcore);
+	if (!rte_lcore_is_enabled(lcore)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
 		return -EINVAL;
 	}
 
@@ -747,8 +748,8 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_set_scaling_freq_max)
 int
 rte_power_pmd_mgmt_set_scaling_freq_max(unsigned int lcore, unsigned int max)
 {
-	if (lcore >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID: %u", lcore);
+	if (!rte_lcore_is_enabled(lcore)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
 		return -EINVAL;
 	}
 
@@ -769,8 +770,8 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_get_scaling_freq_min)
 int
 rte_power_pmd_mgmt_get_scaling_freq_min(unsigned int lcore)
 {
-	if (lcore >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID: %u", lcore);
+	if (!rte_lcore_is_enabled(lcore)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
 		return -EINVAL;
 	}
 
@@ -784,8 +785,8 @@ RTE_EXPORT_SYMBOL(rte_power_pmd_mgmt_get_scaling_freq_max)
 int
 rte_power_pmd_mgmt_get_scaling_freq_max(unsigned int lcore)
 {
-	if (lcore >= RTE_MAX_LCORE) {
-		POWER_LOG(ERR, "Invalid lcore ID: %u", lcore);
+	if (!rte_lcore_is_enabled(lcore)) {
+		POWER_LOG(ERR, "lcore id %u is not enabled", lcore);
 		return -EINVAL;
 	}
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2026-05-07  2:43 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-16  3:05 [PATCH v1 00/15] power: unify and improve lcore ID verification Huisong Li
2026-04-16  3:05 ` [PATCH v1 01/15] power/kvm_vm: enforce enabled lcore ID check Huisong Li
2026-04-16 15:48   ` Stephen Hemminger
2026-04-17  2:51     ` lihuisong (C)
2026-04-21 11:07       ` lihuisong (C)
2026-04-21 14:23       ` Stephen Hemminger
2026-04-22  9:18         ` lihuisong (C)
2026-04-16  3:05 ` [PATCH v1 02/15] power/acpi_cpufreq: " Huisong Li
2026-04-16  3:06 ` [PATCH v1 03/15] power/amd_pstate: " Huisong Li
2026-04-16  3:06 ` [PATCH v1 04/15] power/cppc_cpufreq: " Huisong Li
2026-04-16  3:06 ` [PATCH v1 05/15] power/intel_pstate: " Huisong Li
2026-04-16  3:06 ` [PATCH v1 06/15] power: " Huisong Li
2026-04-16  3:06 ` [PATCH v1 07/15] power: add a common macro to verify lcore ID Huisong Li
2026-04-16  3:06 ` [PATCH v1 08/15] power/pmd_mgmt: replace lcore ID verification with new macro Huisong Li
2026-04-16  3:06 ` [PATCH v1 09/15] power/qos: replace the " Huisong Li
2026-04-16  3:06 ` [PATCH v1 10/15] power/cpufreq: add the lcore ID verification to framework Huisong Li
2026-04-16  3:06 ` [PATCH v1 11/15] power/acpi_cpufreq: remove the verification of lcore ID Huisong Li
2026-04-16  3:06 ` [PATCH v1 12/15] power/amd_pstate: " Huisong Li
2026-04-16  3:06 ` [PATCH v1 13/15] power/cppc_cpufreq: " Huisong Li
2026-04-16  3:06 ` [PATCH v1 14/15] power/intel_pstate: " Huisong Li
2026-04-16  3:06 ` [PATCH v1 15/15] power/kvm_vm: " Huisong Li
2026-04-16 15:51 ` [PATCH v1 00/15] power: unify and improve lcore ID verification Stephen Hemminger
2026-04-17  2:53   ` lihuisong (C)
2026-05-07  2:42 ` [PATCH V2 " Huisong Li
2026-05-07  2:42   ` [PATCH V2 01/15] eal: add interface to check if lcore is EAL managed Huisong Li
2026-05-07  2:42   ` [PATCH V2 02/15] power/kvm_vm: validate lcore role in cpufreq API Huisong Li
2026-05-07  2:42   ` [PATCH V2 03/15] power/acpi_cpufreq: " Huisong Li
2026-05-07  2:42   ` [PATCH V2 04/15] power/amd_pstate: " Huisong Li
2026-05-07  2:42   ` [PATCH V2 05/15] power/cppc_cpufreq: " Huisong Li
2026-05-07  2:42   ` [PATCH V2 06/15] power/intel_pstate: " Huisong Li
2026-05-07  2:42   ` [PATCH V2 07/15] power: add a common macro to verify lcore ID Huisong Li
2026-05-07  2:42   ` [PATCH V2 08/15] power/cpufreq: add the lcore ID verification to framework Huisong Li
2026-05-07  2:42   ` [PATCH V2 09/15] power/acpi_cpufreq: remove the verification of lcore ID Huisong Li
2026-05-07  2:42   ` [PATCH V2 10/15] power/amd_pstate: " Huisong Li
2026-05-07  2:42   ` [PATCH V2 11/15] power/cppc_cpufreq: " Huisong Li
2026-05-07  2:42   ` [PATCH V2 12/15] power/intel_pstate: " Huisong Li
2026-05-07  2:42   ` [PATCH V2 13/15] power/kvm_vm: " Huisong Li
2026-05-07  2:42   ` [PATCH V2 14/15] power: allow the service core to config power QoS Huisong Li
2026-05-07  2:42   ` [PATCH V2 15/15] power: add lcore ID check for PMD mgmt Huisong Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox