linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/13] opp: Implement dev_pm_opp_set_opp()
@ 2021-01-21 11:17 Viresh Kumar
  2021-01-21 11:17 ` [PATCH 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp() Viresh Kumar
       [not found] ` <1585f6c21ea8aee64fe4da0bf72b36ea4d74a779.1611227342.git.viresh.kumar@linaro.org>
  0 siblings, 2 replies; 17+ messages in thread
From: Viresh Kumar @ 2021-01-21 11:17 UTC (permalink / raw)
  To: Dmitry Osipenko, Andy Gross, Bjorn Andersson, Chanwoo Choi,
	Jonathan Hunter, Kyungmin Park, MyungJoo Ham, Nishanth Menon,
	Rafael J. Wysocki, Rob Clark, Sean Paul, Stephen Boyd,
	Thierry Reding, Viresh Kumar, Viresh Kumar
  Cc: linux-pm, Vincent Guittot, Sibi Sankar, linux-kernel,
	linux-arm-kernel, dri-devel, freedreno, linux-arm-msm,
	linux-tegra

Hello,

This patchset implements a new API dev_pm_opp_set_opp(), which
configures the devices represented by an opp table to a particular opp.
The opp core supports a wide variety of devices now, some of them can
change frequency and other properties (like CPUs), while others can just
change their pstates or regulators (like power domains) and then there
are others which can change their bandwidth as well (interconnects).
Instead of having separate implementations for all of them, where all
will eventually lack something or the other, lets try to implement a
common solution for everyone. This takes care of setting regulators, bw,
required opps, etc for all device types.

Dmitry, please go ahead and try this series. This is based of opp tree's
linux-next branch.

Sibi, since you added dev_pm_opp_set_bw() earlier, it would be good if
you can give this a try. In case this breaks anything for you.

I have already tested this on hikey board for CPU devices.

To get this tested better and as early as possible, I have pushed it
here:

git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git opp/linux-next

This will be part of linux-next tomorrow.

Note, all the patches need to go through OPP tree here. Please provide
your Acks for platform specific bits.

--
Viresh

Viresh Kumar (13):
  opp: Rename _opp_set_rate_zero()
  opp: No need to check clk for errors
  opp: Keep track of currently programmed OPP
  opp: Split _set_opp() out of dev_pm_opp_set_rate()
  opp: Allow _set_opp() to work for non-freq devices
  opp: Allow _generic_set_opp_regulator() to work for non-freq devices
  opp: Allow _generic_set_opp_clk_only() to work for non-freq devices
  opp: Update parameters of  _set_opp_custom()
  opp: Implement dev_pm_opp_set_opp()
  cpufreq: qcom: Migrate to dev_pm_opp_set_opp()
  devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  drm: msm: Migrate to dev_pm_opp_set_opp()
  opp: Remove dev_pm_opp_set_bw()

 drivers/cpufreq/qcom-cpufreq-hw.c     |   2 +-
 drivers/devfreq/tegra30-devfreq.c     |   2 +-
 drivers/gpu/drm/msm/adreno/a6xx_gmu.c |   8 +-
 drivers/opp/core.c                    | 314 ++++++++++++++------------
 drivers/opp/opp.h                     |   2 +
 include/linux/pm_opp.h                |   6 +-
 6 files changed, 184 insertions(+), 150 deletions(-)

-- 
2.25.0.rc1.19.g042ed3e048af


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-21 11:17 [PATCH 00/13] opp: Implement dev_pm_opp_set_opp() Viresh Kumar
@ 2021-01-21 11:17 ` Viresh Kumar
  2021-01-21 21:36   ` Dmitry Osipenko
  2021-01-27  9:10   ` [PATCH V2 " Viresh Kumar
       [not found] ` <1585f6c21ea8aee64fe4da0bf72b36ea4d74a779.1611227342.git.viresh.kumar@linaro.org>
  1 sibling, 2 replies; 17+ messages in thread
From: Viresh Kumar @ 2021-01-21 11:17 UTC (permalink / raw)
  To: Dmitry Osipenko, MyungJoo Ham, Kyungmin Park, Chanwoo Choi,
	Thierry Reding, Jonathan Hunter
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rafael Wysocki,
	Stephen Boyd, Nishanth Menon, Sibi Sankar, linux-kernel,
	linux-arm-kernel, linux-tegra

dev_pm_opp_set_bw() is getting removed and dev_pm_opp_set_opp() should
be used instead. Migrate to the new API.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/devfreq/tegra30-devfreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
index 117cad7968ab..d2477d7d1f66 100644
--- a/drivers/devfreq/tegra30-devfreq.c
+++ b/drivers/devfreq/tegra30-devfreq.c
@@ -647,7 +647,7 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq,
 		return PTR_ERR(opp);
 	}
 
