19 #include <linux/kernel.h>
21 #include <linux/export.h>
22 #include <linux/types.h>
27 #include <asm/processor.h>
34 #define CHECK_INTERVAL (300 * HZ)
36 #define THERMAL_THROTTLING_EVENT 0
37 #define POWER_LIMIT_EVENT 1
70 #define define_therm_throt_device_one_ro(_name) \
71 static DEVICE_ATTR(_name, 0444, \
72 therm_throt_device_show_##_name, \
75 #define define_therm_throt_device_show_func(event, name) \
77 static ssize_t therm_throt_device_show_##event##_##name( \
79 struct device_attribute *attr, \
82 unsigned int cpu = dev->id; \
86 if (cpu_online(cpu)) { \
87 ret = sprintf(buf, "%lu\n", \
88 per_cpu(thermal_state, cpu).event.name); \
96 define_therm_throt_device_show_func(core_throttle,
count);
97 define_therm_throt_device_one_ro(core_throttle_count);
99 define_therm_throt_device_show_func(core_power_limit,
count);
100 define_therm_throt_device_one_ro(core_power_limit_count);
102 define_therm_throt_device_show_func(package_throttle,
count);
103 define_therm_throt_device_one_ro(package_throttle_count);
105 define_therm_throt_device_show_func(package_power_limit,
count);
106 define_therm_throt_device_one_ro(package_power_limit_count);
108 static struct attribute *thermal_throttle_attrs[] = {
109 &dev_attr_core_throttle_count.attr,
114 .
attrs = thermal_throttle_attrs,
115 .
name =
"thermal_throttle"
120 #define PACKAGE_LEVEL 1
138 static int therm_throt_process(
bool new_event,
int event,
int level)
180 printk(
KERN_CRIT "CPU%d: %s temperature above threshold, cpu clock throttled (total events = %lu)\n",
185 printk(
KERN_CRIT "CPU%d: %s power limit notification (total events = %lu)\n",
206 static int thresh_event_valid(
int event)
236 &dev_attr_core_power_limit_count.attr,
237 thermal_attr_group.
name);
240 &dev_attr_package_throttle_count.attr,
241 thermal_attr_group.
name);
244 &dev_attr_package_power_limit_count.attr,
245 thermal_attr_group.
name);
265 unsigned int cpu = (
unsigned long)hcpu;
275 err = thermal_throttle_add_dev(dev, cpu);
284 thermal_throttle_remove_dev(dev);
288 return notifier_from_errno(err);
293 .notifier_call = thermal_throttle_cpu_callback,
296 static __init int thermal_throttle_init_device(
void)
298 unsigned int cpu = 0;
306 #ifdef CONFIG_HOTPLUG_CPU
314 #ifdef CONFIG_HOTPLUG_CPU
324 static void notify_thresholds(
__u64 msr_val)
341 static void intel_thermal_interrupt(
void)
348 notify_thresholds(msr_val);
353 mce_log_therm_throt_event(msr_val);
366 therm_throt_process(msr_val &
373 static void unexpected_thermal_interrupt(
void)
379 static void (*smp_thermal_vector)(
void) = unexpected_thermal_interrupt;
386 smp_thermal_vector();
393 static int intel_thermal_supported(
struct cpuinfo_x86 *c)
419 if (!intel_thermal_supported(c))
446 "CPU%d: Thermal monitoring handled by SMI\n", cpu);
453 "CPU%d: Thermal LVT vector (%#x) already installed\n",
454 cpu, (h & APIC_VECTOR_MASK));
494 smp_thermal_vector = intel_thermal_interrupt;
504 tm2 ?
"TM2" :
"TM1");