Skip to contentSkip to conversation

cpufreq: enhance the sequency of governor change

PATCH In review Huang Rui 2 participants 4 messages Jul 21, 2021 – Aug 5, 2021 CPU frequency scaling framework

lore
Share & tools
lore

Huang Rui

author
#0 lore raw

PATCH 1/1 cpufreq: enhance the sequency of governor change

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.

---
 drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/cpufreq/cpufreq.c +15 -8
index 802abc925b2a..4f7005ddb70c 100644
@@ -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))
Signature · 1 line
2.25.1
author
#1 lore raw

Ping~

Quoted 51 lines · Ray

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.

---
 drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/cpufreq/cpufreq.c +15 -8
index 802abc925b2a..4f7005ddb70c 100644
@@ -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))
Signature · 1 line
2.25.1
#2 lore raw
Quoted 2 lines · Huang Rui

Ping~

I prefer the existing code, sorry.

Quoted 50 lines · Ray
Quoted 49 lines

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.

---
 drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/cpufreq/cpufreq.c +15 -9
index 802abc925b2a..4f7005ddb70c 100644
@@ -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))
--
author
#3 lore raw
Quoted 5 lines · Rafael J. Wysocki
Quoted 2 lines · Huang Rui

Ping~

I prefer the existing code, sorry.

It's ok, thanks anyway for the reply.

Thanks,
Ray

Quoted 51 lines
Quoted 51 lines · Ray
Quoted 49 lines

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.

---
 drivers/cpufreq/cpufreq.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/cpufreq/cpufreq.c +15 -9
index 802abc925b2a..4f7005ddb70c 100644
@@ -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))
--