All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/9] support uncore power management on Hisilicon platforms
@ 2026-11-25 14:06 Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 1/9] examples/l3fwd-power: extract function to deinit uncore Shuaisong Yang
                   ` (9 more replies)
  0 siblings, 10 replies; 12+ messages in thread
From: Shuaisong Yang @ 2026-11-25 14:06 UTC (permalink / raw)
  Cc: dev, yangshuaisong, liuyonglong, fengchengwen, yangxingui,
	yangxingui

This series reworks the uncore frequency handling of the l3fwd-power
sample and extends the power library with a Hisilicon uncore driver
and uncore frequency telemetry.

The first six patches restructure the power management code of
l3fwd-power: the uncore and cpufreq/QoS setup and cleanup paths are
extracted into dedicated helpers, the failure paths now roll back
the steps already taken, and the sample can set the frequency of a
specific package/die instead of applying the change to all of them.

The last three patches extend the power library:

- a detect callback is added to the uncore driver ops, letting a
  driver report by itself whether it can manage the platform;
- a new Hisilicon uncore driver is added on top of the devfreq
  sysfs interface of those platforms;
- the current uncore frequency is exposed through telemetry.

Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>

Huisong Li (9):
  examples/l3fwd-power: extract function to deinit uncore
  examples/l3fwd-power: extract functions for cpufreq library
  examples/l3fwd-power: extract functions for power QoS
  examples/l3fwd-power: add rollback in uncore init
  examples/l3fwd-power: add rollback and best-effort deinit
  examples/l3fwd-power: set freq for specific uncore
  power: add detect callback for uncore driver
  power/hisi_uncore: support Hisilicon uncore driver
  power: add uncore frequency telemetry

 MAINTAINERS                                   |   4 +
 doc/guides/prog_guide/power_man.rst           |  38 +
 doc/guides/rel_notes/release_26_11.rst        |  11 +
 .../sample_app_ug/l3_forward_power_man.rst    |  13 +
 drivers/power/hisi_uncore/hisi_uncore.c       | 693 ++++++++++++++++++
 drivers/power/hisi_uncore/hisi_uncore.h       |  39 +
 drivers/power/hisi_uncore/meson.build         |  17 +
 drivers/power/meson.build                     |   1 +
 examples/l3fwd-power/main.c                   | 567 ++++++++++----
 lib/power/meson.build                         |   3 +-
 lib/power/power_uncore_ops.h                  |  17 +
 lib/power/rte_power_telemetry.c               | 129 ++++
 lib/power/rte_power_uncore.c                  |  14 +-
 lib/power/rte_power_uncore.h                  |   3 +-
 14 files changed, 1401 insertions(+), 148 deletions(-)
 create mode 100644 drivers/power/hisi_uncore/hisi_uncore.c
 create mode 100644 drivers/power/hisi_uncore/hisi_uncore.h
 create mode 100644 drivers/power/hisi_uncore/meson.build
 create mode 100644 lib/power/rte_power_telemetry.c

-- 
2.33.0


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

* [PATCH 1/9] examples/l3fwd-power: extract function to deinit uncore
  2026-11-25 14:06 [PATCH 0/9] support uncore power management on Hisilicon platforms Shuaisong Yang
@ 2026-11-25 14:06 ` Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 2/9] examples/l3fwd-power: extract functions for cpufreq library Shuaisong Yang
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shuaisong Yang @ 2026-11-25 14:06 UTC (permalink / raw)
  To: Anatoly Burakov, Sivaprasad Tummala
  Cc: dev, yangshuaisong, liuyonglong, fengchengwen, yangxingui,
	yangxingui, Huisong Li

From: Huisong Li <lihuisong@huawei.com>

Extract the uncore deinitialization from deinit_power_library()
into a dedicated power_uncore_uninit() helper.

The per-die exit loop is made best-effort: a failure is logged and
the loop continues instead of aborting, so all initialized packages
and dies are cleaned up.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>
---
 examples/l3fwd-power/main.c | 53 ++++++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 18 deletions(-)

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index 5b4cb9f210..8f1a398c96 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -2261,6 +2261,36 @@ power_uncore_init(void)
 	return 0;
 }
 
+static int
+power_uncore_uninit(void)
+{
+	unsigned int max_pkg, max_die, die, pkg;
+	int ret, res = 0;
+
+	if (enabled_uncore == -1)
+		return 0;
+
+	max_pkg = rte_power_uncore_get_num_pkgs();
+	if (max_pkg == 0)
+		return -1;
+	for (pkg = 0; pkg < max_pkg; pkg++) {
+		max_die = rte_power_uncore_get_num_dies(pkg);
+		if (max_die == 0)
+			return -1;
+		for (die = 0; die < max_die; die++) {
+			ret = rte_power_uncore_exit(pkg, die);
+			if (ret < 0) {
+				RTE_LOG(ERR, L3FWD_POWER,
+					"Failed to exit uncore for pkg %02u die %02u, ret = %d.\n",
+					pkg, die, ret);
+				res = -1;
+			}
+		}
+	}
+
+	return res;
+}
+
 static int
 init_power_library(void)
 {
@@ -2347,24 +2377,11 @@ deinit_power_library(void)
 		}
 	}
 
-	/* if uncore option was set */
-	if (enabled_uncore == 0) {
-		max_pkg = rte_power_uncore_get_num_pkgs();
-		if (max_pkg == 0)
-			return -1;
-		for (pkg = 0; pkg < max_pkg; pkg++) {
-			max_die = rte_power_uncore_get_num_dies(pkg);
-			if (max_die == 0)
-				return -1;
-			for (die = 0; die < max_die; die++) {
-				ret = rte_power_uncore_exit(pkg, die);
-				if (ret < 0) {
-					RTE_LOG(ERR, L3FWD_POWER, "Failed to exit uncore deinit successfully for pkg %02u die %02u\n"
-						, pkg, die);
-					return -1;
-				}
-			}
-		}
+	ret = power_uncore_uninit();
+	if (ret != 0) {
+		RTE_LOG(ERR, L3FWD_POWER, "Uninit power uncore failed, ret = %d.\n",
+			ret);
+		return ret;
 	}
 
 	if (cpu_resume_latency != -1) {
-- 
2.33.0


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

* [PATCH 2/9] examples/l3fwd-power: extract functions for cpufreq library
  2026-11-25 14:06 [PATCH 0/9] support uncore power management on Hisilicon platforms Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 1/9] examples/l3fwd-power: extract function to deinit uncore Shuaisong Yang
@ 2026-11-25 14:06 ` Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 3/9] examples/l3fwd-power: extract functions for power QoS Shuaisong Yang
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shuaisong Yang @ 2026-11-25 14:06 UTC (permalink / raw)
  To: Anatoly Burakov, Sivaprasad Tummala
  Cc: dev, yangshuaisong, liuyonglong, fengchengwen, yangxingui,
	yangxingui, Huisong Li

From: Huisong Li <lihuisong@huawei.com>

Extract the legacy mode cpufreq initialization and deinitialization
from init_power_library() and deinit_power_library() into dedicated
power_cpufreq_init() and power_cpufreq_uninit() helpers, so each
power management sub-library has its own setup and teardown
functions.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>
---
 examples/l3fwd-power/main.c | 121 ++++++++++++++++++++++++++----------
 1 file changed, 87 insertions(+), 34 deletions(-)

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index 8f1a398c96..dc0002982a 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -2291,37 +2291,96 @@ power_uncore_uninit(void)
 	return res;
 }
 
-static int
-init_power_library(void)
+static int power_cpufreq_init(void)
 {
+	int lcore_init[RTE_MAX_LCORE] = {0};
 	enum power_management_env env;
 	unsigned int lcore_id;
-	int ret = 0;
+	int ret, res;
 
 	/* only legacy mode relies on the initialization of cpufreq library */
-	if (app_mode == APP_MODE_LEGACY) {
-		RTE_LCORE_FOREACH(lcore_id) {
-			/* init power management library */
-			ret = rte_power_init(lcore_id);
-			if (ret) {
-				RTE_LOG(ERR, L3FWD_POWER,
-					"Library initialization failed on core %u\n",
-					lcore_id);
-				return ret;
-			}
-			/* we're not supporting the VM channel mode */
-			env = rte_power_get_env();
-			if (env != PM_ENV_ACPI_CPUFREQ &&
-					env != PM_ENV_PSTATE_CPUFREQ &&
-					env != PM_ENV_AMD_PSTATE_CPUFREQ &&
-					env != PM_ENV_CPPC_CPUFREQ) {
-				RTE_LOG(ERR, L3FWD_POWER,
-					"Only ACPI and PSTATE mode are supported\n");
-				return -1;
-			}
+	if (app_mode != APP_MODE_LEGACY)
+		return 0;
+
+	RTE_LCORE_FOREACH(lcore_id) {
+		/* init power management library */
+		ret = rte_power_init(lcore_id);
+		if (ret != 0) {
+			RTE_LOG(ERR, L3FWD_POWER,
+				"Library initialization failed on core %u\n",
+				lcore_id);
+			goto uninit_cpufreq;
+		}
+
+		/* we're not supporting the VM channel mode */
+		env = rte_power_get_env();
+		if (env != PM_ENV_ACPI_CPUFREQ &&
+				env != PM_ENV_PSTATE_CPUFREQ &&
+				env != PM_ENV_AMD_PSTATE_CPUFREQ &&
+				env != PM_ENV_CPPC_CPUFREQ) {
+			RTE_LOG(ERR, L3FWD_POWER,
+				"Only ACPI and PSTATE mode are supported\n");
+			rte_power_exit(lcore_id);
+			ret = -1;
+			goto uninit_cpufreq;
+		}
+		lcore_init[lcore_id] = 1;
+	}
+
+	return 0;
+
+uninit_cpufreq:
+	RTE_LCORE_FOREACH(lcore_id) {
+		/* deinit power management library */
+		if (lcore_init[lcore_id] == 0)
+			break;
+
+		res = rte_power_exit(lcore_id);
+		if (res != 0)
+			RTE_LOG(ERR, L3FWD_POWER,
+				"uninit cpufreq on core-%u failed, ret = %d.\n",
+				lcore_id, res);
+	}
+
+	return ret;
+}
+
+static int power_cpufreq_uninit(void)
+{
+	unsigned int lcore_id;
+	int ret, res = 0;
+
+	/* only legacy mode relies on the initialization of cpufreq library */
+	if (app_mode != APP_MODE_LEGACY)
+		return 0;
+
+	RTE_LCORE_FOREACH(lcore_id) {
+		/* deinit power management library */
+		ret = rte_power_exit(lcore_id);
+		if (ret != 0) {
+			RTE_LOG(ERR, L3FWD_POWER,
+				"uninit cpufreq on core-%u failed, ret = %d.\n",
+				lcore_id, ret);
+			res = ret;
 		}
 	}
 
+	return res;
+}
+
+static int
+init_power_library(void)
+{
+	unsigned int lcore_id;
+	int ret;
+
+	ret = power_cpufreq_init();
+	if (ret != 0) {
+		RTE_LOG(ERR, L3FWD_POWER,
+			"Initialize cpufreq lib failed, ret = %d.\n", ret);
+		return ret;
+	}
+
 	ret = power_uncore_init();
 	if (ret != 0)
 		return ret;
@@ -2364,17 +2423,11 @@ deinit_power_library(void)
 	unsigned int lcore_id, max_pkg, max_die, die, pkg;
 	int ret = 0;
 
-	if (app_mode == APP_MODE_LEGACY) {
-		RTE_LCORE_FOREACH(lcore_id) {
-			/* deinit power management library */
-			ret = rte_power_exit(lcore_id);
-			if (ret) {
-				RTE_LOG(ERR, L3FWD_POWER,
-					"Library deinitialization failed on core %u\n",
-					lcore_id);
-				return ret;
-			}
-		}
+	ret = power_cpufreq_uninit();
+	if (ret != 0) {
+		RTE_LOG(ERR, L3FWD_POWER,
+			"Uninit cpufreq lib failed, ret = %d.\n", ret);
+		return ret;
 	}
 
 	ret = power_uncore_uninit();
-- 
2.33.0


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

* [PATCH 3/9] examples/l3fwd-power: extract functions for power QoS
  2026-11-25 14:06 [PATCH 0/9] support uncore power management on Hisilicon platforms Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 1/9] examples/l3fwd-power: extract function to deinit uncore Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 2/9] examples/l3fwd-power: extract functions for cpufreq library Shuaisong Yang
@ 2026-11-25 14:06 ` Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 4/9] examples/l3fwd-power: add rollback in uncore init Shuaisong Yang
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shuaisong Yang @ 2026-11-25 14:06 UTC (permalink / raw)
  To: Anatoly Burakov, Sivaprasad Tummala
  Cc: dev, yangshuaisong, liuyonglong, fengchengwen, yangxingui,
	yangxingui, Huisong Li

From: Huisong Li <lihuisong@huawei.com>

