thermal/drivers/intel: Introduce tcc cooling driver
On Intel processors, the core frequency can be reduced below OS request,
when the current temperature reaches the TCC (Thermal Control Circuit)
activation temperature.
The default TCC activation temperature is specified by
MSR_IA32_TEMPERATURE_TARGET. However, it can be adjusted by specifying an
offset in degrees C, using the TCC Offset bits in the same MSR register.
This patch introduces a cooling devices driver that utilizes the TCC
Offset feature. The bigger the current cooling state is, the lower the
effective TCC activation temperature is, so that the processors can be
throttled earlier before system critical overheats.
Note that, on different platforms, the behavior might be different on
how fast the setting takes effect, and how much the CPU frequency is
reduced.
This patch has been tested on a KabyLake mobile platform from me, and also
on a CometLake platform from Doug.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210412125901.12549-1-rui.zhang@intel.com
2021-04-12 12:59:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
/*
|
|
|
|
* cooling device driver that activates the processor throttling by
|
|
|
|
* programming the TCC Offset register.
|
|
|
|
* Copyright (c) 2021, Intel Corporation.
|
|
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
2022-12-19 15:46:18 +00:00
|
|
|
#include <linux/intel_tcc.h>
|
thermal/drivers/intel: Introduce tcc cooling driver
On Intel processors, the core frequency can be reduced below OS request,
when the current temperature reaches the TCC (Thermal Control Circuit)
activation temperature.
The default TCC activation temperature is specified by
MSR_IA32_TEMPERATURE_TARGET. However, it can be adjusted by specifying an
offset in degrees C, using the TCC Offset bits in the same MSR register.
This patch introduces a cooling devices driver that utilizes the TCC
Offset feature. The bigger the current cooling state is, the lower the
effective TCC activation temperature is, so that the processors can be
throttled earlier before system critical overheats.
Note that, on different platforms, the behavior might be different on
how fast the setting takes effect, and how much the CPU frequency is
reduced.
This patch has been tested on a KabyLake mobile platform from me, and also
on a CometLake platform from Doug.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210412125901.12549-1-rui.zhang@intel.com
2021-04-12 12:59:01 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/thermal.h>
|
|
|
|
#include <asm/cpu_device_id.h>
|
|
|
|
|
|
|
|
#define TCC_PROGRAMMABLE BIT(30)
|
2022-11-08 08:12:19 +00:00
|
|
|
#define TCC_LOCKED BIT(31)
|
thermal/drivers/intel: Introduce tcc cooling driver
On Intel processors, the core frequency can be reduced below OS request,
when the current temperature reaches the TCC (Thermal Control Circuit)
activation temperature.
The default TCC activation temperature is specified by
MSR_IA32_TEMPERATURE_TARGET. However, it can be adjusted by specifying an
offset in degrees C, using the TCC Offset bits in the same MSR register.
This patch introduces a cooling devices driver that utilizes the TCC
Offset feature. The bigger the current cooling state is, the lower the
effective TCC activation temperature is, so that the processors can be
throttled earlier before system critical overheats.
Note that, on different platforms, the behavior might be different on
how fast the setting takes effect, and how much the CPU frequency is
reduced.
This patch has been tested on a KabyLake mobile platform from me, and also
on a CometLake platform from Doug.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210412125901.12549-1-rui.zhang@intel.com
2021-04-12 12:59:01 +00:00
|
|
|
|
|
|
|
static struct thermal_cooling_device *tcc_cdev;
|
|
|
|
|
|
|
|
static int tcc_get_max_state(struct thermal_cooling_device *cdev, unsigned long
|
|
|
|
*state)
|
|
|
|
{
|
2024-06-14 21:16:06 +00:00
|
|
|
*state = intel_tcc_get_offset_mask();
|
thermal/drivers/intel: Introduce tcc cooling driver
On Intel processors, the core frequency can be reduced below OS request,
when the current temperature reaches the TCC (Thermal Control Circuit)
activation temperature.
The default TCC activation temperature is specified by
MSR_IA32_TEMPERATURE_TARGET. However, it can be adjusted by specifying an
offset in degrees C, using the TCC Offset bits in the same MSR register.
This patch introduces a cooling devices driver that utilizes the TCC
Offset feature. The bigger the current cooling state is, the lower the
effective TCC activation temperature is, so that the processors can be
throttled earlier before system critical overheats.
Note that, on different platforms, the behavior might be different on
how fast the setting takes effect, and how much the CPU frequency is
reduced.
This patch has been tested on a KabyLake mobile platform from me, and also
on a CometLake platform from Doug.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210412125901.12549-1-rui.zhang@intel.com
2021-04-12 12:59:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tcc_get_cur_state(struct thermal_cooling_device *cdev, unsigned long
|
|
|
|
*state)
|
|
|
|
{
|
2022-12-19 15:46:18 +00:00
|
|
|
int offset = intel_tcc_get_offset(-1);
|
thermal/drivers/intel: Introduce tcc cooling driver
On Intel processors, the core frequency can be reduced below OS request,
when the current temperature reaches the TCC (Thermal Control Circuit)
activation temperature.
The default TCC activation temperature is specified by
MSR_IA32_TEMPERATURE_TARGET. However, it can be adjusted by specifying an
offset in degrees C, using the TCC Offset bits in the same MSR register.
This patch introduces a cooling devices driver that utilizes the TCC
Offset feature. The bigger the current cooling state is, the lower the
effective TCC activation temperature is, so that the processors can be
throttled earlier before system critical overheats.
Note that, on different platforms, the behavior might be different on
how fast the setting takes effect, and how much the CPU frequency is
reduced.
This patch has been tested on a KabyLake mobile platform from me, and also
on a CometLake platform from Doug.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210412125901.12549-1-rui.zhang@intel.com
2021-04-12 12:59:01 +00:00
|
|
|
|
2022-12-19 15:46:18 +00:00
|
|
|
if (offset < 0)
|
|
|
|
return offset;
|
thermal/drivers/intel: Introduce tcc cooling driver
On Intel processors, the core frequency can be reduced below OS request,
when the current temperature reaches the TCC (Thermal Control Circuit)
activation temperature.
The default TCC activation temperature is specified by
MSR_IA32_TEMPERATURE_TARGET. However, it can be adjusted by specifying an
offset in degrees C, using the TCC Offset bits in the same MSR register.
This patch introduces a cooling devices driver that utilizes the TCC
Offset feature. The bigger the current cooling state is, the lower the
effective TCC activation temperature is, so that the processors can be
throttled earlier before system critical overheats.
Note that, on different platforms, the behavior might be different on
how fast the setting takes effect, and how much the CPU frequency is
reduced.
This patch has been tested on a KabyLake mobile platform from me, and also
on a CometLake platform from Doug.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210412125901.12549-1-rui.zhang@intel.com
2021-04-12 12:59:01 +00:00
|
|
|
|
2022-12-19 15:46:18 +00:00
|
|
|
*state = offset;
|
thermal/drivers/intel: Introduce tcc cooling driver
On Intel processors, the core frequency can be reduced below OS request,
when the current temperature reaches the TCC (Thermal Control Circuit)
activation temperature.
The default TCC activation temperature is specified by
MSR_IA32_TEMPERATURE_TARGET. However, it can be adjusted by specifying an
offset in degrees C, using the TCC Offset bits in the same MSR register.
This patch introduces a cooling devices driver that utilizes the TCC
Offset feature. The bigger the current cooling state is, the lower the
effective TCC activation temperature is, so that the processors can be
throttled earlier before system critical overheats.
Note that, on different platforms, the behavior might be different on
how fast the setting takes effect, and how much the CPU frequency is
reduced.
This patch has been tested on a KabyLake mobile platform from me, and also
on a CometLake platform from Doug.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210412125901.12549-1-rui.zhang@intel.com
2021-04-12 12:59:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tcc_set_cur_state(struct thermal_cooling_device *cdev, unsigned long
|
|
|
|
state)
|
|
|
|
{
|
2022-12-19 15:46:18 +00:00
|
|
|
return intel_tcc_set_offset(-1, (int)state);
|
thermal/drivers/intel: Introduce tcc cooling driver
On Intel processors, the core frequency can be reduced below OS request,
when the current temperature reaches the TCC (Thermal Control Circuit)
activation temperature.
The default TCC activation temperature is specified by
MSR_IA32_TEMPERATURE_TARGET. However, it can be adjusted by specifying an
offset in degrees C, using the TCC Offset bits in the same MSR register.
This patch introduces a cooling devices driver that utilizes the TCC
Offset feature. The bigger the current cooling state is, the lower the
effective TCC activation temperature is, so that the processors can be
throttled earlier before system critical overheats.
Note that, on different platforms, the behavior might be different on
how fast the setting takes effect, and how much the CPU frequency is
reduced.
This patch has been tested on a KabyLake mobile platform from me, and also
on a CometLake platform from Doug.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210412125901.12549-1-rui.zhang@intel.com
2021-04-12 12:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct thermal_cooling_device_ops tcc_cooling_ops = {
|
|
|
|
.get_max_state = tcc_get_max_state,
|
|
|
|
.get_cur_state = tcc_get_cur_state,
|
|
|
|
.set_cur_state = tcc_set_cur_state,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct x86_cpu_id tcc_ids[] __initconst = {
|
2024-05-28 18:47:17 +00:00
|
|
|
X86_MATCH_VFM(INTEL_SKYLAKE, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_SKYLAKE_L, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_KABYLAKE, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_KABYLAKE_L, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_ICELAKE, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_ICELAKE_L, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_TIGERLAKE, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_TIGERLAKE_L, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_COMETLAKE, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_ALDERLAKE, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_ALDERLAKE_L, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_ATOM_GRACEMONT, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_RAPTORLAKE, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_RAPTORLAKE_P, NULL),
|
|
|
|
X86_MATCH_VFM(INTEL_RAPTORLAKE_S, NULL),
|
thermal/drivers/intel: Introduce tcc cooling driver
On Intel processors, the core frequency can be reduced below OS request,
when the current temperature reaches the TCC (Thermal Control Circuit)
activation temperature.
The default TCC activation temperature is specified by
MSR_IA32_TEMPERATURE_TARGET. However, it can be adjusted by specifying an
offset in degrees C, using the TCC Offset bits in the same MSR register.
This patch introduces a cooling devices driver that utilizes the TCC
Offset feature. The bigger the current cooling state is, the lower the
effective TCC activation temperature is, so that the processors can be
throttled earlier before system critical overheats.
Note that, on different platforms, the behavior might be different on
how fast the setting takes effect, and how much the CPU frequency is
reduced.
This patch has been tested on a KabyLake mobile platform from me, and also
on a CometLake platform from Doug.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210412125901.12549-1-rui.zhang@intel.com
2021-04-12 12:59:01 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(x86cpu, tcc_ids);
|
|
|
|
|
|
|
|
static int __init tcc_cooling_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u64 val;
|
|
|
|
const struct x86_cpu_id *id;
|
|
|
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
id = x86_match_cpu(tcc_ids);
|
|
|
|
if (!id)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
err = rdmsrl_safe(MSR_PLATFORM_INFO, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!(val & TCC_PROGRAMMABLE))
|
|
|
|
return -ENODEV;
|
|
|
|
|
2022-11-08 08:12:19 +00:00
|
|
|
err = rdmsrl_safe(MSR_IA32_TEMPERATURE_TARGET, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (val & TCC_LOCKED) {
|
|
|
|
pr_info("TCC Offset locked\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
thermal/drivers/intel: Introduce tcc cooling driver
On Intel processors, the core frequency can be reduced below OS request,
when the current temperature reaches the TCC (Thermal Control Circuit)
activation temperature.
The default TCC activation temperature is specified by
MSR_IA32_TEMPERATURE_TARGET. However, it can be adjusted by specifying an
offset in degrees C, using the TCC Offset bits in the same MSR register.
This patch introduces a cooling devices driver that utilizes the TCC
Offset feature. The bigger the current cooling state is, the lower the
effective TCC activation temperature is, so that the processors can be
throttled earlier before system critical overheats.
Note that, on different platforms, the behavior might be different on
how fast the setting takes effect, and how much the CPU frequency is
reduced.
This patch has been tested on a KabyLake mobile platform from me, and also
on a CometLake platform from Doug.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210412125901.12549-1-rui.zhang@intel.com
2021-04-12 12:59:01 +00:00
|
|
|
pr_info("Programmable TCC Offset detected\n");
|
|
|
|
|
|
|
|
tcc_cdev =
|
|
|
|
thermal_cooling_device_register("TCC Offset", NULL,
|
|
|
|
&tcc_cooling_ops);
|
|
|
|
if (IS_ERR(tcc_cdev)) {
|
|
|
|
ret = PTR_ERR(tcc_cdev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(tcc_cooling_init)
|
|
|
|
|
|
|
|
static void __exit tcc_cooling_exit(void)
|
|
|
|
{
|
|
|
|
thermal_cooling_device_unregister(tcc_cdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_exit(tcc_cooling_exit)
|
|
|
|
|
2022-12-19 15:46:18 +00:00
|
|
|
MODULE_IMPORT_NS(INTEL_TCC);
|
thermal/drivers/intel: Introduce tcc cooling driver
On Intel processors, the core frequency can be reduced below OS request,
when the current temperature reaches the TCC (Thermal Control Circuit)
activation temperature.
The default TCC activation temperature is specified by
MSR_IA32_TEMPERATURE_TARGET. However, it can be adjusted by specifying an
offset in degrees C, using the TCC Offset bits in the same MSR register.
This patch introduces a cooling devices driver that utilizes the TCC
Offset feature. The bigger the current cooling state is, the lower the
effective TCC activation temperature is, so that the processors can be
throttled earlier before system critical overheats.
Note that, on different platforms, the behavior might be different on
how fast the setting takes effect, and how much the CPU frequency is
reduced.
This patch has been tested on a KabyLake mobile platform from me, and also
on a CometLake platform from Doug.
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Tested by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20210412125901.12549-1-rui.zhang@intel.com
2021-04-12 12:59:01 +00:00
|
|
|
MODULE_DESCRIPTION("TCC offset cooling device Driver");
|
|
|
|
MODULE_AUTHOR("Zhang Rui <rui.zhang@intel.com>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|