Powercap controllers frequently expose a hierarchy of power zones, for example packages, clusters and CPUs. Until now, each driver had to implement its own hierarchy traversal, parent lookup, error handling and teardown logic.
This series introduces a generic hierarchy description and helper functions allowing a powercap controller to instantiate and destroy an entire hierarchy from a static description. The powercap core takes care of duplicating the hierarchy description, rebasing parent pointers, creating zones in dependency order, and performing the appropriate rollback and cleanup on errors. The API was primarily motivated by the recently posted SPEL series and also provides a migration path for DTPM to use the same generic infrastructure instead of maintaining its own hierarchy handling. Link: SPEL cover letter https://lore.kernel.org/lkml/20260702-qcom_spel_driver_upstream-v3-0-434d50f0c...@oss.qualcomm.com/ A kselftest is added to exercise the new API. It creates a synthetic hierarchy, validates the resulting sysfs hierarchy and attributes, and checks that all resources are correctly released when the hierarchy is destroyed. DTPM currently implements its own hierarchy creation logic to walk a platform-provided description, create the corresponding DTPM zones and tear them down. With the generic powercap hierarchy infrastructure in place, this logic can instead be shared at the powercap core level. The series therefore converts DTPM to use the generic powercap hierarchy helpers. The platform hierarchy is duplicated before use, while powercap_hierarchy_create() and powercap_hierarchy_destroy() handle its lifetime and traversal. DTPM only provides the callbacks responsible for creating and destroying the DTPM instance associated with each powercap node. The CPU and devfreq backends are adjusted accordingly. As part of this conversion, the existing RK3399 description is simplified. The CPU backend creates one DTPM zone per cpufreq policy, so describing every CPU belonging to the same policy results in duplicate zones. The RK3399 hierarchy is therefore reduced to one CPU node per cpufreq policy. The Rockchip virtual node descriptor is also made SoC-independent so it can be reused by other Rockchip platforms. Finally, an RK3588 hierarchy is added. The RK3588 exposes three cpufreq policies, represented by cpu@0, cpu@400 and cpu@600. These three CPU domains are grouped below a virtual package node: rk3588 `-- package |-- cpu0-cpufreq |-- cpu4-cpufreq `-- cpu6-cpufreq Daniel Lezcano (6): powercap: Add generic zone hierarchy creation helpers selftests/powercap: Add powercap hierarchy creation API tests powercap: dtpm: Remove duplicate RK3399 CPU hierarchy nodes powercap: dtpm: Use generic powercap hierarchy helpers powercap: dtpm: Rename Rockchip virtual node descriptor powercap: dtpm: Add RK3588 hierarchy drivers/powercap/dtpm.c | 165 ++++++------ drivers/powercap/dtpm_cpu.c | 22 +- drivers/powercap/dtpm_devfreq.c | 22 +- drivers/powercap/powercap_sys.c | 148 +++++++++++ drivers/soc/rockchip/dtpm.c | 127 ++++++--- include/linux/dtpm.h | 5 +- include/linux/powercap.h | 178 +++++++++++++ tools/testing/selftests/Makefile | 1 + tools/testing/selftests/powercap/Kbuild | 3 + tools/testing/selftests/powercap/Makefile | 17 ++ .../selftests/powercap/powercap_hierarchy.c | 246 ++++++++++++++++++ .../selftests/powercap/powercap_hierarchy.sh | 118 +++++++++ 12 files changed, 906 insertions(+), 146 deletions(-) create mode 100644 tools/testing/selftests/powercap/Kbuild create mode 100644 tools/testing/selftests/powercap/Makefile create mode 100644 tools/testing/selftests/powercap/powercap_hierarchy.c create mode 100755 tools/testing/selftests/powercap/powercap_hierarchy.sh -- 2.43.0
