public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Huang Rui <ray.huang@amd.com>
To: "Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	<linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: Huang Rui <ray.huang@amd.com>
Subject: [PATCH] cpufreq: enhance the sequency of governor change
Date: Wed, 21 Jul 2021 18:16:58 +0800	[thread overview]
Message-ID: <20210721101658.9235-1-ray.huang@amd.com> (raw)

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


             reply	other threads:[~2021-07-21 10:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-21 10:16 Huang Rui [this message]
2021-08-03  0:13 ` [PATCH] cpufreq: enhance the sequency of governor change Huang Rui
2021-08-04 17:00   ` Rafael J. Wysocki
2021-08-05  6:39     ` Huang Rui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210721101658.9235-1-ray.huang@amd.com \
    --to=ray.huang@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox