Skip to contentSkip to conversation

cpufreq: Move cancelling of policy update work just after removing notifiers

PATCH In review Sudeep Holla 3 participants 5 messages Oct 21, 2019 – Oct 22, 2019 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: Move cancelling of policy update work just after removing notifiers

Commit 099967699ad9 ("cpufreq: Cancel policy update work scheduled before freeing") added cancel_work_sync(policy->update) after the frequency QoS were removed. We can cancel the work just after taking the last CPU in the policy offline and unregistering the notifiers as policy->update cannot be scheduled from anywhere at this point.

However, due to other bugs, doing so still triggered the race between freeing of policy and scheduled policy update work. Now that all those issues are resolved, we can move this cancelling of any scheduled policy update work just after removing min/max notifiers.

---
 drivers/cpufreq/cpufreq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Hi Rafael,

Based on Viresh's suggestion, I am posting a patch to move this cancel_work_sync earlier though it's not a must have change. I will leave it up to your preference.

Regards,
Sudeep

drivers/cpufreq/cpufreq.c +3 -2
index 829a3764df1b..48a224a6b178 100644
@@ -1268,6 +1268,9 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
 	freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
 				 &policy->nb_min);
 
+	/* Cancel any pending policy->update work before freeing the policy. */
+	cancel_work_sync(&policy->update);
+
 	if (policy->max_freq_req) {
 		/*
 		 * CPUFREQ_CREATE_POLICY notification is sent only after
@@ -1279,8 +1282,6 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
 	}
 
 	freq_qos_remove_request(policy->min_freq_req);
-	/* Cancel any pending policy->update work before freeing the policy. */
-	cancel_work_sync(&policy->update);
 	kfree(policy->min_freq_req);
 
 	cpufreq_policy_put_kobj(policy);
Signature · 1 line
2.17.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Sudeep Holla

Commit 099967699ad9 ("cpufreq: Cancel policy update work scheduled before freeing") added cancel_work_sync(policy->update) after the frequency QoS were removed. We can cancel the work just after taking the last CPU in the policy offline and unregistering the notifiers as policy->update cannot be scheduled from anywhere at this point.

However, due to other bugs, doing so still triggered the race between freeing of policy and scheduled policy update work. Now that all those issues are resolved, we can move this cancelling of any scheduled policy update work just after removing min/max notifiers.

Quoted 8 lines
---
 drivers/cpufreq/cpufreq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Hi Rafael,

Based on Viresh's suggestion, I am posting a patch to move this cancel_work_sync earlier though it's not a must have change.

For me it is :)

Quoted 20 lines

I will leave it up to your preference.

Regards,
Sudeep

drivers/cpufreq/cpufreq.c +3 -0
index 829a3764df1b..48a224a6b178 100644
@@ -1268,6 +1268,9 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
 	freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
 				 &policy->nb_min);
 
+	/* Cancel any pending policy->update work before freeing the policy. */
+	cancel_work_sync(&policy->update);
+
 	if (policy->max_freq_req) {
 		/*
 		 * CPUFREQ_CREATE_POLICY notification is sent only after

drivers/cpufreq/cpufreq.c static void cpufreq_policy_free(struct cpufreq_policy *policy) · line 1287

Quoted 8 lines
drivers/cpufreq/cpufreq.c +0 -2
@@ -1279,8 +1282,6 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
 	}
 
 	freq_qos_remove_request(policy->min_freq_req);
-	/* Cancel any pending policy->update work before freeing the policy. */
-	cancel_work_sync(&policy->update);
 	kfree(policy->min_freq_req);
 
 	cpufreq_policy_put_kobj(policy);

Thanks for doing this.

Signature · 1 line
viresh
#2 lore raw
Quoted 52 lines · Viresh Kumar
Quoted 12 lines · Sudeep Holla

Commit 099967699ad9 ("cpufreq: Cancel policy update work scheduled before freeing") added cancel_work_sync(policy->update) after the frequency QoS were removed. We can cancel the work just after taking the last CPU in the policy offline and unregistering the notifiers as policy->update cannot be scheduled from anywhere at this point.

However, due to other bugs, doing so still triggered the race between freeing of policy and scheduled policy update work. Now that all those issues are resolved, we can move this cancelling of any scheduled policy update work just after removing min/max notifiers.

Quoted 8 lines
---
 drivers/cpufreq/cpufreq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Hi Rafael,

Based on Viresh's suggestion, I am posting a patch to move this cancel_work_sync earlier though it's not a must have change.

For me it is :)

Quoted 27 lines

I will leave it up to your preference.

Regards,
Sudeep

drivers/cpufreq/cpufreq.c +3 -2
index 829a3764df1b..48a224a6b178 100644
@@ -1268,6 +1268,9 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
      freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
                               &policy->nb_min);
 