-	ret = dev_pm_opp_set_bw(dev, opp);
+	ret = dev_pm_opp_set_opp(dev, opp);
 	dev_pm_opp_put(opp);
 
 	return ret;
-- 
2.25.0.rc1.19.g042ed3e048af


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 07/13] opp: Allow _generic_set_opp_clk_only() to work for non-freq devices
       [not found] ` <1585f6c21ea8aee64fe4da0bf72b36ea4d74a779.1611227342.git.viresh.kumar@linaro.org>
@ 2021-01-21 20:26   ` Dmitry Osipenko
  2021-01-22  4:35     ` Viresh Kumar
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Osipenko @ 2021-01-21 20:26 UTC (permalink / raw)
  To: Viresh Kumar, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: linux-pm, Vincent Guittot, Rafael Wysocki, Sibi Sankar,
	linux-kernel, linux-arm-kernel, linux-tegra

21.01.2021 14:17, Viresh Kumar пишет:
> In order to avoid conditional statements at the caller site, this patch
> updates _generic_set_opp_clk_only() to work for devices that don't
> change frequency (like power domains, etc.). Return 0 if the clk pointer
> passed to this routine is not valid.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
...

Hello Viresh,

Thank you very much for yours effort! I gave a quick test to this series
and instantly found one small issue in this patch.

> +	/* We may reach here for devices which don't change frequency */
> +	if (unlikely(!clk))

I replaced dev_pm_opp_set_voltage() with dev_pm_opp_set_opp() in the
Tegra PD driver and got a crash, which happens because the above line
should be:

	if (IS_ERR(clk))

The opp_table->clk is initialized to ERR_PTR(-ENOENT) if device doesn't
have a clock, like a power domain device in my case.

Everything works good after fixing this patch. I'll keep testing and
will be taking a closer look at the rest of the patches over this weekend.

For the record, here is a backtrace of the crash:

Unable to handle kernel NULL pointer dereference at virtual address 00000016
...
(clk_set_rate) from (_set_opp)
(_set_opp) from (dev_pm_opp_set_opp)
(dev_pm_opp_set_opp) from (tegra_genpd_set_performance_state)
(tegra_genpd_set_performance_state) from (_genpd_set_performance_state)
(_genpd_set_performance_state) from (dev_pm_genpd_set_performance_state)
(dev_pm_genpd_set_performance_state) from (_set_required_opp)
(_set_required_opp) from (_set_opp)
(_set_opp) from (dev_pm_opp_set_rate)
(dev_pm_opp_set_rate) from (host1x_runtime_resume)
(host1x_runtime_resume) from (genpd_runtime_resume)
(genpd_runtime_resume) from (__rpm_callback)
(__rpm_callback) from (rpm_callback)
(rpm_callback) from (rpm_resume)
(rpm_resume) from (__pm_runtime_resume)
(__pm_runtime_resume) from (host1x_probe)
(host1x_probe) from (platform_probe)
(platform_probe) from (really_probe)
(really_probe) from (driver_probe_device)
(driver_probe_device) from (device_driver_attach)
(device_driver_attach) from (__driver_attach)
(__driver_attach) from (bus_for_each_dev)
(bus_for_each_dev) from (bus_add_driver)
(bus_add_driver) from (driver_register)
(driver_register) from (__platform_register_drivers)
(__platform_register_drivers) from (host1x_module_init)
(host1x_module_init) from (do_one_initcall)
(do_one_initcall) from (kernel_init_freeable)
(kernel_init_freeable) from (kernel_init)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-21 11:17 ` [PATCH 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp() Viresh Kumar
@ 2021-01-21 21:36   ` Dmitry Osipenko
  2021-01-22  6:26     ` Viresh Kumar
  2021-01-27  9:10   ` [PATCH V2 " Viresh Kumar
  1 sibling, 1 reply; 17+ messages in thread
From: Dmitry Osipenko @ 2021-01-21 21:36 UTC (permalink / raw)
  To: Viresh Kumar, MyungJoo Ham, Kyungmin Park, Chanwoo Choi,
	Thierry Reding, Jonathan Hunter
  Cc: linux-pm, Vincent Guittot, Rafael Wysocki, Stephen Boyd,
	Nishanth Menon, Sibi Sankar, linux-kernel, linux-arm-kernel,
	linux-tegra

21.01.2021 14:17, Viresh Kumar пишет:
> dev_pm_opp_set_bw() is getting removed and dev_pm_opp_set_opp() should
> be used instead. Migrate to the new API.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  drivers/devfreq/tegra30-devfreq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
> index 117cad7968ab..d2477d7d1f66 100644
> --- a/drivers/devfreq/tegra30-devfreq.c
> +++ b/drivers/devfreq/tegra30-devfreq.c
> @@ -647,7 +647,7 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq,
>  		return PTR_ERR(opp);
>  	}
>  
> -	ret = dev_pm_opp_set_bw(dev, opp);
> +	ret = dev_pm_opp_set_opp(dev, opp);
>  	dev_pm_opp_put(opp);
>  
>  	return ret;
> 

This patch introduces a very serious change that needs to be fixed.

Now dev_pm_opp_set_opp() changes both clock rate and bandwidth, this is
unacceptable for this driver because it shall not touch the clock rate.

I think dev_pm_opp_set_bw() can't be removed.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 07/13] opp: Allow _generic_set_opp_clk_only() to work for non-freq devices
  2021-01-21 20:26   ` [PATCH 07/13] opp: Allow _generic_set_opp_clk_only() to work for non-freq devices Dmitry Osipenko
@ 2021-01-22  4:35     ` Viresh Kumar
  2021-01-25 21:09       ` Dmitry Osipenko
  0 siblings, 1 reply; 17+ messages in thread
From: Viresh Kumar @ 2021-01-22  4:35 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, linux-pm,
	Vincent Guittot, Rafael Wysocki, Sibi Sankar, linux-kernel,
	linux-arm-kernel, linux-tegra

On 21-01-21, 23:26, Dmitry Osipenko wrote:
> 21.01.2021 14:17, Viresh Kumar пишет:
> > In order to avoid conditional statements at the caller site, this patch
> > updates _generic_set_opp_clk_only() to work for devices that don't
> > change frequency (like power domains, etc.). Return 0 if the clk pointer
> > passed to this routine is not valid.
> > 
> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> > ---
> ...
> 
> Hello Viresh,
> 
> Thank you very much for yours effort! I gave a quick test to this series
> and instantly found one small issue in this patch.
> 
> > +	/* We may reach here for devices which don't change frequency */
> > +	if (unlikely(!clk))
> 
> I replaced dev_pm_opp_set_voltage() with dev_pm_opp_set_opp() in the
> Tegra PD driver and got a crash, which happens because the above line
> should be:
> 
> 	if (IS_ERR(clk))

Fixed, thanks.

-- 
viresh

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-21 21:36   ` Dmitry Osipenko
@ 2021-01-22  6:26     ` Viresh Kumar
  2021-01-22 15:28       ` Dmitry Osipenko
  0 siblings, 1 reply; 17+ messages in thread
From: Viresh Kumar @ 2021-01-22  6:26 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Thierry Reding,
	Jonathan Hunter, linux-pm, Vincent Guittot, Rafael Wysocki,
	Stephen Boyd, Nishanth Menon, Sibi Sankar, linux-kernel,
	linux-arm-kernel, linux-tegra

On 22-01-21, 00:36, Dmitry Osipenko wrote:
> 21.01.2021 14:17, Viresh Kumar пишет:
> > dev_pm_opp_set_bw() is getting removed and dev_pm_opp_set_opp() should
> > be used instead. Migrate to the new API.
> > 
> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> > ---
> >  drivers/devfreq/tegra30-devfreq.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
> > index 117cad7968ab..d2477d7d1f66 100644
> > --- a/drivers/devfreq/tegra30-devfreq.c
> > +++ b/drivers/devfreq/tegra30-devfreq.c
> > @@ -647,7 +647,7 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq,
> >  		return PTR_ERR(opp);
> >  	}
> >  
> > -	ret = dev_pm_opp_set_bw(dev, opp);
> > +	ret = dev_pm_opp_set_opp(dev, opp);
> >  	dev_pm_opp_put(opp);
> >  
> >  	return ret;
> > 
> 
> This patch introduces a very serious change that needs to be fixed.
> 
> Now dev_pm_opp_set_opp() changes both clock rate and bandwidth, this is
> unacceptable for this driver because it shall not touch the clock rate.
> 
> I think dev_pm_opp_set_bw() can't be removed.

I am wondering here on what would be a better solution, do what you
said or introduce another helper like dev_pm_opp_clear_clk(), which
will make sure the OPP core doesn't play with device's clk.

-- 
viresh

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-22  6:26     ` Viresh Kumar
@ 2021-01-22 15:28       ` Dmitry Osipenko
  2021-01-25  3:14         ` Viresh Kumar
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Osipenko @ 2021-01-22 15:28 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Thierry Reding,
	Jonathan Hunter, linux-pm, Vincent Guittot, Rafael Wysocki,
	Stephen Boyd, Nishanth Menon, Sibi Sankar, linux-kernel,
	linux-arm-kernel, linux-tegra

22.01.2021 09:26, Viresh Kumar пишет:
> On 22-01-21, 00:36, Dmitry Osipenko wrote:
>> 21.01.2021 14:17, Viresh Kumar пишет:
>>> dev_pm_opp_set_bw() is getting removed and dev_pm_opp_set_opp() should
>>> be used instead. Migrate to the new API.
>>>
>>> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
>>> ---
>>>  drivers/devfreq/tegra30-devfreq.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
>>> index 117cad7968ab..d2477d7d1f66 100644
>>> --- a/drivers/devfreq/tegra30-devfreq.c
>>> +++ b/drivers/devfreq/tegra30-devfreq.c
>>> @@ -647,7 +647,7 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq,
>>>  		return PTR_ERR(opp);
>>>  	}
>>>  
>>> -	ret = dev_pm_opp_set_bw(dev, opp);
>>> +	ret = dev_pm_opp_set_opp(dev, opp);
>>>  	dev_pm_opp_put(opp);
>>>  
>>>  	return ret;
>>>
>>
>> This patch introduces a very serious change that needs to be fixed.
>>
>> Now dev_pm_opp_set_opp() changes both clock rate and bandwidth, this is
>> unacceptable for this driver because it shall not touch the clock rate.
>>
>> I think dev_pm_opp_set_bw() can't be removed.
> 
> I am wondering here on what would be a better solution, do what you
> said or introduce another helper like dev_pm_opp_clear_clk(), which
> will make sure the OPP core doesn't play with device's clk.
> 

