Skip to content

Commit 7251b9e

Browse files
zhang-ruirafaeljw
authored andcommitted
thermal/intel: Fix intel_tcc_get_temp() to support negative CPU temperature
CPU temperature can be negative in some cases. Thus the negative CPU temperature should not be considered as a failure. Fix intel_tcc_get_temp() and its users to support negative CPU temperature. Fixes: a3c1f06 ("thermal/intel: Introduce Intel TCC library") Signed-off-by: Zhang Rui <rui.zhang@intel.com> Reviewed-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> Cc: 6.3+ <stable@vger.kernel.org> # 6.3+ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 841c351 commit 7251b9e

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,14 @@ static int proc_thermal_get_zone_temp(struct thermal_zone_device *zone,
176176
int *temp)
177177
{
178178
int cpu;
179-
int curr_temp;
179+
int curr_temp, ret;
180180

181181
*temp = 0;
182182

183183
for_each_online_cpu(cpu) {
184-
curr_temp = intel_tcc_get_temp(cpu, false);
185-
if (curr_temp < 0)
186-
return curr_temp;
184+
ret = intel_tcc_get_temp(cpu, &curr_temp, false);
185+
if (ret < 0)
186+
return ret;
187187
if (!*temp || curr_temp > *temp)
188188
*temp = curr_temp;
189189
}

drivers/thermal/intel/intel_tcc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,19 @@ EXPORT_SYMBOL_NS_GPL(intel_tcc_set_offset, INTEL_TCC);
103103
/**
104104
* intel_tcc_get_temp() - returns the current temperature
105105
* @cpu: cpu that the MSR should be run on, nagative value means any cpu.
106+
* @temp: pointer to the memory for saving cpu temperature.
106107
* @pkg: true: Package Thermal Sensor. false: Core Thermal Sensor.
107108
*
108109
* Get the current temperature returned by the CPU core/package level
109110
* thermal sensor, in degrees C.
110111
*
111-
* Return: Temperature in degrees C on success, negative error code otherwise.
112+
* Return: 0 on success, negative error code otherwise.
112113
*/
113-
int intel_tcc_get_temp(int cpu, bool pkg)
114+
int intel_tcc_get_temp(int cpu, int *temp, bool pkg)
114115
{
115116
u32 low, high;
116117
u32 msr = pkg ? MSR_IA32_PACKAGE_THERM_STATUS : MSR_IA32_THERM_STATUS;
117-
int tjmax, temp, err;
118+
int tjmax, err;
118119

119120
tjmax = intel_tcc_get_tjmax(cpu);
120121
if (tjmax < 0)
@@ -131,9 +132,8 @@ int intel_tcc_get_temp(int cpu, bool pkg)
131132
if (!(low & BIT(31)))
132133
return -ENODATA;
133134

134-
temp = tjmax - ((low >> 16) & 0x7f);
135+
*temp = tjmax - ((low >> 16) & 0x7f);
135136

136-
/* Do not allow negative CPU temperature */
137-
return temp >= 0 ? temp : -ENODATA;
137+
return 0;
138138
}
139139
EXPORT_SYMBOL_NS_GPL(intel_tcc_get_temp, INTEL_TCC);

drivers/thermal/intel/x86_pkg_temp_thermal.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ static struct zone_device *pkg_temp_thermal_get_dev(unsigned int cpu)
108108
static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
109109
{
110110
struct zone_device *zonedev = thermal_zone_device_priv(tzd);
111-
int val;
111+
int val, ret;
112112

113-
val = intel_tcc_get_temp(zonedev->cpu, true);
114-
if (val < 0)
115-
return val;
113+
ret = intel_tcc_get_temp(zonedev->cpu, &val, true);
114+
if (ret < 0)
115+
return ret;
116116

117117
*temp = val * 1000;
118118
pr_debug("sys_get_curr_temp %d\n", *temp);

include/linux/intel_tcc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
int intel_tcc_get_tjmax(int cpu);
1414
int intel_tcc_get_offset(int cpu);
1515
int intel_tcc_set_offset(int cpu, int offset);
16-
int intel_tcc_get_temp(int cpu, bool pkg);
16+
int intel_tcc_get_temp(int cpu, int *temp, bool pkg);
1717

1818
#endif /* __INTEL_TCC_H__ */

0 commit comments

Comments
 (0)