Re: [PATCH 3/3] PM: domains: Add a ->dev_get_performance_state() callback to genpd

From: Dmitry Osipenko
Date: Fri Sep 03 2021 - 02:01:06 EST


02.09.2021 13:16, Ulf Hansson пишет:
> Hardware may be preprogrammed to a specific performance state, which may
> not be zero initially during boot. This may lead to that genpd's current
> performance state becomes inconsistent with the state of the hardware. To
> deal with this, the driver for a device that is being attached to its
> genpd, need to request an initial performance state vote, which is
> typically done by calling some of the OPP APIs while probing.
>
> In some cases this would lead to boilerplate code in the drivers. Let's
> make it possible to avoid this, by adding a new optional callback to genpd
> and invoke it per device during the attach process. In this way, the genpd
> provider driver can inform genpd about the initial performance state that
> is needed for the device.
>
> Signed-off-by: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
> ---
> drivers/base/power/domain.c | 8 +++++---
> include/linux/pm_domain.h | 2 ++
> 2 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 800adf831cae..1a6f3538af8d 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -2640,13 +2640,15 @@ static void genpd_dev_pm_sync(struct device *dev)
> genpd_queue_power_off_work(pd);
> }
>
> -static int genpd_get_default_performance_state(struct device *dev,
> +static int genpd_get_default_performance_state(struct generic_pm_domain *genpd,
> + struct device *dev,
> unsigned int index)
> {
> int pstate = of_get_required_opp_performance_state(dev->of_node, index);
>
> if (pstate == -ENODEV || pstate == -EOPNOTSUPP)
> - return 0;
> + pstate = genpd->dev_get_performance_state ?
> + genpd->dev_get_performance_state(genpd, dev) : 0;
>
> return pstate;
> }
> @@ -2701,7 +2703,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
> }
>
> /* Set the default performance state */
> - pstate = genpd_get_default_performance_state(dev, index);
> + pstate = genpd_get_default_performance_state(pd, dev, index);

If base device is suspended, then its performance state is zero.

When device will be rpm-resumed, then its performance should be set to
the default state.

You're setting performance state of the wrong device, it should be the
base device and not the virtual domain device.

These all is handled properly by my patch [1]. Hence it's complicated
for the reason.

[1]
https://patchwork.ozlabs.org/project/linux-tegra/patch/20210831135450.26070-5-digetx@xxxxxxxxx/