Re: [PATCH v5 0/6] powercap: Add generic hierarchy support and convert DTPM

From: Rafael J. Wysocki (Intel)

Date: Fri Nov 06 2026 - 10:24:55 EST


On Tue, Nov 3, 2026 at 5:48 AM Daniel Lezcano
<daniel.lezcano@xxxxxxxxxxxxxxxx> wrote:
>
> Powercap controllers may expose trees of power zones, such as packages,
> clusters and CPUs. This series adds generic helpers to duplicate a static
> hierarchy description, create its zones through backend callbacks, and
> destroy them in reverse order. Parents must precede their children in the
> node array; the helpers validate that ordering rather than sorting nodes.
>
> Drivers supporting multiple platforms can place each platform's hierarchy
> description and node array in initdata. powercap_hierarchy_dup() creates a
> working copy of the selected hierarchy and rebases its parent pointers.
> All original descriptions, including those for unused platforms, can then
> be reclaimed automatically with init memory. Names and backend-private
> data are not duplicated and must remain valid for the working hierarchy.
>
> The controller supplies creation and destruction callbacks to connect the
> generic hierarchy traversal to its backend. The creation callback receives
> the control type, node name, private data and parent zone, registers the
> zone with its operations and constraints, and returns it to the helper.
> The destruction callback unregisters it during rollback or teardown.
>
> The API supports both fatal creation errors, which roll back previously
> created zones, and optional nodes: a NULL callback result skips a node and
> its descendants while allowing independent branches to be created.
>
> The helpers were motivated by the SPEL work and also let DTPM share the
> same hierarchy infrastructure:
> https://lore.kernel.org/lkml/20260702-qcom_spel_driver_upstream-v3-0-434d50f0c5b0@xxxxxxxxxxxxxxxx/
>
> A kselftest exercises static and duplicated hierarchies, skipped branches,
> reuse after partial destruction, and rejection of repeated creation. Its
> userspace script checks the 16 exported zones and selected attribute
> values, then removes the module with a sysfs attribute descriptor open.
>
> DTPM is converted to the generic helpers while preserving best-effort
> creation when individual backends are unavailable. The CPU backend finds
> an online sibling when a hierarchy's representative CPU is offline.
> Entirely offline policies remain unavailable during initialization.
>
> The RK3399 description is reduced to one CPU entry per cpufreq policy.
> The old backend already suppressed duplicate registration; the extra
> entries were redundant descriptions, not additional registered zones.
> Finally, a shared Rockchip virtual descriptor and an RK3588 CPU hierarchy
> are added. RK3588's three frequency domains are represented by cpu@0,
> cpu@400 and cpu@600 below a virtual package node; no GPU zone is added
> for RK3588 in this series.
>
> Changes in v5 (since v4):
> - Address Lukasz Luba's review of patch 4: reject a DTPM DT node with a
> NULL path before calling of_find_node_by_path(). Treat the missing path
> as an invalid descriptor (-EINVAL), rather than skipping it as an
> unavailable backend.
> - Collect Reviewed-by tags from Lukasz Luba for patches 1, 3, 5 and 6.
> - Keep the v7.3 base and the six-patch organization.
>
> Changes in v4 (since v3):
> - Rebase on v7.3.
> - Address the selftest issues reported by Sashiko:
> - Add a kselftest config fragment requesting CONFIG_POWERCAP,
> CONFIG_MODULES and CONFIG_MODULE_UNLOAD, guard the module build with
> CONFIG_POWERCAP, and skip building when prerequisites or Module.symvers
> are missing instead of failing at modpost.
> - Resolve the kernel output directory and pass absolute O=,
> KBUILD_OUTPUT and module-output paths to Kbuild so cleanup works when
> a relative O= is inherited from the parent selftest make invocation.
> - Keep the statically initialized mutex in permanent module data so its
> lockdep key does not point into freed module init memory. Retain a
> separate init-only description for the hierarchy duplication test.
> - Return KSFT_SKIP when powercap sysfs support or the test module is
> unavailable, while retaining failures for actual module-load errors.
>
> Changes in v3 (since v2):
> - Rebase on v7.3-rc7.
> - Add POWERCAP_HIERARCHY_INIT() and document static versus duplicated
> hierarchy ownership and lock initialization.
> - Explain how duplication retains the selected platform hierarchy while
> init memory containing the original descriptions is reclaimed, and
> describe the controller callbacks and their arguments.
> - Reject populated hierarchies with -EBUSY before invoking callbacks.
> - Validate names and parent ordering before zone creation, including for
> static hierarchies; document the accepted hierarchy structure.
> - Use explicit mutex locking, a signed reverse-loop index, and the clearer
> powercap_node.zone member name.
> - Define NULL creation results as skipped branches and retain rollback for
> error pointers, preserving DTPM's best-effort behavior.
> - Handle offline CPU representatives through an online policy sibling
> while holding the CPU hotplug read lock.
> - Fix selftest output-directory handling and module cleanup, use
> powercap-owned zone allocations, and keep shell validation/counting in
> the main shell so failures propagate.
> - Extend and document selftest coverage for static creation, skipped
> branches, hierarchy reuse, -EBUSY, and an open descriptor at teardown.
> - Fix indentation, __initdata placement, unnamed setup callback arguments,
> and whitespace-only lines reported by checkpatch and patch application.
> - Correct descriptions of redundant CPU entries and actual sysfs checks.
>
> Earlier generic hierarchy API and selftest submission:
> https://lore.kernel.org/all/20260806110159.69690-1-daniel.lezcano@xxxxxxxxxxxxxxxx/
>
> 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 | 180 +++++-----
> drivers/powercap/dtpm_cpu.c | 62 +++-
> drivers/powercap/dtpm_devfreq.c | 22 +-
> drivers/powercap/powercap_sys.c | 204 ++++++++++++
> drivers/soc/rockchip/dtpm.c | 129 +++++--
> include/linux/dtpm.h | 6 +-
> include/linux/powercap.h | 205 ++++++++++++
> tools/testing/selftests/Makefile | 1 +
> tools/testing/selftests/powercap/Kbuild | 5 +
> tools/testing/selftests/powercap/Makefile | 46 +++
> tools/testing/selftests/powercap/config | 3 +
> .../selftests/powercap/powercap_hierarchy.c | 314 ++++++++++++++++++
> .../selftests/powercap/powercap_hierarchy.sh | 128 +++++++
> 13 files changed, 1153 insertions(+), 152 deletions(-)
> create mode 100644 tools/testing/selftests/powercap/Kbuild
> create mode 100644 tools/testing/selftests/powercap/Makefile
> create mode 100644 tools/testing/selftests/powercap/config
> create mode 100644 tools/testing/selftests/powercap/powercap_hierarchy.c
> create mode 100755 tools/testing/selftests/powercap/powercap_hierarchy.sh
>
>
> base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
> --

Since Likasz is happy with the first patch and the majority of the
others, and Sashiko doesn't complain either, please feel free to send
a pull request to me for 7.5 including this series when you consider
it as ready.

Thanks!