Skip to content

Commit 0043ee4

Browse files
committed
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux
Pull thermal updates from Zhang Rui: - Fix a race condition when updating cooling device, which may lead to a situation where a thermal governor never updates the cooling device. From Michele Di Giorgio. - Fix a zero division error when disabling the forced idle injection from the intel powerclamp. From Petr Mladek. - Add suspend/resume callback for intel_pch_thermal thermal driver. From Srinivas Pandruvada. - Another two fixes for clocking cooling driver and hwmon sysfs I/F. From Michele Di Giorgio and Kuninori Morimoto. [ Hmm. That suspend/resume callback for intel_pch_thermal doesn't look like a fix, but I'm letting it slide.. - Linus ] * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/rzhang/linux: thermal: clock_cooling: Fix missing mutex_init() thermal: hwmon: EXPORT_SYMBOL_GPL for thermal hwmon sysfs thermal: fix race condition when updating cooling device thermal/powerclamp: Prevent division by zero when counting interval thermal: intel_pch_thermal: Add suspend/resume callback
2 parents 4ef870e + 1577ddf commit 0043ee4

File tree

9 files changed

+84
-8
lines changed

9 files changed

+84
-8
lines changed

drivers/thermal/clock_cooling.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ clock_cooling_register(struct device *dev, const char *clock_name)
426426
if (!ccdev)
427427
return ERR_PTR(-ENOMEM);
428428

429+
mutex_init(&ccdev->lock);
429430
ccdev->dev = dev;
430431
ccdev->clk = devm_clk_get(dev, clock_name);
431432
if (IS_ERR(ccdev->clk))

drivers/thermal/fair_share.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
116116
instance->target = get_target_state(tz, cdev, percentage,
117117
cur_trip_level);
118118

119+
mutex_lock(&instance->cdev->lock);
119120
instance->cdev->updated = false;
121+
mutex_unlock(&instance->cdev->lock);
120122
thermal_cdev_update(cdev);
121123
}
122124
return 0;

drivers/thermal/gov_bang_bang.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
7171
dev_dbg(&instance->cdev->device, "target=%d\n",
7272
(int)instance->target);
7373

74+
mutex_lock(&instance->cdev->lock);
7475
instance->cdev->updated = false; /* cdev needs update */
76+
mutex_unlock(&instance->cdev->lock);
7577
}
7678

7779
mutex_unlock(&tz->lock);

drivers/thermal/intel_pch_thermal.c

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/init.h>
2222
#include <linux/pci.h>
2323
#include <linux/thermal.h>
24+
#include <linux/pm.h>
2425

2526
/* Intel PCH thermal Device IDs */
2627
#define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */
@@ -65,6 +66,7 @@ struct pch_thermal_device {
6566
unsigned long crt_temp;
6667
int hot_trip_id;
6768
unsigned long hot_temp;
69+
bool bios_enabled;
6870
};
6971

7072
static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
@@ -75,8 +77,10 @@ static int pch_wpt_init(struct pch_thermal_device *ptd, int *nr_trips)
7577
*nr_trips = 0;
7678

7779
/* Check if BIOS has already enabled thermal sensor */
78-
if (WPT_TSS_TSDSS & readb(ptd->hw_base + WPT_TSS))
80+
if (WPT_TSS_TSDSS & readb(ptd->hw_base + WPT_TSS)) {
81+
ptd->bios_enabled = true;
7982
goto read_trips;
83+
}
8084

8185
tsel = readb(ptd->hw_base + WPT_TSEL);
8286
/*
@@ -130,16 +134,48 @@ static int pch_wpt_get_temp(struct pch_thermal_device *ptd, int *temp)
130134
return 0;
131135
}
132136

137+
static int pch_wpt_suspend(struct pch_thermal_device *ptd)
138+
{
139+
u8 tsel;
140+
141+
if (ptd->bios_enabled)
142+
return 0;
143+
144+
tsel = readb(ptd->hw_base + WPT_TSEL);
145+
146+
writeb(tsel & 0xFE, ptd->hw_base + WPT_TSEL);
147+
148+
return 0;
149+
}
150+
151+
static int pch_wpt_resume(struct pch_thermal_device *ptd)
152+
{
153+
u8 tsel;
154+
155+
if (ptd->bios_enabled)
156+
return 0;
157+
158+
tsel = readb(ptd->hw_base + WPT_TSEL);
159+
160+
writeb(tsel | WPT_TSEL_ETS, ptd->hw_base + WPT_TSEL);
161+
162+
return 0;
163+
}
164+
133165
struct pch_dev_ops {
134166
int (*hw_init)(struct pch_thermal_device *ptd, int *nr_trips);
135167
int (*get_temp)(struct pch_thermal_device *ptd, int *temp);
168+
int (*suspend)(struct pch_thermal_device *ptd);
169+
int (*resume)(struct pch_thermal_device *ptd);
136170
};
137171

138172

139173
/* dev ops for Wildcat Point */
140174
static const struct pch_dev_ops pch_dev_ops_wpt = {
141175
.hw_init = pch_wpt_init,
142176
.get_temp = pch_wpt_get_temp,
177+
.suspend = pch_wpt_suspend,
178+
.resume = pch_wpt_resume,
143179
};
144180

145181
static int pch_thermal_get_temp(struct thermal_zone_device *tzd, int *temp)
@@ -269,18 +305,40 @@ static void intel_pch_thermal_remove(struct pci_dev *pdev)
269305
pci_disable_device(pdev);
270306
}
271307

