Skip to contentSkip to conversation

thermal: core: Clean up thermal_list_lock locking

PATCH In review Rafael J. Wysocki 3 participants 3 messages Mar 22, 2023 – Apr 3, 2023 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: core: Clean up thermal_list_lock locking

From: Rafael J. Wysocki <[email protected]>

Once thermal_list_lock has been acquired in __thermal_cooling_device_register(), it is not necessary to drop it and take it again until all of the thermal zones have been updated, so change the code accordingly.

No expected functional impact.

---
 drivers/thermal/thermal_core.c |    8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/thermal/thermal_core.c +2 -6
Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
@@ -826,8 +826,6 @@ static void bind_cdev(struct thermal_coo
 	const struct thermal_zone_params *tzp;
 	struct thermal_zone_device *pos = NULL;
 
-	mutex_lock(&thermal_list_lock);
-
 	list_for_each_entry(pos, &thermal_tz_list, node) {
 		if (!pos->tzp && !pos->ops->bind)
 			continue;
@@ -854,8 +852,6 @@ static void bind_cdev(struct thermal_coo
 			       tzp->tbp[i].weight);
 		}
 	}
-
-	mutex_unlock(&thermal_list_lock);
 }
 
 /**
@@ -933,17 +929,17 @@ __thermal_cooling_device_register(struct
 
 	/* Add 'this' new cdev to the global cdev list */
 	mutex_lock(&thermal_list_lock);
+
 	list_add(&cdev->node, &thermal_cdev_list);
-	mutex_unlock(&thermal_list_lock);
 
 	/* Update binding information for 'this' new cdev */
 	bind_cdev(cdev);
 
-	mutex_lock(&thermal_list_lock);
 	list_for_each_entry(pos, &thermal_tz_list, node)
 		if (atomic_cmpxchg(&pos->need_update, 1, 0))
 			thermal_zone_device_update(pos,
 						   THERMAL_EVENT_UNSPECIFIED);
+
 	mutex_unlock(&thermal_list_lock);
 
 	return cdev;
#1 lore raw
Quoted 11 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Once thermal_list_lock has been acquired in __thermal_cooling_device_register(), it is not necessary to drop it and take it again until all of the thermal zones have been updated, so change the code accordingly.

No expected functional impact.

---

Looks good to me, shall I pick it in my branch ?

Quoted 48 lines
  drivers/thermal/thermal_core.c |    8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)

Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================

drivers/thermal/thermal_core.c +2 -6
@@ -826,8 +826,6 @@ static void bind_cdev(struct thermal_coo
  	const struct thermal_zone_params *tzp;
  	struct thermal_zone_device *pos = NULL;
 
-	mutex_lock(&thermal_list_lock);
-
  	list_for_each_entry(pos, &thermal_tz_list, node) {
  		if (!pos->tzp && !pos->ops->bind)
  			continue;
@@ -854,8 +852,6 @@ static void bind_cdev(struct thermal_coo
  			       tzp->tbp[i].weight);
  		}
  	}
-
-	mutex_unlock(&thermal_list_lock);
  }
 
  /**
@@ -933,17 +929,17 @@ __thermal_cooling_device_register(struct
 
  	/* Add 'this' new cdev to the global cdev list */
  	mutex_lock(&thermal_list_lock);
+
  	list_add(&cdev->node, &thermal_cdev_list);
-	mutex_unlock(&thermal_list_lock);
 
  	/* Update binding information for 'this' new cdev */
  	bind_cdev(cdev);
 
-	mutex_lock(&thermal_list_lock);
  	list_for_each_entry(pos, &thermal_tz_list, node)
  		if (atomic_cmpxchg(&pos->need_update, 1, 0))
  			thermal_zone_device_update(pos,
  						   THERMAL_EVENT_UNSPECIFIED);
+
  	mutex_unlock(&thermal_list_lock);
 
  	return cdev;
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#2 lore raw
Quoted 9 lines · Daniel Lezcano
Quoted 7 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Once thermal_list_lock has been acquired in __thermal_cooling_device_register(), it is not necessary to drop it and take it again until all of the thermal zones have been updated, so change the code accordingly.

Quoted 6 lines
Quoted 4 lines

No expected functional impact.

---

Looks good to me, shall I pick it in my branch ?

No, I;ll take care of it myself, thanks!

Quoted 56 lines
Quoted 38 lines
  drivers/thermal/thermal_core.c |    8 ++------
  1 file changed, 2 insertions(+), 6 deletions(-)

Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================

drivers/thermal/thermal_core.c +1 -5
@@ -826,8 +826,6 @@ static void bind_cdev(struct thermal_coo
      const struct thermal_zone_params *tzp;
      struct thermal_zone_device *pos = NULL;
 
-     mutex_lock(&thermal_list_lock);
-
      list_for_each_entry(pos, &thermal_tz_list, node) {
              if (!pos->tzp && !pos->ops->bind)
                      continue;
@@ -854,8 +852,6 @@ static void bind_cdev(struct thermal_coo
                             tzp->tbp[i].weight);
              }
      }
-
-     mutex_unlock(&thermal_list_lock);
  }
 
  /**
@@ -933,17 +929,17 @@ __thermal_cooling_device_register(struct
 
      /* Add 'this' new cdev to the global cdev list */
      mutex_lock(&thermal_list_lock);
+
      list_add(&cdev->node, &thermal_cdev_list);
-     mutex_unlock(&thermal_list_lock);
 
      /* Update binding information for 'this' new cdev */
      bind_cdev(cdev);

drivers/thermal/thermal_core.c __thermal_cooling_device_register(struct · line 945

Quoted 10 lines
drivers/thermal/thermal_core.c +1 -1
 
-     mutex_lock(&thermal_list_lock);
      list_for_each_entry(pos, &thermal_tz_list, node)
              if (atomic_cmpxchg(&pos->need_update, 1, 0))
                      thermal_zone_device_update(pos,
                                                 THERMAL_EVENT_UNSPECIFIED);
+
      mutex_unlock(&thermal_list_lock);
 
      return cdev;

--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog