thermal/intel: Introduce intel-tcc lib and enhance tjmax handling
Zhang Rui
reviewercover thermal/intel: Introduce intel-tcc lib and enhance tjmax handling
Currently, all the thermal drivers that access the Intel CPU TCC (thermal control circuitry) MSRs have two problems,
1. they have their own implementation for the same TCC functionalities, including getting the tjmax/temperature, getting/setting the TCC offset. This introduces a lot of duplicate code.
2. they get TjMax value once and always use the cached value later. But Tjmax value retrieved from MSR_IA32_TEMPERATURE_TARGET can be changed at runtime for cases like the Intel SST-PP (Intel Speed Select Technology- Performance Profile) level change.
The intel-tcc library is introduced in patch 1/6 for cleaning up the duplicate code among these drivers, and it also ensures the temperature is alway got based on the updated tjmax value.
Patch 2 ~ 5 cleans up the drivers by using the new Intel TCC lib APIs.
Patch 6/6 enhances the x86_pkg_temp driver to handle dynamic tjmax when progamming the thermal interrupt threshold.
Actually, the thermal interrupt threshold programming can also be part of the TCC library, but I didn't do it in this version because x86_pkg_temp is the only user for now.
thanks,
rui
----------------------------------------------------------------
Zhang Rui (6):
thermal/intel: Introduce Intel TCC library thermal/x86_pkg_temp_thermal: Use Intel TCC library thermal/int340x/processor_thermal: Use Intel TCC library thermal/intel/intel_soc_dts_iosf: Use Intel TCC library thermal/intel/intel_tcc_cooling: Use Intel TCC library thermal/x86_pkg_temp_thermal: Add support for handling dynamic tjmax
drivers/thermal/intel/Kconfig | 7 ++ drivers/thermal/intel/Makefile | 1 + drivers/thermal/intel/int340x_thermal/Kconfig | 1 + .../int340x_thermal/processor_thermal_device.c | 123 ++++--------------- drivers/thermal/intel/intel_soc_dts_iosf.c | 33 +----- drivers/thermal/intel/intel_tcc.c | 132 +++++++++++++++++++++ drivers/thermal/intel/intel_tcc_cooling.c | 37 +----- drivers/thermal/intel/x86_pkg_temp_thermal.c | 62 ++++------ include/linux/intel_tcc.h | 18 +++ 9 files changed, 219 insertions(+), 195 deletions(-) create mode 100644 drivers/thermal/intel/intel_tcc.c create mode 100644 include/linux/intel_tcc.h
Zhang Rui
reviewerPATCH 1/6 thermal/intel: Introduce Intel TCC library
There are several different drivers that accesses the Intel TCC (thermal control circuitry) MSRs, and each of them has its own implementation for the same functionalities, e.g. getting the current temperature, getting the tj_max, and getting/setting the tj_max offset.
Introduce a library to unify the code for Intel CPU TCC MSR access.
At the same time, ensure the temperature is got based on the updated tjmax value because tjmax can be changed at runtime for cases like the Intel SST-PP (Intel Speed Select Technology - Performance Profile) level change.
--- drivers/thermal/intel/Kconfig | 4 + drivers/thermal/intel/Makefile | 1 + drivers/thermal/intel/intel_tcc.c | 131 ++++++++++++++++++++++++++++++ include/linux/intel_tcc.h | 18 ++++ 4 files changed, 154 insertions(+) create mode 100644 drivers/thermal/intel/intel_tcc.c create mode 100644 include/linux/intel_tcc.h
drivers/thermal/intel/Kconfig +4 -0
@@ -12,6 +12,10 @@ config X86_THERMAL_VECTOR def_bool y depends on X86 && CPU_SUP_INTEL && X86_LOCAL_APIC +config INTEL_TCC + bool + depends on X86 + config X86_PKG_TEMP_THERMAL tristate "X86 package temperature thermal driver" depends on X86_THERMAL_VECTOR
drivers/thermal/intel/Makefile +1 -0
@@ -2,6 +2,7 @@ # # Makefile for various Intel thermal drivers. +obj-$(CONFIG_INTEL_TCC) += intel_tcc.o obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o obj-$(CONFIG_INTEL_SOC_DTS_IOSF_CORE) += intel_soc_dts_iosf.o
drivers/thermal/intel/intel_tcc.c new file +131 -0
131 lines not on this page · raw message
include/linux/intel_tcc.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* header for Intel TCC (thermal control circuitry) library +* +* Copyright (C) 2022 Intel Corporation. +*/ + +#ifndef __INTEL_TCC_H__ +#define __INTEL_TCC_H__ + +#include <linux/types.h> + +int intel_tcc_get_tjmax (int cpu,int *tjmax); +int intel_tcc_get_offset (int cpu,int *offset); +int intel_tcc_set_offset (int cpu,int offset); +int intel_tcc_get_temp (int cpu,bool pkg,int *temp); + +#endif /* __INTEL_TCC_H__ */
Signature · 1 line
2.25.1
Rafael J. Wysocki
maintainerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 6 lines · Zhang Rui
There are several different drivers that accesses the Intel TCC (thermal control circuitry) MSRs, and each of them has its own implementation for the same functionalities, e.g. getting the current temperature, getting the
tj_max, and getting/setting thetj_maxoffset.
Quoted 8 lines
Introduce a library to unify the code for Intel CPU TCC MSR access.
At the same time, ensure the temperature is got based on the updated tjmax value because tjmax can be changed at runtime for cases like the Intel SST-PP (Intel Speed Select Technology - Performance Profile) level change.
Signed-off-by Zhang Rui <[email protected]>
Nice series, overall I like it a lot, but I have some comments regarding this particular patch (below). Some of them are arguably minor, but at least one thing is more serious.
Quoted 53 lines
--- drivers/thermal/intel/Kconfig | 4 + drivers/thermal/intel/Makefile | 1 + drivers/thermal/intel/intel_tcc.c | 131 ++++++++++++++++++++++++++++++ include/linux/intel_tcc.h | 18 ++++ 4 files changed, 154 insertions(+) create mode 100644 drivers/thermal/intel/intel_tcc.c create mode 100644 include/linux/intel_tcc.hdrivers/thermal/intel/Kconfig +4
-0@@ -12,6 +12,10 @@ config X86_THERMAL_VECTOR def_bool y depends on X86 && CPU_SUP_INTEL && X86_LOCAL_APIC +config INTEL_TCC + bool + depends on X86 + config X86_PKG_TEMP_THERMAL tristate "X86 package temperature thermal driver" depends on X86_THERMAL_VECTORdrivers/thermal/intel/Makefile +1
-0@@ -2,6 +2,7 @@ # # Makefile for various Intel thermal drivers. +obj-$(CONFIG_INTEL_TCC) += intel_tcc.o obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o obj-$(CONFIG_INTEL_SOC_DTS_IOSF_CORE) += intel_soc_dts_iosf.odrivers/thermal/intel/intel_tcc.c new file +11
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* intel_tcc.c - Library for Intel TCC (thermal control circuitry) MSR access +* Copyright (c) 2022, Intel Corporation. +*/ + +#include <linux/errno.h> +#include <linux/intel_tcc.h> +#include <asm/msr.h> + +/**
drivers/thermal/intel/intel_tcc.c line 21
Quoted 10 lines
drivers/thermal/intel/intel_tcc.c new file +10
-0+* intel_tcc_get_tjmax() - returns the default TCC activation Temperature +* @cpu: cpu that the MSR should be run on. +* @tjmax: a valid pointer to where to store the Tjmax value +* +* Get the TjMax value, which is the default thermal throttling or TCC +* activation temperature in degrees C. +* +* Return: On success returns 0, an error code otherwise +*/ +
This extra empty line is not needed (and not desirable even). And same below.
drivers/thermal/intel/intel_tcc.c line 28
Quoted 7 lines
drivers/thermal/intel/intel_tcc.c new file +7
-0+int intel_tcc_get_tjmax (int cpu,int *tjmax) +{ +u32 eax, edx; +int err; + + err =rdmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , + &eax, &edx);
The current trend is to align the arguments after a line break with the first one, but I would just put them all on the same line (and below too).
drivers/thermal/intel/intel_tcc.c line 32
Quoted 4 lines
drivers/thermal/intel/intel_tcc.c new file +4
-0+if (err) +return err; + + *tjmax = (eax >>16 ) &0xff ;
This means that the tjmax value cannot be negative.
drivers/thermal/intel/intel_tcc.c line 34
Quoted 2 lines
drivers/thermal/intel/intel_tcc.c new file +2
-0+ +return *tjmax ?0 : -EINVAL ;
So the return value of this function could be tjmax if positive or a negative error code otherwise. No return pointers needed.
And why do you want to return -EINVAL (rather than any other error code) if tjmax turns out to be 0?
Quoted 15 lines
drivers/thermal/intel/intel_tcc.c new file +15
-0+} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_tjmax,INTEL_TCC ); + +/** +* intel_tcc_get_offset() - returns the TCC Offset value to Tjmax +* @cpu: cpu that the MSR should be run on. +* @offset: a valid pointer to where to store the offset value +* +* Get the TCC offset value to Tjmax. The effective thermal throttling or TCC +* activation temperature equals "Tjmax" - "TCC Offset", in degrees C. +* +* Return: On success returns 0, an error code otherwise +*/ + +int intel_tcc_get_offset (int cpu,int *offset)
drivers/thermal/intel/intel_tcc.c line 59
Quoted 10 lines
drivers/thermal/intel/intel_tcc.c new file +10
-0+{ +u32 eax, edx; +int err; + + err =rdmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , + &eax, &edx); +if (err) +return err; + + *offset = (eax >>24 ) &0x3f ;
Well, offset cannot be negative here, so (again) the return value of this function could be interpreted as the offsent (if non-negative) or a negative error code on failure.
drivers/thermal/intel/intel_tcc.c line 68
Quoted 9 lines
drivers/thermal/intel/intel_tcc.c new file +9
-0+ +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_offset,INTEL_TCC ); + +/** +* intel_tcc_set_offset() - set the TCC offset value to Tjmax +* @cpu: cpu that the MSR should be run on. +* @offset: TCC offset value in degree C
I think that this cannot be negative, so maybe say "in K" instead of "in degree C"?
And maybe it's better to pass u8 here?
Quoted 12 lines
drivers/thermal/intel/intel_tcc.c new file +12
-0+* +* Set the TCC Offset value to Tjmax. The effective thermal throttling or TCC +* activation temperature equals "Tjmax" - "TCC Offset", in degree C. +* +* Return: On success returns 0, an error code otherwise +*/ + +int intel_tcc_set_offset (int cpu,int offset) +{ +u32 eax, edx; +int err; +
drivers/thermal/intel/intel_tcc.c line 90
Quoted 10 lines
drivers/thermal/intel/intel_tcc.c new file +10
-0+if (offset >0x3f ) +return -EINVAL ; + + err =rdmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , + &eax, &edx); +if (err) +return err; + +if (eax &BIT (31 )) +return -EPERM ;
Why -EPERM?
drivers/thermal/intel/intel_tcc.c line 93
Quoted 3 lines
drivers/thermal/intel/intel_tcc.c new file +3
-0+ + eax &= ~(0x3f <<24 ); + eax |= (offset <<24 );
The parens are not needed AFAICS.
drivers/thermal/intel/intel_tcc.c line 95
Quoted 2 lines
drivers/thermal/intel/intel_tcc.c new file +2
-0+ +return wrmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , eax, edx);
So is any protection against concurrent access needed here? Like what if two different callers invoke this function at the same time for the same CPU?
Quoted 13 lines
drivers/thermal/intel/intel_tcc.c new file +13
-0+} +EXPORT_SYMBOL_NS_GPL (intel_tcc_set_offset,INTEL_TCC ); + +/** +* intel_tcc_get_temp() - returns the current temperature +* @cpu: cpu that the MSR should be run on. +* @pkg: true: Package Thermal Sensor. false: Core Thermal Sensor. +* @temp: a valid pointer to where to store the resulting temperature +* +* Get the current temperature returned by the CPU core/package level +* thermal sensor, in degrees C. +* +* Return: On success returns 0, an error code otherwise
drivers/thermal/intel/intel_tcc.c line 118
Quoted 10 lines
drivers/thermal/intel/intel_tcc.c new file +10
-0+*/ +int intel_tcc_get_temp (int cpu,bool pkg,int *temp) +{ +u32 eax, edx; +u32 msr = pkg ?MSR_IA32_PACKAGE_THERM_STATUS :MSR_IA32_THERM_STATUS ; +int tjmax, err; + + err =intel_tcc_get_tjmax (cpu, &tjmax); +if (err) +return err;
Well, what if somebody change tjmax on this cpu while this function is running?
Quoted 38 lines
drivers/thermal/intel/intel_tcc.c new file +13
-0+ + err =rdmsr_safe_on_cpu (cpu, msr, &eax, &edx); +if (err) +return err; + +if (eax &0x80000000 ) { + *temp = tjmax - ((eax >>16 ) &0x7f ); +return 0 ; + } +return -EINVAL ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_temp,INTEL_TCC ); +include/linux/intel_tcc.h new file +18
-1@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* header for Intel TCC (thermal control circuitry) library +* +* Copyright (C) 2022 Intel Corporation. +*/ + +#ifndef __INTEL_TCC_H__ +#define __INTEL_TCC_H__ + +#include <linux/types.h> + +int intel_tcc_get_tjmax (int cpu,int *tjmax); +int intel_tcc_get_offset (int cpu,int *offset); +int intel_tcc_set_offset (int cpu,int offset); +int intel_tcc_get_temp (int cpu,bool pkg,int *temp); + +#endif /* __INTEL_TCC_H__ */ --
Rafael J. Wysocki
maintainerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 215 lines · Rafael J. Wysocki
Quoted 6 lines · Zhang Rui
There are several different drivers that accesses the Intel TCC (thermal control circuitry) MSRs, and each of them has its own implementation for the same functionalities, e.g. getting the current temperature, getting the
tj_max, and getting/setting thetj_maxoffset.Quoted 8 lines
Introduce a library to unify the code for Intel CPU TCC MSR access.
At the same time, ensure the temperature is got based on the updated tjmax value because tjmax can be changed at runtime for cases like the Intel SST-PP (Intel Speed Select Technology - Performance Profile) level change.
Signed-off-by Zhang Rui <[email protected]>Nice series, overall I like it a lot, but I have some comments regarding this particular patch (below). Some of them are arguably minor, but at least one thing is more serious.
Quoted 53 lines
--- drivers/thermal/intel/Kconfig | 4 + drivers/thermal/intel/Makefile | 1 + drivers/thermal/intel/intel_tcc.c | 131 ++++++++++++++++++++++++++++++ include/linux/intel_tcc.h | 18 ++++ 4 files changed, 154 insertions(+) create mode 100644 drivers/thermal/intel/intel_tcc.c create mode 100644 include/linux/intel_tcc.hdrivers/thermal/intel/Kconfig +4
-0@@ -12,6 +12,10 @@ config X86_THERMAL_VECTOR def_bool y depends on X86 && CPU_SUP_INTEL && X86_LOCAL_APIC +config INTEL_TCC + bool + depends on X86 + config X86_PKG_TEMP_THERMAL tristate "X86 package temperature thermal driver" depends on X86_THERMAL_VECTORdrivers/thermal/intel/Makefile +1
-0@@ -2,6 +2,7 @@ # # Makefile for various Intel thermal drivers. +obj-$(CONFIG_INTEL_TCC) += intel_tcc.o obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o obj-$(CONFIG_INTEL_SOC_DTS_IOSF_CORE) += intel_soc_dts_iosf.odrivers/thermal/intel/intel_tcc.c new file +11
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* intel_tcc.c - Library for Intel TCC (thermal control circuitry) MSR access +* Copyright (c) 2022, Intel Corporation. +*/ + +#include <linux/errno.h> +#include <linux/intel_tcc.h> +#include <asm/msr.h> + +/** drivers/thermal/intel/intel_tcc.c line 21
Quoted 10 lines
drivers/thermal/intel/intel_tcc.c new file +10
-0+* intel_tcc_get_tjmax() - returns the default TCC activation Temperature +* @cpu: cpu that the MSR should be run on. +* @tjmax: a valid pointer to where to store the Tjmax value +* +* Get the TjMax value, which is the default thermal throttling or TCC +* activation temperature in degrees C. +* +* Return: On success returns 0, an error code otherwise +*/ +This extra empty line is not needed (and not desirable even). And same below.
drivers/thermal/intel/intel_tcc.c line 28
Quoted 7 lines
drivers/thermal/intel/intel_tcc.c new file +7
-0+int intel_tcc_get_tjmax (int cpu,int *tjmax) +{ +u32 eax, edx; +int err; + + err =rdmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , + &eax, &edx);The current trend is to align the arguments after a line break with the first one, but I would just put them all on the same line (and below too).
drivers/thermal/intel/intel_tcc.c line 32
Quoted 4 lines
drivers/thermal/intel/intel_tcc.c new file +4
-0+if (err) +return err; + + *tjmax = (eax >>16 ) &0xff ;This means that the tjmax value cannot be negative.
drivers/thermal/intel/intel_tcc.c line 34
Quoted 2 lines
drivers/thermal/intel/intel_tcc.c new file +2
-0+ +return *tjmax ?0 : -EINVAL ;So the return value of this function could be tjmax if positive or a negative error code otherwise. No return pointers needed.
And why do you want to return
-EINVAL(rather than any other error code) if tjmax turns out to be 0?Quoted 15 lines
drivers/thermal/intel/intel_tcc.c new file +15
-0+} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_tjmax,INTEL_TCC ); + +/** +* intel_tcc_get_offset() - returns the TCC Offset value to Tjmax +* @cpu: cpu that the MSR should be run on. +* @offset: a valid pointer to where to store the offset value +* +* Get the TCC offset value to Tjmax. The effective thermal throttling or TCC +* activation temperature equals "Tjmax" - "TCC Offset", in degrees C. +* +* Return: On success returns 0, an error code otherwise +*/ + +int intel_tcc_get_offset (int cpu,int *offset)drivers/thermal/intel/intel_tcc.c line 59
Quoted 10 lines
drivers/thermal/intel/intel_tcc.c new file +10
-0+{ +u32 eax, edx; +int err; + + err =rdmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , + &eax, &edx); +if (err) +return err; + + *offset = (eax >>24 ) &0x3f ;Well, offset cannot be negative here, so (again) the return value of this function could be interpreted as the offsent (if non-negative) or a negative error code on failure.
drivers/thermal/intel/intel_tcc.c line 68
Quoted 9 lines
drivers/thermal/intel/intel_tcc.c new file +9
-0+ +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_offset,INTEL_TCC ); + +/** +* intel_tcc_set_offset() - set the TCC offset value to Tjmax +* @cpu: cpu that the MSR should be run on. +* @offset: TCC offset value in degree C I think that this cannot be negative, so maybe say "in K" instead of "in degree C"?
And maybe it's better to pass u8 here?
Quoted 12 lines
drivers/thermal/intel/intel_tcc.c new file +12
-0+* +* Set the TCC Offset value to Tjmax. The effective thermal throttling or TCC +* activation temperature equals "Tjmax" - "TCC Offset", in degree C. +* +* Return: On success returns 0, an error code otherwise +*/ + +int intel_tcc_set_offset (int cpu,int offset) +{ +u32 eax, edx; +int err; +drivers/thermal/intel/intel_tcc.c line 90
Quoted 10 lines
drivers/thermal/intel/intel_tcc.c new file +10
-0+if (offset >0x3f ) +return -EINVAL ; + + err =rdmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , + &eax, &edx); +if (err) +return err; + +if (eax &BIT (31 )) +return -EPERM ;Why
-EPERM?drivers/thermal/intel/intel_tcc.c line 93
Quoted 3 lines
drivers/thermal/intel/intel_tcc.c new file +3
-0+ + eax &= ~(0x3f <<24 ); + eax |= (offset <<24 );The parens are not needed AFAICS.
drivers/thermal/intel/intel_tcc.c line 95
Quoted 2 lines
drivers/thermal/intel/intel_tcc.c new file +2
-0+ +return wrmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , eax, edx);So is any protection against concurrent access needed here? Like what if two different callers invoke this function at the same time for the same CPU?
Quoted 17 lines
drivers/thermal/intel/intel_tcc.c new file +17
-0+} +EXPORT_SYMBOL_NS_GPL (intel_tcc_set_offset,INTEL_TCC ); + +/** +* intel_tcc_get_temp() - returns the current temperature +* @cpu: cpu that the MSR should be run on. +* @pkg: true: Package Thermal Sensor. false: Core Thermal Sensor. +* @temp: a valid pointer to where to store the resulting temperature +* +* Get the current temperature returned by the CPU core/package level +* thermal sensor, in degrees C. +* +* Return: On success returns 0, an error code otherwise +*/ +int intel_tcc_get_temp (int cpu,bool pkg,int *temp) +{ +u32 eax, edx;
Quoted 8 lines
drivers/thermal/intel/intel_tcc.c line 118
Quoted 6 lines
drivers/thermal/intel/intel_tcc.c new file +6
-0+u32 msr = pkg ?MSR_IA32_PACKAGE_THERM_STATUS :MSR_IA32_THERM_STATUS ; +int tjmax, err; + + err =intel_tcc_get_tjmax (cpu, &tjmax); +if (err) +return err;Well, what if somebody change tjmax on this cpu while this function is running?
Sorry, scratch this. The offset can be updated, not tjmax.
But can tjmax change anyway or is it just a property of the hardware?
Quoted 4 lines
Quoted 4 lines
drivers/thermal/intel/intel_tcc.c new file +4
-0+ + err =rdmsr_safe_on_cpu (cpu, msr, &eax, &edx); +if (err) +return err;
Quoted 8 lines
drivers/thermal/intel/intel_tcc.c line 130
Quoted 8 lines
drivers/thermal/intel/intel_tcc.c new file +8
-0+ +if (eax &0x80000000 ) { + *temp = tjmax - ((eax >>16 ) &0x7f ); +return 0 ; + } +return -EINVAL ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_temp,INTEL_TCC );
And one more thing, but rather for the future.
Reading from these MSRs can be costly, especially when done on a remote CPU, so would it make sense to cache the retrieved values in case they are read relatively often?
Zhang Rui
reviewerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
drivers/thermal/intel/intel_tcc.c new file +4
-0+ + err =rdmsr_safe_on_cpu (cpu, msr, &eax, &edx); +if (err) +return err;Quoted 8 lines
drivers/thermal/intel/intel_tcc.c line 130
Quoted 8 lines
drivers/thermal/intel/intel_tcc.c new file +8
-0+ +if (eax &0x80000000 ) { + *temp = tjmax - ((eax >>16 ) &0x7f ); +return 0 ; + } +return -EINVAL ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_temp,INTEL_TCC );And one more thing, but rather for the future.
Quoted 4 lines
Reading from these MSRs can be costly, especially when done on a remote CPU, so would it make sense to cache the retrieved values in case they are read relatively often?like the coretemp driver already has similar code.
For now, this API is called from sysfs attribute callback so it is okay to add a unified rate_limit here, say 1 second like coretemp driver.
But for the future, I'm not sure. This really depends on the expectation of the caller.
BTW, this reminds me that I can improve the code a little bit, to avoid reading MSR from remote CPU when possible.
thanks,
rui
Zhang Rui
reviewerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
In reply to Rafael J. WysockiQuoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Zhang Rui
There are several different drivers that accesses the Intel TCC (thermal control circuitry) MSRs, and each of them has its own implementation for the same functionalities, e.g. getting the current
temperature, getting thetj_max, and getting/setting thetj_maxoffset.Introduce a library to unify the code for Intel CPU TCC MSR access.
At the same time, ensure the temperature is got based on the updated
tjmax value because tjmax can be changed at runtime for cases like the Intel SST-PP (Intel Speed Select Technology - Performance Profile)
level change.
Quoted 5 lines
Quoted 1 line
Signed-off-by Zhang Rui <[email protected]>Nice series, overall I like it a lot, but I have some comments regarding this particular patch (below). Some of them are arguably minor, but at least one thing is more serious.
Hi, Rafael,
Thanks for reviewing the patch set.
Quoted 66 lines
Quoted 66 lines
--- drivers/thermal/intel/Kconfig | 4 + drivers/thermal/intel/Makefile | 1 + drivers/thermal/intel/intel_tcc.c | 131 ++++++++++++++++++++++++++++++ include/linux/intel_tcc.h | 18 ++++ 4 files changed, 154 insertions(+) create mode 100644 drivers/thermal/intel/intel_tcc.c create mode 100644 include/linux/intel_tcc.hdrivers/thermal/intel/Kconfig +4
-0@@ -12,6 +12,10 @@ config X86_THERMAL_VECTOR def_bool y depends on X86 && CPU_SUP_INTEL && X86_LOCAL_APIC +config INTEL_TCC + bool + depends on X86 + config X86_PKG_TEMP_THERMAL tristate "X86 package temperature thermal driver" depends on X86_THERMAL_VECTORdrivers/thermal/intel/Makefile +1
-0@@ -2,6 +2,7 @@ # # Makefile for various Intel thermal drivers. +obj-$(CONFIG_INTEL_TCC) += intel_tcc.o obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o obj-$(CONFIG_INTEL_SOC_DTS_IOSF_CORE) += intel_soc_dts_iosf.odrivers/thermal/intel/intel_tcc.c new file +3
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* intel_tcc.c - Library for Intel TCC (thermal control circuitry) MSR access
+ * Copyright (c) 2022, Intel Corporation.
+ */drivers/thermal/intel/intel_tcc.c new file +7
-0+ +#include <linux/errno.h> +#include <linux/intel_tcc.h> +#include <asm/msr.h> + +/** +* intel_tcc_get_tjmax() - returns the default TCC activation Temperature
+ * @cpu: cpu that the MSR should be run on.
+ * @tjmax: a valid pointer to where to store the Tjmax value
+ *
+ * Get the TjMax value, which is the default thermal throttling or TCC
Quoted 8 lines
Quoted 5 lines
+ * activation temperature in degrees C.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */
+This extra empty line is not needed (and not desirable even). And same below.
Sure. will remove it.
Quoted 12 lines
drivers/thermal/intel/intel_tcc.c line 28
Quoted 8 lines
drivers/thermal/intel/intel_tcc.c new file +7
-0+int intel_tcc_get_tjmax (int cpu,int *tjmax) +{ +u32 eax, edx; +int err; + + err =rdmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , + &eax, &edx);The current trend is to align the arguments after a line break with the first one, but I would just put them all on the same line (and below too).
I agree putting them in the same line looks prettier.
Quoted 6 lines
drivers/thermal/intel/intel_tcc.c line 32
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +4
-0+if (err) +return err; + + *tjmax = (eax >>16 ) &0xff ;
Quoted 7 lines
This means that the tjmax value cannot be negative.
drivers/thermal/intel/intel_tcc.c
Quoted 2 lines
drivers/thermal/intel/intel_tcc.c new file +2
-0+ +return *tjmax ?0 : -EINVAL ;So the return value of this function could be tjmax if positive or a negative error code otherwise. No return pointers needed.
I tried both. And I think I chose this solution just because it makes the following cleanup patches in this series looks prettier.
I will try your suggestion, and if there is any other reason I wrote it in this way, I will find it out again. :p
Quoted 3 lines
And why do you want to return
-EINVAL(rather than any other error code) if tjmax turns out to be 0?
Because x86_pkg_temp_thermal driver returns -EINVAL previously. Any suggestions on this?
Quoted 33 lines
Quoted 17 lines
drivers/thermal/intel/intel_tcc.c new file +9
-0+} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_tjmax,INTEL_TCC ); + +/** +* intel_tcc_get_offset() - returns the TCC Offset value to Tjmax +* @cpu: cpu that the MSR should be run on. +* @offset: a valid pointer to where to store the offset value +* +* Get the TCC offset value to Tjmax. The effective thermal throttling or TCC
+ * activation temperature equals "Tjmax" - "TCC Offset", in degrees C.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */drivers/thermal/intel/intel_tcc.c new file +2
-0+ +int intel_tcc_get_offset (int cpu,int *offset)drivers/thermal/intel/intel_tcc.c line 59
Quoted 10 lines
drivers/thermal/intel/intel_tcc.c new file +10
-0+{ +u32 eax, edx; +int err; + + err =rdmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , + &eax, &edx); +if (err) +return err; + + *offset = (eax >>24 ) &0x3f ;Well, offset cannot be negative here, so (again) the return value of this function could be interpreted as the offsent (if non-negative) or
a negative error code on failure.
Quoted 12 lines
drivers/thermal/intel/intel_tcc.c line 68
Quoted 9 lines
drivers/thermal/intel/intel_tcc.c new file +9
-0+ +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_offset,INTEL_TCC ); + +/** +* intel_tcc_set_offset() - set the TCC offset value to Tjmax +* @cpu: cpu that the MSR should be run on. +* @offset: TCC offset value in degree C I think that this cannot be negative, so maybe say "in K" instead of "in degree C"?
degree C is the unit used in the Intel SDM, so better to keep this comment aligned.
Quoted 2 lines
And maybe it's better to pass u8 here?
sounds good, will do in next version.
Quoted 19 lines
Quoted 19 lines
+ *
+ * Set the TCC Offset value to Tjmax. The effective thermal throttling or TCC
+ * activation temperature equals "Tjmax" - "TCC Offset", in degree C.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */drivers/thermal/intel/intel_tcc.c new file +10
-0+ +int intel_tcc_set_offset (int cpu,int offset) +{ +u32 eax, edx; +int err; + +if (offset >0x3f ) +return -EINVAL ; + + err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET,
Quoted 8 lines
drivers/thermal/intel/intel_tcc.c line 90
Quoted 6 lines
drivers/thermal/intel/intel_tcc.c new file +6
-0+ &eax, &edx); +if (err) +return err; + +if (eax &BIT (31 )) +return -EPERM ;Why
-EPERM?
Bit 31 set means the MSR is locked, and os software cannot write it. should I use -EACCES instead?
Quoted 7 lines
drivers/thermal/intel/intel_tcc.c line 93
Quoted 4 lines
drivers/thermal/intel/intel_tcc.c new file +3
-0+ + eax &= ~(0x3f <<24 ); + eax |= (offset <<24 );The parens are not needed AFAICS.
Agreed.
Quoted 9 lines
Quoted 3 lines
drivers/thermal/intel/intel_tcc.c new file +2
-0+ + return wrmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET,eax, edx);
So is any protection against concurrent access needed here? Like what
if two different callers invoke this function at the same time for the
same CPU?
Given that the tcc offset is the only field that kernel code writes, all the other bits won't change, so this is not a problem.
Quoted 22 lines
Quoted 22 lines
drivers/thermal/intel/intel_tcc.c new file +8
-0+} +EXPORT_SYMBOL_NS_GPL (intel_tcc_set_offset,INTEL_TCC ); + +/** +* intel_tcc_get_temp() - returns the current temperature +* @cpu: cpu that the MSR should be run on. +* @pkg: true: Package Thermal Sensor. false: Core Thermal Sensor. +* @temp: a valid pointer to where to store the resulting temperature
+ *
+ * Get the current temperature returned by the CPU core/package level
+ * thermal sensor, in degrees C.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */drivers/thermal/intel/intel_tcc.c new file +4
-0+int intel_tcc_get_temp (int cpu,bool pkg,int *temp) +{ +u32 eax, edx; + u32 msr = pkg ? MSR_IA32_PACKAGE_THERM_STATUS :
MSR_IA32_THERM_STATUS;
Quoted 8 lines
drivers/thermal/intel/intel_tcc.c line 118
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +5
-0+int tjmax, err; + + err =intel_tcc_get_tjmax (cpu, &tjmax); +if (err) +return err;Well, what if somebody change tjmax on this cpu while this function is running?
tjmax is read only. Only firmware can change its value at runtime, say this field is updated when SST-PP level is changed.
thanks,
rui
Quoted 39 lines
Quoted 39 lines
drivers/thermal/intel/intel_tcc.c new file +13
-0+ + err =rdmsr_safe_on_cpu (cpu, msr, &eax, &edx); +if (err) +return err; + +if (eax &0x80000000 ) { + *temp = tjmax - ((eax >>16 ) &0x7f ); +return 0 ; + } +return -EINVAL ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_temp,INTEL_TCC ); +include/linux/intel_tcc.h new file +18
-1@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* header for Intel TCC (thermal control circuitry) library +* +* Copyright (C) 2022 Intel Corporation. +*/ + +#ifndef __INTEL_TCC_H__ +#define __INTEL_TCC_H__ + +#include <linux/types.h> + +int intel_tcc_get_tjmax (int cpu,int *tjmax); +int intel_tcc_get_offset (int cpu,int *offset); +int intel_tcc_set_offset (int cpu,int offset); +int intel_tcc_get_temp (int cpu,bool pkg,int *temp); + +#endif /* __INTEL_TCC_H__ */ --
Rafael J. Wysocki
maintainerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 140 lines · Zhang Rui
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Zhang Rui
There are several different drivers that accesses the Intel TCC (thermal control circuitry) MSRs, and each of them has its own implementation for the same functionalities, e.g. getting the current
temperature, getting thetj_max, and getting/setting thetj_maxoffset.Introduce a library to unify the code for Intel CPU TCC MSR access.
At the same time, ensure the temperature is got based on the updated
tjmax value because tjmax can be changed at runtime for cases like the Intel SST-PP (Intel Speed Select Technology - Performance Profile)
level change.Quoted 5 lines
Quoted 1 line
Signed-off-by Zhang Rui <[email protected]>Nice series, overall I like it a lot, but I have some comments regarding this particular patch (below). Some of them are arguably minor, but at least one thing is more serious.
Hi, Rafael,
Thanks for reviewing the patch set.
Quoted 66 lines
Quoted 66 lines
--- drivers/thermal/intel/Kconfig | 4 + drivers/thermal/intel/Makefile | 1 + drivers/thermal/intel/intel_tcc.c | 131 ++++++++++++++++++++++++++++++ include/linux/intel_tcc.h | 18 ++++ 4 files changed, 154 insertions(+) create mode 100644 drivers/thermal/intel/intel_tcc.c create mode 100644 include/linux/intel_tcc.hdrivers/thermal/intel/Kconfig +4
-0@@ -12,6 +12,10 @@ config X86_THERMAL_VECTOR def_bool y depends on X86 && CPU_SUP_INTEL && X86_LOCAL_APIC +config INTEL_TCC + bool + depends on X86 + config X86_PKG_TEMP_THERMAL tristate "X86 package temperature thermal driver" depends on X86_THERMAL_VECTORdrivers/thermal/intel/Makefile +1
-0@@ -2,6 +2,7 @@ # # Makefile for various Intel thermal drivers. +obj-$(CONFIG_INTEL_TCC) += intel_tcc.o obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o obj-$(CONFIG_INTEL_SOC_DTS_IOSF_CORE) += intel_soc_dts_iosf.odrivers/thermal/intel/intel_tcc.c new file +3
-0@@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* intel_tcc.c - Library for Intel TCC (thermal control circuitry) MSR access
+ * Copyright (c) 2022, Intel Corporation.
+ */drivers/thermal/intel/intel_tcc.c new file +7
-0+ +#include <linux/errno.h> +#include <linux/intel_tcc.h> +#include <asm/msr.h> + +/** +* intel_tcc_get_tjmax() - returns the default TCC activation Temperature
+ * @cpu: cpu that the MSR should be run on.
+ * @tjmax: a valid pointer to where to store the Tjmax value
+ *
+ * Get the TjMax value, which is the default thermal throttling or TCCQuoted 8 lines
Quoted 5 lines
+ * activation temperature in degrees C.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */
+This extra empty line is not needed (and not desirable even). And same below.
Sure. will remove it.
Quoted 12 lines
drivers/thermal/intel/intel_tcc.c line 28
Quoted 8 lines
drivers/thermal/intel/intel_tcc.c new file +7
-0+int intel_tcc_get_tjmax (int cpu,int *tjmax) +{ +u32 eax, edx; +int err; + + err =rdmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , + &eax, &edx);The current trend is to align the arguments after a line break with the first one, but I would just put them all on the same line (and below too).
I agree putting them in the same line looks prettier.
Quoted 6 lines
drivers/thermal/intel/intel_tcc.c line 32
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +4
-0+if (err) +return err; + + *tjmax = (eax >>16 ) &0xff ;Quoted 7 lines
This means that the tjmax value cannot be negative.
drivers/thermal/intel/intel_tcc.c
Quoted 2 lines
drivers/thermal/intel/intel_tcc.c new file +2
-0+ +return *tjmax ?0 : -EINVAL ;So the return value of this function could be tjmax if positive or a negative error code otherwise. No return pointers needed.
I tried both. And I think I chose this solution just because it makes the following cleanup patches in this series looks prettier.
I will try your suggestion, and if there is any other reason I wrote it in this way, I will find it out again. :p
Quoted 1 line
Quoted 5 lines
Quoted 2 lines
And why do you want to return
-EINVAL(rather than any other error code) if tjmax turns out to be 0?Because
x86_pkg_temp_thermaldriver returns-EINVALpreviously. Any suggestions on this?
I would use -ENODATA.
Quoted 46 lines
Quoted 33 lines
Quoted 17 lines
drivers/thermal/intel/intel_tcc.c new file +9
-0+} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_tjmax,INTEL_TCC ); + +/** +* intel_tcc_get_offset() - returns the TCC Offset value to Tjmax +* @cpu: cpu that the MSR should be run on. +* @offset: a valid pointer to where to store the offset value +* +* Get the TCC offset value to Tjmax. The effective thermal throttling or TCC
+ * activation temperature equals "Tjmax" - "TCC Offset", in degrees C.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */drivers/thermal/intel/intel_tcc.c new file +2
-0+ +int intel_tcc_get_offset (int cpu,int *offset)drivers/thermal/intel/intel_tcc.c line 59
Quoted 10 lines
drivers/thermal/intel/intel_tcc.c new file +10
-0+{ +u32 eax, edx; +int err; + + err =rdmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , + &eax, &edx); +if (err) +return err; + + *offset = (eax >>24 ) &0x3f ;Well, offset cannot be negative here, so (again) the return value of this function could be interpreted as the offsent (if non-negative) or
a negative error code on failure.Quoted 12 lines
drivers/thermal/intel/intel_tcc.c line 68
Quoted 9 lines
drivers/thermal/intel/intel_tcc.c new file +9
-0+ +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_offset,INTEL_TCC ); + +/** +* intel_tcc_set_offset() - set the TCC offset value to Tjmax +* @cpu: cpu that the MSR should be run on. +* @offset: TCC offset value in degree C I think that this cannot be negative, so maybe say "in K" instead of "in degree C"?
Quoted 2 lines
degree C is the unit used in the Intel SDM, so better to keep this comment aligned.
OK
Quoted 33 lines
Quoted 2 lines
And maybe it's better to pass u8 here?
sounds good, will do in next version.
Quoted 19 lines
Quoted 19 lines
+ *
+ * Set the TCC Offset value to Tjmax. The effective thermal throttling or TCC
+ * activation temperature equals "Tjmax" - "TCC Offset", in degree C.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */drivers/thermal/intel/intel_tcc.c new file +10
-0+ +int intel_tcc_set_offset (int cpu,int offset) +{ +u32 eax, edx; +int err; + +if (offset >0x3f ) +return -EINVAL ; + + err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET,Quoted 8 lines
drivers/thermal/intel/intel_tcc.c line 90
Quoted 6 lines
drivers/thermal/intel/intel_tcc.c new file +6
-0+ &eax, &edx); +if (err) +return err; + +if (eax &BIT (31 )) +return -EPERM ;Why
-EPERM?
Quoted 2 lines
Bit 31 set means the MSR is locked, and os software cannot write it. should I use
-EACCESinstead?
No, -EPERM is fine in this case, but a short comment would be useful.
Quoted 13 lines
Quoted 7 lines
drivers/thermal/intel/intel_tcc.c line 93
Quoted 4 lines
drivers/thermal/intel/intel_tcc.c new file +3
-0+ + eax &= ~(0x3f <<24 ); + eax |= (offset <<24 );The parens are not needed AFAICS.
Agreed.
Quoted 4 lines
Quoted 3 lines
drivers/thermal/intel/intel_tcc.c new file +2
-0+ + return wrmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET,eax, edx);
Quoted 8 lines
Quoted 5 lines
So is any protection against concurrent access needed here? Like what
if two different callers invoke this function at the same time for the
same CPU?Given that the tcc offset is the only field that kernel code writes, all the other bits won't change, so this is not a problem.
OK
Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
drivers/thermal/intel/intel_tcc.c new file +8
-0+} +EXPORT_SYMBOL_NS_GPL (intel_tcc_set_offset,INTEL_TCC ); + +/** +* intel_tcc_get_temp() - returns the current temperature +* @cpu: cpu that the MSR should be run on. +* @pkg: true: Package Thermal Sensor. false: Core Thermal Sensor. +* @temp: a valid pointer to where to store the resulting temperature
+ *
+ * Get the current temperature returned by the CPU core/package level
+ * thermal sensor, in degrees C.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */drivers/thermal/intel/intel_tcc.c new file +4
-0+int intel_tcc_get_temp (int cpu,bool pkg,int *temp) +{ +u32 eax, edx; + u32 msr = pkg ? MSR_IA32_PACKAGE_THERM_STATUS :
MSR_IA32_THERM_STATUS;Quoted 8 lines
drivers/thermal/intel/intel_tcc.c line 118
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +5
-0+int tjmax, err; + + err =intel_tcc_get_tjmax (cpu, &tjmax); +if (err) +return err;Well, what if somebody change tjmax on this cpu while this function is running?
Quoted 2 lines
tjmax is read only. Only firmware can change its value at runtime, say this field is updated when SST-PP level is changed.
Do we get any type of notification on tjmax changes, or do we need to poll for it?
Zhang Rui
reviewerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 16 lines
Quoted 16 lines
Quoted 7 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ + return *tjmax ? 0 : -EINVAL;So the return value of this function could be tjmax if positive or a
negative error code otherwise. No return pointers needed.I tried both. And I think I chose this solution just because it makes
the following cleanup patches in this series looks prettier.I will try your suggestion, and if there is any other reason I wrote it
in this way, I will find it out again. :p
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
And why do you want to return
-EINVAL(rather than any other error
code) if tjmax turns out to be 0?Because
x86_pkg_temp_thermaldriver returns-EINVALpreviously. Any suggestions on this?I would use
-ENODATA.
Sure, will do.
Quoted 33 lines
Quoted 33 lines
Quoted 32 lines
Quoted 23 lines
drivers/thermal/intel/intel_tcc.c new file +7
-0+} +EXPORT_SYMBOL_NS_GPL (intel_tcc_set_offset,INTEL_TCC ); + +/** +* intel_tcc_get_temp() - returns the current temperature +* @cpu: cpu that the MSR should be run on. +* @pkg: true: Package Thermal Sensor. false: Core Thermal Sensor.
+ * @temp: a valid pointer to where to store the resulting temperature
+ *
+ * Get the current temperature returned by the CPU core/package
level
+ * thermal sensor, in degrees C.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */drivers/thermal/intel/intel_tcc.c new file +4
-0+int intel_tcc_get_temp (int cpu,bool pkg,int *temp) +{ +u32 eax, edx; + u32 msr = pkg ? MSR_IA32_PACKAGE_THERM_STATUS :
MSR_IA32_THERM_STATUS;drivers/thermal/intel/intel_tcc.c line 118
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +5
-0+int tjmax, err; + + err =intel_tcc_get_tjmax (cpu, &tjmax); +if (err) +return err;Well, what if somebody change tjmax on this cpu while this function
is running?
Quoted 6 lines
Quoted 3 lines
tjmax is read only. Only firmware can change its value at runtime, say
this field is updated when SST-PP level is changed.Do we get any type of notification on tjmax changes, or do we need to poll for it?
I'm not aware of such a notification.
Srinivas, do you know if there is one?
thanks,
rui
Re: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 2 lines · Zhang Rui
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
[...]
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
Well, what if somebody change tjmax on this cpu while this function
is running?tjmax is read only. Only firmware can change its value at runtime,
say
this field is updated when SST-PP level is changed.
Quoted 6 lines
Quoted 3 lines
Do we get any type of notification on tjmax changes, or do we need to
poll for it?I'm not aware of such a notification.
Srinivas, do you know if there is one?
There is no explicit notification. You can infer from HWP guaranteed change interrupt.
Thanks,
Srinivas
Quoted 5 lines
thanks,
rui
Zhang Rui
reviewerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 18 lines · srinivas pandruvada
On Fri, 2022-12-09 at 21:32 +0800, Zhang Rui wrote:
[...]
Quoted 14 lines
Quoted 13 lines
Quoted 8 lines
Quoted 3 lines
Well, what if somebody change tjmax on this cpu while this function
is running?tjmax is read only. Only firmware can change its value at runtime,
say
this field is updated when SST-PP level is changed.Do we get any type of notification on tjmax changes, or do we need
to
poll for it?
Quoted 4 lines
Quoted 2 lines
I'm not aware of such a notification.
Srinivas, do you know if there is one?There is no explicit notification. You can infer from HWP guaranteed change interrupt.
But
1. tjmax may or may not change when HWP guaranteed change interrupt fires. And it does not change in most cases, right?
2. HWP guaranteed change interrupt is per CPU, so if we update tjmax in the interrupt handler, we also need to cache the timestamp to avoid duplicate updates from multiple CPUs in the same package/die.
Given that the TCC lib APIs may or may not be called, depends on the usersapce behavior, do you think this is a win by adding this extra cost?
Instead, update the tjmax value only when the API is called, and then cache it to handle frequent read is sufficient. what do you think?
thanks,
rui
Quoted 10 lines
Thanks,
SrinivasQuoted 4 lines
thanks,
rui
Rafael J. Wysocki
maintainerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 32 lines · Zhang Rui
Quoted 18 lines · srinivas pandruvada
On Fri, 2022-12-09 at 21:32 +0800, Zhang Rui wrote:
[...]
Quoted 14 lines
Quoted 13 lines
Quoted 8 lines
Quoted 3 lines
Well, what if somebody change tjmax on this cpu while this function
is running?tjmax is read only. Only firmware can change its value at runtime,
say
this field is updated when SST-PP level is changed.Do we get any type of notification on tjmax changes, or do we need
to
poll for it?Quoted 4 lines
Quoted 2 lines
I'm not aware of such a notification.
Srinivas, do you know if there is one?There is no explicit notification. You can infer from HWP guaranteed change interrupt.
But
1. tjmax may or may not change when HWP guaranteed change interrupt fires. And it does not change in most cases, right?
2. HWP guaranteed change interrupt is per CPU, so if we update tjmax in the interrupt handler, we also need to cache the timestamp to avoid duplicate updates from multiple CPUs in the same package/die.
Quoted 3 lines
Given that the TCC lib APIs may or may not be called, depends on the usersapce behavior, do you think this is a win by adding this extra cost?
Not really.
Quoted 2 lines
Instead, update the tjmax value only when the API is called, and then cache it to handle frequent read is sufficient. what do you think?
Yes, that should be sufficient, but I wouldn't do it in this series anyway.
Zhang Rui
reviewerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
In reply to Zhang RuiQuoted 15 lines
Quoted 6 lines
drivers/thermal/intel/intel_tcc.c line 32
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +4
-0+if (err) +return err; + + *tjmax = (eax >>16 ) &0xff ;Quoted 8 lines
This means that the tjmax value cannot be negative.
Review
Quoted 2 lines
(quoted diff) +2
-0+ + return *tjmax ? 0 : -EINVAL;So the return value of this function could be tjmax if positive or a
negative error code otherwise. No return pointers needed.
Quoted 6 lines
I tried both. And I think I chose this solution just because it makes the following cleanup patches in this series looks prettier.
I will try your suggestion, and if there is any other reason I wrote it
in this way, I will find it out again. :p
I see.
Say, we have to use
intel_tcc_get_temp(int cpu, int *temp)
so I keep the same format for all the intel_tcc_get_XXX APIs
intel_tcc_get_tjmax(int cpu, int *tjmax)intel_tcc_get_offset(int cpu, int *offset)
so that the return value is decoded in the same way. This helps avoid return value check mistakes for the callers.
surely I can remove the return pointer if you still prefer that. :p
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +5
-0+ +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_offset,INTEL_TCC ); +Quoted 8 lines
Quoted 4 lines
+/**
+ *intel_tcc_set_offset()- set the TCC offset value to Tjmax
+ * @cpu: cpu that the MSR should be run on.
+ * @offset: TCC offset value in degree CI think that this cannot be negative, so maybe say "in K" instead of
"in degree C"?
Quoted 7 lines
degree C is the unit used in the Intel SDM, so better to keep this comment aligned.
Quoted 1 line
And maybe it's better to pass u8 here?
sounds good, will do in next version.
to keep consistent, we can use either
int intel_tcc_get_offset(int cpu)
int intel_tcc_set_offset(int cpu, int offset)
or
int intel_tcc_get_offset(int cpu, u8 *offset)
int intel_tcc_set_offset(int cpu, u8 offset)
or else callers need to declare 'offset' but with different type, when getting and setting it, which looks strange.
thanks,
rui
Quoted 129 lines
Quoted 19 lines
Quoted 19 lines
+ *
+ * Set the TCC Offset value to Tjmax. The effective thermal throttling or TCC
+ * activation temperature equals "Tjmax" - "TCC Offset", in degree
C.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */drivers/thermal/intel/intel_tcc.c new file +10
-0+ +int intel_tcc_set_offset (int cpu,int offset) +{ +u32 eax, edx; +int err; + +if (offset >0x3f ) +return -EINVAL ; + + err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET,Quoted 8 lines
drivers/thermal/intel/intel_tcc.c line 90
Quoted 6 lines
drivers/thermal/intel/intel_tcc.c new file +6
-0+ &eax, &edx); +if (err) +return err; + +if (eax &BIT (31 )) +return -EPERM ;Why
-EPERM?Bit 31 set means the MSR is locked, and os software cannot write it. should I use
-EACCESinstead?Quoted 6 lines
drivers/thermal/intel/intel_tcc.c line 93
Quoted 3 lines
drivers/thermal/intel/intel_tcc.c new file +3
-0+ + eax &= ~(0x3f <<24 ); + eax |= (offset <<24 );The parens are not needed AFAICS.
Agreed.
Quoted 10 lines
Quoted 4 lines
(quoted diff) +2
-0+ + return wrmsr_safe_on_cpu(cpu,
MSR_IA32_TEMPERATURE_TARGET,
eax, edx);So is any protection against concurrent access needed here? Like what
if two different callers invoke this function at the same time for the
same CPU?Given that the tcc offset is the only field that kernel code writes, all the other bits won't change, so this is not a problem.
Quoted 22 lines
Quoted 22 lines
drivers/thermal/intel/intel_tcc.c new file +7
-0+} +EXPORT_SYMBOL_NS_GPL (intel_tcc_set_offset,INTEL_TCC ); + +/** +* intel_tcc_get_temp() - returns the current temperature +* @cpu: cpu that the MSR should be run on. +* @pkg: true: Package Thermal Sensor. false: Core Thermal Sensor.
+ * @temp: a valid pointer to where to store the resulting temperature
+ *
+ * Get the current temperature returned by the CPU core/package level
+ * thermal sensor, in degrees C.
+ *
+ * Return: On success returns 0, an error code otherwise
+ */drivers/thermal/intel/intel_tcc.c new file +4
-0+int intel_tcc_get_temp (int cpu,bool pkg,int *temp) +{ +u32 eax, edx; + u32 msr = pkg ? MSR_IA32_PACKAGE_THERM_STATUS :
MSR_IA32_THERM_STATUS;Quoted 8 lines
drivers/thermal/intel/intel_tcc.c line 118
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +5
-0+int tjmax, err; + + err =intel_tcc_get_tjmax (cpu, &tjmax); +if (err) +return err;Well, what if somebody change tjmax on this cpu while this function is running?
tjmax is read only. Only firmware can change its value at runtime, say
this field is updated when SST-PP level is changed.thanks,
ruiQuoted 39 lines
Quoted 39 lines
drivers/thermal/intel/intel_tcc.c new file +13
-0+ + err =rdmsr_safe_on_cpu (cpu, msr, &eax, &edx); +if (err) +return err; + +if (eax &0x80000000 ) { + *temp = tjmax - ((eax >>16 ) &0x7f ); +return 0 ; + } +return -EINVAL ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_temp,INTEL_TCC ); +include/linux/intel_tcc.h new file +18
-1@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* header for Intel TCC (thermal control circuitry) library +* +* Copyright (C) 2022 Intel Corporation. +*/ + +#ifndef __INTEL_TCC_H__ +#define __INTEL_TCC_H__ + +#include <linux/types.h> + +int intel_tcc_get_tjmax (int cpu,int *tjmax); +int intel_tcc_get_offset (int cpu,int *offset); +int intel_tcc_set_offset (int cpu,int offset); +int intel_tcc_get_temp (int cpu,bool pkg,int *temp); + +#endif /* __INTEL_TCC_H__ */ --
Rafael J. Wysocki
maintainerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 19 lines · Zhang Rui
Quoted 19 lines
Quoted 7 lines
drivers/thermal/intel/intel_tcc.c line 32
Quoted 6 lines
drivers/thermal/intel/intel_tcc.c new file +4
-0+if (err) +return err; + + *tjmax = (eax >>16 ) &0xff ;Quoted 8 lines
This means that the tjmax value cannot be negative.
Review
Quoted 2 lines
(quoted diff) +2
-0+ + return *tjmax ? 0 : -EINVAL;So the return value of this function could be tjmax if positive or a
negative error code otherwise. No return pointers needed.I tried both. And I think I chose this solution just because it makes the following cleanup patches in this series looks prettier.
Quoted 8 lines
Quoted 3 lines
I will try your suggestion, and if there is any other reason I wrote it
in this way, I will find it out again. :pI see.
Say, we have to use
intel_tcc_get_temp(int cpu, int *temp)
Do we?
Quoted 9 lines
so I keep the same format for all the
intel_tcc_get_XXXAPIs
intel_tcc_get_tjmax(int cpu, int *tjmax)intel_tcc_get_offset(int cpu, int *offset)so that the return value is decoded in the same way. This helps avoid return value check mistakes for the callers.
surely I can remove the return pointer if you still prefer that. :p
Using a function value directly is very much preferred unless there really are two values to return.
In these particular cases a negative return value can be clearly interpreted as an error condition, so using the return value directly is sufficient.
Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +5
-0+ +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_offset,INTEL_TCC ); +Quoted 8 lines
Quoted 4 lines
+/**
+ *intel_tcc_set_offset()- set the TCC offset value to Tjmax
+ * @cpu: cpu that the MSR should be run on.
+ * @offset: TCC offset value in degree CI think that this cannot be negative, so maybe say "in K" instead of
"in degree C"?degree C is the unit used in the Intel SDM, so better to keep this comment aligned.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
And maybe it's better to pass u8 here?
sounds good, will do in next version.
to keep consistent, we can use either
intintel_tcc_get_offset(int cpu)
intintel_tcc_set_offset(int cpu, int offset)
What about intel_tcc_set_offset(int cpu, u8 offset)?
Quoted 6 lines
or
intintel_tcc_get_offset(int cpu, u8 *offset)
intintel_tcc_set_offset(int cpu, u8 offset)or else callers need to declare 'offset' but with different type, when getting and setting it, which looks strange.
Well, one can surely pass an int as a u8 argument and assign a u8 return value to an int variable.
Zhang Rui
reviewerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 27 lines · Rafael J. Wysocki
Quoted 25 lines · Zhang Rui
Quoted 24 lines
Quoted 8 lines
drivers/thermal/intel/intel_tcc.c line 32
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +4
-0+if (err) +return err; + + *tjmax = (eax >>16 ) &0xff ;This means that the tjmax value cannot be negative.
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + return *tjmax ? 0 : -EINVAL;So the return value of this function could be tjmax if positive or
a
negative error code otherwise. No return pointers needed.I tried both. And I think I chose this solution just because it makes
the following cleanup patches in this series looks prettier.I will try your suggestion, and if there is any other reason I wrote
it
in this way, I will find it out again. :p
Quoted 6 lines
Quoted 4 lines
I see.
Say, we have to use
intel_tcc_get_temp(int cpu, int *temp)Do we?
temp = tjmax - digital_readout
tjmax and digital_readout are from MSR and they are both positive values, but temp can be negative in theory.
so are you suggesting that we should treat the negative CPU temperature as an error because this won't happen in real world?
thanks,
rui
Quoted 59 lines
Quoted 11 lines
so I keep the same format for all the
intel_tcc_get_XXXAPIs
intel_tcc_get_tjmax(int cpu, int *tjmax)intel_tcc_get_offset(int cpu, int *offset)so that the return value is decoded in the same way. This helps avoid
return value check mistakes for the callers.surely I can remove the return pointer if you still prefer that. :p
Using a function value directly is very much preferred unless there really are two values to return.
In these particular cases a negative return value can be clearly interpreted as an error condition, so using the return value directly is sufficient.
Quoted 20 lines
Quoted 20 lines
Quoted 7 lines
Quoted 7 lines
drivers/thermal/intel/intel_tcc.c new file +7
-0+ +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_offset,INTEL_TCC ); + +/** +* intel_tcc_set_offset() - set the TCC offset value to Quoted 8 lines
Quoted 3 lines
Tjmax
+ * @cpu: cpu that the MSR should be run on.
+ * @offset: TCC offset value in degree CI think that this cannot be negative, so maybe say "in K" instead
of
"in degree C"?degree C is the unit used in the Intel SDM, so better to keep this
comment aligned.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
And maybe it's better to pass u8 here?
sounds good, will do in next version.
to keep consistent, we can use either
intintel_tcc_get_offset(int cpu)
intintel_tcc_set_offset(int cpu, int offset)What about
intel_tcc_set_offset(int cpu, u8 offset)?Quoted 7 lines
or
intintel_tcc_get_offset(int cpu, u8 *offset)
intintel_tcc_set_offset(int cpu, u8 offset)or else callers need to declare 'offset' but with different type, when
getting and setting it, which looks strange.Well, one can surely pass an int as a u8 argument and assign a u8 return value to an int variable.
Rafael J. Wysocki
maintainerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 32 lines · Zhang Rui
Quoted 30 lines · Rafael J. Wysocki
Quoted 28 lines · Zhang Rui
Quoted 16 lines
Quoted 8 lines
drivers/thermal/intel/intel_tcc.c line 32
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +4
-0+if (err) +return err; + + *tjmax = (eax >>16 ) &0xff ;This means that the tjmax value cannot be negative.
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + return *tjmax ? 0 : -EINVAL;So the return value of this function could be tjmax if positive or
a
negative error code otherwise. No return pointers needed.Quoted 8 lines
I tried both. And I think I chose this solution just because it makes
the following cleanup patches in this series looks prettier.I will try your suggestion, and if there is any other reason I wrote
it
in this way, I will find it out again. :pI see.
Say, we have to use
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
intel_tcc_get_temp(int cpu, int *temp)Do we?
temp = tjmax -
digital_readouttjmax and
digital_readoutare from MSR and they are both positive values, but temp can be negative in theory.
I know, but is this ever expected to happen?
Quoted 2 lines
so are you suggesting that we should treat the negative CPU temperature as an error because this won't happen in real world?
No.
If it's necessary to handle negative temperatures, an int is needed and the additional return value is useful.
Now there is also the question of what the callers will do with a negative temperature value. Do they care?
Zhang Rui
reviewerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 50 lines · Rafael J. Wysocki
Quoted 33 lines · Zhang Rui
Quoted 32 lines · Rafael J. Wysocki
Quoted 30 lines · Zhang Rui
Quoted 21 lines
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (err) + return err; + + *tjmax = (eax >> 16) & 0xff;This means that the tjmax value cannot be negative.
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + return *tjmax ? 0 : -EINVAL;So the return value of this function could be tjmax if positive
or
a
negative error code otherwise. No return pointers needed.I tried both. And I think I chose this solution just because it
makes
the following cleanup patches in this series looks prettier.Quoted 5 lines
I will try your suggestion, and if there is any other reason I
wrote
it
in this way, I will find it out again. :pI see.
Say, we have to useQuoted 8 lines
Quoted 3 lines
Quoted 1 line
intel_tcc_get_temp(int cpu, int *temp)Do we?
temp = tjmax -
digital_readouttjmax and
digital_readoutare from MSR and they are both positive values, but temp can be negative in theory.I know, but is this ever expected to happen?
Quoted 3 lines
so are you suggesting that we should treat the negative CPU temperature
as an error because this won't happen in real world?
Quoted 7 lines
No.
If it's necessary to handle negative temperatures, an int is needed and the additional return value is useful.
Now there is also the question of what the callers will do with a negative temperature value. Do they care?
Currently, all the callers are from sysfs attribute.
for userspace tools, at least thermald ignores negative CPU temperature.
So I will return an error for negative temperature in next version.
thanks,
rui
Rafael J. Wysocki
maintainerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
Quoted 57 lines · Zhang Rui
Quoted 55 lines · Rafael J. Wysocki
Quoted 33 lines · Zhang Rui
Quoted 32 lines · Rafael J. Wysocki
Quoted 30 lines · Zhang Rui
Quoted 21 lines
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (err) + return err; + + *tjmax = (eax >> 16) & 0xff;This means that the tjmax value cannot be negative.
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + return *tjmax ? 0 : -EINVAL;So the return value of this function could be tjmax if positive
or
a
negative error code otherwise. No return pointers needed.I tried both. And I think I chose this solution just because it
makes
the following cleanup patches in this series looks prettier.Quoted 5 lines
I will try your suggestion, and if there is any other reason I
wrote
it
in this way, I will find it out again. :pI see.
Say, we have to useQuoted 8 lines
Quoted 3 lines
Quoted 1 line
intel_tcc_get_temp(int cpu, int *temp)Do we?
temp = tjmax -
digital_readouttjmax and
digital_readoutare from MSR and they are both positive values, but temp can be negative in theory.I know, but is this ever expected to happen?
Quoted 3 lines
so are you suggesting that we should treat the negative CPU temperature
as an error because this won't happen in real world?No.
If it's necessary to handle negative temperatures, an int is needed and the additional return value is useful.
Quoted 7 lines
Quoted 2 lines
Now there is also the question of what the callers will do with a negative temperature value. Do they care?
Currently, all the callers are from sysfs attribute.
for userspace tools, at least thermald ignores negative CPU temperature.
So I will return an error for negative temperature in next version.
Sounds good.
Rafael J. Wysocki
maintainerRe: [PATCH 1/6] thermal/intel: Introduce Intel TCC library
In reply to Rafael J. WysockiQuoted 80 lines · Rafael J. Wysocki
Quoted 19 lines · Zhang Rui
Quoted 19 lines
Quoted 7 lines
drivers/thermal/intel/intel_tcc.c line 32
Quoted 6 lines
drivers/thermal/intel/intel_tcc.c new file +4
-0+if (err) +return err; + + *tjmax = (eax >>16 ) &0xff ;Quoted 8 lines
This means that the tjmax value cannot be negative.
Review
Quoted 2 lines
(quoted diff) +2
-0+ + return *tjmax ? 0 : -EINVAL;So the return value of this function could be tjmax if positive or a
negative error code otherwise. No return pointers needed.I tried both. And I think I chose this solution just because it makes the following cleanup patches in this series looks prettier.
Quoted 8 lines
Quoted 3 lines
I will try your suggestion, and if there is any other reason I wrote it
in this way, I will find it out again. :pI see.
Say, we have to use
intel_tcc_get_temp(int cpu, int *temp)Do we?
Quoted 9 lines
so I keep the same format for all the
intel_tcc_get_XXXAPIs
intel_tcc_get_tjmax(int cpu, int *tjmax)intel_tcc_get_offset(int cpu, int *offset)so that the return value is decoded in the same way. This helps avoid return value check mistakes for the callers.
surely I can remove the return pointer if you still prefer that. :p
Using a function value directly is very much preferred unless there really are two values to return.
In these particular cases a negative return value can be clearly interpreted as an error condition, so using the return value directly is sufficient.
Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
Quoted 5 lines
drivers/thermal/intel/intel_tcc.c new file +5
-0+ +return 0 ; +} +EXPORT_SYMBOL_NS_GPL (intel_tcc_get_offset,INTEL_TCC ); +Quoted 8 lines
Quoted 4 lines
+/**
+ *intel_tcc_set_offset()- set the TCC offset value to Tjmax
+ * @cpu: cpu that the MSR should be run on.
+ * @offset: TCC offset value in degree CI think that this cannot be negative, so maybe say "in K" instead of
"in degree C"?degree C is the unit used in the Intel SDM, so better to keep this comment aligned.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
And maybe it's better to pass u8 here?
sounds good, will do in next version.
to keep consistent, we can use either
intintel_tcc_get_offset(int cpu)
intintel_tcc_set_offset(int cpu, int offset)What about
intel_tcc_set_offset(int cpu, u8 offset)?Quoted 4 lines
or
intintel_tcc_get_offset(int cpu, u8 *offset)
intintel_tcc_set_offset(int cpu, u8 offset)
Quoted 5 lines
Quoted 2 lines
or else callers need to declare 'offset' but with different type, when getting and setting it, which looks strange.
Well, one can surely pass an int as a u8 argument and assign a u8 return value to an int variable.
That said, I see your point regarding the consistency, so if you decide to pass an int argument, that's fine with me too, but in that case the function needs to check against negative offset values.
Zhang Rui
reviewerPATCH 2/6 thermal/int340x/processor_thermal: Use Intel TCC library
In reply to Zhang RuiCleanup the code by using Intel TCC library for TCC (Thermal Control Circuitry) MSR access.
--- drivers/thermal/intel/int340x_thermal/Kconfig | 1 + .../processor_thermal_device.c | 123 ++++-------------- 2 files changed, 25 insertions(+), 99 deletions(-)
drivers/thermal/intel/int340x_thermal/Kconfig +1 -0
@@ -10,6 +10,7 @@ config INT340X_THERMAL select ACPI_THERMAL_REL select ACPI_FAN select INTEL_SOC_DTS_IOSF_CORE + select INTEL_TCC select PROC_THERMAL_MMIO_RAPL if POWERCAP help Newer laptops and tablets that use ACPI may have thermal sensors and
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +24 -99
194 lines not on this page · raw message
Signature · 1 line
2.25.1
Zhang Rui
reviewerPATCH 3/6 thermal/intel/intel_soc_dts_iosf: Use Intel TCC library
In reply to Zhang RuiCleanup the code by using Intel TCC library for TCC (Thermal Control Circuitry) MSR access.
--- drivers/thermal/intel/Kconfig | 1 + drivers/thermal/intel/intel_soc_dts_iosf.c | 33 ++++------------------ 2 files changed, 6 insertions(+), 28 deletions(-)
drivers/thermal/intel/Kconfig +1 -0
@@ -32,6 +32,7 @@ config INTEL_SOC_DTS_IOSF_CORE tristate depends on X86 && PCI select IOSF_MBI + select INTEL_TCC help This is becoming a common feature for Intel SoCs to expose the additional digital temperature sensors (DTSs) using side band interface (IOSF). This
drivers/thermal/intel/intel_soc_dts_iosf.c +5 -28
@@ -7,6 +7,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/bitops.h> +#include <linux/intel_tcc.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/interrupt.h>
@@ -45,32 +46,6 @@/* DTS0 and DTS 1 */ #define SOC_MAX_DTS_SENSORS 2 -static int get_tj_max (u32 *tj_max) -{ -u32 eax, edx; -u32 val; -int err; - - err =rdmsr_safe (MSR_IA32_TEMPERATURE_TARGET , &eax, &edx); -if (err) - goto err_ret; -else { - val = (eax >>16 ) &0xff ; -if (val) - *tj_max = val *1000 ; -else { - err = -EINVAL ; - goto err_ret; - } - } - -return 0 ; -err_ret: - *tj_max =0 ; - -return err; -} -static int sys_get_trip_temp (struct thermal_zone_device *tzd,int trip,int *temp) {
@@ -415,8 +390,9 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init(if (!trip_count || read_only_trip_count > trip_count)return ERR_PTR (-EINVAL ); -if (get_tj_max (&tj_max)) -return ERR_PTR (-EINVAL ); + ret =intel_tcc_get_tjmax (cpumask_any (cpu_online_mask), &tj_max); +if (ret) +return ERR_PTR (ret); sensors =kzalloc (sizeof (*sensors),GFP_KERNEL );if (!sensors)
@@ -475,4 +451,5 @@ void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors) }EXPORT_SYMBOL_GPL (intel_soc_dts_iosf_exit); +MODULE_IMPORT_NS (INTEL_TCC );MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.25.1
Zhang Rui
reviewerPATCH 4/6 thermal/intel/intel_tcc_cooling: Use Intel TCC library
In reply to Zhang RuiCleanup the code by using Intel TCC library for TCC (Thermal Control Circuitry) MSR access.
--- drivers/thermal/intel/Kconfig | 1 + drivers/thermal/intel/intel_tcc_cooling.c | 37 +++-------------------- 2 files changed, 6 insertions(+), 32 deletions(-)
drivers/thermal/intel/Kconfig +1 -0
@@ -88,6 +88,7 @@ config INTEL_PCH_THERMAL config INTEL_TCC_COOLING tristate "Intel TCC offset cooling Driver" depends on X86 + select INTEL_TCC help Enable this to support system cooling by adjusting the effective TCC activation temperature via the TCC Offset register, which is widely
drivers/thermal/intel/intel_tcc_cooling.c +5 -32
@@ -7,12 +7,11 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/device.h> +#include <linux/intel_tcc.h> #include <linux/module.h> #include <linux/thermal.h> #include <asm/cpu_device_id.h> -#define TCC_SHIFT 24 -#define TCC_MASK (0x3fULL<<24)#define TCC_PROGRAMMABLE BIT(30)static struct thermal_cooling_device *tcc_cdev;
@@ -20,47 +19,20 @@ static struct thermal_cooling_device *tcc_cdev;static int tcc_get_max_state (struct thermal_cooling_device *cdev,unsigned long *state) { - *state =TCC_MASK >>TCC_SHIFT ; -return 0 ; -} - -static int tcc_offset_update (int tcc) -{ -u64 val; -int err; - - err =rdmsrl_safe (MSR_IA32_TEMPERATURE_TARGET , &val); -if (err) -return err; - - val &= ~TCC_MASK ; - val |= tcc <<TCC_SHIFT ; - - err =wrmsrl_safe (MSR_IA32_TEMPERATURE_TARGET , val); -if (err) -return err; - + *state =0x3f ;return 0 ; }static int tcc_get_cur_state (struct thermal_cooling_device *cdev,unsigned long *state) { -u64 val; -int err; - - err =rdmsrl_safe (MSR_IA32_TEMPERATURE_TARGET , &val); -if (err) -return err; - - *state = (val &TCC_MASK ) >>TCC_SHIFT ; -return 0 ; +return intel_tcc_get_offset (cpumask_any (cpu_online_mask), (int *)state); }static int tcc_set_cur_state (struct thermal_cooling_device *cdev,unsigned long state) { -return tcc_offset_update (state); +return intel_tcc_set_offset (cpumask_any (cpu_online_mask), (int )state); }static const struct thermal_cooling_device_ops tcc_cooling_ops = {
@@ -129,6 +101,7 @@ static void __exit tcc_cooling_exit(void)module_exit (tcc_cooling_exit) +MODULE_IMPORT_NS (INTEL_TCC);MODULE_DESCRIPTION ("TCC offset cooling device Driver" );MODULE_AUTHOR ("Zhang Rui <[email protected]>" );MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.25.1
Zhang Rui
reviewerPATCH 5/6 thermal/x86_pkg_temp_thermal: Use Intel TCC library
In reply to Zhang RuiCleanup the code by using Intel TCC library for TCC (Thermal Control Circuitry) MSR access.
--- drivers/thermal/intel/Kconfig | 1 + drivers/thermal/intel/x86_pkg_temp_thermal.c | 40 ++++++-------------- 2 files changed, 12 insertions(+), 29 deletions(-)
drivers/thermal/intel/Kconfig +1 -0
@@ -21,6 +21,7 @@ config X86_PKG_TEMP_THERMAL depends on X86_THERMAL_VECTOR select THERMAL_GOV_USER_SPACE select THERMAL_WRITABLE_TRIPS + select INTEL_TCC default m help Enable this to register CPU digital sensor for package temperature as
drivers/thermal/intel/x86_pkg_temp_thermal.c +11 -29
@@ -7,6 +7,7 @@#include <linux/module.h> #include <linux/init.h> +#include <linux/intel_tcc.h> #include <linux/err.h> #include <linux/param.h> #include <linux/device.h>
@@ -104,38 +105,18 @@ static struct zone_device *pkg_temp_thermal_get_dev(unsigned int cpu)return NULL ; } -/* -* tj-max is interesting because threshold is set relative to this -* temperature. -*/ -static int get_tj_max (int cpu,u32 *tj_max) -{ -u32 eax, edx, val; -int err; - - err =rdmsr_safe_on_cpu (cpu,MSR_IA32_TEMPERATURE_TARGET , &eax, &edx); -if (err) -return err; - - val = (eax >>16 ) &0xff ; - *tj_max = val *1000 ; - -return val ?0 : -EINVAL ; -} -static int sys_get_curr_temp (struct thermal_zone_device *tzd,int *temp) {struct zone_device *zonedev = tzd->devdata; -u32 eax, edx; +int ret; -rdmsr_on_cpu (zonedev->cpu,MSR_IA32_PACKAGE_THERM_STATUS , - &eax, &edx); -if (eax &0x80000000 ) { - *temp = zonedev->tj_max - ((eax >>16 ) &0x7f ) *1000 ; -pr_debug ("sys_get_curr_temp %d\n" , *temp); -return 0 ; - } -return -EINVAL ; + ret =intel_tcc_get_temp (zonedev->cpu, true, temp); +if (ret) +return ret; + + *temp *=1000 ; +pr_debug ("sys_get_curr_temp %d\n" , *temp); +return 0 ; } static int sys_get_trip_temp(struct thermal_zone_device *tzd,
@@ -345,7 +326,7 @@ static int pkg_temp_thermal_device_add(unsigned int cpu) thres_count =clamp_val (thres_count,0 ,MAX_NUMBER_OF_TRIPS ); - err =get_tj_max (cpu, &tj_max); + err =intel_tcc_get_tjmax (cpu, &tj_max);if (err)return err;
@@ -536,6 +517,7 @@ static void __exit pkg_temp_thermal_exit(void) }module_exit (pkg_temp_thermal_exit) +MODULE_IMPORT_NS (INTEL_TCC);MODULE_DESCRIPTION ("X86 PKG TEMP Thermal Driver" );MODULE_AUTHOR ("Srinivas Pandruvada <[email protected]>" );MODULE_LICENSE ("GPL v2" );
Signature · 1 line
2.25.1
Zhang Rui
reviewerPATCH 6/6 thermal/x86_pkg_temp_thermal: Add support for handling dynamic tjmax
In reply to Zhang RuiTjmax value retrieved from MSR_IA32_TEMPERATURE_TARGET can be changed at runtime when the Intel SST-PP (Intel Speed Select Technology - Performance Profile) level is changed.
Enhance the code to use updated tjmax when programming the thermal interrupt thresholds.
--- drivers/thermal/intel/x86_pkg_temp_thermal.c | 22 +++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/thermal/intel/x86_pkg_temp_thermal.c +15 -7
@@ -49,7 +49,6 @@ MODULE_PARM_DESC(notify_delay_ms,struct zone_device {int cpu;bool work_scheduled; -u32 tj_max;u32 msr_pkg_therm_low;u32 msr_pkg_therm_high;struct delayed_work work;
@@ -125,7 +124,7 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd,struct zone_device *zonedev = tzd->devdata;unsigned long thres_reg_value;u32 mask, shift, eax, edx; -int ret; +int tj_max, ret;if (trip >=MAX_NUMBER_OF_TRIPS )return -EINVAL ;
@@ -138,6 +137,11 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd, shift =THERM_SHIFT_THRESHOLD0 ; } + ret =intel_tcc_get_tjmax (zonedev->cpu, &tj_max); +if (ret) +return ret; + tj_max *=1000 ; + ret =rdmsr_on_cpu (zonedev->cpu,MSR_IA32_PACKAGE_THERM_INTERRUPT , &eax, &edx);if (ret <0 )
@@ -145,7 +149,7 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd, thres_reg_value = (eax & mask) >> shift;if (thres_reg_value) - *temp = zonedev->tj_max - thres_reg_value *1000 ; + *temp = tj_max - thres_reg_value *1000 ;else *temp =THERMAL_TEMP_INVALID ;pr_debug ("sys_get_trip_temp %d\n" , *temp);
@@ -158,9 +162,14 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) {struct zone_device *zonedev = tzd->devdata;u32 l, h, mask, shift, intr; -int ret; +int tj_max, ret; + + ret =intel_tcc_get_tjmax (zonedev->cpu, &tj_max); +if (ret) +return ret; + tj_max *=1000 ; -if (trip >=MAX_NUMBER_OF_TRIPS || temp >= zonedev->tj_max) +if (trip >=MAX_NUMBER_OF_TRIPS || temp >= tj_max)return -EINVAL ; ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
@@ -185,7 +194,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)if (!temp) { l &= ~intr; }else { - l |= (zonedev->tj_max - temp)/1000 << shift; + l |= (tj_max - temp)/1000 << shift; l |= intr; }
@@ -336,7 +345,6 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)INIT_DELAYED_WORK (&zonedev->work, pkg_temp_thermal_threshold_work_fn); zonedev->cpu = cpu; - zonedev->tj_max = tj_max; zonedev->tzone = thermal_zone_device_register("x86_pkg_temp", thres_count, (thres_count == MAX_NUMBER_OF_TRIPS) ? 0x03 : 0x01,
Signature · 1 line
2.25.1