Thread (4 messages) 4 messages, 2 authors, 2021-08-05

Re: [PATCH] cpufreq: enhance the sequency of governor change

From: Huang Rui <ray.huang@amd.com>
Date: 2021-08-03 00:13:10
Also in: lkml

Ping~

On Wed, Jul 21, 2021 at 06:16:58PM +0800, Huang, Ray wrote:
quoted hunk ↗ jump to hunk
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help