There are many places to verify lcore ID in power. It is necessary
to add a common macro in power core.

According to the applicattion in l3fwd-power, the lcore must be at
least within the RTE_MAX_LCORE range and be a core of the ROLE_RTE
role. But the service on the ROLE_SERVICE core also can use and
require power management feature.

So this common macro restricts that the lcore ID must be ROLE_RTE
and ROLE_SERVICE.

Signed-off-by: Huisong Li <[email protected]>
---
 doc/guides/rel_notes/release_26_07.rst | 4 ++++
 lib/power/power_common.h               | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/doc/guides/rel_notes/release_26_07.rst 
b/doc/guides/rel_notes/release_26_07.rst
index 5d7aa8d1bf..aeabb908ec 100644
--- a/doc/guides/rel_notes/release_26_07.rst
+++ b/doc/guides/rel_notes/release_26_07.rst
@@ -155,6 +155,10 @@ New Features
   Added AGENTS.md file for AI review
   and supporting scripts to review patches and documentation.
 
+* **Added a common macro to verify lcore ID in power core.**
+
+  Added the ``RTE_POWER_VALID_LCOREID_OR_ERR_RET`` macro to verify lcore ID
+  in power core.
 
 Removed Items
 -------------
diff --git a/lib/power/power_common.h b/lib/power/power_common.h
index e2d5b68a17..370c5246c6 100644
--- a/lib/power/power_common.h
+++ b/lib/power/power_common.h
@@ -25,6 +25,14 @@ extern int rte_power_logtype;
 
 #define POWER_CONVERT_TO_DECIMAL 10
 
+#define RTE_POWER_VALID_LCOREID_OR_ERR_RET(lcore_id, retval) do {   \
+       if (rte_eal_lcore_role(lcore_id) != ROLE_RTE &&             \
+           rte_eal_lcore_role(lcore_id) != ROLE_SERVICE) {         \
+               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

Reply via email to