Extract the power QoS initialization and deinitialization from
init_power_library() and deinit_power_library() into dedicated
power_qos_init() and power_qos_uninit() helpers.

power_qos_init() also gains a rollback path which restores the CPU
resume latency of the cores that were already configured when a
later step fails.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>
---
 examples/l3fwd-power/main.c | 109 ++++++++++++++++++++++++------------
 1 file changed, 72 insertions(+), 37 deletions(-)

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index dc0002982a..03d8b3f5e1 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -2369,11 +2369,77 @@ static int power_cpufreq_uninit(void)
 }
 
 static int
-init_power_library(void)
+power_qos_init(void)
 {
+	int lcore_init[RTE_MAX_LCORE] = {0};
 	unsigned int lcore_id;
 	int ret;
 
+	if (cpu_resume_latency == -1)
+		return 0;
+
+	RTE_LCORE_FOREACH(lcore_id) {
+		/* Back old CPU resume latency. */
+		ret = rte_power_qos_get_cpu_resume_latency(lcore_id);
+		if (ret < 0) {
+			RTE_LOG(ERR, L3FWD_POWER,
+				"Failed to get cpu resume latency on lcore-%u, ret=%d.\n",
+				lcore_id, ret);
+			goto uninit_qos;
+		}
+		resume_latency_bk[lcore_id] = ret;
+
+		/*
+		 * Set the cpu resume latency of the worker lcore based
+		 * on user's request. If set strict latency (0), just
+		 * allow the CPU to enter the shallowest idle state to
+		 * improve performance.
+		 */
+		ret = rte_power_qos_set_cpu_resume_latency(lcore_id, cpu_resume_latency);
+		if (ret != 0) {
+			RTE_LOG(ERR, L3FWD_POWER,
+				"Failed to set cpu resume latency on lcore-%u, ret=%d.\n",
+				lcore_id, ret);
+			goto uninit_qos;
+		}
+		lcore_init[lcore_id] = 1;
+	}
+
+	return 0;
+
+uninit_qos:
+	RTE_LCORE_FOREACH(lcore_id) {
+		if (lcore_init[lcore_id] == 0)
+			break;
+
+		/* Restore the original value. */
+		rte_power_qos_set_cpu_resume_latency(lcore_id,
+						     resume_latency_bk[lcore_id]);
+	}
+
+	return ret;
+}
+
+static void
+power_qos_uninit(void)
+{
+	unsigned int lcore_id;
+
+	if (cpu_resume_latency == -1)
+		return;
+
+	RTE_LCORE_FOREACH(lcore_id) {
+		/* Restore the original value. */
+		rte_power_qos_set_cpu_resume_latency(lcore_id,
+						     resume_latency_bk[lcore_id]);
+	}
+}
+
+static int
+init_power_library(void)
+{
+	int ret;
+
 	ret = power_cpufreq_init();
 	if (ret != 0) {
 		RTE_LOG(ERR, L3FWD_POWER,
@@ -2385,34 +2451,10 @@ init_power_library(void)
 	if (ret != 0)
 		return ret;
 
-	if (cpu_resume_latency != -1) {
-		RTE_LCORE_FOREACH(lcore_id) {
-			/* Back old CPU resume latency. */
-			ret = rte_power_qos_get_cpu_resume_latency(lcore_id);
-			if (ret < 0) {
-				RTE_LOG(ERR, L3FWD_POWER,
-					"Failed to get cpu resume latency on lcore-%u, ret=%d.\n",
-					lcore_id, ret);
-				return ret;
-			}
-			resume_latency_bk[lcore_id] = ret;
-
-			/*
-			 * Set the cpu resume latency of the worker lcore based
-			 * on user's request. If set strict latency (0), just
-			 * allow the CPU to enter the shallowest idle state to
-			 * improve performance.
-			 */
-			ret = rte_power_qos_set_cpu_resume_latency(lcore_id,
-							cpu_resume_latency);
-			if (ret != 0) {
-				RTE_LOG(ERR, L3FWD_POWER,
-					"Failed to set cpu resume latency on lcore-%u, ret=%d.\n",
-					lcore_id, ret);
-				return ret;
-			}
-		}
-	}
+	ret = power_qos_init();
+	if (ret != 0)
+		RTE_LOG(ERR, L3FWD_POWER,
+			"Initialize power QoS lib failed, ret = %d.\n", ret);
 
 	return ret;
 }
@@ -2420,7 +2462,6 @@ init_power_library(void)
 static int
 deinit_power_library(void)
 {
-	unsigned int lcore_id, max_pkg, max_die, die, pkg;
 	int ret = 0;
 
 	ret = power_cpufreq_uninit();
@@ -2437,13 +2478,7 @@ deinit_power_library(void)
 		return ret;
 	}
 
-	if (cpu_resume_latency != -1) {
-		RTE_LCORE_FOREACH(lcore_id) {
-			/* Restore the original value. */
-			rte_power_qos_set_cpu_resume_latency(lcore_id,
-						resume_latency_bk[lcore_id]);
-		}
-	}
+	power_qos_uninit();
 
 	return ret;
 }
-- 
2.33.0


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

* [PATCH 4/9] examples/l3fwd-power: add rollback in uncore init
  2026-11-25 14:06 [PATCH 0/9] support uncore power management on Hisilicon platforms Shuaisong Yang
                   ` (2 preceding siblings ...)
  2026-11-25 14:06 ` [PATCH 3/9] examples/l3fwd-power: extract functions for power QoS Shuaisong Yang
@ 2026-11-25 14:06 ` Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 5/9] examples/l3fwd-power: add rollback and best-effort deinit Shuaisong Yang
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shuaisong Yang @ 2026-11-25 14:06 UTC (permalink / raw)
  To: Anatoly Burakov, Sivaprasad Tummala
  Cc: dev, yangshuaisong, liuyonglong, fengchengwen, yangxingui,
	yangxingui, Huisong Li

From: Huisong Li <lihuisong@huawei.com>

Make power_uncore_init() roll back the packages and dies that were
already initialized when a later step fails, instead of leaving
them configured after an error return.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>
---
 examples/l3fwd-power/main.c | 44 ++++++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 8 deletions(-)

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index 03d8b3f5e1..857b885f43 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -2193,6 +2193,8 @@ static int
 power_uncore_init(void)
 {
 	unsigned int die, pkg, max_pkg, max_die;
+	unsigned int init_pkg = 0, init_die = 0;
+	bool init_done = false;
 	int ret;
 
 	if (enabled_uncore == -1)
@@ -2210,22 +2212,28 @@ power_uncore_init(void)
 
 	for (pkg = 0; pkg < max_pkg; pkg++) {
 		max_die = rte_power_uncore_get_num_dies(pkg);
-		if (max_die == 0)
-			return -1;
+		if (max_die == 0) {
+			ret = -1;
+			goto uninit_uncore;
+		}
 		for (die = 0; die < max_die; die++) {
 			ret = rte_power_uncore_init(pkg, die);
 			if (ret == -1) {
 				RTE_LOG(INFO, L3FWD_POWER, "Unable to initialize uncore for pkg %02u die %02u\n"
 				, pkg, die);
-				return ret;
+				goto uninit_uncore;
 			}
+			init_pkg = pkg;
+			init_die = die;
+			init_done = true;
+
 			if (uncore_cfg.uncore_choice == UNCORE_MIN) {
 				ret = rte_power_uncore_freq_min(pkg, die);
 				if (ret == -1) {
 					RTE_LOG(INFO, L3FWD_POWER,
 					"Unable to set the uncore frequency to minimum value for pkg %02u die %02u\n"
 					, pkg, die);
-					return ret;
+					goto uninit_uncore;
 				}
 			} else if (uncore_cfg.uncore_choice == UNCORE_MAX) {
 				ret = rte_power_uncore_freq_max(pkg, die);
@@ -2233,32 +2241,52 @@ power_uncore_init(void)
 					RTE_LOG(INFO, L3FWD_POWER,
 					"Unable to set uncore frequency to maximum value for pkg %02u die %02u\n"
 					, pkg, die);
-					return ret;
+					goto uninit_uncore;
 				}
 			} else if (uncore_cfg.uncore_choice == UNCORE_IDX) {
 				int freq_array_len = rte_power_uncore_get_num_freqs(pkg, die);
 				if (freq_array_len <= 0) {
 					RTE_LOG(INFO, L3FWD_POWER, "Get uncore frequency number failed.\n");
-					return -1;
+					ret = -1;
+					goto uninit_uncore;
 				}
 				if (uncore_cfg.freq_idx > (uint32_t)(freq_array_len - 1)) {
 					RTE_LOG(INFO, L3FWD_POWER,
 					"Frequency index given out of range, please choose a value from 0 to %d.\n",
 					freq_array_len - 1);
-					return -1;
+					ret = -1;
+					goto uninit_uncore;
 				}
 				ret = rte_power_set_uncore_freq(pkg, die, uncore_cfg.freq_idx);
 				if (ret == -1) {
 					RTE_LOG(INFO, L3FWD_POWER,
 					"Unable to set specified frequency index for pkg %02u die %02u\n",
 					pkg, die);
-					return ret;
+					goto uninit_uncore;
 				}
 			}
 		}
 	}
 
 	return 0;
+
+uninit_uncore:
+	/* Roll back the pkg/die that were initialized before the failure. */
+	if (init_done) {
+		for (pkg = 0; pkg <= init_pkg; pkg++) {
+			if (pkg == init_pkg)
+				max_die = init_die + 1;
+			else {
+				max_die = rte_power_uncore_get_num_dies(pkg);
+				if (max_die == 0)
+					break;
+			}
+			for (die = 0; die < max_die; die++)
+				rte_power_uncore_exit(pkg, die);
+		}
+	}
+
+	return ret;
 }
 
 static int
-- 
2.33.0


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

* [PATCH 5/9] examples/l3fwd-power: add rollback and best-effort deinit
  2026-11-25 14:06 [PATCH 0/9] support uncore power management on Hisilicon platforms Shuaisong Yang
                   ` (3 preceding siblings ...)
  2026-11-25 14:06 ` [PATCH 4/9] examples/l3fwd-power: add rollback in uncore init Shuaisong Yang
@ 2026-11-25 14:06 ` Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 6/9] examples/l3fwd-power: set freq for specific uncore Shuaisong Yang
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shuaisong Yang @ 2026-11-25 14:06 UTC (permalink / raw)
  To: Anatoly Burakov, Sivaprasad Tummala
  Cc: dev, yangshuaisong, liuyonglong, fengchengwen, yangxingui,
	yangxingui, Huisong Li

From: Huisong Li <lihuisong@huawei.com>

Make the deinitialization path best-effort: power_uncore_uninit(),
power_cpufreq_uninit() and deinit_power_library() now return void
and continue the cleanup on intermediate failures instead of
aborting it.

init_power_library() is also updated to roll back the cpufreq
library and the uncore units when a later initialization step
fails.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>
---
 examples/l3fwd-power/main.c | 67 +++++++++++++------------------------
 1 file changed, 23 insertions(+), 44 deletions(-)

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index 857b885f43..b6430f0c78 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -2289,34 +2289,26 @@ power_uncore_init(void)
 	return ret;
 }
 
-static int
+static void
 power_uncore_uninit(void)
 {
 	unsigned int max_pkg, max_die, die, pkg;
-	int ret, res = 0;
+	int ret;
 
 	if (enabled_uncore == -1)
-		return 0;
+		return;
 
 	max_pkg = rte_power_uncore_get_num_pkgs();
-	if (max_pkg == 0)
-		return -1;
 	for (pkg = 0; pkg < max_pkg; pkg++) {
 		max_die = rte_power_uncore_get_num_dies(pkg);
-		if (max_die == 0)
-			return -1;
 		for (die = 0; die < max_die; die++) {
 			ret = rte_power_uncore_exit(pkg, die);
-			if (ret < 0) {
+			if (ret < 0)
 				RTE_LOG(ERR, L3FWD_POWER,
 					"Failed to exit uncore for pkg %02u die %02u, ret = %d.\n",
 					pkg, die, ret);
-				res = -1;
-			}
 		}
 	}
-
-	return res;
 }
 
 static int power_cpufreq_init(void)
@@ -2373,27 +2365,23 @@ static int power_cpufreq_init(void)
 	return ret;
 }
 
-static int power_cpufreq_uninit(void)
+static void power_cpufreq_uninit(void)
 {
 	unsigned int lcore_id;
-	int ret, res = 0;
+	int ret;
 
 	/* only legacy mode relies on the initialization of cpufreq library */
 	if (app_mode != APP_MODE_LEGACY)
-		return 0;
+		return;
 
 	RTE_LCORE_FOREACH(lcore_id) {
 		/* deinit power management library */
 		ret = rte_power_exit(lcore_id);
-		if (ret != 0) {
+		if (ret != 0)
 			RTE_LOG(ERR, L3FWD_POWER,
 				"uninit cpufreq on core-%u failed, ret = %d.\n",
 				lcore_id, ret);
-			res = ret;
-		}
 	}
-
-	return res;
 }
 
 static int