+     /* Cancel any pending policy->update work before freeing the policy. */
+     cancel_work_sync(&policy->update);
+
      if (policy->max_freq_req) {
              /*
               * CPUFREQ_CREATE_POLICY notification is sent only after
@@ -1279,8 +1282,6 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
      }
 
      freq_qos_remove_request(policy->min_freq_req);
-     /* Cancel any pending policy->update work before freeing the policy. */
-     cancel_work_sync(&policy->update);
      kfree(policy->min_freq_req);
 
Quoted 5 lines

drivers/cpufreq/cpufreq.c static void cpufreq_policy_free(struct cpufreq_policy *policy) · line 1287

Quoted 1 line
drivers/cpufreq/cpufreq.c +0 -0
      cpufreq_policy_put_kobj(policy);

Thanks for doing this.

Folded into the previous patch and applied.

Please double check the result in the current linux-next branch in my tree.

maintainer
#3 lore raw
Quoted 57 lines · Rafael J. Wysocki
Quoted 56 lines · Viresh Kumar
Quoted 12 lines · Sudeep Holla

Commit 099967699ad9 ("cpufreq: Cancel policy update work scheduled before freeing") added cancel_work_sync(policy->update) after the frequency QoS were removed. We can cancel the work just after taking the last CPU in the policy offline and unregistering the notifiers as policy->update cannot be scheduled from anywhere at this point.

However, due to other bugs, doing so still triggered the race between freeing of policy and scheduled policy update work. Now that all those issues are resolved, we can move this cancelling of any scheduled policy update work just after removing min/max notifiers.

Quoted 8 lines
---
 drivers/cpufreq/cpufreq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Hi Rafael,

Based on Viresh's suggestion, I am posting a patch to move this cancel_work_sync earlier though it's not a must have change.

For me it is :)

Quoted 20 lines

I will leave it up to your preference.

Regards,
Sudeep

drivers/cpufreq/cpufreq.c +3 -0
index 829a3764df1b..48a224a6b178 100644
@@ -1268,6 +1268,9 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
      freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
                               &policy->nb_min);
 
+     /* Cancel any pending policy->update work before freeing the policy. */
+     cancel_work_sync(&policy->update);
+
      if (policy->max_freq_req) {
              /*
               * CPUFREQ_CREATE_POLICY notification is sent only after

drivers/cpufreq/cpufreq.c static void cpufreq_policy_free(struct cpufreq_policy *policy) · line 1287

Quoted 8 lines
drivers/cpufreq/cpufreq.c +0 -2
@@ -1279,8 +1282,6 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
      }
 
      freq_qos_remove_request(policy->min_freq_req);
-     /* Cancel any pending policy->update work before freeing the policy. */
-     cancel_work_sync(&policy->update);
      kfree(policy->min_freq_req);
 
      cpufreq_policy_put_kobj(policy);

Thanks for doing this.

Quoted 5 lines
Quoted 1 line

Folded into the previous patch and applied.

Please double check the result in the current linux-next branch in my tree.

I would have kept the blank line after cancel_work_sync() which isn't there anymore.

Signature · 1 line
viresh
#4 lore raw
Quoted 59 lines · Viresh Kumar
Quoted 57 lines · Rafael J. Wysocki
Quoted 56 lines · Viresh Kumar
Quoted 12 lines · Sudeep Holla

Commit 099967699ad9 ("cpufreq: Cancel policy update work scheduled before freeing") added cancel_work_sync(policy->update) after the frequency QoS were removed. We can cancel the work just after taking the last CPU in the policy offline and unregistering the notifiers as policy->update cannot be scheduled from anywhere at this point.

However, due to other bugs, doing so still triggered the race between freeing of policy and scheduled policy update work. Now that all those issues are resolved, we can move this cancelling of any scheduled policy update work just after removing min/max notifiers.

Quoted 8 lines
---
 drivers/cpufreq/cpufreq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Hi Rafael,

Based on Viresh's suggestion, I am posting a patch to move this cancel_work_sync earlier though it's not a must have change.

For me it is :)

Quoted 20 lines

I will leave it up to your preference.

Regards,
Sudeep

drivers/cpufreq/cpufreq.c +3 -0
index 829a3764df1b..48a224a6b178 100644
@@ -1268,6 +1268,9 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
      freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
                               &policy->nb_min);
 
+     /* Cancel any pending policy->update work before freeing the policy. */
+     cancel_work_sync(&policy->update);
+
      if (policy->max_freq_req) {
              /*
               * CPUFREQ_CREATE_POLICY notification is sent only after

drivers/cpufreq/cpufreq.c static void cpufreq_policy_free(struct cpufreq_policy *policy) · line 1287

Quoted 8 lines
drivers/cpufreq/cpufreq.c +0 -2
@@ -1279,8 +1282,6 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
      }
 
      freq_qos_remove_request(policy->min_freq_req);
-     /* Cancel any pending policy->update work before freeing the policy. */
-     cancel_work_sync(&policy->update);
      kfree(policy->min_freq_req);
 
      cpufreq_policy_put_kobj(policy);

Thanks for doing this.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Folded into the previous patch and applied.

Please double check the result in the current linux-next branch in my tree.

I would have kept the blank line after cancel_work_sync() which isn't there anymore.

OK, it looks better with the extra blank line, so updated. Thanks!