[PATCH v5 11/12] powercap: arm_scmi: Add get_power_uw to synthetic node
Cristian Marussi
cristian.marussi at arm.com
Tue May 5 15:13:44 PDT 2026
On Tue, Apr 28, 2026 at 10:09:20AM +0100, Philip Radford wrote:
> Exposes the current power usage from the immediate children of
> the synthetic (root) powercap node. Iterates over pr->spzones and
> sums per-zone power.
>
> Signed-off-by: Philip Radford <philip.radford at arm.com>
> ---
> drivers/powercap/arm_scmi_powercap.c | 29 ++++++++++++++++++++++++++--
> 1 file changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/powercap/arm_scmi_powercap.c b/drivers/powercap/arm_scmi_powercap.c
> index d74869af1633..81b5214acda4 100644
> --- a/drivers/powercap/arm_scmi_powercap.c
> +++ b/drivers/powercap/arm_scmi_powercap.c
> @@ -270,9 +270,34 @@ static int instance_root_release(struct powercap_zone *pz)
> return 0;
> }
>
> -static int instance_root_get_power_uw(struct powercap_zone *pz, u64 *v)
> +static int instance_root_get_power_uw(struct powercap_zone *pz, u64 *power_uw)
> {
> - *v = 0;
> + struct scmi_powercap_zone *root = to_scmi_powercap_zone(pz);
> + struct scmi_powercap_zone *child;
> + struct scmi_powercap_root *pr;
> + u64 acc = 0;
> + u64 p;
These u64 can live on a single line...
> + int ret;
> +
> + if (!pz || !power_uw)
> + return -EINVAL;
> +
> + pr = container_of(root, struct scmi_powercap_root, instance_root);
usually we define macros to wrap this like to_scmi_powercap_zone()...
...even if used only once...this could be a new to_scmi_powercap_root()
> + if (!pr)
> + return -ENODEV;
> +
> + list_for_each_entry(child, &pr->registered_zones[0], node) {
> + if (child == &pr->instance_root)
> + continue;
You'll need to check this in light of the fixes of previous patch
> +
> + ret = scmi_powercap_get_power_uw(&child->zone, &p);
> + if (!ret)
> + acc += p;
> + else
> + dev_dbg(child->dev, "Failed to read child power: %u\n", ret);
> + }
> +
> + *power_uw = acc;
> return 0;
> }
>
Thanks,
Cristian
More information about the linux-arm-kernel
mailing list