@@ -2476,39 +2464,31 @@ init_power_library(void)
 	}
 
 	ret = power_uncore_init();
-	if (ret != 0)
+	if (ret != 0) {
+		RTE_LOG(ERR, L3FWD_POWER,
+			"Initialize power uncore failed, ret = %d.\n", ret);
+		power_cpufreq_uninit();
 		return ret;
+	}
 
 	ret = power_qos_init();
-	if (ret != 0)
+	if (ret != 0) {
 		RTE_LOG(ERR, L3FWD_POWER,
 			"Initialize power QoS lib failed, ret = %d.\n", ret);
+		power_uncore_uninit();
+		power_cpufreq_uninit();
+		return ret;
+	}
 
-	return ret;
+	return 0;
 }
 
-static int
+static void
 deinit_power_library(void)
 {
-	int ret = 0;
-
-	ret = power_cpufreq_uninit();
-	if (ret != 0) {
-		RTE_LOG(ERR, L3FWD_POWER,
-			"Uninit cpufreq lib failed, ret = %d.\n", ret);
-		return ret;
-	}
-
-	ret = power_uncore_uninit();
-	if (ret != 0) {
-		RTE_LOG(ERR, L3FWD_POWER, "Uninit power uncore failed, ret = %d.\n",
-			ret);
-		return ret;
-	}
-
 	power_qos_uninit();
-
-	return ret;
+	power_uncore_uninit();
+	power_cpufreq_uninit();
 }
 
 static void
@@ -3114,8 +3094,7 @@ main(int argc, char **argv)
 		rte_eth_dev_close(portid);
 	}
 
-	if (deinit_power_library())
-		rte_exit(EXIT_FAILURE, "deinit_power_library failed\n");
+	deinit_power_library();
 
 	if (rte_eal_cleanup() < 0)
 		RTE_LOG(ERR, L3FWD_POWER, "EAL cleanup failed\n");
-- 
2.33.0


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

* [PATCH 6/9] examples/l3fwd-power: set freq for specific uncore
  2026-11-25 14:06 [PATCH 0/9] support uncore power management on Hisilicon platforms Shuaisong Yang
                   ` (4 preceding siblings ...)
  2026-11-25 14:06 ` [PATCH 5/9] examples/l3fwd-power: add rollback and best-effort deinit Shuaisong Yang
@ 2026-11-25 14:06 ` Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 7/9] power: add detect callback for uncore driver Shuaisong Yang
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shuaisong Yang @ 2026-11-25 14:06 UTC (permalink / raw)
  To: Anatoly Burakov, Sivaprasad Tummala
  Cc: dev, yangshuaisong, liuyonglong, fengchengwen, yangxingui,
	yangxingui, Huisong Li

From: Huisong Li <lihuisong@huawei.com>

l3fwd-power only supports the -u/-U/-i options which apply the
uncore frequency to all packages and dies. Add a new --uncore-freq
option so users can set the uncore frequency for specific
package/die pairs.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>
---
 .../sample_app_ug/l3_forward_power_man.rst    |  13 +
 examples/l3fwd-power/main.c                   | 309 ++++++++++++++----
 2 files changed, 253 insertions(+), 69 deletions(-)

diff --git a/doc/guides/sample_app_ug/l3_forward_power_man.rst b/doc/guides/sample_app_ug/l3_forward_power_man.rst
index ef3f1f1519..442d8f0c8f 100644
--- a/doc/guides/sample_app_ug/l3_forward_power_man.rst
+++ b/doc/guides/sample_app_ug/l3_forward_power_man.rst
@@ -108,6 +108,8 @@ where,
 
 *   -i (frequency index): set target frequency for uncore by specified frequency index.
 
+*   --uncore-freq=(\\(package,\\domain,\\frequency\\))(\\(package,\\domain,\\frequency\\)): optional, set target frequency for the specified uncore. <frequency> is min, max or a frequency index. If not given, -u/-U/-i apply to all uncore. May be specified multiple times.
+
 *   --config (port,queue,lcore)[,(port,queue,lcore)]: determines which queues from which ports are mapped to which cores.
 
 *   --cpu-resume-latency LATENCY: set CPU resume latency to control C-state selection, 0 : just allow entering C0-state.
@@ -333,6 +335,17 @@ Three options are available for setting uncore frequency:
   Frequency index values are in descending order,
   i.e., index 0 is maximum frequency index.
 
+``--uncore-freq``
+  This will allow you to set the uncore frequency for specific packages and dies.
+  Each ``(package,domain,frequency)`` group targets one uncore, where ``frequency``
+  is ``min``, ``max`` or a frequency index. Multiple groups can be given in a single
+  option. The ``-u``, ``-U`` and ``-i`` options apply to all packages and dies and
+  cannot be used together with ``--uncore-freq``.
+
 .. code-block:: console
 
    dpdk-l3fwd-power -l 1-3 -- -p 0x0f --config="(0,0,2),(0,1,3)" -i 1
+
+.. code-block:: console
+
+   dpdk-l3fwd-power -l 1-3 -- -p 0x0f --config="(0,0,2),(0,1,3)" --uncore-freq="(0,0,max)(0,1,1)"
diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index b6430f0c78..da44d74c0f 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -211,10 +211,15 @@ enum uncore_choice {
 
 /* flag to check if uncore option enabled */
 int enabled_uncore = -1;
+#define MAX_UNCORE_CFG 32
 static struct uncore_cfg {
+	uint16_t pkg;
+	uint16_t die;
 	enum uncore_choice uncore_choice;
 	uint32_t freq_idx;
-} uncore_cfg;
+} uncore_cfg[MAX_UNCORE_CFG];
+static uint32_t nb_uncore_cfg;
+static bool uncore_legacy;
 
 struct __rte_cache_aligned lcore_rx_queue {
 	uint16_t port_id;
@@ -1494,6 +1499,7 @@ print_usage(const char *prgname)
 {
 	printf ("%s [EAL options] -- -p PORTMASK -P"
 		"  [--config (port,queue,lcore)[,(port,queue,lcore]]"
+		"  [--uncore-freq (pkg,die,freq)[,(pkg,die,freq]]"
 		"  [--high-perf-cores CORELIST"
 		"  [--perf-config (port,queue,hi_perf,lcore_index)[,(port,queue,hi_perf,lcore_index]]"
 		"  [--max-pkt-len PKTLEN]\n"
@@ -1502,6 +1508,8 @@ print_usage(const char *prgname)
 		"  -u: set min/max frequency for uncore to minimum value\n"
 		"  -U: set min/max frequency for uncore to maximum value\n"
 		"  -i (frequency index): set target frequency for uncore by specified frequency index\n"
+		"  --uncore-freq (pkg,die,freq)[,(pkg,die,freq)]: set target frequency for the"
+		" specified uncore where freq is min, max or a frequency index\n"
 		"  --config (port,queue,lcore): rx queues configuration\n"
 		"  --eth-link-speed: force link speed\n"
 		"  --cpu-resume-latency LATENCY: set CPU resume latency to control C-state selection,"
@@ -1569,6 +1577,66 @@ parse_portmask(const char *portmask)
 	return pm;
 }
 
+static int
+parse_uncore_freq(const char *q_arg)
+{
+	unsigned long  pkg, die, freq_idx = 0;
+	const char *p, *p0 = q_arg;
+	enum uncore_choice choice;
+	char s[64];
+	char *end;
+	int i;
+
+	while ((p = strchr(p0, '(')) != NULL) {
+		++p;
+		p0 = strchr(p, ')');
+		if (p0 == NULL)
+			return -1;
+
+		if ((uint32_t)(p0 - p) >= sizeof(s))
+			return -1;
+		snprintf(s, sizeof(s), "%.*s", (int)(p0 - p), p);
+
+		end = s;
+		pkg = strtoul(end, &end, 0);
+		if (*end != ',' || pkg > UINT16_MAX)
+			return -1;
+		die = strtoul(++end, &end, 0);
+		if (*end != ',' || die > UINT16_MAX)
+			return -1;
+		end++;
+		if (strncmp(end, "min", 3) == 0) {
+			choice = UNCORE_MIN;
+			end += 3;
+		} else if (strncmp(end, "max", 3) == 0) {
+			choice = UNCORE_MAX;
+			end += 3;
+		} else {
+			freq_idx = strtoul(end, &end, 0);
+			if (end == s || freq_idx > UINT32_MAX)
+				return -1;
+			choice = UNCORE_IDX;
+		}
+		if (*end != '\0')
+			return -1;
+
+		if (nb_uncore_cfg >= MAX_UNCORE_CFG) {
+			RTE_LOG(INFO, L3FWD_POWER, "Too many uncore freq options,"
+				" max is %d\n", MAX_UNCORE_CFG);
+			return -1;
+		}
+
+		i = nb_uncore_cfg;
+		uncore_cfg[i].pkg = pkg;
+		uncore_cfg[i].die = die;
+		uncore_cfg[i].uncore_choice = choice;
+		uncore_cfg[i].freq_idx = freq_idx;
+		nb_uncore_cfg++;
+	}
+
+	return 0;
+}
+
 static int
 parse_config(const char *q_arg)
 {
@@ -1671,6 +1739,7 @@ parse_pmd_mgmt_config(const char *name)
 #define CMD_LINE_OPT_SCALE_FREQ_MIN "scale-freq-min"
 #define CMD_LINE_OPT_SCALE_FREQ_MAX "scale-freq-max"
 #define CMD_LINE_OPT_CPU_RESUME_LATENCY "cpu-resume-latency"
+#define CMD_LINE_OPT_UNCORE_FREQ "uncore-freq"
 #define CMD_LINK_OPT_ETH_LINK_SPEED "eth-link-speed"
 
 /* Parse the argument given in the command line of the application */
@@ -1699,6 +1768,7 @@ parse_args(int argc, char **argv)
 		{CMD_LINE_OPT_SCALE_FREQ_MIN, 1, 0, 0},
 		{CMD_LINE_OPT_SCALE_FREQ_MAX, 1, 0, 0},
 		{CMD_LINK_OPT_ETH_LINK_SPEED, 1, 0, 0},
+		{CMD_LINE_OPT_UNCORE_FREQ, 1, 0, 0},
 		{NULL, 0, 0, 0}
 	};
 
@@ -1722,21 +1792,42 @@ parse_args(int argc, char **argv)
 			promiscuous_on = 1;
 			break;
 		case 'u':
+			if (nb_uncore_cfg > 0) {
+				RTE_LOG(INFO, L3FWD_POWER,
+					"Option -u cannot be used together with --uncore-freq\n");
+				print_usage(prgname);
+				return -1;
+			}
 			enabled_uncore = 0;
-			uncore_cfg.uncore_choice = UNCORE_MIN;
+			uncore_legacy = true;
+			uncore_cfg[0].uncore_choice = UNCORE_MIN;
 			break;
 		case 'U':
+			if (nb_uncore_cfg > 0) {
+				RTE_LOG(INFO, L3FWD_POWER,
+					"Option -U cannot be used together with --uncore-freq\n");
+				print_usage(prgname);
+				return -1;
+			}
 			enabled_uncore = 0;
-			uncore_cfg.uncore_choice = UNCORE_MAX;
+			uncore_legacy = true;
+			uncore_cfg[0].uncore_choice = UNCORE_MAX;
 			break;
 		case 'i':
+			if (nb_uncore_cfg > 0) {
+				RTE_LOG(INFO, L3FWD_POWER,
+					"Option -i cannot be used together with --uncore-freq\n");
+				print_usage(prgname);
+				return -1;
+			}
 			enabled_uncore = 0;
-			if (parse_uint(optarg, UINT32_MAX, &uncore_cfg.freq_idx) != 0) {
-				RTE_LOG(INFO, L3FWD_POWER, "Index given is not a valid number.");
+			uncore_legacy = true;
+			if (parse_uint(optarg, UINT32_MAX, &uncore_cfg[0].freq_idx) != 0) {
+				RTE_LOG(INFO, L3FWD_POWER, "Invalid freq index");
 				print_usage(prgname);
 				return -1;
 			}
-			uncore_cfg.uncore_choice = UNCORE_IDX;
+			uncore_cfg[0].uncore_choice = UNCORE_IDX;
 			break;
 		/* long options */
 		case 0:
@@ -1893,6 +1984,26 @@ parse_args(int argc, char **argv)
 					port_conf.link_speeds = rte_eth_speed_bitflag(speed_num, 0);
 			}
 
+			if (!strncmp(lgopts[option_index].name,
+					CMD_LINE_OPT_UNCORE_FREQ,
+					sizeof(CMD_LINE_OPT_UNCORE_FREQ))) {
+				if (uncore_legacy) {
+					RTE_LOG(INFO, L3FWD_POWER,
+						"Option --uncore-freq cannot be used together"
+						" with -u/-U/-i\n");
+					print_usage(prgname);
+					return -1;
+				}
+				if (parse_uncore_freq(optarg) != 0) {
+					RTE_LOG(INFO, L3FWD_POWER,
+						"Invalid uncore freq, expected <package>,<domain>,<frequency>\n");
+					print_usage(prgname);
+					return -1;
+				}
+				enabled_uncore = 0;
+				uncore_legacy = false;
+			}
+
 			break;
 
 		default:
@@ -2189,12 +2300,60 @@ static int check_ptype(uint16_t portid)
 
 }
 
+static int
+set_uncore_freq(uint32_t pkg, uint32_t die, struct uncore_cfg *cfg)
+{
+	int freq_array_len;
+	int ret;
+
+	if (cfg->uncore_choice == UNCORE_MIN) {
+		ret = rte_power_uncore_freq_min(pkg, die);
+		if (ret == -1) {
+			RTE_LOG(INFO, L3FWD_POWER,
+			"Unable to set the uncore frequency to minimum value for pkg %u die %u\n"
+			, pkg, die);
+			return -1;
+		}
+	} else if (cfg->uncore_choice == UNCORE_MAX) {
+		ret = rte_power_uncore_freq_max(pkg, die);
+		if (ret == -1) {
+			RTE_LOG(INFO, L3FWD_POWER,
+			"Unable to set uncore frequency to maximum value for pkg %u die %u\n"
+			, pkg, die);
+			return -1;
+		}
+	} else if (cfg->uncore_choice == UNCORE_IDX) {
+		freq_array_len = rte_power_uncore_get_num_freqs(pkg, die);
+		if (freq_array_len <= 0) {
+			RTE_LOG(INFO, L3FWD_POWER, "Get uncore frequency number failed.\n");
+			return -1;
+		}
+		if (cfg->freq_idx > (uint32_t)(freq_array_len - 1)) {
+			RTE_LOG(INFO, L3FWD_POWER,
+			"Invalid freq index, please choose a value from 0 to %d.\n",
+			freq_array_len - 1);
+			return -1;
+		}
+		ret = rte_power_set_uncore_freq(pkg, die, cfg->freq_idx);
+		if (ret == -1) {
+			RTE_LOG(INFO, L3FWD_POWER,
+			"Unable to set specified frequency index for pkg %u die %u\n",
+			pkg, die);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
 static int
 power_uncore_init(void)
 {
-	unsigned int die, pkg, max_pkg, max_die;
-	unsigned int init_pkg = 0, init_die = 0;
+	uint32_t max_pkg, max_die, die, pkg;
+	uint32_t init_pkg = 0, init_die = 0;
 	bool init_done = false;
+	uint32_t init_nb = 0;
+	uint32_t i;
 	int ret;
 
 	if (enabled_uncore == -1)
@@ -2206,84 +2365,96 @@ power_uncore_init(void)
 		return ret;
 	}
 
-	max_pkg = rte_power_uncore_get_num_pkgs();
-	if (max_pkg == 0)
-		return -1;
+	if (uncore_legacy) {
+		/* No specific uncore targeted, apply to all pkg/die. */
+		max_pkg = rte_power_uncore_get_num_pkgs();
+		if (max_pkg == 0)
+			return -1;
 
-	for (pkg = 0; pkg < max_pkg; pkg++) {
-		max_die = rte_power_uncore_get_num_dies(pkg);
-		if (max_die == 0) {
-			ret = -1;
-			goto uninit_uncore;
-		}
-		for (die = 0; die < max_die; die++) {
-			ret = rte_power_uncore_init(pkg, die);
-			if (ret == -1) {
-				RTE_LOG(INFO, L3FWD_POWER, "Unable to initialize uncore for pkg %02u die %02u\n"
-				, pkg, die);
+		for (pkg = 0; pkg < max_pkg; pkg++) {
+			max_die = rte_power_uncore_get_num_dies(pkg);
+			if (max_die == 0) {
+				ret = -1;
 				goto uninit_uncore;
 			}
-			init_pkg = pkg;
-			init_die = die;
-			init_done = true;
-
-			if (uncore_cfg.uncore_choice == UNCORE_MIN) {
-				ret = rte_power_uncore_freq_min(pkg, die);
-				if (ret == -1) {
-					RTE_LOG(INFO, L3FWD_POWER,
-					"Unable to set the uncore frequency to minimum value for pkg %02u die %02u\n"
-					, pkg, die);
-					goto uninit_uncore;
-				}
-			} else if (uncore_cfg.uncore_choice == UNCORE_MAX) {
-				ret = rte_power_uncore_freq_max(pkg, die);
+			for (die = 0; die < max_die; die++) {
+				ret = rte_power_uncore_init(pkg, die);
 				if (ret == -1) {
-					RTE_LOG(INFO, L3FWD_POWER,
-					"Unable to set uncore frequency to maximum value for pkg %02u die %02u\n"
+					RTE_LOG(INFO, L3FWD_POWER, "Unable to initialize uncore for pkg %u die %u\n"
 					, pkg, die);
 					goto uninit_uncore;
 				}
-			} else if (uncore_cfg.uncore_choice == UNCORE_IDX) {
-				int freq_array_len = rte_power_uncore_get_num_freqs(pkg, die);
-				if (freq_array_len <= 0) {
-					RTE_LOG(INFO, L3FWD_POWER, "Get uncore frequency number failed.\n");
-					ret = -1;
-					goto uninit_uncore;
-				}
-				if (uncore_cfg.freq_idx > (uint32_t)(freq_array_len - 1)) {
-					RTE_LOG(INFO, L3FWD_POWER,
-					"Frequency index given out of range, please choose a value from 0 to %d.\n",
-					freq_array_len - 1);
-					ret = -1;
-					goto uninit_uncore;
-				}
-				ret = rte_power_set_uncore_freq(pkg, die, uncore_cfg.freq_idx);
-				if (ret == -1) {
-					RTE_LOG(INFO, L3FWD_POWER,
-					"Unable to set specified frequency index for pkg %02u die %02u\n",
-					pkg, die);
+				init_pkg = pkg;
+				init_die = die;
+				init_done = true;
+
+				ret = set_uncore_freq(pkg, die, &uncore_cfg[0]);
+				if (ret == -1)
 					goto uninit_uncore;
-				}
 			}
 		}
+	} else {
+		max_pkg = rte_power_uncore_get_num_pkgs();
+		if (max_pkg == 0)
+			return -1;
+
+		for (i = 0; i < nb_uncore_cfg; i++) {
+			pkg = uncore_cfg[i].pkg;
+			die = uncore_cfg[i].die;
+
+			if (pkg >= max_pkg) {
+				RTE_LOG(INFO, L3FWD_POWER,
+					"Invalid package id %u, must be less than %u\n",
+					pkg, max_pkg);
+				ret = -1;
+				goto uninit_uncore;
+			}
+			max_die = rte_power_uncore_get_num_dies(pkg);
+			if (die >= max_die) {
+				RTE_LOG(INFO, L3FWD_POWER,
+					"Invalid die id %u for pkg %u, must be less than %u\n",
+					die, pkg, max_die);
+				ret = -1;
+				goto uninit_uncore;
+			}
+
+			ret = rte_power_uncore_init(pkg, die);
+			if (ret == -1) {
+				RTE_LOG(INFO, L3FWD_POWER, "Unable to initialize uncore for pkg %u die %u\n"
+				, pkg, die);
+				goto uninit_uncore;
+			}
+			init_nb = i + 1;
+
+			ret = set_uncore_freq(pkg, die, &uncore_cfg[i]);
+			if (ret == -1)
+				goto uninit_uncore;
+		}
 	}
 
 	return 0;
 
 uninit_uncore:
 	/* Roll back the pkg/die that were initialized before the failure. */
-	if (init_done) {
-		for (pkg = 0; pkg <= init_pkg; pkg++) {
-			if (pkg == init_pkg)
-				max_die = init_die + 1;
-			else {
-				max_die = rte_power_uncore_get_num_dies(pkg);
-				if (max_die == 0)
-					break;
+	if (uncore_legacy) {
+		if (init_done) {
+			for (pkg = 0; pkg <= init_pkg; pkg++) {
+				if (pkg == init_pkg)
+					max_die = init_die + 1;
+				else {
+					max_die = rte_power_uncore_get_num_dies(pkg);
+					if (max_die == 0)
+						break;
+				}
+				for (die = 0; die < max_die; die++)
+					rte_power_uncore_exit(pkg, die);
 			}
-			for (die = 0; die < max_die; die++)
-				rte_power_uncore_exit(pkg, die);
 		}
+	} else {
+		/* Only uninit the targeted uncore that were initialized. */
+		for (i = 0; i < init_nb; i++)
+			rte_power_uncore_exit(uncore_cfg[i].pkg,
+				uncore_cfg[i].die);
 	}
 
 	return ret;
@@ -2305,7 +2476,7 @@ power_uncore_uninit(void)
 			ret = rte_power_uncore_exit(pkg, die);
 			if (ret < 0)
 				RTE_LOG(ERR, L3FWD_POWER,
-					"Failed to exit uncore for pkg %02u die %02u, ret = %d.\n",
+					"Failed to exit uncore for pkg %u die %u, ret = %d.\n",
 					pkg, die, ret);
 		}
 	}
-- 
2.33.0


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

* [PATCH 7/9] power: add detect callback for uncore driver
  2026-11-25 14:06 [PATCH 0/9] support uncore power management on Hisilicon platforms Shuaisong Yang
                   ` (5 preceding siblings ...)
  2026-11-25 14:06 ` [PATCH 6/9] examples/l3fwd-power: set freq for specific uncore Shuaisong Yang
@ 2026-11-25 14:06 ` Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 8/9] power/hisi_uncore: support Hisilicon " Shuaisong Yang
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: Shuaisong Yang @ 2026-11-25 14:06 UTC (permalink / raw)
  To: Anatoly Burakov, Sivaprasad Tummala
  Cc: dev, yangshuaisong, liuyonglong, fengchengwen, yangxingui,
	yangxingui, Huisong Li