Either way will work, but maybe keeping the dev_pm_opp_set_bw() is a bit
more straightforward variant for now since it will avoid the code's
changes and it's probably a bit more obvious variant for the OPP users.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-22 15:28       ` Dmitry Osipenko
@ 2021-01-25  3:14         ` Viresh Kumar
  2021-01-25 16:00           ` Dmitry Osipenko
  0 siblings, 1 reply; 17+ messages in thread
From: Viresh Kumar @ 2021-01-25  3:14 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Thierry Reding,
	Jonathan Hunter, linux-pm, Vincent Guittot, Rafael Wysocki,
	Stephen Boyd, Nishanth Menon, Sibi Sankar, linux-kernel,
	linux-arm-kernel, linux-tegra

On 22-01-21, 18:28, Dmitry Osipenko wrote:
> Either way will work, but maybe keeping the dev_pm_opp_set_bw() is a bit
> more straightforward variant for now since it will avoid the code's
> changes and it's probably a bit more obvious variant for the OPP users.

The problem is it creates unnecessary paths which we need to support. For
example, in case of bandwidth itself we may want to update regulator/pm
domain/required OPPs and this should all be done for everyone. I really do not
want to keep separate paths for such stuff, it makes it hard to maintain..

-- 
viresh

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-25  3:14         ` Viresh Kumar
@ 2021-01-25 16:00           ` Dmitry Osipenko
  0 siblings, 0 replies; 17+ messages in thread
