DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] power: some cleancode for cpufreq library
@ 2026-05-09  8:45 Huisong Li
  2026-05-09  8:45 ` [PATCH 1/3] power: move power state structure to power cpufreq header Huisong Li
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Huisong Li @ 2026-05-09  8:45 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, stephen, fengchengwen, yangxingui, zhanjie9,
	lihuisong

Move some common definition to common header file.

Huisong Li (3):
  power: move power state structure to power cpufreq header
  power: unify decimal format macro for strtoul
  power: use common decimal macro definition

 drivers/power/acpi/acpi_cpufreq.c                 |  8 --------
 drivers/power/amd_pstate/amd_pstate_cpufreq.c     |  9 ---------
 drivers/power/cppc/cppc_cpufreq.c                 |  9 ---------
 drivers/power/intel_pstate/intel_pstate_cpufreq.c |  8 --------
 lib/power/power_common.c                          |  1 -
 lib/power/power_common.h                          |  2 ++
 lib/power/power_cpufreq.h                         | 10 ++++++++++
 lib/power/rte_power_qos.c                         |  2 +-
 8 files changed, 13 insertions(+), 36 deletions(-)

-- 
2.33.0


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

* [PATCH 1/3] power: move power state structure to power cpufreq header
  2026-05-09  8:45 [PATCH 0/3] power: some cleancode for cpufreq library Huisong Li
@ 2026-05-09  8:45 ` Huisong Li
  2026-05-09  8:45 ` [PATCH 2/3] power: unify decimal format macro for strtoul Huisong Li
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Huisong Li @ 2026-05-09  8:45 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, stephen, fengchengwen, yangxingui, zhanjie9,
	lihuisong

The "enum power_state" structure is defined by each cpufreq driver.
So move it to power_cpufreq.h to facilitate maintenance.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/acpi/acpi_cpufreq.c                 |  7 -------
 drivers/power/amd_pstate/amd_pstate_cpufreq.c     |  7 -------
 drivers/power/cppc/cppc_cpufreq.c                 |  7 -------
 drivers/power/intel_pstate/intel_pstate_cpufreq.c |  8 --------
 lib/power/power_cpufreq.h                         | 10 ++++++++++
 5 files changed, 10 insertions(+), 29 deletions(-)

diff --git a/drivers/power/acpi/acpi_cpufreq.c b/drivers/power/acpi/acpi_cpufreq.c
index 81a5e3f6ea..21991af36a 100644
--- a/drivers/power/acpi/acpi_cpufreq.c
+++ b/drivers/power/acpi/acpi_cpufreq.c
@@ -31,13 +31,6 @@
 #define IA32_PERF_CTL     0x199
 #define CORE_TURBO_DISABLE_BIT ((uint64_t)1<<32)
 
-enum power_state {
-	POWER_IDLE = 0,
-	POWER_ONGOING,
-	POWER_USED,
-	POWER_UNKNOWN
-};
-
 /**
  * Power info per lcore.
  */
diff --git a/drivers/power/amd_pstate/amd_pstate_cpufreq.c b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
index 95495bff7d..318f8c00e1 100644
--- a/drivers/power/amd_pstate/amd_pstate_cpufreq.c
+++ b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
@@ -35,13 +35,6 @@
 #define POWER_AMD_PSTATE_DRIVER "amd-pstate"
 #define BUS_FREQ     1000	/* khz */
 
-enum power_state {
-	POWER_IDLE = 0,
-	POWER_ONGOING,
-	POWER_USED,
-	POWER_UNKNOWN
-};
-
 /**
  * Power info per lcore.
  */
diff --git a/drivers/power/cppc/cppc_cpufreq.c b/drivers/power/cppc/cppc_cpufreq.c
index 3cd4165c83..e3ba9bb60a 100644
--- a/drivers/power/cppc/cppc_cpufreq.c
+++ b/drivers/power/cppc/cppc_cpufreq.c
@@ -39,13 +39,6 @@
 #define POWER_CPPC_DRIVER "cppc_cpufreq"
 #define BUS_FREQ     100000
 
-enum power_state {
-	POWER_IDLE = 0,
-	POWER_ONGOING,
-	POWER_USED,
-	POWER_UNKNOWN
-};
-
 /**
  * Power info per lcore.
  */
diff --git a/drivers/power/intel_pstate/intel_pstate_cpufreq.c b/drivers/power/intel_pstate/intel_pstate_cpufreq.c
index 8e27570e3c..22a1b4465a 100644
--- a/drivers/power/intel_pstate/intel_pstate_cpufreq.c
+++ b/drivers/power/intel_pstate/intel_pstate_cpufreq.c
@@ -41,14 +41,6 @@
 		"/sys/devices/system/cpu/intel_pstate/turbo_pct"
 #define POWER_PSTATE_DRIVER "intel_pstate"
 
-
-enum power_state {
-	POWER_IDLE = 0,
-	POWER_ONGOING,
-	POWER_USED,
-	POWER_UNKNOWN
-};
-
 struct __rte_cache_aligned pstate_power_info {
 	unsigned int lcore_id;               /**< Logical core id */
 	uint32_t freqs[RTE_MAX_LCORE_FREQS]; /**< Frequency array */
diff --git a/lib/power/power_cpufreq.h b/lib/power/power_cpufreq.h
index fb0b7feb82..41bfaed7bb 100644
--- a/lib/power/power_cpufreq.h
+++ b/lib/power/power_cpufreq.h
@@ -18,6 +18,16 @@
 
 #define RTE_POWER_DRIVER_NAMESZ 24
 
+/**
+ * Power state of cpufreq driver
+ */
+enum power_state {
+	POWER_IDLE = 0,
+	POWER_ONGOING,
+	POWER_USED,
+	POWER_UNKNOWN
+};
+
 /**
  * Initialize power management for a specific lcore. If rte_power_set_env() has
  * not been called then an auto-detect of the environment will start and
-- 
2.33.0


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

* [PATCH 2/3] power: unify decimal format macro for strtoul
  2026-05-09  8:45 [PATCH 0/3] power: some cleancode for cpufreq library Huisong Li
  2026-05-09  8:45 ` [PATCH 1/3] power: move power state structure to power cpufreq header Huisong Li