From: Huisong Li <lihuisong@huawei.com>

The automatic uncore driver detection currently probes drivers by
calling their init() and exit() callbacks on package 0 and die 0,
which may have side effects on the system.

Add an optional detect() callback to struct rte_power_uncore_ops so
a driver can check platform support, e.g. sysfs entries or device
nodes, without a full initialization. power_uncore_probe_driver()
uses detect() when available and falls back to the existing
init/exit probing for drivers without one.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>
---
 lib/power/power_uncore_ops.h | 17 +++++++++++++++++
 lib/power/rte_power_uncore.c | 11 ++++++++---
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/lib/power/power_uncore_ops.h b/lib/power/power_uncore_ops.h
index 025a55cb97..e3c8f0b741 100644
--- a/lib/power/power_uncore_ops.h
+++ b/lib/power/power_uncore_ops.h
@@ -183,11 +183,28 @@ typedef unsigned int (*rte_power_uncore_get_num_pkgs_t)(void);
 typedef unsigned int (*rte_power_uncore_get_num_dies_t)(unsigned int pkg);
 typedef void (*rte_power_uncore_driver_cb_t)(void);
 
+/**
+ * Detect if the current platform supports this uncore frequency management driver.
+ *
+ * This callback is used during automatic driver detection to check whether
+ * the platform has the necessary hardware/software support (e.g., sysfs
+ * entries, device nodes) without performing a full initialization that may
+ * have side effects.
+ *
+ * This function should NOT be called in the fast path.
+ *
+ * @return
+ *  - 0 on success, the platform supports this driver.
+ *  - Negative on error, the platform does not support this driver.
+ */
+typedef int (*rte_power_uncore_detect_t)(void);
+
 /** Structure defining uncore power operations structure */
 struct rte_power_uncore_ops {
 	RTE_TAILQ_ENTRY(rte_power_uncore_ops) next;     /**< Next in list. */
 	char name[RTE_POWER_UNCORE_DRIVER_NAMESZ];      /**< power mgmt driver. */
 	rte_power_uncore_driver_cb_t cb;                /**< Driver specific callbacks. */
+	rte_power_uncore_detect_t detect;               /**< Detect platform support. */
 	rte_power_uncore_init_t init;                   /**< Initialize power management. */
 	rte_power_uncore_exit_t exit;                   /**< Exit power management. */
 	rte_power_uncore_get_num_pkgs_t get_num_pkgs;
diff --git a/lib/power/rte_power_uncore.c b/lib/power/rte_power_uncore.c
index cd2b2a51d5..1ec029702b 100644
--- a/lib/power/rte_power_uncore.c
+++ b/lib/power/rte_power_uncore.c
@@ -66,11 +66,16 @@ power_uncore_probe_driver(void)
 	int ret;
 
 	global_uncore_ops = NULL;
-	/* Use package-0 and die-0 to probe uncore driver. */
 	RTE_TAILQ_FOREACH(ops, &uncore_ops_list, next) {
-		ret = ops->init(0, 0);
+		if (ops->detect) {
+			ret = ops->detect();
+		} else {
+			/* Use package-0 and die-0 to probe uncore driver. */
+			ret = ops->init(0, 0);
+			if (ret == 0)
+				ops->exit(0, 0);
+		}
 		if (ret == 0) {
-			ops->exit(0, 0);
 			env = power_uncore_driver_name2env(ops->name);
 			if (env == UINT32_MAX)
 				continue;
-- 
2.33.0


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

* [PATCH 8/9] power/hisi_uncore: support Hisilicon uncore driver
  2026-11-25 14:06 [PATCH 0/9] support uncore power management on Hisilicon platforms Shuaisong Yang
                   ` (6 preceding siblings ...)
  2026-11-25 14:06 ` [PATCH 7/9] power: add detect callback for uncore driver Shuaisong Yang
@ 2026-11-25 14:06 ` Shuaisong Yang
  2026-11-25 14:06 ` [PATCH 9/9] power: add uncore frequency telemetry Shuaisong Yang
  2026-11-25 18:56 ` [PATCH 0/9] support uncore power management on Hisilicon platforms Stephen Hemminger
  9 siblings, 0 replies; 12+ messages in thread
From: Shuaisong Yang @ 2026-11-25 14:06 UTC (permalink / raw)
  To: Thomas Monjalon, Anatoly Burakov, Sivaprasad Tummala,
	Shuaisong Yang
  Cc: dev, liuyonglong, fengchengwen, yangxingui, yangxingui,
	Huisong Li

From: Huisong Li <lihuisong@huawei.com>

DPDK uncore power framework currently only supports Intel and AMD
platforms. HiSilicon platforms lack an uncore frequency management
driver, so applications cannot manage uncore frequency on these
systems.

This patch introduces a new hisi_uncore driver that manages uncore
frequency via the Linux devfreq sysfs interface (device HID
HISI04F1:), which depends on the kernel hisi_uncore_freq module.

The driver is registered into the rte_power_uncore ops framework,
supports package/die enumeration, available frequency query, and
get/set/min/max frequency operations. It is restricted to Linux and
aarch64.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>
---
 MAINTAINERS                             |   4 +
 doc/guides/prog_guide/power_man.rst     |  15 +
 doc/guides/rel_notes/release_26_11.rst  |   5 +
 drivers/power/hisi_uncore/hisi_uncore.c | 693 ++++++++++++++++++++++++
 drivers/power/hisi_uncore/hisi_uncore.h |  39 ++
 drivers/power/hisi_uncore/meson.build   |  17 +
 drivers/power/meson.build               |   1 +
 lib/power/rte_power_uncore.c            |   3 +-
 lib/power/rte_power_uncore.h            |   3 +-
 9 files changed, 778 insertions(+), 2 deletions(-)
 create mode 100644 drivers/power/hisi_uncore/hisi_uncore.c
 create mode 100644 drivers/power/hisi_uncore/hisi_uncore.h
 create mode 100644 drivers/power/hisi_uncore/meson.build

diff --git a/MAINTAINERS b/MAINTAINERS
index cdc1ce259a..402164f534 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1871,6 +1871,10 @@ F: doc/guides/sample_app_ug/l3_forward_power_man.rst
 F: examples/vm_power_manager/
 F: doc/guides/sample_app_ug/vm_power_management.rst
 
+Hisilicon uncore power
+M: Shuaisong Yang <yangshuaisong@h-partners.com>
+F: drivers/power/hisi_uncore/
+
 Timers
 M: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>
 F: lib/timer/
diff --git a/doc/guides/prog_guide/power_man.rst b/doc/guides/prog_guide/power_man.rst
index 72f6dc9ea5..40ba7850a7 100644
--- a/doc/guides/prog_guide/power_man.rst
+++ b/doc/guides/prog_guide/power_man.rst
@@ -249,6 +249,21 @@ Additionally, the EPYC System Management Interface In-band Library for Linux
 offers essential API, enabling user-space software
 to effectively manage system functions.
 
+HiSilicon Uncore
+~~~~~~~~~~~~~~~~
+
+On HiSilicon platforms, the uncore frequency is managed through the Linux
+devfreq subsystem. The kernel ``hisi_uncore_freq`` module exposes the
+uncore device (HID ``HISI04F1:``) under ``/sys/devices/platform/``,
+providing devfreq sysfs entries for frequency control.
+
+Please ensure that the ``hisi_uncore_freq`` kernel module is loaded.
+The driver switches the devfreq governor to ``userspace`` during
+initialization to allow manual frequency setting, and restores the
+original governor on exit.
+
+This driver is only supported on Linux and aarch64.
+
 Uncore API Overview
 ~~~~~~~~~~~~~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_26_11.rst b/doc/guides/rel_notes/release_26_11.rst
index 8387949ef3..dbb9cb6d93 100644
--- a/doc/guides/rel_notes/release_26_11.rst
+++ b/doc/guides/rel_notes/release_26_11.rst
@@ -337,6 +337,11 @@ New Features
   when using ``RTE_UNCORE_PM_ENV_AUTO_DETECT``,
   instead of defaulting only to the Intel uncore driver.
 
+* **Added Hisilicon uncore power driver.**
+
+  Added the ``hisi_uncore`` driver for managing uncore frequency on
+  Hisilicon platforms via the Linux devfreq sysfs interface.
+
 * **Added graph profiling.**
 
   Added build time configurable graph node profiling statistics
diff --git a/drivers/power/hisi_uncore/hisi_uncore.c b/drivers/power/hisi_uncore/hisi_uncore.c
new file mode 100644
index 0000000000..0f22182767
--- /dev/null
+++ b/drivers/power/hisi_uncore/hisi_uncore.c
@@ -0,0 +1,693 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2026 HiSilicon Technologies Co., Ltd. All rights reserved.
+ */
+#include <dirent.h>
+#include <errno.h>
+#include <linux/limits.h>
+#include <rte_string_fns.h>
+#include <rte_memcpy.h>
+#include <rte_lcore.h>
+#include <rte_stdatomic.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "hisi_uncore.h"
+#include "power_common.h"
+#include "power_uncore_ops.h"
+
+#define HISI_UNCORE_DRIVER_NAME			"hisi-uncore"
+#define HISI_UNCORE_DEVICE_HID			"HISI04F1:"
+#define HISI_UNCORE_DEVICE_NAME_FMT		"HISI04F1:%02u"
+
+#define HISI_UNCORE_DEVFREQ_DEV_PATH		"/sys/devices/platform/"
+#define HISI_UNCORE_DEPEND_MODULE		"hisi_uncore_freq"
+#define HISI_UNCORE_DIE_NUM_PER_PKG		1
+
+#define HISI_UNCORE_DEVFREQ_GOVERNOR \
+	"/sys/devices/platform/HISI04F1:%02u/devfreq/HISI04F1:%02u/governor"
+#define HISI_UNCORE_USERSPACE_GOVERNOR "userspace"
+
+#define HISI_UNCORE_DEVFREQ_AVAILABLE_FREQ  \
+	"/sys/devices/platform/HISI04F1:%02u/devfreq/HISI04F1:%02u/available_frequencies"
+#define HISI_UNCORE_DEVFREQ_MIN_FREQ  \
+	"/sys/devices/platform/HISI04F1:%02u/devfreq/HISI04F1:%02u/min_freq"
+#define HISI_UNCORE_DEVFREQ_MAX_FREQ  \
+	"/sys/devices/platform/HISI04F1:%02u/devfreq/HISI04F1:%02u/max_freq"
+#define HISI_UNCORE_CUR_FREQ  \
+	"/sys/devices/platform/HISI04F1:%02u/devfreq/HISI04F1:%02u/cur_freq"
+#define HISI_UNCORE_SET_FREQ  \
+		"/sys/devices/platform/HISI04F1:%02u/devfreq/HISI04F1:%02u/userspace/set_freq"
+
+#define POWER_CONVERT_TO_DECIMAL 10
+
+static struct hisi_uncore_info *hisi_uncore;
+
+enum hisi_uncore_sysfs_type {
+	HISI_UNCORE_SYSFS_MIN_FREQ,
+	HISI_UNCORE_SYSFS_MAX_FREQ,
+	HISI_UNCORE_SYSFS_CUR_FREQ,
+	HISI_UNCORE_SYSFS_GOVERNOR,
+	HISI_UNCORE_SYSFS_AVAIL_FREQS,
+};
+
+static int hisi_uncore_probe_device(void)
+{
+	char driver_path[PATH_MAX];
+	bool access_ok = false;
+	struct dirent *dir;
+	DIR *d;
+
+	d = opendir(HISI_UNCORE_DEVFREQ_DEV_PATH);
+	if (d == NULL) {
+		POWER_LOG(DEBUG, "Open %s path error", HISI_UNCORE_DEVFREQ_DEV_PATH);
+		return -EINVAL;
+	}
+	while ((dir = readdir(d)) != NULL) {
+		if (!strncmp(dir->d_name, HISI_UNCORE_DEVICE_HID,
+		    strlen(HISI_UNCORE_DEVICE_HID))) {
+			snprintf(driver_path, sizeof(driver_path), "%s/%s/driver",
+				 HISI_UNCORE_DEVFREQ_DEV_PATH, dir->d_name);
+			if (access(driver_path, F_OK))
+				POWER_LOG(DEBUG, "Please load %s module",
+					  HISI_UNCORE_DEPEND_MODULE);
+			else
+				access_ok = true;
+			break;
+		}
+	}
+	closedir(d);
+
+	return access_ok ? 0 : -ENOENT;
+}
+
+static uint32_t hisi_uncore_get_pkg_num(void)
+{
+	struct dirent *dir;
+	uint32_t num = 0;
+	DIR *d;
+
+	d = opendir(HISI_UNCORE_DEVFREQ_DEV_PATH);
+	if (d == NULL) {
+		POWER_LOG(DEBUG, "Open %s path error", HISI_UNCORE_DEVFREQ_DEV_PATH);
+		return 0;
+	}
+	while ((dir = readdir(d)) != NULL) {
+		if (strncmp(dir->d_name, HISI_UNCORE_DEVICE_HID,
+		    strlen(HISI_UNCORE_DEVICE_HID)) == 0)
+			num++;
+	}
+	closedir(d);
+
+	return num;
+}
+
+static void hisi_uncore_plat_data_uninit(void)
+{
+	uint32_t i;
+
+	if (!hisi_uncore)
+		return;
+
+	for (i = 0; i < hisi_uncore->pkg_num; i++)
+		free(hisi_uncore->pkg_data[i].die_data);
+	free(hisi_uncore->pkg_data);
+	free(hisi_uncore);
+	hisi_uncore = NULL;
+}
+
+static int hisi_uncore_plat_data_init(void)
+{
+	struct hisi_uncore_die_data *die_data;
+	uint32_t pkg_num, die_num;
+	uint32_t i, j;
+	int ret;
+
+	if (hisi_uncore)
+		return 0;
+
+	ret = hisi_uncore_probe_device();
+	if (ret) {
+		POWER_LOG(DEBUG, "%s: Probe uncore device failed",
+			  HISI_UNCORE_DRIVER_NAME);
+		return ret;
+	}
+	hisi_uncore = calloc(1, sizeof(struct hisi_uncore_info));
+	if (!hisi_uncore)
+		return -ENOMEM;
+
+	pkg_num = hisi_uncore_get_pkg_num();
+	hisi_uncore->pkg_data = calloc(pkg_num, sizeof(struct hisi_uncore_pkg_data));
+	if (!hisi_uncore->pkg_data) {
+		ret = -ENOMEM;
+		goto uninit_plat_uncore;
+	}
+	hisi_uncore->pkg_num = pkg_num;
+
+	for (i = 0; i < hisi_uncore->pkg_num; i++) {
+		die_num = HISI_UNCORE_DIE_NUM_PER_PKG;
+		hisi_uncore->pkg_data[i].die_data =
+			calloc(die_num, sizeof(struct hisi_uncore_die_data));
+		if (!hisi_uncore->pkg_data[i].die_data) {
+			ret = -ENOMEM;
+			goto uninit_plat_uncore;
+		}
+		hisi_uncore->pkg_data[i].pkg_id = i;
+		hisi_uncore->pkg_data[i].die_num = die_num;
+		for (j = 0; j < die_num; j++) {
+			die_data = &hisi_uncore->pkg_data[i].die_data[j];
+			die_data->die_id = j;
+		}
+	}
+
+	return 0;
+
+uninit_plat_uncore:
+	hisi_uncore_plat_data_uninit();
+
+	return ret;
+}
+
+static int
+hisi_uncore_pkg_die_valid(unsigned int pkg, unsigned int die)
+{
+	return hisi_uncore && (pkg < hisi_uncore->pkg_num) &&
+	       (die < hisi_uncore->pkg_data[pkg].die_num);
+}
+
+static int
+hisi_uncore_read_sysfs_str(struct hisi_uncore_die_data *die_data,
+			   enum hisi_uncore_sysfs_type type,
+			   char *buf, size_t bufsz)
+{
+	const char *item_name;
+	FILE *f = NULL;
+	int ret;
+
+	switch (type) {
+	case HISI_UNCORE_SYSFS_MIN_FREQ:
+		item_name = "min_freq";
+		ret = open_core_sysfs_file(&f, "r", HISI_UNCORE_DEVFREQ_MIN_FREQ,
+					   die_data->uid, die_data->uid);
+		break;
+	case HISI_UNCORE_SYSFS_MAX_FREQ:
+		item_name = "max_freq";
+		ret = open_core_sysfs_file(&f, "r", HISI_UNCORE_DEVFREQ_MAX_FREQ,
+					   die_data->uid, die_data->uid);
+		break;
+	case HISI_UNCORE_SYSFS_CUR_FREQ:
+		item_name = "cur_freq";
+		ret = open_core_sysfs_file(&f, "r", HISI_UNCORE_CUR_FREQ,
+					   die_data->uid, die_data->uid);
+		break;
+	case HISI_UNCORE_SYSFS_GOVERNOR:
+		item_name = "governor";
+		ret = open_core_sysfs_file(&f, "r", HISI_UNCORE_DEVFREQ_GOVERNOR,
+					   die_data->uid, die_data->uid);
+		break;
+	case HISI_UNCORE_SYSFS_AVAIL_FREQS:
+		item_name = "available_frequencies";
+		ret = open_core_sysfs_file(&f, "r", HISI_UNCORE_DEVFREQ_AVAILABLE_FREQ,
+					   die_data->uid, die_data->uid);
+		break;
+	default:
+		return -EINVAL;
+	}
+	if (ret != 0) {
+		POWER_LOG(ERR, "Failed to open %s under " HISI_UNCORE_DEVICE_NAME_FMT,
+			  item_name, die_data->uid);
+		goto err;
+	}
+
+	ret = read_core_sysfs_s(f, buf, bufsz);
+	if (ret != 0) {
+		POWER_LOG(ERR, "Failed to read %s under " HISI_UNCORE_DEVICE_NAME_FMT,
+			  item_name, die_data->uid);
+		goto err;
+	}
+
+err:
+	if (f != NULL)
+		fclose(f);
+
+	return ret;
+}
+
+static int
+hisi_uncore_read_freq_sysfs(struct hisi_uncore_die_data *die_data,
+			    enum hisi_uncore_sysfs_type type, uint32_t *val)
+{
+	unsigned long tmp;
+	char buf[BUFSIZ];
+	int ret;
+
+	ret = hisi_uncore_read_sysfs_str(die_data, type, buf, sizeof(buf));
+	if (ret != 0)
+		return ret;
+
+	tmp = strtoul(buf, NULL, POWER_CONVERT_TO_DECIMAL);
+	if (tmp > UINT32_MAX)
+		return -EINVAL;
+	*val = tmp;
+
+	return 0;
+}
+
+static int
+hisi_uncore_get_min_freq(struct hisi_uncore_die_data *die_data)
+{
+	return hisi_uncore_read_freq_sysfs(die_data,
+					   HISI_UNCORE_SYSFS_MIN_FREQ,
+					   &die_data->min_freq);
+}
+
+static int
+hisi_uncore_get_max_freq(struct hisi_uncore_die_data *die_data)
+{
+	return hisi_uncore_read_freq_sysfs(die_data,
+					   HISI_UNCORE_SYSFS_MAX_FREQ,
+					   &die_data->max_freq);
+}
+
+static int
+hisi_uncore_get_cur_freq_helper(struct hisi_uncore_die_data *die_data, uint32_t *freq)
+{
+	return hisi_uncore_read_freq_sysfs(die_data, HISI_UNCORE_SYSFS_CUR_FREQ, freq);
+}
+
+static int
+hisi_uncore_get_governor_ori(struct hisi_uncore_die_data *die_data)
+{
+	char buf[BUFSIZ];
+	int ret;
+
+	ret = hisi_uncore_read_sysfs_str(die_data, HISI_UNCORE_SYSFS_GOVERNOR, buf, sizeof(buf));
+	if (ret != 0)
+		return ret;
+
+	rte_strscpy(die_data->governor_ori, buf, sizeof(die_data->governor_ori));
+	return 0;
+}
+
+static uint32_t
+hisi_uncore_parse_available_freqs(char *buf, uint32_t *freqs, int max_num)
+{
+	unsigned long val;
+	char *next = buf;
+	int count = 0;
+
+	while (*next != '\0' && count < max_num) {
+		char *endptr;
+
+		val = strtoul(next, &endptr, POWER_CONVERT_TO_DECIMAL);
+		if (endptr == next) {
+			next++;
+			continue;
+		}
+		if (val > UINT32_MAX) {
+			POWER_LOG(ERR, "Frequency value is more than %u", UINT32_MAX);
+			break;
+		}
+
+		freqs[count++] = val;
+		next = endptr;
+	}
+
+	if (count >= max_num)
+		POWER_LOG(ERR, "Available frequency number exceeds the maximum capacity %u",
+				max_num);
+
+	return count;
+}
+
+static int
+hisi_uncore_freq_cmp(const void *a, const void *b)
+{
+	uint32_t f1 = *(const uint32_t *)a;
+	uint32_t f2 = *(const uint32_t *)b;
+
+	return (f1 > f2) - (f1 < f2);
+}
+
+static int
+hisi_uncore_get_avail_freqs_inner(struct hisi_uncore_die_data *die_data)
+{
+	char buf[BUFSIZ];
+	int ret;
+
+	ret = hisi_uncore_read_sysfs_str(die_data, HISI_UNCORE_SYSFS_AVAIL_FREQS,
+					 buf, sizeof(buf));
+	if (ret != 0)
+		return ret;
+
+	die_data->nb_freqs = hisi_uncore_parse_available_freqs(buf, die_data->freqs,
+								RTE_MAX_UNCORE_FREQS);
+	qsort(die_data->freqs, die_data->nb_freqs, sizeof(uint32_t), hisi_uncore_freq_cmp);
+	return 0;
+}
+
+static int
+hisi_uncore_set_governor(struct hisi_uncore_die_data *die_data, const char *governor)
+{
+	FILE *f = NULL;
+	int ret;
+
+	ret = open_core_sysfs_file(&f, "w", HISI_UNCORE_DEVFREQ_GOVERNOR,
+				   die_data->uid, die_data->uid);
+	if (ret != 0) {
+		POWER_LOG(ERR, "Failed to open governor under " HISI_UNCORE_DEVICE_NAME_FMT,
+			  die_data->uid);
+		goto err;
+	}
+
+	ret = write_core_sysfs_s(f, governor);
+	if (ret != 0)
+		POWER_LOG(ERR, "Failed to write governor (%s) under " HISI_UNCORE_DEVICE_NAME_FMT,
+			  governor, die_data->uid);
+
+err:
+	if (f != NULL)
+		fclose(f);
+
+	return ret;
+}
+
+static int
+hisi_uncore_die_setup(struct hisi_uncore_die_data *die_data)
+{
+	int ret;
+
+	ret = hisi_uncore_get_min_freq(die_data);
+	if (ret != 0) {
+		POWER_LOG(ERR, "Get the min_freq of uncore die (uid-%u) failed",
+			  die_data->uid);
+		return ret;
+	}
+
+	ret = hisi_uncore_get_max_freq(die_data);
+	if (ret != 0) {
+		POWER_LOG(ERR, "Get the max_freq of uncore die (uid-%u) failed",
+			  die_data->uid);
+		return ret;
+	}
+	ret = hisi_uncore_get_cur_freq_helper(die_data, &die_data->cur_freq_ori);
+	if (ret != 0) {
+		POWER_LOG(ERR, "Get the original cur_freq of uncore die (uid-%u) failed",
+			  die_data->uid);
+		return ret;
+	}
+
+	ret = hisi_uncore_get_avail_freqs_inner(die_data);
+	if (ret != 0) {
+		POWER_LOG(ERR, "Get the available frequency of uncore die (uid-%u) failed",
+			  die_data->uid);
+		return ret;
+	}
+
+	ret = hisi_uncore_get_governor_ori(die_data);
+	if (ret != 0) {
+		POWER_LOG(ERR, "Get the original governor of uncore die (uid-%u) failed",
+			  die_data->uid);
+		return ret;
+	}
+
+	ret = hisi_uncore_set_governor(die_data, HISI_UNCORE_USERSPACE_GOVERNOR);
+	if (ret != 0) {
+		POWER_LOG(ERR, "Set %s governor for uncore die (uid-%u) failed",
+			  HISI_UNCORE_USERSPACE_GOVERNOR, die_data->uid);
+		return ret;
+	}
+
+	ret = open_core_sysfs_file(&die_data->f_set_freq, "rw+", HISI_UNCORE_SET_FREQ,
+				   die_data->uid, die_data->uid);
+	if (ret != 0) {
+		POWER_LOG(ERR, "Failed to open set_freq " HISI_UNCORE_DEVICE_NAME_FMT,
+			  die_data->uid);
+		(void)hisi_uncore_set_governor(die_data, die_data->governor_ori);
+	}
+
+	return ret;
+}
+
+static void
+hisi_uncore_die_teardown(struct hisi_uncore_die_data *die_data)
+{
+	if (die_data == NULL)
+		return;
+	if (die_data->f_set_freq == NULL)
+		return;
+
+	(void)fprintf(die_data->f_set_freq, "%u\n", die_data->cur_freq_ori);
+	fclose(die_data->f_set_freq);
+	die_data->f_set_freq = NULL;
+	(void)hisi_uncore_set_governor(die_data, die_data->governor_ori);
+}
+
+static int
+hisi_uncore_init(unsigned int pkg, unsigned int die)
+{
+	struct hisi_uncore_die_data *die_data;
+	int ret;
+
+	ret = hisi_uncore_plat_data_init();
+	if (ret != 0) {
+		POWER_LOG(DEBUG, "%s: Initialize platform uncore data failed",
+			  HISI_UNCORE_DRIVER_NAME);
+		return ret;
+	}
+
+	if (!hisi_uncore_pkg_die_valid(pkg, die)) {
+		POWER_LOG(ERR, "Invalid pkg-%u or die-%u for %s",
+			  pkg, die, HISI_UNCORE_DRIVER_NAME);
+		ret = -EINVAL;
+		goto plat_data_uninit;
+	}
+
+	die_data = &hisi_uncore->pkg_data[pkg].die_data[die];
+	die_data->uid = pkg * HISI_UNCORE_DIE_NUM_PER_PKG + die;
+	ret = hisi_uncore_die_setup(die_data);
+	if (ret != 0) {
+		POWER_LOG(ERR, "%s: Initialize die data (pkg-%u die-%u) failed",
+			  HISI_UNCORE_DRIVER_NAME, pkg, die);
+		goto plat_data_uninit;
+	}
+
+	rte_atomic_fetch_add_explicit(&hisi_uncore->ref, 1,
+				      rte_memory_order_relaxed);
+
+	return 0;
+
+plat_data_uninit:
+	if (rte_atomic_load_explicit(&hisi_uncore->ref,
+				     rte_memory_order_relaxed) == 0)
+		hisi_uncore_plat_data_uninit();
+
+	return ret;
+}
+
+static int
+hisi_uncore_exit(unsigned int pkg, unsigned int die)
+{
+	struct hisi_uncore_die_data *die_data;
+
+	if (!hisi_uncore_pkg_die_valid(pkg, die)) {
+		POWER_LOG(ERR, "Invalid pkg-%u or die-%u for %s",
+			  pkg, die, HISI_UNCORE_DRIVER_NAME);
+		return -EINVAL;
+	}
+
+	die_data = &hisi_uncore->pkg_data[pkg].die_data[die];
+	hisi_uncore_die_teardown(die_data);
+
+	rte_atomic_fetch_sub_explicit(&hisi_uncore->ref, 1,
+				      rte_memory_order_relaxed);
+	if (rte_atomic_load_explicit(&hisi_uncore->ref,
+				     rte_memory_order_relaxed) == 0)
+		hisi_uncore_plat_data_uninit();
+
+	return 0;
+}
+static uint32_t
+hisi_uncore_get_cur_freq(unsigned int pkg, unsigned int die)
+{
+	struct hisi_uncore_die_data *die_data;
+	uint32_t freq, idx;
+	int ret;
+
+	if (!hisi_uncore_pkg_die_valid(pkg, die)) {
+		POWER_LOG(ERR, "Invalid pkg-%u or die-%u for %s",
+			  pkg, die, HISI_UNCORE_DRIVER_NAME);
+		return RTE_POWER_INVALID_FREQ_INDEX;
+	}
+
+	die_data = &hisi_uncore->pkg_data[pkg].die_data[die];
+	ret = hisi_uncore_get_cur_freq_helper(die_data, &freq);
+	if (ret != 0)
+		return RTE_POWER_INVALID_FREQ_INDEX;
+
+	for (idx = 0; idx < die_data->nb_freqs; idx++) {
+		if (die_data->freqs[idx] == freq)
+			break;
+	}
+	if (idx == die_data->nb_freqs) {
+		POWER_LOG(ERR, "Invalid cur_freq on die (pkg-%u die-%u)",
+			  pkg, die);
+		return RTE_POWER_INVALID_FREQ_INDEX;
+	}
+
+	return idx;
+}
+
+static int
+hisi_uncore_set_freq(unsigned int pkg, unsigned int die, uint32_t index)
+{
+	struct hisi_uncore_die_data *die_data;
+
+	if (!hisi_uncore_pkg_die_valid(pkg, die)) {
+		POWER_LOG(ERR, "Invalid pkg-%u or die-%u for %s",
+			  pkg, die, HISI_UNCORE_DRIVER_NAME);
+		return -EINVAL;
+	}
+
+	die_data = &hisi_uncore->pkg_data[pkg].die_data[die];
+	if (index >= RTE_MAX_UNCORE_FREQS || index >= die_data->nb_freqs) {
+		POWER_LOG(ERR, "%s: Invalid frequency index-%u",
+			  HISI_UNCORE_DRIVER_NAME, index);
+		return -EINVAL;
+	}
+
+	if (fprintf(die_data->f_set_freq, "%u\n", die_data->freqs[index]) < 0) {
+		POWER_LOG(ERR, "%s: Set freq on uncore die (pkg-%u die-%u) failed",
+			  HISI_UNCORE_DRIVER_NAME, pkg, die);
+		return -errno;
+	}
+
+	if (fflush(die_data->f_set_freq) < 0)
+		return -errno;
+
+	return 0;
+}
+
+static int
+hisi_uncore_set_freq_max(unsigned int pkg, unsigned int die)
+{
+	struct hisi_uncore_die_data *die_data;
+
+	if (!hisi_uncore_pkg_die_valid(pkg, die)) {
+		POWER_LOG(ERR, "Invalid pkg-%u or die-%u for %s",
+			  pkg, die, HISI_UNCORE_DRIVER_NAME);
+		return -EINVAL;
+	}
+
+	die_data = &hisi_uncore->pkg_data[pkg].die_data[die];
+	if (fprintf(die_data->f_set_freq, "%u\n", die_data->max_freq) < 0) {
+		POWER_LOG(ERR, "%s: Set max freq on uncore die (pkg-%u die-%u) failed",
+			  HISI_UNCORE_DRIVER_NAME, pkg, die);
+		return -errno;
+	}
+
+	if (fflush(die_data->f_set_freq) < 0)
+		return -errno;
+
+	return 0;
+}
+
+static int
+hisi_uncore_set_freq_min(unsigned int pkg, unsigned int die)
+{
+	struct hisi_uncore_die_data *die_data;
+
+	if (!hisi_uncore_pkg_die_valid(pkg, die)) {
+		POWER_LOG(ERR, "Invalid pkg-%u or die-%u for %s",
+			  pkg, die, HISI_UNCORE_DRIVER_NAME);
+		return -EINVAL;
+	}
+
+	die_data = &hisi_uncore->pkg_data[pkg].die_data[die];
+	if (fprintf(die_data->f_set_freq, "%u\n", die_data->min_freq) < 0) {
+		POWER_LOG(ERR, "%s: Set min freq on uncore die (pkg-%u die-%u) failed",
+			  HISI_UNCORE_DRIVER_NAME, pkg, die);
+		return -errno;
+	}
+
+	if (fflush(die_data->f_set_freq) < 0)
+		return -errno;
+
+	return 0;
+}
+
+static int
+hisi_uncore_get_avail_freqs(unsigned int pkg, unsigned int die,
+			    uint32_t *freqs, uint32_t num)
+{
+	struct hisi_uncore_die_data *die_data;
+
+	if (!hisi_uncore_pkg_die_valid(pkg, die)) {
+		POWER_LOG(ERR, "Invalid pkg-%u or die-%u for %s",
+			  pkg, die, HISI_UNCORE_DRIVER_NAME);
+		return -EINVAL;
+	}
+
+	if (freqs == NULL || num == 0) {
+		POWER_LOG(ERR, "NULL buffer supplied");
+		return -EINVAL;
+	}
+
+	die_data = &hisi_uncore->pkg_data[pkg].die_data[die];
+	if (num < die_data->nb_freqs) {
+		POWER_LOG(ERR, "Buffer size is not enough");
+		return -EINVAL;
+	}
+	rte_memcpy(freqs, die_data->freqs, die_data->nb_freqs * sizeof(uint32_t));
+
+	return die_data->nb_freqs;
+}
+
+static int
+hisi_uncore_get_num_freqs(unsigned int pkg, unsigned int die)
+{
+	struct hisi_uncore_die_data *die_data;
+
+	if (!hisi_uncore_pkg_die_valid(pkg, die)) {
+		POWER_LOG(ERR, "Invalid pkg-%u or die-%u for %s",
+			  pkg, die, HISI_UNCORE_DRIVER_NAME);
+		return -EINVAL;
+	}
+
+	die_data = &hisi_uncore->pkg_data[pkg].die_data[die];
+	return die_data->nb_freqs;
+}
+
+static unsigned int
+hisi_uncore_get_num_pkgs(void)
+{
+	return hisi_uncore_get_pkg_num();
+}
+
+static unsigned int
+hisi_uncore_get_num_dies(__rte_unused unsigned int pkg)
+{
+	return HISI_UNCORE_DIE_NUM_PER_PKG;
+}
+
+static int
+hisi_uncore_detect(void)
+{
+	return hisi_uncore_probe_device();
+}
+
+static struct rte_power_uncore_ops hisi_uncore_ops = {
+	.name = HISI_UNCORE_DRIVER_NAME,
+	.detect = hisi_uncore_detect,
+	.init = hisi_uncore_init,
+	.exit = hisi_uncore_exit,
+	.get_avail_freqs = hisi_uncore_get_avail_freqs,
+	.get_num_pkgs = hisi_uncore_get_num_pkgs,
+	.get_num_dies = hisi_uncore_get_num_dies,
+	.get_num_freqs = hisi_uncore_get_num_freqs,
+	.get_freq = hisi_uncore_get_cur_freq,
+	.set_freq = hisi_uncore_set_freq,
+	.freq_max = hisi_uncore_set_freq_max,
+	.freq_min = hisi_uncore_set_freq_min,
+};
+
+RTE_POWER_REGISTER_UNCORE_OPS(hisi_uncore_ops);
diff --git a/drivers/power/hisi_uncore/hisi_uncore.h b/drivers/power/hisi_uncore/hisi_uncore.h
new file mode 100644
index 0000000000..a4ff7bc74b
--- /dev/null
+++ b/drivers/power/hisi_uncore/hisi_uncore.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2026 HiSilicon Technologies Co., Ltd. All rights reserved.
+ */
+#ifndef HISI_UNCORE_H
+#define HISI_UNCORE_H
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <rte_stdatomic.h>
+
+#define HISI_UNCORE_GOV_NAME_LEN	32
+struct hisi_uncore_die_data {
+	uint32_t die_id;
+	uint32_t uid;
+	uint32_t freqs[RTE_MAX_UNCORE_FREQS];
+	uint32_t nb_freqs;
+	uint32_t max_freq;
+	uint32_t min_freq;
+	uint32_t cur_freq_ori;
+	uint32_t curr_idx;
+	char governor_ori[HISI_UNCORE_GOV_NAME_LEN];
+	FILE *f_set_freq;
+};
+
+struct hisi_uncore_pkg_data {
+	uint32_t pkg_id;
+	uint32_t die_num;
+	struct hisi_uncore_die_data *die_data;
+};
+
+struct hisi_uncore_info {
+	RTE_ATOMIC(uint32_t) ref;
+	uint32_t pkg_num;
+	struct hisi_uncore_pkg_data *pkg_data;
+};
+
+#endif
diff --git a/drivers/power/hisi_uncore/meson.build b/drivers/power/hisi_uncore/meson.build
new file mode 100644
index 0000000000..13ba6ab100
--- /dev/null
+++ b/drivers/power/hisi_uncore/meson.build
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright (c) 2026 HiSilicon Technologies Co., Ltd. All rights reserved.
+
+if not is_linux
+    build = false
+    reason = 'only supported on Linux'
+    subdir_done()
+endif
+
+if (arch_subdir != 'arm') or (not dpdk_conf.get('RTE_ARCH_64'))
+    build = false
+    reason = 'only supported on aarch64'
+    subdir_done()
+endif
+
+deps += ['power']
+sources = files('hisi_uncore.c')
diff --git a/drivers/power/meson.build b/drivers/power/meson.build
index 0a703bce38..c49ed68daa 100644
--- a/drivers/power/meson.build
+++ b/drivers/power/meson.build
@@ -9,6 +9,7 @@ drivers = [
         'intel_pstate',
         'intel_uncore',
         'kvm_vm',
+        'hisi_uncore'
 ]
 
 std_deps = ['power']
diff --git a/lib/power/rte_power_uncore.c b/lib/power/rte_power_uncore.c
index 1ec029702b..698f0f36f3 100644
--- a/lib/power/rte_power_uncore.c
+++ b/lib/power/rte_power_uncore.c
@@ -22,7 +22,8 @@ const char *uncore_env_str[] = {
 	"not set",
 	"auto-detect",
 	"intel-uncore",
-	"amd-hsmp"
+	"amd-hsmp",
+	"hisi-uncore"
 };
 
 /* register the ops struct in rte_power_uncore_ops, return 0 on success. */
diff --git a/lib/power/rte_power_uncore.h b/lib/power/rte_power_uncore.h
index 66aea1b37f..9375e65766 100644
--- a/lib/power/rte_power_uncore.h
+++ b/lib/power/rte_power_uncore.h
@@ -23,7 +23,8 @@ enum rte_uncore_power_mgmt_env {
 	RTE_UNCORE_PM_ENV_NOT_SET,
 	RTE_UNCORE_PM_ENV_AUTO_DETECT,
 	RTE_UNCORE_PM_ENV_INTEL_UNCORE,
-	RTE_UNCORE_PM_ENV_AMD_HSMP
+	RTE_UNCORE_PM_ENV_AMD_HSMP,
+	RTE_UNCORE_PM_ENV_HISI_UNCORE
 };
 
 /**
-- 
2.33.0


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

* [PATCH 9/9] power: add uncore frequency telemetry
  2026-11-25 14:06 [PATCH 0/9] support uncore power management on Hisilicon platforms Shuaisong Yang
                   ` (7 preceding siblings ...)
  2026-11-25 14:06 ` [PATCH 8/9] power/hisi_uncore: support Hisilicon " Shuaisong Yang
@ 2026-11-25 14:06 ` Shuaisong Yang
  2026-11-25 18:56 ` [PATCH 0/9] support uncore power management on Hisilicon platforms Stephen Hemminger
  9 siblings, 0 replies; 12+ messages in thread
From: Shuaisong Yang @ 2026-11-25 14:06 UTC (permalink / raw)
  To: Anatoly Burakov, Sivaprasad Tummala
  Cc: dev, yangshuaisong, liuyonglong, fengchengwen, yangxingui,
	yangxingui, Huisong Li

From: Huisong Li <lihuisong@huawei.com>

The uncore power management API exposes frequency information that is
useful for runtime monitoring, but currently can only be queried through
application code calling the API directly. This makes it inconvenient
for operators to inspect uncore frequency status on a running DPDK
application.

Add telemetry endpoints to the power library so that uncore frequency
information can be queried externally via the standard DPDK telemetry
interface (e.g. dpdk-telemetry tool), without writing dedicated
application code.

Two commands are registered:
- /power/uncore/curr_freq: returns the current frequency index for a
  given package and die.
- /power/uncore/avail_freqs: returns the available frequencies for a
  given package and die.

Both commands take "pkg,die" as parameters and require the uncore power
environment to be initialized.

Documentation is updated to describe the new telemetry commands.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>
---
 doc/guides/prog_guide/power_man.rst    |  23 +++++
 doc/guides/rel_notes/release_26_11.rst |   6 ++
 lib/power/meson.build                  |   3 +-
 lib/power/rte_power_telemetry.c        | 129 +++++++++++++++++++++++++
 4 files changed, 160 insertions(+), 1 deletion(-)
 create mode 100644 lib/power/rte_power_telemetry.c

diff --git a/doc/guides/prog_guide/power_man.rst b/doc/guides/prog_guide/power_man.rst
index 40ba7850a7..1af5adeec3 100644
--- a/doc/guides/prog_guide/power_man.rst
+++ b/doc/guides/prog_guide/power_man.rst
@@ -302,6 +302,29 @@ Get Num Pkgs
 Get Num Dies
   Get the number of dies on a given package.
 
+Uncore Telemetry
+~~~~~~~~~~~~~~~~
+
+The power library provides telemetry commands to query uncore frequency
+information for a given package and die.
+The uncore power management environment must be initialized before using
+these commands. The parameters are specified as a comma-separated pair
+``pkg,die`` (e.g. ``0,0``).
+
+#. Get the current frequency index for a given package and die::
+
+     --> /power/uncore/curr_freq,0,0
+     {"/power/uncore/curr_freq": {"pkg": 0, "die": 0, "curr_freq_idx": 3}}
+
+#. Get the available frequencies for a given package and die::
+
+     --> /power/uncore/avail_freqs,0,0
+     {"/power/uncore/avail_freqs": {"pkg": 0, "die": 0, "num_freqs": 4,
+      "0": 1800000000, "1": 2000000000, "2": 2200000000, "3": 2400000000}}
+
+For more information on how to use the Telemetry interface, see
+the :doc:`../howto/telemetry`.
+
 References
 ----------
 
diff --git a/doc/guides/rel_notes/release_26_11.rst b/doc/guides/rel_notes/release_26_11.rst
index dbb9cb6d93..2386f57614 100644
--- a/doc/guides/rel_notes/release_26_11.rst
+++ b/doc/guides/rel_notes/release_26_11.rst
@@ -342,6 +342,12 @@ New Features
   Added the ``hisi_uncore`` driver for managing uncore frequency on
   Hisilicon platforms via the Linux devfreq sysfs interface.
 
+* **Added uncore frequency telemetry.**
+
+  Added ``/power/uncore/curr_freq`` and ``/power/uncore/avail_freqs``
+  telemetry commands to query the current frequency index and the
+  available frequencies of a given uncore package and die.
+
 * **Added graph profiling.**
 
   Added build time configurable graph node profiling statistics
diff --git a/lib/power/meson.build b/lib/power/meson.build
index d89fb55514..292d31bf8a 100644
--- a/lib/power/meson.build
+++ b/lib/power/meson.build
@@ -20,6 +20,7 @@ sources = files(
         'rte_power_pmd_mgmt.c',
         'rte_power_qos.c',
         'rte_power_uncore.c',
+        'rte_power_telemetry.c',
 )
 headers = files(
         'rte_power_cpufreq.h',
@@ -33,4 +34,4 @@ driver_sdk_headers = files(
         'power_uncore_ops.h',
 )
 
-deps += ['timer', 'ethdev']
+deps += ['timer', 'ethdev', 'telemetry']
diff --git a/lib/power/rte_power_telemetry.c b/lib/power/rte_power_telemetry.c
new file mode 100644
index 0000000000..0217c39734
--- /dev/null
+++ b/lib/power/rte_power_telemetry.c
@@ -0,0 +1,129 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2026 Huawei Technologies Co., Ltd
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <rte_telemetry.h>
+#include <rte_power_uncore.h>
+
+#include "power_common.h"
+
+static int
+parse_uncore_param(const char *params, unsigned int *pkg, unsigned int *die)
+{
+	unsigned long pkg_id, die_id;
+	char *end = NULL;
+
+	if (params == NULL || params[0] == '\0' || !isdigit((unsigned char)params[0]))
+		return -EINVAL;
+
+	pkg_id = strtoul(params, &end, 0);
+	if (end == NULL || *end != ',')
+		return -EINVAL;
+	die_id = strtoul(end + 1, &end, 0);
+	if (*end != '\0')
+		return -EINVAL;
+
+	if (pkg_id > UINT_MAX || die_id > UINT_MAX)
+		return -EINVAL;
+
+	*pkg = (unsigned int)pkg_id;
+	*die = (unsigned int)die_id;
+
+	return 0;
+}
+
+static int
+handle_power_uncore_curr_freq(const char *cmd __rte_unused, const char *params,
+		struct rte_tel_data *d)
+{
+	unsigned int pkg, die;
+	uint32_t curr_idx;
+	int ret;
+
+	if (rte_power_get_uncore_env() == RTE_UNCORE_PM_ENV_NOT_SET)
+		return -EINVAL;
+
+	ret = parse_uncore_param(params, &pkg, &die);
+	if (ret != 0)
+		return ret;
+
+	if (pkg >= rte_power_uncore_get_num_pkgs())
+		return -EINVAL;
+	if (die >= rte_power_uncore_get_num_dies(pkg))
+		return -EINVAL;
+
+	curr_idx = rte_power_get_uncore_freq(pkg, die);
+	if (curr_idx == (uint32_t)RTE_POWER_INVALID_FREQ_INDEX)
+		return -EINVAL;
+
+	rte_tel_data_start_dict(d);
+	rte_tel_data_add_dict_uint(d, "pkg", pkg);
+	rte_tel_data_add_dict_uint(d, "die", die);
+	rte_tel_data_add_dict_uint(d, "curr_freq_idx", curr_idx);
+	return 0;
+}
+
+static int
+handle_power_uncore_avail_freqs(const char *cmd __rte_unused, const char *params,
+		struct rte_tel_data *d)
+{
+	unsigned int pkg, die;
+	uint32_t *freqs;
+	char key[12];
+	int num_freqs;
+	int ret;
+	int i;
+
+	if (rte_power_get_uncore_env() == RTE_UNCORE_PM_ENV_NOT_SET)
+		return -EINVAL;
+
+	ret = parse_uncore_param(params, &pkg, &die);
+	if (ret != 0)
+		return ret;
+
+	if (pkg >= rte_power_uncore_get_num_pkgs())
+		return -EINVAL;
+	if (die >= rte_power_uncore_get_num_dies(pkg))
+		return -EINVAL;
+
+	num_freqs = rte_power_uncore_get_num_freqs(pkg, die);
+	if (num_freqs <= 0)
+		return -EINVAL;
+
+	freqs = malloc(sizeof(uint32_t) * num_freqs);
+	if (freqs == NULL)
+		return -ENOMEM;
+
+	if (rte_power_uncore_freqs(pkg, die, freqs, num_freqs) != num_freqs) {
+		free(freqs);
+		return -EINVAL;
+	}
+
+	rte_tel_data_start_dict(d);
+	rte_tel_data_add_dict_uint(d, "pkg", pkg);
+	rte_tel_data_add_dict_uint(d, "die", die);
+	rte_tel_data_add_dict_uint(d, "num_freqs", num_freqs);
+
+	for (i = 0; i < num_freqs; i++) {
+		snprintf(key, sizeof(key), "%d", i);
+		rte_tel_data_add_dict_uint(d, key, freqs[i]);
+	}
+
+	free(freqs);
+	return 0;
+}
+
+RTE_INIT(power_uncore_init_telemetry)
+{
+	rte_telemetry_register_cmd("/power/uncore/curr_freq", handle_power_uncore_curr_freq,
+			"Returns the current frequency index of an uncore domain. "
+			"Parameters: int pkg, int die");
+	rte_telemetry_register_cmd("/power/uncore/avail_freqs", handle_power_uncore_avail_freqs,
+			"Returns the available frequencies of an uncore domain. "
+			"Parameters: int pkg, int die");
+}
-- 
2.33.0


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

* Re: [PATCH 0/9] support uncore power management on Hisilicon platforms
  2026-11-25 14:06 [PATCH 0/9] support uncore power management on Hisilicon platforms Shuaisong Yang
                   ` (8 preceding siblings ...)
  2026-11-25 14:06 ` [PATCH 9/9] power: add uncore frequency telemetry Shuaisong Yang
@ 2026-11-25 18:56 ` Stephen Hemminger
  2026-11-26 11:47   ` Shuaisong Yang
  9 siblings, 1 reply; 12+ messages in thread
From: Stephen Hemminger @ 2026-11-25 18:56 UTC (permalink / raw)
  To: Shuaisong Yang; +Cc: dev, liuyonglong, fengchengwen, yangxingui, yangxingui

On Wed, 25 Nov 2026 22:06:06 +0800
Shuaisong Yang <yangshuaisong@h-partners.com> wrote:

> This series reworks the uncore frequency handling of the l3fwd-power
> sample and extends the power library with a Hisilicon uncore driver
> and uncore frequency telemetry.
> 
> The first six patches restructure the power management code of
> l3fwd-power: the uncore and cpufreq/QoS setup and cleanup paths are
> extracted into dedicated helpers, the failure paths now roll back
> the steps already taken, and the sample can set the frequency of a
> specific package/die instead of applying the change to all of them.
> 
> The last three patches extend the power library:
> 
> - a detect callback is added to the uncore driver ops, letting a
>   driver report by itself whether it can manage the platform;
> - a new Hisilicon uncore driver is added on top of the devfreq
>   sysfs interface of those platforms;
> - the current uncore frequency is exposed through telemetry.
> 
> Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>

Why does application need to handle args about uncore?
Seems to defeat the purpose having EAL.
The setup should be in EAL not the application.

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

* Re: [PATCH 0/9] support uncore power management on Hisilicon platforms
  2026-11-25 18:56 ` [PATCH 0/9] support uncore power management on Hisilicon platforms Stephen Hemminger
@ 2026-11-26 11:47   ` Shuaisong Yang
  0 siblings, 0 replies; 12+ messages in thread
From: Shuaisong Yang @ 2026-11-26 11:47 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, liuyonglong, fengchengwen, yangxingui, yangxingui

Hi Stephen,

The uncore options in l3fwd-power are not introduced by this series:
-u/-U/-i have been there since 10db2a5b87 ("examples/l3fwd-power:
add options for uncore frequency"). On the application side, this
series only cleans up that pre-existing handling (dedicated helpers,
rollback on failure) and lets users pick which package/die to control
instead of always applying to all of them (--uncore-freq).

The intended split is:
- Driver/environment setup stays inside the library: the app just
  calls rte_power_set_uncore_env(RTE_UNCORE_PM_ENV_AUTO_DETECT) and
  the library selects the driver itself. Patch 7 adds the detect
  callback used by that mechanism, and the Hisilicon driver registers
  itself without any application configuration.
- What remains in the application is the policy: which uncore domains
  to control and which frequency to pin (min/max/index). That is a
  per-application choice, and l3fwd-power is the sample demonstrating
  the rte_power APIs, as it already does for cpufreq and PM QoS.

We kept this out of EAL because uncore pinning is a policy rather
than environment abstraction: whether to touch uncore at all, and
which dies and values to use, differs from application to
application, while an EAL option would force one static policy on
all of them.

That said, if you think one-shot static uncore pinning belongs in
EAL, or a library-level "init all" helper would help, we are happy
to discuss it as a follow-up. Would the current approach be
acceptable for this series?

Thanks,
Shuaisong Yang

On 2026/11/26 2:56, Stephen Hemminger wrote:
> On Wed, 25 Nov 2026 22:06:06 +0800
> Shuaisong Yang <yangshuaisong@h-partners.com> wrote:
> 
>> This series reworks the uncore frequency handling of the l3fwd-power
>> sample and extends the power library with a Hisilicon uncore driver
>> and uncore frequency telemetry.
>>
>> The first six patches restructure the power management code of
>> l3fwd-power: the uncore and cpufreq/QoS setup and cleanup paths are
>> extracted into dedicated helpers, the failure paths now roll back
>> the steps already taken, and the sample can set the frequency of a
>> specific package/die instead of applying the change to all of them.
>>
>> The last three patches extend the power library:
>>
>> - a detect callback is added to the uncore driver ops, letting a
>>   driver report by itself whether it can manage the platform;
>> - a new Hisilicon uncore driver is added on top of the devfreq
>>   sysfs interface of those platforms;
>> - the current uncore frequency is exposed through telemetry.
>>
>> Signed-off-by: Shuaisong Yang <yangshuaisong@h-partners.com>
> 
> Why does application need to handle args about uncore?
> Seems to defeat the purpose having EAL.
> The setup should be in EAL not the application.


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

end of thread, other threads:[~2026-11-26 11:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 14:06 [PATCH 0/9] support uncore power management on Hisilicon platforms Shuaisong Yang
2026-11-25 14:06 ` [PATCH 1/9] examples/l3fwd-power: extract function to deinit uncore Shuaisong Yang
2026-11-25 14:06 ` [PATCH 2/9] examples/l3fwd-power: extract functions for cpufreq library Shuaisong Yang
2026-11-25 14:06 ` [PATCH 3/9] examples/l3fwd-power: extract functions for power QoS Shuaisong Yang
2026-11-25 14:06 ` [PATCH 4/9] examples/l3fwd-power: add rollback in uncore init Shuaisong Yang
2026-11-25 14:06 ` [PATCH 5/9] examples/l3fwd-power: add rollback and best-effort deinit Shuaisong Yang
2026-11-25 14:06 ` [PATCH 6/9] examples/l3fwd-power: set freq for specific uncore Shuaisong Yang
2026-11-25 14:06 ` [PATCH 7/9] power: add detect callback for uncore driver Shuaisong Yang
2026-11-25 14:06 ` [PATCH 8/9] power/hisi_uncore: support Hisilicon " Shuaisong Yang
2026-11-25 14:06 ` [PATCH 9/9] power: add uncore frequency telemetry Shuaisong Yang
2026-11-25 18:56 ` [PATCH 0/9] support uncore power management on Hisilicon platforms Stephen Hemminger
2026-11-26 11:47   ` Shuaisong Yang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.