308+
static int intel_pch_thermal_suspend(struct device *device)
309+
{
310+
struct pci_dev *pdev = to_pci_dev(device);
311+
struct pch_thermal_device *ptd = pci_get_drvdata(pdev);
312+
313+
return ptd->ops->suspend(ptd);
314+
}
315+
316+
static int intel_pch_thermal_resume(struct device *device)
317+
{
318+
struct pci_dev *pdev = to_pci_dev(device);
319+
struct pch_thermal_device *ptd = pci_get_drvdata(pdev);
320+
321+
return ptd->ops->resume(ptd);
322+
}
323+
272324
static struct pci_device_id intel_pch_thermal_id[] = {
273325
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) },
274326
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) },
275327
{ 0, },
276328
};
277329
MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id);
278330

331+
static const struct dev_pm_ops intel_pch_pm_ops = {
332+
.suspend = intel_pch_thermal_suspend,
333+
.resume = intel_pch_thermal_resume,
334+
};
335+
279336
static struct pci_driver intel_pch_thermal_driver = {
280337
.name = "intel_pch_thermal",
281338
.id_table = intel_pch_thermal_id,
282339
.probe = intel_pch_thermal_probe,
283340
.remove = intel_pch_thermal_remove,
341+
.driver.pm = &intel_pch_pm_ops,
284342
};
285343

286344
module_pci_driver(intel_pch_thermal_driver);

drivers/thermal/intel_powerclamp.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static int clamp_thread(void *arg)
388388
int sleeptime;
389389
unsigned long target_jiffies;
390390
unsigned int guard;
391-
unsigned int compensation = 0;
391+
unsigned int compensated_ratio;
392392
int interval; /* jiffies to sleep for each attempt */
393393
unsigned int duration_jiffies = msecs_to_jiffies(duration);
394394
unsigned int window_size_now;
@@ -409,8 +409,11 @@ static int clamp_thread(void *arg)
409409
* c-states, thus we need to compensate the injected idle ratio
410410
* to achieve the actual target reported by the HW.
411411
*/
412-
compensation = get_compensation(target_ratio);
413-
interval = duration_jiffies*100/(target_ratio+compensation);
412+
compensated_ratio = target_ratio +
413+
get_compensation(target_ratio);
414+
if (compensated_ratio <= 0)
415+
compensated_ratio = 1;
416+
interval = duration_jiffies * 100 / compensated_ratio;
414417

415418
/* align idle time */
416419
target_jiffies = roundup(jiffies, interval);
@@ -647,8 +650,8 @@ static int powerclamp_set_cur_state(struct thermal_cooling_device *cdev,
647650
goto exit_set;
648651
} else if (set_target_ratio > 0 && new_target_ratio == 0) {
649652
pr_info("Stop forced idle injection\n");
650-
set_target_ratio = 0;
651653
end_power_clamp();
654+
set_target_ratio = 0;
652655
} else /* adjust currently running */ {
653656
set_target_ratio = new_target_ratio;
654657
/* make new set_target_ratio visible to other cpus */

drivers/thermal/power_allocator.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,9 @@ static void allow_maximum_power(struct thermal_zone_device *tz)
529529
continue;
530530

531531
instance->target = 0;
532+
mutex_lock(&instance->cdev->lock);
532533
instance->cdev->updated = false;
534+
mutex_unlock(&instance->cdev->lock);
533535
thermal_cdev_update(instance->cdev);
534536
}
535537
}

drivers/thermal/step_wise.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
175175
update_passive_instance(tz, trip_type, -1);
176176

177177
instance->initialized = true;
178+
mutex_lock(&instance->cdev->lock);
178179
instance->cdev->updated = false; /* cdev needs update */
180+
mutex_unlock(&instance->cdev->lock);
179181
}
180182

181183
mutex_unlock(&tz->lock);

drivers/thermal/thermal_core.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,9 @@ int power_actor_set_power(struct thermal_cooling_device *cdev,
10931093
return ret;
10941094

10951095
instance->target = state;
1096+
mutex_lock(&cdev->lock);
10961097
cdev->updated = false;
1098+
mutex_unlock(&cdev->lock);
10971099
thermal_cdev_update(cdev);
10981100

10991101
return 0;
@@ -1623,11 +1625,13 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
16231625
struct thermal_instance *instance;
16241626
unsigned long target = 0;
16251627

1628+
mutex_lock(&cdev->lock);
16261629
/* cooling device is updated*/
1627-
if (cdev->updated)
1630+
if (cdev->updated) {
1631+
mutex_unlock(&cdev->lock);
16281632
return;
1633+
}
16291634

1630-
mutex_lock(&cdev->lock);
16311635
/* Make sure cdev enters the deepest cooling state */
16321636
list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
16331637
dev_dbg(&cdev->device, "zone%d->target=%lu\n",
@@ -1637,9 +1641,9 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
16371641
if (instance->target > target)
16381642
target = instance->target;
16391643
}
1640-
mutex_unlock(&cdev->lock);
16411644
cdev->ops->set_cur_state(cdev, target);
16421645
cdev->updated = true;
1646+
mutex_unlock(&cdev->lock);
16431647
trace_cdev_update(cdev, target);
16441648
dev_dbg(&cdev->device, "set to state %lu\n", target);
16451649
}

drivers/thermal/thermal_hwmon.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ int thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
232232

233233
return result;
234234
}
235+
EXPORT_SYMBOL_GPL(thermal_add_hwmon_sysfs);
235236

236237
void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
237238
{
@@ -270,3 +271,4 @@ void thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
270271
hwmon_device_unregister(hwmon->device);
271272
kfree(hwmon);
272273
}
274+
EXPORT_SYMBOL_GPL(thermal_remove_hwmon_sysfs);

0 commit comments

Comments
 (0)