lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPDyKFp6KLuuuVFcEWGxn5NkuDSkhM-MjRiiYj_zC4mFxhOBag@mail.gmail.com>
Date:   Tue, 21 Apr 2020 16:00:09 +0200
From:   Ulf Hansson <ulf.hansson@...aro.org>
To:     Daniel Baluta <daniel.baluta@....nxp.com>
Cc:     "Rafael J. Wysocki" <rjw@...ysocki.net>,
        Len Brown <len.brown@...el.com>,
        ranjani.sridharan@...ux.intel.com,
        Aisheng Dong <aisheng.dong@....com>,
        Fabio Estevam <festevam@...il.com>,
        alsa-devel@...a-project.org, Linux PM <linux-pm@...r.kernel.org>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Sascha Hauer <s.hauer@...gutronix.de>,
        Kevin Hilman <khilman@...nel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Daniel Baluta <daniel.baluta@....com>,
        Pierre-Louis Bossart <pierre-louis.bossart@...ux.intel.com>,
        paul.olaru@....com, dl-linux-imx <linux-imx@....com>,
        Sascha Hauer <kernel@...gutronix.de>,
        Shawn Guo <shawnguo@...nel.org>, shengjiu.wang@....com,
        Linux ARM <linux-arm-kernel@...ts.infradead.org>
Subject: Re: [RFC PATCH v2 1/2] PM / domains: Introduce multi PM domains helpers

On Wed, 4 Mar 2020 at 13:20, Daniel Baluta <daniel.baluta@....nxp.com> wrote:
>
> From: Daniel Baluta <daniel.baluta@....com>
>
> This patch introduces helpers support for multi PM domains.
>
> API consists of:
>
> 1) dev_multi_pm_attach - powers up all PM domains associated with a given
> device. Because we can attach one PM domain per device, we create
> virtual devices (children of initial device) and associate PM domains
> one per virtual device.
>
> 2) dev_multi_pm_detach - detaches all virtual devices from PM domains
> attached with.
>
> Signed-off-by: Daniel Baluta <daniel.baluta@....com>

First, apologize for the delay.

In general I don't mind adding helpers that can be used to decrease
open coding. However, in this case, I wonder how useful the helpers
would really be.

More precisely, according to the information I have, a device may not
always need all of its PM domains to be turned on together, but
perhaps only a subset of them. Depending on the current use case that
is running.

Of course, some cases follow your expectations, but as stated, some
others do not.

Do you have an idea how many users that would be able to switch to
these new APIs as of today?

Kind regards
Uffe

