diff mbox series

[6/9] OPP: Extend support for the opp-level beyond required-opps

Message ID 20230925131715.138411-7-ulf.hansson@linaro.org (mailing list archive)
State New
Delegated to: viresh kumar
Headers show
Series PM: domains/opp/arm_scmi: Extend performance scaling support | expand

Commit Message

Ulf Hansson Sept. 25, 2023, 1:17 p.m. UTC
At this point the level (performance state) for an OPP is currently limited
to be requested for a device that is attached to a PM domain.  Moreover,
the device needs to have the so called required-opps assigned to it, which
are based upon OPP tables being described in DT.

To extend the support beyond required-opps and DT, let's enable the level
to be set for all OPPs. More precisely, if the requested OPP has a valid
level let's try to request it through the device's optional PM domain, via
calling dev_pm_domain_set_performance_state().

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/opp/core.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Comments

Ulf Hansson Sept. 25, 2023, 1:33 p.m. UTC | #1
On Mon, 25 Sept 2023 at 15:18, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> At this point the level (performance state) for an OPP is currently limited
> to be requested for a device that is attached to a PM domain.  Moreover,
> the device needs to have the so called required-opps assigned to it, which
> are based upon OPP tables being described in DT.
>
> To extend the support beyond required-opps and DT, let's enable the level
> to be set for all OPPs. More precisely, if the requested OPP has a valid
> level let's try to request it through the device's optional PM domain, via
> calling dev_pm_domain_set_performance_state().
>
> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> ---
>  drivers/opp/core.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
>
> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> index 60dca60ac4af..afb73978cdcb 100644
> --- a/drivers/opp/core.c
> +++ b/drivers/opp/core.c
> @@ -1107,6 +1107,22 @@ void _update_set_required_opps(struct opp_table *opp_table)
>                 opp_table->set_required_opps = _opp_set_required_opps_generic;
>  }
>
> +static int _set_opp_level(struct device *dev, struct opp_table *opp_table,
> +                         struct dev_pm_opp *opp)
> +{
> +       int ret = 0;
> +
> +       /* Request a new performance state through the device's PM domain. */
> +       if (opp && opp->level) {
> +               ret = dev_pm_domain_set_performance_state(dev, opp->level);
> +               if (ret)
> +                       dev_err(dev, "Failed to set performance state %u (%d)\n",
> +                               opp->level, ret);
> +       }

Okay, so reviewing my own code found a problem here. We need an "else"
here, that should request the performance state to be set to 0.

I am not sending a new version at this point, but awaiting more feedback first.

> +
> +       return ret;
> +}
> +
>  static void _find_current_opp(struct device *dev, struct opp_table *opp_table)
>  {
>         struct dev_pm_opp *opp = ERR_PTR(-ENODEV);
> @@ -1154,8 +1170,13 @@ static int _disable_opp_table(struct device *dev, struct opp_table *opp_table)
>         if (opp_table->regulators)
>                 regulator_disable(opp_table->regulators[0]);
>
> +       ret = _set_opp_level(dev, opp_table, NULL);
> +       if (ret)
> +               goto out;
> +
>         ret = _set_required_opps(dev, opp_table, NULL, false);
>
> +out:
>         opp_table->enabled = false;
>         return ret;
>  }
> @@ -1198,6 +1219,10 @@ static int _set_opp(struct device *dev, struct opp_table *opp_table,
>                         return ret;
>                 }
>
> +               ret = _set_opp_level(dev, opp_table, opp);
> +               if (ret)
> +                       return ret;
> +
>                 ret = _set_opp_bw(opp_table, opp, dev);
>                 if (ret) {
>                         dev_err(dev, "Failed to set bw: %d\n", ret);
> @@ -1241,6 +1266,10 @@ static int _set_opp(struct device *dev, struct opp_table *opp_table,
>                         return ret;
>                 }
>
> +               ret = _set_opp_level(dev, opp_table, opp);
> +               if (ret)
> +                       return ret;
> +
>                 ret = _set_required_opps(dev, opp_table, opp, false);
>                 if (ret) {
>                         dev_err(dev, "Failed to set required opps: %d\n", ret);
> --
> 2.34.1
>

Kind regards
Uffe
Viresh Kumar Oct. 3, 2023, 8:23 a.m. UTC | #2
On 25-09-23, 15:33, Ulf Hansson wrote:
> On Mon, 25 Sept 2023 at 15:18, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> >
> > At this point the level (performance state) for an OPP is currently limited
> > to be requested for a device that is attached to a PM domain.  Moreover,
> > the device needs to have the so called required-opps assigned to it, which
> > are based upon OPP tables being described in DT.
> >
> > To extend the support beyond required-opps and DT, let's enable the level
> > to be set for all OPPs. More precisely, if the requested OPP has a valid
> > level let's try to request it through the device's optional PM domain, via
> > calling dev_pm_domain_set_performance_state().
> >
> > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > ---
> >  drivers/opp/core.c | 29 +++++++++++++++++++++++++++++
> >  1 file changed, 29 insertions(+)
> >
> > diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> > index 60dca60ac4af..afb73978cdcb 100644
> > --- a/drivers/opp/core.c
> > +++ b/drivers/opp/core.c
> > @@ -1107,6 +1107,22 @@ void _update_set_required_opps(struct opp_table *opp_table)
> >                 opp_table->set_required_opps = _opp_set_required_opps_generic;
> >  }
> >
> > +static int _set_opp_level(struct device *dev, struct opp_table *opp_table,
> > +                         struct dev_pm_opp *opp)
> > +{
> > +       int ret = 0;
> > +
> > +       /* Request a new performance state through the device's PM domain. */
> > +       if (opp && opp->level) {
> > +               ret = dev_pm_domain_set_performance_state(dev, opp->level);
> > +               if (ret)
> > +                       dev_err(dev, "Failed to set performance state %u (%d)\n",
> > +                               opp->level, ret);
> > +       }
> 
> Okay, so reviewing my own code found a problem here. We need an "else"
> here, that should request the performance state to be set to 0.
> 
> I am not sending a new version at this point, but awaiting more feedback first.

I am looking to add below to this patch, is that okay with you ?

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 7b505316bb1c..a113e9caaa5a 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -1135,16 +1135,22 @@ void _update_set_required_opps(struct opp_table *opp_table)
 static int _set_opp_level(struct device *dev, struct opp_table *opp_table,
                          struct dev_pm_opp *opp)
 {
+       unsigned int level = 0;
        int ret = 0;

-       /* Request a new performance state through the device's PM domain. */
-       if (opp && opp->level) {
-               ret = dev_pm_domain_set_performance_state(dev, opp->level);
-               if (ret)
-                       dev_err(dev, "Failed to set performance state %u (%d)\n",
-                               opp->level, ret);
+       if (opp) {
+               if (!opp->level)
+                       return 0;
+
+               level = opp->level;
        }

+       /* Request a new performance state through the device's PM domain. */
+       ret = dev_pm_genpd_set_performance_state(dev, level);
+       if (ret)
+               dev_err(dev, "Failed to set performance state %u (%d)\n", level,
+                       ret);
+
        return ret;
 }

I am switching back to dev_pm_genpd_set_performance_state() as I won't be
applying the power domain changes. I will then push out a branch and you can
rebase your patches on top of it ? And then probably Sudeep or someone else can
apply everything ?
Ulf Hansson Oct. 3, 2023, 12:36 p.m. UTC | #3
On Tue, 3 Oct 2023 at 10:23, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> On 25-09-23, 15:33, Ulf Hansson wrote:
> > On Mon, 25 Sept 2023 at 15:18, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > >
> > > At this point the level (performance state) for an OPP is currently limited
> > > to be requested for a device that is attached to a PM domain.  Moreover,
> > > the device needs to have the so called required-opps assigned to it, which
> > > are based upon OPP tables being described in DT.
> > >
> > > To extend the support beyond required-opps and DT, let's enable the level
> > > to be set for all OPPs. More precisely, if the requested OPP has a valid
> > > level let's try to request it through the device's optional PM domain, via
> > > calling dev_pm_domain_set_performance_state().
> > >
> > > Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
> > > ---
> > >  drivers/opp/core.c | 29 +++++++++++++++++++++++++++++
> > >  1 file changed, 29 insertions(+)
> > >
> > > diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> > > index 60dca60ac4af..afb73978cdcb 100644
> > > --- a/drivers/opp/core.c
> > > +++ b/drivers/opp/core.c
> > > @@ -1107,6 +1107,22 @@ void _update_set_required_opps(struct opp_table *opp_table)
> > >                 opp_table->set_required_opps = _opp_set_required_opps_generic;
> > >  }
> > >
> > > +static int _set_opp_level(struct device *dev, struct opp_table *opp_table,
> > > +                         struct dev_pm_opp *opp)
> > > +{
> > > +       int ret = 0;
> > > +
> > > +       /* Request a new performance state through the device's PM domain. */
> > > +       if (opp && opp->level) {
> > > +               ret = dev_pm_domain_set_performance_state(dev, opp->level);
> > > +               if (ret)
> > > +                       dev_err(dev, "Failed to set performance state %u (%d)\n",
> > > +                               opp->level, ret);
> > > +       }
> >
> > Okay, so reviewing my own code found a problem here. We need an "else"
> > here, that should request the performance state to be set to 0.
> >
> > I am not sending a new version at this point, but awaiting more feedback first.
>
> I am looking to add below to this patch, is that okay with you ?
>
> diff --git a/drivers/opp/core.c b/drivers/opp/core.c
> index 7b505316bb1c..a113e9caaa5a 100644
> --- a/drivers/opp/core.c
> +++ b/drivers/opp/core.c
> @@ -1135,16 +1135,22 @@ void _update_set_required_opps(struct opp_table *opp_table)
>  static int _set_opp_level(struct device *dev, struct opp_table *opp_table,
>                           struct dev_pm_opp *opp)
>  {
> +       unsigned int level = 0;
>         int ret = 0;
>
> -       /* Request a new performance state through the device's PM domain. */
> -       if (opp && opp->level) {
> -               ret = dev_pm_domain_set_performance_state(dev, opp->level);
> -               if (ret)
> -                       dev_err(dev, "Failed to set performance state %u (%d)\n",
> -                               opp->level, ret);
> +       if (opp) {
> +               if (!opp->level)
> +                       return 0;
> +
> +               level = opp->level;
>         }
>
> +       /* Request a new performance state through the device's PM domain. */
> +       ret = dev_pm_genpd_set_performance_state(dev, level);
> +       if (ret)
> +               dev_err(dev, "Failed to set performance state %u (%d)\n", level,
> +                       ret);
> +
>         return ret;
>  }
>
> I am switching back to dev_pm_genpd_set_performance_state() as I won't be
> applying the power domain changes.

Can you please explain further on this. Rafael has acked those
patches, so it should be perfectly fine for you to pick them via your
tree too. There is no need to defer them.

> I will then push out a branch and you can
> rebase your patches on top of it ? And then probably Sudeep or someone else can
> apply everything ?

Or are you suggesting to just take one of the patches from my series,
and then I will re-base everything on top?

Just trying to understand the way forward. :-)

Kind regards
Uffe
Viresh Kumar Oct. 4, 2023, 5:04 a.m. UTC | #4
On 03-10-23, 14:36, Ulf Hansson wrote:
> Can you please explain further on this. Rafael has acked those
> patches, so it should be perfectly fine for you to pick them via your
> tree too. There is no need to defer them.

Ahh, then it is fine.

> > I will then push out a branch and you can
> > rebase your patches on top of it ? And then probably Sudeep or someone else can
> > apply everything ?
> 
> Or are you suggesting to just take one of the patches from my series,
> and then I will re-base everything on top?
> 
> Just trying to understand the way forward. :-)

Applied patches 1-6/9 and the fixed routine looks like this now:

+static int _set_opp_level(struct device *dev, struct opp_table *opp_table,
+                         struct dev_pm_opp *opp)
+{
+       unsigned int level = 0;
+       int ret = 0;
+
+       if (opp) {
+               if (!opp->level)
+                       return 0;
+
+               level = opp->level;
+       }
+
+       /* Request a new performance state through the device's PM domain. */
+       ret = dev_pm_domain_set_performance_state(dev, level);
+       if (ret)
+               dev_err(dev, "Failed to set performance state %u (%d)\n", level,
+                       ret);
+
+       return ret;
+}

Does it look okay now ?
Ulf Hansson Oct. 4, 2023, 9:06 a.m. UTC | #5
On Wed, 4 Oct 2023 at 07:04, Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> On 03-10-23, 14:36, Ulf Hansson wrote:
> > Can you please explain further on this. Rafael has acked those
> > patches, so it should be perfectly fine for you to pick them via your
> > tree too. There is no need to defer them.
>
> Ahh, then it is fine.
>
> > > I will then push out a branch and you can
> > > rebase your patches on top of it ? And then probably Sudeep or someone else can
> > > apply everything ?
> >
> > Or are you suggesting to just take one of the patches from my series,
> > and then I will re-base everything on top?
> >
> > Just trying to understand the way forward. :-)
>
> Applied patches 1-6/9 and the fixed routine looks like this now:
>
> +static int _set_opp_level(struct device *dev, struct opp_table *opp_table,
> +                         struct dev_pm_opp *opp)
> +{
> +       unsigned int level = 0;
> +       int ret = 0;
> +
> +       if (opp) {
> +               if (!opp->level)
> +                       return 0;
> +
> +               level = opp->level;
> +       }
> +
> +       /* Request a new performance state through the device's PM domain. */
> +       ret = dev_pm_domain_set_performance_state(dev, level);
> +       if (ret)
> +               dev_err(dev, "Failed to set performance state %u (%d)\n", level,
> +                       ret);
> +
> +       return ret;
> +}
>
> Does it look okay now ?

Yes, perfect! Thanks for helping out!

Kind regards
Uffe
diff mbox series

Patch

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 60dca60ac4af..afb73978cdcb 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -1107,6 +1107,22 @@  void _update_set_required_opps(struct opp_table *opp_table)
 		opp_table->set_required_opps = _opp_set_required_opps_generic;
 }
 
