Skip to content

Commit bdfc34b

Browse files
yu-chen-surfsashalevin
authored andcommitted
Thermal: do thermal zone update after a cooling device registered
[ Upstream commit 4511f71 ] When a new cooling device is registered, we need to update the thermal zone to set the new registered cooling device to a proper state. This fixes a problem that the system is cool, while the fan devices are left running on full speed after boot, if fan device is registered after thermal zone device. Here is the history of why current patch looks like this: https://patchwork.kernel.org/patch/7273041/ CC: <[email protected]> #3.18+ Reference:https://bugzilla.kernel.org/show_bug.cgi?id=92431 Tested-by: Manuel Krause <[email protected]> Tested-by: szegad <[email protected]> Tested-by: prash <[email protected]> Tested-by: amish <[email protected]> Reviewed-by: Javi Merino <[email protected]> Signed-off-by: Zhang Rui <[email protected]> Signed-off-by: Chen Yu <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent ab48276 commit bdfc34b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

drivers/thermal/thermal_core.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
10361036
if (!result) {
10371037
list_add_tail(&dev->tz_node, &tz->thermal_instances);
10381038
list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
1039+
atomic_set(&tz->need_update, 1);
10391040
}
10401041
mutex_unlock(&cdev->lock);
10411042
mutex_unlock(&tz->lock);
@@ -1142,6 +1143,7 @@ __thermal_cooling_device_register(struct device_node *np,
11421143
const struct thermal_cooling_device_ops *ops)
11431144
{
11441145
struct thermal_cooling_device *cdev;
1146+
struct thermal_zone_device *pos = NULL;
11451147
int result;
11461148

11471149
if (type && strlen(type) >= THERMAL_NAME_LENGTH)
@@ -1186,6 +1188,12 @@ __thermal_cooling_device_register(struct device_node *np,
11861188
/* Update binding information for 'this' new cdev */
11871189
bind_cdev(cdev);
11881190

1191+
mutex_lock(&thermal_list_lock);
1192+
list_for_each_entry(pos, &thermal_tz_list, node)
1193+
if (atomic_cmpxchg(&pos->need_update, 1, 0))
1194+
thermal_zone_device_update(pos);
1195+
mutex_unlock(&thermal_list_lock);
1196+
11891197
return cdev;
11901198
}
11911199

@@ -1516,6 +1524,8 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
15161524
tz->trips = trips;
15171525
tz->passive_delay = passive_delay;
15181526
tz->polling_delay = polling_delay;
1527+
/* A new thermal zone needs to be updated anyway. */
1528+
atomic_set(&tz->need_update, 1);
15191529

15201530
dev_set_name(&tz->device, "thermal_zone%d", tz->id);
15211531
result = device_register(&tz->device);
@@ -1597,7 +1607,9 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
15971607
thermal_zone_device_set_polling(tz, 0);
15981608

15991609
thermal_zone_device_reset(tz);
1600-
thermal_zone_device_update(tz);
1610+
/* Update the new thermal zone and mark it as already updated. */
1611+
if (atomic_cmpxchg(&tz->need_update, 1, 0))
1612+
thermal_zone_device_update(tz);
16011613

16021614
return tz;
16031615

include/linux/thermal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ struct thermal_attr {
162162
* @forced_passive: If > 0, temperature at which to switch on all ACPI
163163
* processor cooling devices. Currently only used by the
164164
* step-wise governor.
165+
* @need_update: if equals 1, thermal_zone_device_update needs to be invoked.
165166
* @ops: operations this &thermal_zone_device supports
166167
* @tzp: thermal zone parameters
167168
* @governor: pointer to the governor for this thermal zone
@@ -188,6 +189,7 @@ struct thermal_zone_device {
188189
int emul_temperature;
189190
int passive;
190191
unsigned int forced_passive;
192+
atomic_t need_update;
191193
struct thermal_zone_device_ops *ops;
192194
const struct thermal_zone_params *tzp;
193195
struct thermal_governor *governor;

0 commit comments

Comments
 (0)