@ 2026-05-09  8:45 ` Huisong Li
  2026-05-09  8:45 ` [PATCH 3/3] power: use common decimal macro definition Huisong Li
  2026-05-11  1:10 ` [PATCH 0/3] power: some cleancode for cpufreq library fengchengwen
  3 siblings, 0 replies; 5+ messages in thread
From: Huisong Li @ 2026-05-09  8:45 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, stephen, fengchengwen, yangxingui, zhanjie9,
	lihuisong

Unify and move POWER_CONVERT_TO_DECIMAL definition to common header
file to facilitate the use of drivers and library.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/power/acpi/acpi_cpufreq.c             | 1 -
 drivers/power/amd_pstate/amd_pstate_cpufreq.c | 2 --
 drivers/power/cppc/cppc_cpufreq.c             | 2 --
 lib/power/power_common.c                      | 1 -
 lib/power/power_common.h                      | 2 ++
 5 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/power/acpi/acpi_cpufreq.c b/drivers/power/acpi/acpi_cpufreq.c
index 21991af36a..875c66336d 100644
--- a/drivers/power/acpi/acpi_cpufreq.c
+++ b/drivers/power/acpi/acpi_cpufreq.c
@@ -14,7 +14,6 @@
 #include "power_common.h"
 
 #define STR_SIZE     1024
-#define POWER_CONVERT_TO_DECIMAL 10
 
 #define POWER_GOVERNOR_USERSPACE "userspace"
 #define POWER_SYSFILE_AVAIL_FREQ \
diff --git a/drivers/power/amd_pstate/amd_pstate_cpufreq.c b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
index 318f8c00e1..bc67981d71 100644
--- a/drivers/power/amd_pstate/amd_pstate_cpufreq.c
+++ b/drivers/power/amd_pstate/amd_pstate_cpufreq.c
@@ -16,8 +16,6 @@
 #define FREQ_ROUNDING_DELTA 500
 #define ROUND_FREQ_TO_N_1000 1000
 
-#define POWER_CONVERT_TO_DECIMAL 10
-
 #define POWER_GOVERNOR_USERSPACE "userspace"
 #define POWER_SYSFILE_SETSPEED   \
 		"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_setspeed"
diff --git a/drivers/power/cppc/cppc_cpufreq.c b/drivers/power/cppc/cppc_cpufreq.c
index e3ba9bb60a..9ae25bad27 100644
--- a/drivers/power/cppc/cppc_cpufreq.c
+++ b/drivers/power/cppc/cppc_cpufreq.c
@@ -20,8 +20,6 @@
  */
 #define UNIT_DIFF 10000
 
-#define POWER_CONVERT_TO_DECIMAL 10
-
 #define POWER_GOVERNOR_USERSPACE "userspace"
 #define POWER_SYSFILE_SETSPEED   \
 		"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_setspeed"
diff --git a/lib/power/power_common.c b/lib/power/power_common.c
index 2da034e9d0..da22a4d160 100644
--- a/lib/power/power_common.c
+++ b/lib/power/power_common.c
@@ -21,7 +21,6 @@ RTE_LOG_REGISTER_DEFAULT(rte_power_logtype, INFO);
 		"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_driver"
 #define POWER_SYSFILE_GOVERNOR  \
 		"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_governor"
-#define POWER_CONVERT_TO_DECIMAL 10
 
 RTE_EXPORT_INTERNAL_SYMBOL(cpufreq_check_scaling_driver)
 int
diff --git a/lib/power/power_common.h b/lib/power/power_common.h
index 3f56b1103d..e2d5b68a17 100644
--- a/lib/power/power_common.h
+++ b/lib/power/power_common.h
@@ -23,6 +23,8 @@ extern int rte_power_logtype;
 #define POWER_DEBUG_LOG(...)
 #endif
 
+#define POWER_CONVERT_TO_DECIMAL 10
+
 /* 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] 5+ messages in thread

* [PATCH 3/3] power: use common decimal macro definition
  2026-05-09  8:45 [PATCH 0/3] power: some cleancode for cpufreq library Huisong Li
  2026-05-09  8:45 ` [PATCH 1/3] power: move power state structure to power cpufreq header Huisong Li
  2026-05-09  8:45 ` [PATCH 2/3] power: unify decimal format macro for strtoul Huisong Li
@ 2026-05-09  8:45 ` Huisong Li
  2026-05-11  1:10 ` [PATCH 0/3] power: some cleancode for cpufreq library fengchengwen
  3 siblings, 0 replies; 5+ messages in thread
From: Huisong Li @ 2026-05-09  8:45 UTC (permalink / raw)
  To: anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, stephen, fengchengwen, yangxingui, zhanjie9,
	lihuisong

Power QoS uses the common decimal macro definition
to replace magic number.

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

diff --git a/lib/power/rte_power_qos.c b/lib/power/rte_power_qos.c
index be230d1c50..f991230532 100644
--- a/lib/power/rte_power_qos.c
+++ b/lib/power/rte_power_qos.c
@@ -115,7 +115,7 @@ rte_power_qos_get_cpu_resume_latency(uint16_t lcore_id)
 	if (strcmp(buf, "n/a") == 0)
 		latency = RTE_POWER_QOS_STRICT_LATENCY_VALUE;
 	else {
-		latency = strtoul(buf, NULL, 10);
+		latency = strtoul(buf, NULL, POWER_CONVERT_TO_DECIMAL);
 		latency = latency == 0 ? RTE_POWER_QOS_RESUME_LATENCY_NO_CONSTRAINT : latency;
 	}
 
-- 
2.33.0


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

* Re: [PATCH 0/3] power: some cleancode for cpufreq library
  2026-05-09  8:45 [PATCH 0/3] power: some cleancode for cpufreq library Huisong Li
                   ` (2 preceding siblings ...)
  2026-05-09  8:45 ` [PATCH 3/3] power: use common decimal macro definition Huisong Li
@ 2026-05-11  1:10 ` fengchengwen
  3 siblings, 0 replies; 5+ messages in thread
