2021-03-23 07:35:51

by Aisheng Dong

[permalink] [raw]
Subject: [PATCH V2 RESEND 3/4] PM / devfreq: bail out early if no freq changes in devfreq_set_target

It's unnecessary to set the same freq again and run notifier calls.

Signed-off-by: Dong Aisheng <[email protected]>
---
drivers/devfreq/devfreq.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 85927bd7ee76..a6ee91dd17bd 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -352,13 +352,16 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
{
struct devfreq_freqs freqs;
unsigned long cur_freq;
- int err = 0;
+ int err;

if (devfreq->profile->get_cur_freq)
devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq);
else
cur_freq = devfreq->previous_freq;

+ if (new_freq == cur_freq)
+ return 0;
+
freqs.old = cur_freq;
freqs.new = new_freq;
devfreq_notify_transition(devfreq, &freqs, DEVFREQ_PRECHANGE);
@@ -375,7 +378,7 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
* and DEVFREQ_POSTCHANGE because for showing the correct frequency
* change order of between devfreq device and passive devfreq device.
*/
- if (trace_devfreq_frequency_enabled() && new_freq != cur_freq)
+ if (trace_devfreq_frequency_enabled())
trace_devfreq_frequency(devfreq, new_freq, cur_freq);

freqs.new = new_freq;
@@ -390,7 +393,7 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
if (devfreq->suspend_freq)
devfreq->resume_freq = new_freq;

- return err;
+ return 0;
}

/**
--
2.25.1


2021-03-23 15:05:17

by Chanwoo Choi

[permalink] [raw]
Subject: Re: [PATCH V2 RESEND 3/4] PM / devfreq: bail out early if no freq changes in devfreq_set_target

On 21. 3. 23. 오후 4:20, Dong Aisheng wrote:
> It's unnecessary to set the same freq again and run notifier calls.
>
> Signed-off-by: Dong Aisheng <[email protected]>
> ---
> drivers/devfreq/devfreq.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> index 85927bd7ee76..a6ee91dd17bd 100644
> --- a/drivers/devfreq/devfreq.c
> +++ b/drivers/devfreq/devfreq.c
> @@ -352,13 +352,16 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
> {
> struct devfreq_freqs freqs;
> unsigned long cur_freq;
> - int err = 0;
> + int err;
>
> if (devfreq->profile->get_cur_freq)
> devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq);
> else
> cur_freq = devfreq->previous_freq;
>
> + if (new_freq == cur_freq)
> + return 0;

cur_freq is one of the OPP frequencies. But, new_freq is calculated from
governor algorithm. It means that new_freq is not one of the
frequencies. Actually, it is not efficient.

After devfreq->profile->target() which almost uses
devfreq_recommended_opp(), new_freq is one of OPP frequencies.

> +
> freqs.old = cur_freq;
> freqs.new = new_freq;
> devfreq_notify_transition(devfreq, &freqs, DEVFREQ_PRECHANGE);
> @@ -375,7 +378,7 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
> * and DEVFREQ_POSTCHANGE because for showing the correct frequency
> * change order of between devfreq device and passive devfreq device.
> */
> - if (trace_devfreq_frequency_enabled() && new_freq != cur_freq)
> + if (trace_devfreq_frequency_enabled())
> trace_devfreq_frequency(devfreq, new_freq, cur_freq);
>
> freqs.new = new_freq;
> @@ -390,7 +393,7 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
> if (devfreq->suspend_freq)
> devfreq->resume_freq = new_freq;
>
> - return err;
> + return 0;
> }
>
> /**
>


--
Best Regards,
Samsung Electronics
Chanwoo Choi

2021-05-19 19:18:53

by Dong Aisheng

[permalink] [raw]
Subject: Re: [PATCH V2 RESEND 3/4] PM / devfreq: bail out early if no freq changes in devfreq_set_target

On Tue, Mar 23, 2021 at 11:01 PM Chanwoo Choi <[email protected]> wrote:
>
> On 21. 3. 23. 오후 4:20, Dong Aisheng wrote:
> > It's unnecessary to set the same freq again and run notifier calls.
> >
> > Signed-off-by: Dong Aisheng <[email protected]>
> > ---
> > drivers/devfreq/devfreq.c | 9 ++++++---
> > 1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
> > index 85927bd7ee76..a6ee91dd17bd 100644
> > --- a/drivers/devfreq/devfreq.c
> > +++ b/drivers/devfreq/devfreq.c
> > @@ -352,13 +352,16 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
> > {
> > struct devfreq_freqs freqs;
> > unsigned long cur_freq;
> > - int err = 0;
> > + int err;
> >
> > if (devfreq->profile->get_cur_freq)
> > devfreq->profile->get_cur_freq(devfreq->dev.parent, &cur_freq);
> > else
> > cur_freq = devfreq->previous_freq;
> >
> > + if (new_freq == cur_freq)
> > + return 0;
>
> cur_freq is one of the OPP frequencies. But, new_freq is calculated from
> governor algorithm. It means that new_freq is not one of the
> frequencies. Actually, it is not efficient.
>
> After devfreq->profile->target() which almost uses
> devfreq_recommended_opp(), new_freq is one of OPP frequencies.
>

Yes, but i feel at least when the desired new_freq is equal to cur_freq
which is the last successfully set rate, it is sufficient to bail out early as
it's meaningless to re-set the same rate as the last one and notify the
an unchanged rate transition in HW.
Does that make sense?

Regards
Aisheng

> > +
> > freqs.old = cur_freq;
> > freqs.new = new_freq;
> > devfreq_notify_transition(devfreq, &freqs, DEVFREQ_PRECHANGE);
> > @@ -375,7 +378,7 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
> > * and DEVFREQ_POSTCHANGE because for showing the correct frequency
> > * change order of between devfreq device and passive devfreq device.
> > */
> > - if (trace_devfreq_frequency_enabled() && new_freq != cur_freq)
> > + if (trace_devfreq_frequency_enabled())
> > trace_devfreq_frequency(devfreq, new_freq, cur_freq);
> >
> > freqs.new = new_freq;
> > @@ -390,7 +393,7 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq,
> > if (devfreq->suspend_freq)
> > devfreq->resume_freq = new_freq;
> >
> > - return err;
> > + return 0;
> > }
> >
> > /**
> >
>
>
> --
> Best Regards,
> Samsung Electronics
> Chanwoo Choi