> ---
>  drivers/base/power/common.c | 93 +++++++++++++++++++++++++++++++++++++
>  include/linux/pm_domain.h   | 19 ++++++++
>  2 files changed, 112 insertions(+)
>
> diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
> index bbddb267c2e6..6d1f142833b1 100644
> --- a/drivers/base/power/common.c
> +++ b/drivers/base/power/common.c
> @@ -228,3 +228,96 @@ void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd)
>         device_pm_check_callbacks(dev);
>  }
>  EXPORT_SYMBOL_GPL(dev_pm_domain_set);
> +
> +/**
> + * dev_multi_pm_attach - power up device associated power domains
> + * @dev: The device used to lookup the PM domains
> + *
> + * Parse device's OF node to find all PM domains specifiers. For each power
> + * domain found, create a virtual device and associate it with the
> + * current power domain.
> + *
> + * This function should typically be invoked by a driver during the
> + * probe phase, in the case its device requires power management through
> + * multiple PM domains.
> + *
> + * Returns a pointer to @dev_multi_pm_domain_data if successfully attached PM
> + * domains, NULL when the device doesn't need a PM domain or when single
> + * power-domains exists for it, else an ERR_PTR() in case of
> + * failures.
> + */
> +struct dev_multi_pm_domain_data *dev_multi_pm_attach(struct device *dev)
> +{
> +       struct dev_multi_pm_domain_data *mpd, *retp;
> +       int num_domains;
> +       int i;
> +
> +       num_domains = of_count_phandle_with_args(dev->of_node, "power-domains",
> +                                                "#power-domain-cells");
> +       if (num_domains < 2)
> +               return NULL;
> +
> +       mpd = devm_kzalloc(dev, GFP_KERNEL, sizeof(*mpd));
> +       if (!mpd)
> +               return ERR_PTR(-ENOMEM);
> +
> +       mpd->dev = dev;
> +       mpd->num_domains = num_domains;
> +
> +       mpd->virt_devs = devm_kmalloc_array(dev, mpd->num_domains,
> +                                           sizeof(*mpd->virt_devs),
> +                                           GFP_KERNEL);
> +       if (!mpd->virt_devs)
> +               return ERR_PTR(-ENOMEM);
> +
> +       mpd->links = devm_kmalloc_array(dev, mpd->num_domains,
> +                                       sizeof(*mpd->links), GFP_KERNEL);
> +       if (!mpd->links)
> +               return ERR_PTR(-ENOMEM);
> +
> +       for (i = 0; i < mpd->num_domains; i++) {
> +               mpd->virt_devs[i] = dev_pm_domain_attach_by_id(dev, i);
> +               if (IS_ERR(mpd->virt_devs[i])) {
> +                       retp = (struct dev_multi_pm_domain_data *)
> +                               mpd->virt_devs[i];
> +                       goto exit_unroll_pm;
> +               }
> +               mpd->links[i] = device_link_add(dev, mpd->virt_devs[i],
> +                                               DL_FLAG_STATELESS |
> +                                               DL_FLAG_PM_RUNTIME |
> +                                               DL_FLAG_RPM_ACTIVE);
> +               if (!mpd->links[i]) {
> +                       retp = ERR_PTR(-ENOMEM);
> +                       dev_pm_domain_detach(mpd->virt_devs[i], false);
> +                       goto exit_unroll_pm;
> +               }
> +       }
> +       return mpd;
> +
> +exit_unroll_pm:
> +       while (--i >= 0) {
> +               device_link_del(mpd->links[i]);
> +               dev_pm_domain_detach(mpd->virt_devs[i], false);
> +       }
> +
> +       return retp;
> +}
> +EXPORT_SYMBOL(dev_multi_pm_attach);
> +
> +/**
> + * dev_multi_pm_detach - Detach a device from its PM domains.
> + * Each multi power domain is attached to a virtual children device
> + *
> + * @mpd: multi power domains data, contains the association between
> + * virtul device and PM domain
> + */
> +void dev_multi_pm_detach(struct dev_multi_pm_domain_data *mpd)
> +{
> +       int i;
> +
> +       for (i = 0; i < mpd->num_domains; i++) {
> +               device_link_del(mpd->links[i]);
> +               dev_pm_domain_detach(mpd->virt_devs[i], false);
> +       }
> +}
> +EXPORT_SYMBOL(dev_multi_pm_detach);
> diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
> index 9ec78ee53652..5bcb35150af2 100644
> --- a/include/linux/pm_domain.h
> +++ b/include/linux/pm_domain.h
> @@ -183,6 +183,13 @@ struct generic_pm_domain_data {
>         void *data;
>  };
>
> +struct dev_multi_pm_domain_data {
> +       struct device *dev; /* parent device */
> +       struct device **virt_devs; /* virtual children links */
> +       struct device_link **links; /*  links parent <-> virtual children */
> +       int num_domains;
> +};
> +
>  #ifdef CONFIG_PM_GENERIC_DOMAINS
>  static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
>  {
> @@ -369,18 +376,27 @@ struct generic_pm_domain *of_genpd_remove_last(struct device_node *np)
>
>  #ifdef CONFIG_PM
>  int dev_pm_domain_attach(struct device *dev, bool power_on);
> +struct dev_multi_pm_domain_data *dev_multi_pm_attach(struct device *dev);
>  struct device *dev_pm_domain_attach_by_id(struct device *dev,
>                                           unsigned int index);
>  struct device *dev_pm_domain_attach_by_name(struct device *dev,
>                                             const char *name);
>  void dev_pm_domain_detach(struct device *dev, bool power_off);
>  int dev_pm_domain_start(struct device *dev);
> +void dev_multi_pm_detach(struct dev_multi_pm_domain_data *mpd);
>  void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
> +
>  #else
>  static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
>  {
>         return 0;
>  }
> +
> +struct dev_multi_pm_domain_data *dev_multi_pm_attach(struct device *dev)
> +{
> +       return NULL;
> +}
> +
>  static inline struct device *dev_pm_domain_attach_by_id(struct device *dev,
>                                                         unsigned int index)
>  {
> @@ -396,6 +412,9 @@ static inline int dev_pm_domain_start(struct device *dev)
>  {
>         return 0;
>  }
> +
> +void dev_multi_pm_detach(struct dev_multi_pm_domain_data *mpd) {}
> +
>  static inline void dev_pm_domain_set(struct device *dev,
>                                      struct dev_pm_domain *pd) {}
>  #endif
> --
> 2.17.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