From: fengchengwen @ 2026-05-11  1:10 UTC (permalink / raw)
  To: Huisong Li, anatoly.burakov, sivaprasad.tummala
  Cc: dev, thomas, stephen, yangxingui, zhanjie9

Series-acked-by: Chengwen Feng <fengchengwen@huawei.com>

On 5/9/2026 4:45 PM, Huisong Li wrote:
> Move some common definition to common header file.
> 
> Huisong Li (3):
>   power: move power state structure to power cpufreq header
>   power: unify decimal format macro for strtoul
>   power: use common decimal macro definition
> 
>  drivers/power/acpi/acpi_cpufreq.c                 |  8 --------
>  drivers/power/amd_pstate/amd_pstate_cpufreq.c     |  9 ---------
>  drivers/power/cppc/cppc_cpufreq.c                 |  9 ---------
>  drivers/power/intel_pstate/intel_pstate_cpufreq.c |  8 --------
>  lib/power/power_common.c                          |  1 -
>  lib/power/power_common.h                          |  2 ++
>  lib/power/power_cpufreq.h                         | 10 ++++++++++
>  lib/power/rte_power_qos.c                         |  2 +-
>  8 files changed, 13 insertions(+), 36 deletions(-)
> 


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

end of thread, other threads:[~2026-05-11  1:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-09  8:45 [PATCH 0/3] power: some cleancode for cpufreq library Huisong Li
2026-05-09  8:45 ` [PATCH 1/3] power: move power state structure to power cpufreq header Huisong Li
2026-05-09  8:45 ` [PATCH 2/3] power: unify decimal format macro for strtoul Huisong Li
2026-05-09  8:45 ` [PATCH 3/3] power: use common decimal macro definition Huisong Li
2026-05-11  1:10 ` [PATCH 0/3] power: some cleancode for cpufreq library fengchengwen

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