From: Huisong Li <[email protected]> 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 <[email protected]> Signed-off-by: Shuaisong Yang <[email protected]> --- 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

