linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpufreq: enhance the sequency of governor change
@ 2021-07-21 10:16 Huang Rui
  2021-08-03  0:13 ` Huang Rui
  0 siblings, 1 reply; 4+ messages in thread
From: Huang Rui @ 2021-07-21 10:16 UTC (permalink / raw)
  To: Rafael J . Wysocki, linux-pm, linux-kernel; +Cc: Huang Rui

Keep the "success" case of governor change in the mainline of the
function not in "if" case. And using restart_old_gov flag to indicate
the fallback case to old governor. This is more readable and no function
change.

Signed-off-by: Huang Rui <ray.huang@amd.com>
---
 drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 802abc925b2a..4f7005ddb70c 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2545,18 +2545,25 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
 	/* start new governor */
 	policy->governor = new_gov;
 	ret = cpufreq_init_governor(policy);
-	if (!ret) {
-		ret = cpufreq_start_governor(policy);
-		if (!ret) {
-			pr_debug("governor change\n");
-			sched_cpufreq_governor_change(policy, old_gov);
-			return 0;
-		}
+	if (ret)
+		goto restart_old_gov;
+
+	ret = cpufreq_start_governor(policy);
+	if (ret) {
 		cpufreq_exit_governor(policy);
+		goto restart_old_gov;
 	}
 
+	pr_debug("governor change\n");
+
+	sched_cpufreq_governor_change(policy, old_gov);
+
+	return 0;
+
+restart_old_gov:
 	/* new governor failed, so re-start old one */
-	pr_debug("starting governor %s failed\n", policy->governor->name);
+	pr_debug("starting governor %s failed\n",
+		 policy->governor->name);
 	if (old_gov) {
 		policy->governor = old_gov;
 		if (cpufreq_init_governor(policy))
-- 
2.25.1


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

* Re: [PATCH] cpufreq: enhance the sequency of governor change
  2021-07-21 10:16 [PATCH] cpufreq: enhance the sequency of governor change Huang Rui
@ 2021-08-03  0:13 ` Huang Rui
  2021-08-04 17:00   ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Huang Rui @ 2021-08-03  0:13 UTC (permalink / raw)
  To: Rafael J . Wysocki, linux-pm, linux-kernel

Ping~