From: Dmitry Osipenko @ 2021-01-25 16:00 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Thierry Reding,
	Jonathan Hunter, linux-pm, Vincent Guittot, Rafael Wysocki,
	Stephen Boyd, Nishanth Menon, Sibi Sankar, linux-kernel,
	linux-arm-kernel, linux-tegra

25.01.2021 06:14, Viresh Kumar пишет:
> On 22-01-21, 18:28, Dmitry Osipenko wrote:
>> Either way will work, but maybe keeping the dev_pm_opp_set_bw() is a bit
>> more straightforward variant for now since it will avoid the code's
>> changes and it's probably a bit more obvious variant for the OPP users.
> 
> The problem is it creates unnecessary paths which we need to support. For
> example, in case of bandwidth itself we may want to update regulator/pm
> domain/required OPPs and this should all be done for everyone. I really do not
> want to keep separate paths for such stuff, it makes it hard to maintain..
> 

Maybe we could add dev_pm_opp_of_add_table_without_clock(), at least
that should be a bit nicer from a drivers perspective than having to
care about dev_pm_opp_clear_clk(), IMO.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 07/13] opp: Allow _generic_set_opp_clk_only() to work for non-freq devices
  2021-01-22  4:35     ` Viresh Kumar
@ 2021-01-25 21:09       ` Dmitry Osipenko
  2021-01-27  6:58         ` Viresh Kumar
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Osipenko @ 2021-01-25 21:09 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, linux-pm,
	Vincent Guittot, Rafael Wysocki, Sibi Sankar, linux-kernel,
	linux-arm-kernel, linux-tegra

22.01.2021 07:35, Viresh Kumar пишет:
> On 21-01-21, 23:26, Dmitry Osipenko wrote:
>> 21.01.2021 14:17, Viresh Kumar пишет:
>>> In order to avoid conditional statements at the caller site, this patch
>>> updates _generic_set_opp_clk_only() to work for devices that don't
>>> change frequency (like power domains, etc.). Return 0 if the clk pointer
>>> passed to this routine is not valid.
>>>
>>> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
>>> ---
>> ...
>>
>> Hello Viresh,
>>
>> Thank you very much for yours effort! I gave a quick test to this series
>> and instantly found one small issue in this patch.
>>
>>> +	/* We may reach here for devices which don't change frequency */
>>> +	if (unlikely(!clk))
>>
>> I replaced dev_pm_opp_set_voltage() with dev_pm_opp_set_opp() in the
>> Tegra PD driver and got a crash, which happens because the above line
>> should be:
>>
>> 	if (IS_ERR(clk))
> 
> Fixed, thanks.
> 

Please remove unlikely() around IS_ERR(), it already has the unlikely().

https://elixir.bootlin.com/linux/v5.11-rc4/source/include/linux/err.h#L22

I'd also recommend to remove all the unlikely() from OPP code since it
doesn't bring any value if not used in a very performance-critical code
path. OPP core doesn't have such code paths. The [un]likely() only make
code less readable and may result in a worse assembly.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 07/13] opp: Allow _generic_set_opp_clk_only() to work for non-freq devices
  2021-01-25 21:09       ` Dmitry Osipenko