+static int _set_opp_level(struct device *dev, struct opp_table *opp_table,
+			  struct dev_pm_opp *opp)
+{
+	int ret = 0;
+
+	/* Request a new performance state through the device's PM domain. */
+	if (opp && opp->level) {
+		ret = dev_pm_domain_set_performance_state(dev, opp->level);
+		if (ret)
+			dev_err(dev, "Failed to set performance state %u (%d)\n",
+				opp->level, ret);
+	}
+
+	return ret;
+}
+
 static void _find_current_opp(struct device *dev, struct opp_table *opp_table)
 {
 	struct dev_pm_opp *opp = ERR_PTR(-ENODEV);
@@ -1154,8 +1170,13 @@  static int _disable_opp_table(struct device *dev, struct opp_table *opp_table)
 	if (opp_table->regulators)
 		regulator_disable(opp_table->regulators[0]);
 
+	ret = _set_opp_level(dev, opp_table, NULL);
+	if (ret)
+		goto out;
+
 	ret = _set_required_opps(dev, opp_table, NULL, false);
 
+out:
 	opp_table->enabled = false;
 	return ret;
 }
@@ -1198,6 +1219,10 @@  static int _set_opp(struct device *dev, struct opp_table *opp_table,
 			return ret;
 		}
 
+		ret = _set_opp_level(dev, opp_table, opp);
+		if (ret)
+			return ret;
+
 		ret = _set_opp_bw(opp_table, opp, dev);
 		if (ret) {
 			dev_err(dev, "Failed to set bw: %d\n", ret);
@@ -1241,6 +1266,10 @@  static int _set_opp(struct device *dev, struct opp_table *opp_table,
 			return ret;
 		}
 
+		ret = _set_opp_level(dev, opp_table, opp);
+		if (ret)
+			return ret;
+
 		ret = _set_required_opps(dev, opp_table, opp, false);
 		if (ret) {
 			dev_err(dev, "Failed to set required opps: %d\n", ret);