mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kevin Hilman <khilman@baylibre.com>
To: Ulf Hansson <ulf.hansson@oss.qualcomm.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	linux-pm@vger.kernel.org, Ulf Hansson <ulfh@kernel.org>,
	linux-kernel@vger.kernel.org,
	Abel Vesa <abel.vesa@oss.qualcomm.com>
Subject: Re: [PATCH v5 3/4] pmdomain: core: add genpd_for_each_child() helper
Date: Thu, 24 Sep 2026 11:51:05 -0700	[thread overview]
Message-ID: <7hwlsabi06.fsf@baylibre.com> (raw)
In-Reply-To: <CAPx+jO98X6dr20r3o7iHUq7zrjsDy+6YDM=FiO6MOkpCJFfhEA@mail.gmail.com>

Ulf Hansson <ulf.hansson@oss.qualcomm.com> writes:

> On Thu, Aug 27, 2026 at 12:23 AM Kevin Hilman (TI) <khilman@baylibre.com> wrote:
>>
>> Add a new internal helper function genpd_for_each_child() that recursively
>> iterates over all devices in a PM domain and its child domains (subdomains).
>> This helper is useful for governors and other core PM domain code that needs
>> to examine or apply operations to all devices within a domain hierarchy.
>>
>> The function takes a callback that is invoked for each device, and supports
>> early termination if the callback returns a non-zero value.
>>
>> The helper is defined in a new internal header drivers/pmdomain/core.h and
>> implemented in drivers/pmdomain/core.c, making it available to other PM
>> domain subsystem components.
>>
>> The first user of this helper is the cpu_system_power_down_ok() governor
>> function, which uses it to check device QoS latency constraints across the
>> entire domain hierarchy.
>>
>> Reviewed-by: Abel Vesa <abel.vesa@oss.qualcomm.com>
>> Signed-off-by: Kevin Hilman (TI) <khilman@baylibre.com>
>> ---
>>  drivers/pmdomain/core.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
>>  drivers/pmdomain/core.h | 17 +++++++++++++++++
>>  2 files changed, 62 insertions(+)
>>
>> diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
>> index 842c4169e290..ff27369d9a97 100644
>> --- a/drivers/pmdomain/core.c
>> +++ b/drivers/pmdomain/core.c
>> @@ -24,6 +24,8 @@
>>  #include <linux/cpu.h>
>>  #include <linux/debugfs.h>
>>
>> +#include "core.h"
>> +
>>  /* Provides a unique ID for each genpd device */
>>  static DEFINE_IDA(genpd_ida);
>>
>> @@ -276,6 +278,49 @@ static void genpd_sd_counter_inc(struct generic_pm_domain *genpd)
>>         smp_mb__after_atomic();
>>  }
>>
>> +/**
>> + * genpd_for_each_child - Recursively iterate over all devices
>> + *                        in a PM domain and its subdomains.
>> + * @genpd: PM domain to iterate over.
>> + * @fn: Callback function to invoke for each device.
>> + * @data: Data to pass to the callback function.
>> + *
>> + * This function recursively walks through all devices in the given PM domain
>> + * and all devices in its child PM domains (subdomains). For each device found,
>> + * the callback function @fn is invoked with the device and @data as arguments.
>> + *
>> + * Note: this function is inteded for use by the core and governors,
>> + * not for pmdomain providers.
>> + *
>> + * Returns: 0 on success, or the first non-zero value returned by @fn.
>> + */
>> +int genpd_for_each_child(struct generic_pm_domain *genpd,
>> +                        int (*fn)(struct device *dev, void *data),
>> +                        void *data)
>> +{
>> +       struct pm_domain_data *pdd;
>> +       struct gpd_link *link;
>> +       int ret;
>> +
>> +       /* First, iterate over all devices in this domain */
>> +       list_for_each_entry(pdd, &genpd->dev_list, list_node) {
>> +               ret = fn(pdd->dev, data);
>> +               if (ret)
>> +                       return ret;
>> +       }
>> +
>> +       /* Then, recursively iterate over all child domains (subdomains) */
>> +       list_for_each_entry(link, &genpd->parent_links, parent_node) {
>> +               struct generic_pm_domain *child_pd = link->child;
>> +
>> +               ret = genpd_for_each_child(child_pd, fn, data);
>> +               if (ret)
>> +                       return ret;
>> +       }
>> +
>> +       return 0;
>> +}
>> +
>>  #ifdef CONFIG_DEBUG_FS
>>  static struct dentry *genpd_debugfs_dir;
>>
>> diff --git a/drivers/pmdomain/core.h b/drivers/pmdomain/core.h
>> new file mode 100644
>> index 000000000000..a296134d4005
>> --- /dev/null
>> +++ b/drivers/pmdomain/core.h
>> @@ -0,0 +1,17 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/*
>> + * Internal header for PM domain core
>> + *
>> + * Copyright (C) 2026 Kevin Hilman <khilman@baylibre.com>, Texas Instruments
>> + */
>> +
>> +#ifndef __PM_DOMAIN_CORE_H__
>> +#define __PM_DOMAIN_CORE_H__
>> +
>> +#include <linux/pm_domain.h>
>
> I don't think this is needed. Instead please make forward declaration
> of the structs we need. Like:
>
> struct device;
> struct generic_pm_domain;

OK.

Kevin

  reply	other threads:[~2026-09-24 18:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 22:23 [PATCH v5 0/4] PM: QoS/pmdomains: support resume latencies for system-wide PM Kevin Hilman (TI)
2026-08-26 22:23 ` [PATCH v5 1/4] PM / QoS: add flag to indicate latency applies system-wide Kevin Hilman (TI)
2026-08-26 22:23 ` [PATCH v5 2/4] PM / QoS: add lockless read for flags Kevin Hilman (TI)
2026-09-11 13:59   ` Rafael J. Wysocki (Intel)
2026-08-26 22:23 ` [PATCH v5 3/4] pmdomain: core: add genpd_for_each_child() helper Kevin Hilman (TI)
2026-09-16 10:04   ` Ulf Hansson
2026-09-24 18:51     ` Kevin Hilman [this message]
2026-08-26 22:23 ` [PATCH v5 4/4] pmdomain: add support system-wide resume latency constraints Kevin Hilman (TI)
2026-09-16 10:43   ` Ulf Hansson
2026-09-24 19:13     ` Kevin Hilman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7hwlsabi06.fsf@baylibre.com \
    --to=khilman@baylibre.com \
    --cc=abel.vesa@oss.qualcomm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=ulf.hansson@oss.qualcomm.com \
    --cc=ulfh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®