@ 2021-01-27  6:58         ` Viresh Kumar
  0 siblings, 0 replies; 17+ messages in thread
From: Viresh Kumar @ 2021-01-27  6:58 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, linux-pm,
	Vincent Guittot, Rafael Wysocki, Sibi Sankar, linux-kernel,
	linux-arm-kernel, linux-tegra

On 26-01-21, 00:09, Dmitry Osipenko wrote:
> Please remove unlikely() around IS_ERR(), it already has the unlikely().

Right.

> https://elixir.bootlin.com/linux/v5.11-rc4/source/include/linux/err.h#L22
> 
> I'd also recommend to remove all the unlikely() from OPP code since it
> doesn't bring any value if not used in a very performance-critical code
> path. OPP core doesn't have such code paths. The [un]likely() only make
> code less readable and may result in a worse assembly.

The likely/unlikely() stuff is to optimize code, not necessarily the stuff in
the hot path alone, therwise stuff like IS_ERR() would never have it. It surely
does bring value by optimizing the code, surely the result isn't significant
enough but that is fine, every effort counts.

AFAIK, if we are sure of path the code will almost always take, then we should
rather use these and so I am inclined towards keeping them. Though I understand
that using them may result in bad behavior (performance) if they fail.

-- 
viresh

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH V2 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-21 11:17 ` [PATCH 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp() Viresh Kumar
  2021-01-21 21:36   ` Dmitry Osipenko
@ 2021-01-27  9:10   ` Viresh Kumar
  2021-01-27 10:02     ` Viresh Kumar
                       ` (2 more replies)
  1 sibling, 3 replies; 17+ messages in thread
From: Viresh Kumar @ 2021-01-27  9:10 UTC (permalink / raw)
  To: Dmitry Osipenko, MyungJoo Ham, Kyungmin Park, Chanwoo Choi,
	Thierry Reding, Jonathan Hunter
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rafael Wysocki,
	Stephen Boyd, Nishanth Menon, linux-tegra, linux-kernel

dev_pm_opp_set_bw() is getting removed and dev_pm_opp_set_opp() should
be used instead. Migrate to the new API.

We don't want the OPP core to manage the clk for this driver, migrate to
dev_pm_opp_of_add_table_noclk() to make sure dev_pm_opp_set_opp()
doesn't have any side effects.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
Dmitry,

This is based over the patches sent here:

https://lore.kernel.org/lkml/6c2160ff30a8f421563793020264cf9f533f293c.1611738228.git.viresh.kumar@linaro.org/

This should fix the problem you mentioned earlier. Will push this for
linux-next unless you have any issues with it.

 drivers/devfreq/tegra30-devfreq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
index 117cad7968ab..31f7dec5990b 100644
--- a/drivers/devfreq/tegra30-devfreq.c
+++ b/drivers/devfreq/tegra30-devfreq.c
@@ -647,7 +647,7 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq,
 		return PTR_ERR(opp);
 	}
 
-	ret = dev_pm_opp_set_bw(dev, opp);
+	ret = dev_pm_opp_set_opp(dev, opp);
 	dev_pm_opp_put(opp);
 
 	return ret;
