Currently, many cpufreq drivers verify the lcore ID in their
own driver and just restrict it to the RTE_MAX_LCORE range.
Actually, the lcore ID verification is common for each cpufreq
driver. It is better to add this verification to framework.

In addition, the lcore ID for cpufreq library is used by the
application and managed by the EAL layer. So this patch use
rte_lcore_is_eal_managed to verify the lcore ID in cpufreq
core.

Please note the lcore ID for cpufreq library must be ROLE_RTE
or ROLE_SERVICE after this patch.

Signed-off-by: Huisong Li <[email protected]>
---
 doc/guides/rel_notes/release_26_07.rst |  7 +++++++
 lib/power/rte_power_cpufreq.c          | 13 +++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/doc/guides/rel_notes/release_26_07.rst 
b/doc/guides/rel_notes/release_26_07.rst
index be5ccecd46..98a7cf0203 100644
--- a/doc/guides/rel_notes/release_26_07.rst
+++ b/doc/guides/rel_notes/release_26_07.rst
@@ -69,6 +69,13 @@ New Features
   to check whether a logical core is managed by EAL
   (i.e., its role is ``ROLE_RTE`` or ``ROLE_SERVICE``).
 
+* **Added lcore ID verification to power cpufreq framework.**
+
+  Added centralized lcore ID validation using ``rte_lcore_is_eal_managed()``
+  in the power cpufreq framework. All cpufreq API functions now verify
+  that the lcore ID is EAL-managed (``ROLE_RTE`` or ``ROLE_SERVICE``)
+  before proceeding, replacing per-driver range checks.
+
 
 Removed Items
 -------------
diff --git a/lib/power/rte_power_cpufreq.c b/lib/power/rte_power_cpufreq.c
index f63e976dc2..8394cbc77f 100644
--- a/lib/power/rte_power_cpufreq.c
+++ b/lib/power/rte_power_cpufreq.c
@@ -116,6 +116,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 +148,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 +163,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 +172,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 +181,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 +190,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 +199,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 +208,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 +217,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 +226,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 +235,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 +244,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 +254,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

Reply via email to