On Wed, Jul 21, 2021 at 06:16:58PM +0800, Huang, Ray wrote:
> Keep the "success" case of governor change in the mainline of the
> function not in "if" case. And using restart_old_gov flag to indicate
> the fallback case to old governor. This is more readable and no function
> change.
> 
> Signed-off-by: Huang Rui <ray.huang@amd.com>
> ---
>  drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 802abc925b2a..4f7005ddb70c 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2545,18 +2545,25 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
>  	/* start new governor */
>  	policy->governor = new_gov;
>  	ret = cpufreq_init_governor(policy);
> -	if (!ret) {
> -		ret = cpufreq_start_governor(policy);
> -		if (!ret) {
> -			pr_debug("governor change\n");
> -			sched_cpufreq_governor_change(policy, old_gov);
> -			return 0;
> -		}
> +	if (ret)
> +		goto restart_old_gov;
> +
> +	ret = cpufreq_start_governor(policy);
> +	if (ret) {
>  		cpufreq_exit_governor(policy);
> +		goto restart_old_gov;
>  	}
>  
> +	pr_debug("governor change\n");
> +
> +	sched_cpufreq_governor_change(policy, old_gov);
> +
> +	return 0;
> +
> +restart_old_gov:
>  	/* new governor failed, so re-start old one */
> -	pr_debug("starting governor %s failed\n", policy->governor->name);
> +	pr_debug("starting governor %s failed\n",
> +		 policy->governor->name);
>  	if (old_gov) {
>  		policy->governor = old_gov;
>  		if (cpufreq_init_governor(policy))
> -- 
> 2.25.1
> 

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

* Re: [PATCH] cpufreq: enhance the sequency of governor change
  2021-08-03  0:13 ` Huang Rui
@ 2021-08-04 17:00   ` Rafael J. Wysocki
  2021-08-05  6:39     ` Huang Rui
  0 siblings, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2021-08-04 17:00 UTC (permalink / raw)
  To: Huang Rui; +Cc: Rafael J . Wysocki, linux-pm, linux-kernel

On Tue, Aug 3, 2021 at 2:13 AM Huang Rui <ray.huang@amd.com> wrote:
>
> Ping~

I prefer the existing code, sorry.

> On Wed, Jul 21, 2021 at 06:16:58PM +0800, Huang, Ray wrote:
> > Keep the "success" case of governor change in the mainline of the
> > function not in "if" case. And using restart_old_gov flag to indicate
> > the fallback case to old governor. This is more readable and no function
> > change.
> >
> > Signed-off-by: Huang Rui <ray.huang@amd.com>
> > ---
> >  drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
> >  1 file changed, 15 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> > index 802abc925b2a..4f7005ddb70c 100644
> > --- a/drivers/cpufreq/cpufreq.c
> > +++ b/drivers/cpufreq/cpufreq.c
> > @@ -2545,18 +2545,25 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
> >       /* start new governor */
> >       policy->governor = new_gov;
> >       ret = cpufreq_init_governor(policy);
> > -     if (!ret) {
> > -             ret = cpufreq_start_governor(policy);
> > -             if (!ret) {
> > -                     pr_debug("governor change\n");
> > -                     sched_cpufreq_governor_change(policy, old_gov);
> > -                     return 0;
> > -             }
> > +     if (ret)
> > +             goto restart_old_gov;
> > +
> > +     ret = cpufreq_start_governor(policy);
> > +     if (ret) {
> >               cpufreq_exit_governor(policy);
> > +             goto restart_old_gov;
> >       }
> >
> > +     pr_debug("governor change\n");
> > +
> > +     sched_cpufreq_governor_change(policy, old_gov);
> > +
> > +     return 0;
> > +
> > +restart_old_gov:
> >       /* new governor failed, so re-start old one */
> > -     pr_debug("starting governor %s failed\n", policy->governor->name);
> > +     pr_debug("starting governor %s failed\n",
> > +              policy->governor->name);
> >       if (old_gov) {
> >               policy->governor = old_gov;
> >               if (cpufreq_init_governor(policy))
> > --

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

* Re: [PATCH] cpufreq: enhance the sequency of governor change
  2021-08-04 17:00   ` Rafael J. Wysocki
@ 2021-08-05  6:39     ` Huang Rui
  0 siblings, 0 replies; 4+ messages in thread
From: Huang Rui @ 2021-08-05  6:39 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Rafael J . Wysocki, linux-pm, linux-kernel

On Thu, Aug 05, 2021 at 01:00:23AM +0800, Rafael J. Wysocki wrote:
> On Tue, Aug 3, 2021 at 2:13 AM Huang Rui <ray.huang@amd.com> wrote:
> >
> > Ping~
> 
> I prefer the existing code, sorry.

It's ok, thanks anyway for the reply.

Thanks,
Ray

> 
> > On Wed, Jul 21, 2021 at 06:16:58PM +0800, Huang, Ray wrote:
> > > Keep the "success" case of governor change in the mainline of the
> > > function not in "if" case. And using restart_old_gov flag to indicate
> > > the fallback case to old governor. This is more readable and no function
> > > change.
> > >
> > > Signed-off-by: Huang Rui <ray.huang@amd.com>
> > > ---
> > >  drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
> > >  1 file changed, 15 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> > > index 802abc925b2a..4f7005ddb70c 100644
> > > --- a/drivers/cpufreq/cpufreq.c
> > > +++ b/drivers/cpufreq/cpufreq.c
> > > @@ -2545,18 +2545,25 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
> > >       /* start new governor */
> > >       policy->governor = new_gov;
> > >       ret = cpufreq_init_governor(policy);
> > > -     if (!ret) {
> > > -             ret = cpufreq_start_governor(policy);
> > > -             if (!ret) {
> > > -                     pr_debug("governor change\n");
> > > -                     sched_cpufreq_governor_change(policy, old_gov);
> > > -                     return 0;
> > > -             }
> > > +     if (ret)
> > > +             goto restart_old_gov;
> > > +
> > > +     ret = cpufreq_start_governor(policy);
> > > +     if (ret) {
> > >               cpufreq_exit_governor(policy);
> > > +             goto restart_old_gov;
> > >       }
> > >
> > > +     pr_debug("governor change\n");
> > > +
> > > +     sched_cpufreq_governor_change(policy, old_gov);
> > > +
> > > +     return 0;
> > > +
> > > +restart_old_gov:
> > >       /* new governor failed, so re-start old one */
> > > -     pr_debug("starting governor %s failed\n", policy->governor->name);
> > > +     pr_debug("starting governor %s failed\n",
> > > +              policy->governor->name);
> > >       if (old_gov) {
> > >               policy->governor = old_gov;
> > >               if (cpufreq_init_governor(policy))
> > > --

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

end of thread, other threads:[~2021-08-05  6:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21 10:16 [PATCH] cpufreq: enhance the sequency of governor change Huang Rui
2021-08-03  0:13 ` Huang Rui
2021-08-04 17:00   ` Rafael J. Wysocki
2021-08-05  6:39     ` Huang Rui

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).