@@ -849,7 +849,7 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	err = dev_pm_opp_of_add_table(&pdev->dev);
+	err = dev_pm_opp_of_add_table_noclk(&pdev->dev);
 	if (err) {
 		dev_err(&pdev->dev, "Failed to add OPP table: %d\n", err);
 		goto put_hw;
-- 
2.25.0.rc1.19.g042ed3e048af


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH V2 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-27  9:10   ` [PATCH V2 " Viresh Kumar
@ 2021-01-27 10:02     ` Viresh Kumar
  2021-01-27 15:58       ` Dmitry Osipenko
  2021-02-01  0:21     ` Chanwoo Choi
  2021-02-01 19:57     ` Dmitry Osipenko
  2 siblings, 1 reply; 17+ messages in thread
From: Viresh Kumar @ 2021-01-27 10:02 UTC (permalink / raw)
  To: Dmitry Osipenko, MyungJoo Ham, Kyungmin Park, Chanwoo Choi,
	Thierry Reding, Jonathan Hunter
  Cc: linux-pm, Vincent Guittot, Rafael Wysocki, Stephen Boyd,
	Nishanth Menon, linux-tegra, linux-kernel

On 27-01-21, 14:40, Viresh Kumar wrote:
> dev_pm_opp_set_bw() is getting removed and dev_pm_opp_set_opp() should
> be used instead. Migrate to the new API.
> 
> We don't want the OPP core to manage the clk for this driver, migrate to
> dev_pm_opp_of_add_table_noclk() to make sure dev_pm_opp_set_opp()
> doesn't have any side effects.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> Dmitry,
> 
> This is based over the patches sent here:
> 
> https://lore.kernel.org/lkml/6c2160ff30a8f421563793020264cf9f533f293c.1611738228.git.viresh.kumar@linaro.org/
> 
> This should fix the problem you mentioned earlier. Will push this for
> linux-next unless you have any issues with it.
> 
>  drivers/devfreq/tegra30-devfreq.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
> index 117cad7968ab..31f7dec5990b 100644
> --- a/drivers/devfreq/tegra30-devfreq.c
> +++ b/drivers/devfreq/tegra30-devfreq.c
> @@ -647,7 +647,7 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq,
>  		return PTR_ERR(opp);
>  	}
>  
> -	ret = dev_pm_opp_set_bw(dev, opp);
> +	ret = dev_pm_opp_set_opp(dev, opp);
>  	dev_pm_opp_put(opp);
>  
>  	return ret;
> @@ -849,7 +849,7 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
>  		return err;
>  	}
>  
> -	err = dev_pm_opp_of_add_table(&pdev->dev);
> +	err = dev_pm_opp_of_add_table_noclk(&pdev->dev);

Plus this, somehow was left uncommited in my tree :(

diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
index 31f7dec5990b..ce83f883ca65 100644
--- a/drivers/devfreq/tegra30-devfreq.c
+++ b/drivers/devfreq/tegra30-devfreq.c
@@ -849,7 +849,7 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
                return err;
        }
 
-       err = dev_pm_opp_of_add_table_noclk(&pdev->dev);
+       err = dev_pm_opp_of_add_table_noclk(&pdev->dev, 0);
        if (err) {
                dev_err(&pdev->dev, "Failed to add OPP table: %d\n", err);
                goto put_hw;

-- 
viresh

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH V2 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-27 10:02     ` Viresh Kumar
@ 2021-01-27 15:58       ` Dmitry Osipenko
  2021-01-28  7:01         ` Viresh Kumar
  0 siblings, 1 reply; 17+ messages in thread
From: Dmitry Osipenko @ 2021-01-27 15:58 UTC (permalink / raw)
  To: Viresh Kumar, MyungJoo Ham, Kyungmin Park, Chanwoo Choi,
	Thierry Reding, Jonathan Hunter
  Cc: linux-pm, Vincent Guittot, Rafael Wysocki, Stephen Boyd,
	Nishanth Menon, linux-tegra, linux-kernel

27.01.2021 13:02, Viresh Kumar пишет:
> On 27-01-21, 14:40, Viresh Kumar wrote:
>> dev_pm_opp_set_bw() is getting removed and dev_pm_opp_set_opp() should
>> be used instead. Migrate to the new API.
>>
>> We don't want the OPP core to manage the clk for this driver, migrate to
>> dev_pm_opp_of_add_table_noclk() to make sure dev_pm_opp_set_opp()
>> doesn't have any side effects.
>>
>> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
>> ---
>> Dmitry,
>>
>> This is based over the patches sent here:
>>
>> https://lore.kernel.org/lkml/6c2160ff30a8f421563793020264cf9f533f293c.1611738228.git.viresh.kumar@linaro.org/
>>
>> This should fix the problem you mentioned earlier. Will push this for
>> linux-next unless you have any issues with it.
>>
>>  drivers/devfreq/tegra30-devfreq.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
>> index 117cad7968ab..31f7dec5990b 100644
>> --- a/drivers/devfreq/tegra30-devfreq.c
>> +++ b/drivers/devfreq/tegra30-devfreq.c
>> @@ -647,7 +647,7 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq,
>>  		return PTR_ERR(opp);
>>  	}
>>  
>> -	ret = dev_pm_opp_set_bw(dev, opp);
>> +	ret = dev_pm_opp_set_opp(dev, opp);
>>  	dev_pm_opp_put(opp);
>>  
>>  	return ret;
>> @@ -849,7 +849,7 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
>>  		return err;
>>  	}
>>  
>> -	err = dev_pm_opp_of_add_table(&pdev->dev);
>> +	err = dev_pm_opp_of_add_table_noclk(&pdev->dev);
> 
> Plus this, somehow was left uncommited in my tree :(
> 
> diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
> index 31f7dec5990b..ce83f883ca65 100644
> --- a/drivers/devfreq/tegra30-devfreq.c
> +++ b/drivers/devfreq/tegra30-devfreq.c
> @@ -849,7 +849,7 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
>                 return err;
>         }
>  
> -       err = dev_pm_opp_of_add_table_noclk(&pdev->dev);
> +       err = dev_pm_opp_of_add_table_noclk(&pdev->dev, 0);
>         if (err) {
>                 dev_err(&pdev->dev, "Failed to add OPP table: %d\n", err);
>                 goto put_hw;
> 

Sadly this doesn't work because we missed that clk is assigned to
opp_table when OPP table is allocated and not when it's added to device.

Hence we're now set back to the dev_pm_opp_clear_clk() variant.

What about to add a new OPP API which will allow OPP users to configure
behaviour that user wants from OPP core in a generic way, something like
this:

struct opp_config {
	bool no_clk;
	...
};

devm_pm_opp_set_config(dev, struct opp_config);
dev_pm_opp_set_config(dev, struct opp_config);
dev_pm_opp_unset_config(dev);

Or maybe even rename it dev_pm_opp_allocate_table(dev, struct
opp_config), which will allow users to directly allocate OPP table
instead of relying on the implicit allocations. Then there won't be a
need for drivers to use a dummy devm_pm_opp_set_clkname(dev, NULL) just
to allocate the table usable for dev_pm_opp_set_rate().

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH V2 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-27 15:58       ` Dmitry Osipenko
@ 2021-01-28  7:01         ` Viresh Kumar
  0 siblings, 0 replies; 17+ messages in thread
From: Viresh Kumar @ 2021-01-28  7:01 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: MyungJoo Ham, Kyungmin Park, Chanwoo Choi, Thierry Reding,
	Jonathan Hunter, linux-pm, Vincent Guittot, Rafael Wysocki,
	Stephen Boyd, Nishanth Menon, linux-tegra, linux-kernel

On 27-01-21, 18:58, Dmitry Osipenko wrote:
> Sadly this doesn't work because we missed that clk is assigned to
> opp_table when OPP table is allocated and not when it's added to device.

Ahh, I missed that.

I have bumped up the other patchset to V2, that should work fine with
this patch for tegra30 (this shouldn't require any update).

Everything is pushed in opp/linux-next, fetch and try it. Thanks.

-- 
viresh

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH V2 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-27  9:10   ` [PATCH V2 " Viresh Kumar
  2021-01-27 10:02     ` Viresh Kumar
@ 2021-02-01  0:21     ` Chanwoo Choi
  2021-02-01 19:57     ` Dmitry Osipenko
  2 siblings, 0 replies; 17+ messages in thread
From: Chanwoo Choi @ 2021-02-01  0:21 UTC (permalink / raw)
  To: Viresh Kumar, Dmitry Osipenko, MyungJoo Ham, Kyungmin Park,
	Thierry Reding, Jonathan Hunter
  Cc: linux-pm, Vincent Guittot, Rafael Wysocki, Stephen Boyd,
	Nishanth Menon, linux-tegra, linux-kernel

On 1/27/21 6:10 PM, Viresh Kumar wrote:
> dev_pm_opp_set_bw() is getting removed and dev_pm_opp_set_opp() should
> be used instead. Migrate to the new API.
> 
> We don't want the OPP core to manage the clk for this driver, migrate to
> dev_pm_opp_of_add_table_noclk() to make sure dev_pm_opp_set_opp()
> doesn't have any side effects.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> Dmitry,
> 
> This is based over the patches sent here:
> 
> https://protect2.fireeye.com/v1/url?k=72d88562-2d43bc78-72d90e2d-000babff24ad-e4764030101eaedc&q=1&e=a25b5db7-346b-47b2-9c0a-3945e579f389&u=https%3A%2F%2Flore.kernel.org%2Flkml%2F6c2160ff30a8f421563793020264cf9f533f293c.1611738228.git.viresh.kumar%40linaro.org%2F
> 
> This should fix the problem you mentioned earlier. Will push this for
> linux-next unless you have any issues with it.
> 
>  drivers/devfreq/tegra30-devfreq.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
> index 117cad7968ab..31f7dec5990b 100644
> --- a/drivers/devfreq/tegra30-devfreq.c
> +++ b/drivers/devfreq/tegra30-devfreq.c
> @@ -647,7 +647,7 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq,
>  		return PTR_ERR(opp);
>  	}
>  
> -	ret = dev_pm_opp_set_bw(dev, opp);
> +	ret = dev_pm_opp_set_opp(dev, opp);
>  	dev_pm_opp_put(opp);
>  
>  	return ret;
> @@ -849,7 +849,7 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
>  		return err;
>  	}
>  
> -	err = dev_pm_opp_of_add_table(&pdev->dev);
> +	err = dev_pm_opp_of_add_table_noclk(&pdev->dev);
>  	if (err) {
>  		dev_err(&pdev->dev, "Failed to add OPP table: %d\n", err);
>  		goto put_hw;
> 

Acked-by: Chanwoo Choi <cw00.choi@samsung.com>

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH V2 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp()
  2021-01-27  9:10   ` [PATCH V2 " Viresh Kumar
  2021-01-27 10:02     ` Viresh Kumar
  2021-02-01  0:21     ` Chanwoo Choi
@ 2021-02-01 19:57     ` Dmitry Osipenko
  2 siblings, 0 replies; 17+ messages in thread
From: Dmitry Osipenko @ 2021-02-01 19:57 UTC (permalink / raw)
  To: Viresh Kumar, MyungJoo Ham, Kyungmin Park, Chanwoo Choi,
	Thierry Reding, Jonathan Hunter
  Cc: linux-pm, Vincent Guittot, Rafael Wysocki, Stephen Boyd,
	Nishanth Menon, linux-tegra, linux-kernel

27.01.2021 12:10, Viresh Kumar пишет:
> dev_pm_opp_set_bw() is getting removed and dev_pm_opp_set_opp() should
> be used instead. Migrate to the new API.
> 
> We don't want the OPP core to manage the clk for this driver, migrate to
> dev_pm_opp_of_add_table_noclk() to make sure dev_pm_opp_set_opp()
> doesn't have any side effects.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> Dmitry,
> 
> This is based over the patches sent here:
> 
> https://lore.kernel.org/lkml/6c2160ff30a8f421563793020264cf9f533f293c.1611738228.git.viresh.kumar@linaro.org/
> 
> This should fix the problem you mentioned earlier. Will push this for
> linux-next unless you have any issues with it.
> 
>  drivers/devfreq/tegra30-devfreq.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/devfreq/tegra30-devfreq.c b/drivers/devfreq/tegra30-devfreq.c
> index 117cad7968ab..31f7dec5990b 100644
> --- a/drivers/devfreq/tegra30-devfreq.c
> +++ b/drivers/devfreq/tegra30-devfreq.c
> @@ -647,7 +647,7 @@ static int tegra_devfreq_target(struct device *dev, unsigned long *freq,
>  		return PTR_ERR(opp);
>  	}
>  
> -	ret = dev_pm_opp_set_bw(dev, opp);
> +	ret = dev_pm_opp_set_opp(dev, opp);
>  	dev_pm_opp_put(opp);
>  
>  	return ret;
> @@ -849,7 +849,7 @@ static int tegra_devfreq_probe(struct platform_device *pdev)
>  		return err;
>  	}
>  
> -	err = dev_pm_opp_of_add_table(&pdev->dev);
> +	err = dev_pm_opp_of_add_table_noclk(&pdev->dev);
>  	if (err) {
>  		dev_err(&pdev->dev, "Failed to add OPP table: %d\n", err);
>  		goto put_hw;
> 

Tested-by: Dmitry Osipenko <digetx@gmail.com>

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-02-01 19:59 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21 11:17 [PATCH 00/13] opp: Implement dev_pm_opp_set_opp() Viresh Kumar
2021-01-21 11:17 ` [PATCH 11/13] devfreq: tegra30: Migrate to dev_pm_opp_set_opp() Viresh Kumar
2021-01-21 21:36   ` Dmitry Osipenko
2021-01-22  6:26     ` Viresh Kumar
2021-01-22 15:28       ` Dmitry Osipenko
2021-01-25  3:14         ` Viresh Kumar
2021-01-25 16:00           ` Dmitry Osipenko
2021-01-27  9:10   ` [PATCH V2 " Viresh Kumar
2021-01-27 10:02     ` Viresh Kumar
2021-01-27 15:58       ` Dmitry Osipenko
2021-01-28  7:01         ` Viresh Kumar
2021-02-01  0:21     ` Chanwoo Choi
2021-02-01 19:57     ` Dmitry Osipenko
     [not found] ` <1585f6c21ea8aee64fe4da0bf72b36ea4d74a779.1611227342.git.viresh.kumar@linaro.org>
2021-01-21 20:26   ` [PATCH 07/13] opp: Allow _generic_set_opp_clk_only() to work for non-freq devices Dmitry Osipenko
2021-01-22  4:35     ` Viresh Kumar
2021-01-25 21:09       ` Dmitry Osipenko
2021-01-27  6:58         ` Viresh Kumar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).