x86: remove pointless comments
[linux-2.6/mini2440.git] / arch / x86 / kernel / cpu / mcheck / therm_throt.c
blob1f4cc48c14c633be4e0a1ca62b1502616337b048
1 /*
3 * Thermal throttle event support code (such as syslog messaging and rate
4 * limiting) that was factored out from x86_64 (mce_intel.c) and i386 (p4.c).
5 * This allows consistent reporting of CPU thermal throttle events.
7 * Maintains a counter in /sys that keeps track of the number of thermal
8 * events, such that the user knows how bad the thermal problem might be
9 * (since the logging to syslog and mcelog is rate limited).
11 * Author: Dmitriy Zavin (dmitriyz@google.com)
13 * Credits: Adapted from Zwane Mwaikambo's original code in mce_intel.c.
14 * Inspired by Ross Biro's and Al Borchers' counter code.
17 #include <linux/percpu.h>
18 #include <linux/sysdev.h>
19 #include <linux/cpu.h>
20 #include <asm/cpu.h>
21 #include <linux/notifier.h>
22 #include <linux/jiffies.h>
23 #include <asm/therm_throt.h>
25 /* How long to wait between reporting thermal events */
26 #define CHECK_INTERVAL (300 * HZ)
28 static DEFINE_PER_CPU(__u64, next_check) = INITIAL_JIFFIES;
29 static DEFINE_PER_CPU(unsigned long, thermal_throttle_count);
30 atomic_t therm_throt_en = ATOMIC_INIT(0);
32 #ifdef CONFIG_SYSFS
33 #define define_therm_throt_sysdev_one_ro(_name) \
34 static SYSDEV_ATTR(_name, 0444, therm_throt_sysdev_show_##_name, NULL)
36 #define define_therm_throt_sysdev_show_func(name) \
37 static ssize_t therm_throt_sysdev_show_##name(struct sys_device *dev, \
38 char *buf) \
39 { \
40 unsigned int cpu = dev->id; \
41 ssize_t ret; \
43 preempt_disable(); /* CPU hotplug */ \
44 if (cpu_online(cpu)) \
45 ret = sprintf(buf, "%lu\n", \
46 per_cpu(thermal_throttle_##name, cpu)); \
47 else \
48 ret = 0; \
49 preempt_enable(); \
51 return ret; \
54 define_therm_throt_sysdev_show_func(count);
55 define_therm_throt_sysdev_one_ro(count);
57 static struct attribute *thermal_throttle_attrs[] = {
58 &attr_count.attr,
59 NULL
62 static struct attribute_group thermal_throttle_attr_group = {
63 .attrs = thermal_throttle_attrs,
64 .name = "thermal_throttle"
66 #endif /* CONFIG_SYSFS */
68 /***
69 * therm_throt_process - Process thermal throttling event from interrupt
70 * @curr: Whether the condition is current or not (boolean), since the
71 * thermal interrupt normally gets called both when the thermal
72 * event begins and once the event has ended.
74 * This function is called by the thermal interrupt after the
75 * IRQ has been acknowledged.
77 * It will take care of rate limiting and printing messages to the syslog.
79 * Returns: 0 : Event should NOT be further logged, i.e. still in
80 * "timeout" from previous log message.
81 * 1 : Event should be logged further, and a message has been
82 * printed to the syslog.
84 int therm_throt_process(int curr)
86 unsigned int cpu = smp_processor_id();
87 __u64 tmp_jiffs = get_jiffies_64();
89 if (curr)
90 __get_cpu_var(thermal_throttle_count)++;
92 if (time_before64(tmp_jiffs, __get_cpu_var(next_check)))
93 return 0;
95 __get_cpu_var(next_check) = tmp_jiffs + CHECK_INTERVAL;
97 /* if we just entered the thermal event */
98 if (curr) {
99 printk(KERN_CRIT "CPU%d: Temperature above threshold, "
100 "cpu clock throttled (total events = %lu)\n", cpu,
101 __get_cpu_var(thermal_throttle_count));
103 add_taint(TAINT_MACHINE_CHECK);
104 } else {
105 printk(KERN_CRIT "CPU%d: Temperature/speed normal\n", cpu);
108 return 1;
111 #ifdef CONFIG_SYSFS
112 /* Add/Remove thermal_throttle interface for CPU device */
113 static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev)
115 return sysfs_create_group(&sys_dev->kobj, &thermal_throttle_attr_group);
118 static __cpuinit void thermal_throttle_remove_dev(struct sys_device *sys_dev)
120 sysfs_remove_group(&sys_dev->kobj, &thermal_throttle_attr_group);
123 /* Mutex protecting device creation against CPU hotplug */
124 static DEFINE_MUTEX(therm_cpu_lock);
126 /* Get notified when a cpu comes on/off. Be hotplug friendly. */
127 static __cpuinit int thermal_throttle_cpu_callback(struct notifier_block *nfb,
128 unsigned long action,
129 void *hcpu)
131 unsigned int cpu = (unsigned long)hcpu;
132 struct sys_device *sys_dev;
133 int err = 0;
135 sys_dev = get_cpu_sysdev(cpu);
136 switch (action) {
137 case CPU_UP_PREPARE:
138 case CPU_UP_PREPARE_FROZEN:
139 mutex_lock(&therm_cpu_lock);
140 err = thermal_throttle_add_dev(sys_dev);
141 mutex_unlock(&therm_cpu_lock);
142 WARN_ON(err);
143 break;
144 case CPU_UP_CANCELED:
145 case CPU_UP_CANCELED_FROZEN:
146 case CPU_DEAD:
147 case CPU_DEAD_FROZEN:
148 mutex_lock(&therm_cpu_lock);
149 thermal_throttle_remove_dev(sys_dev);
150 mutex_unlock(&therm_cpu_lock);
151 break;
153 return err ? NOTIFY_BAD : NOTIFY_OK;
156 static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
158 .notifier_call = thermal_throttle_cpu_callback,
161 static __init int thermal_throttle_init_device(void)
163 unsigned int cpu = 0;
164 int err;
166 if (!atomic_read(&therm_throt_en))
167 return 0;
169 register_hotcpu_notifier(&thermal_throttle_cpu_notifier);
171 #ifdef CONFIG_HOTPLUG_CPU
172 mutex_lock(&therm_cpu_lock);
173 #endif
174 /* connect live CPUs to sysfs */
175 for_each_online_cpu(cpu) {
176 err = thermal_throttle_add_dev(get_cpu_sysdev(cpu));
177 WARN_ON(err);
179 #ifdef CONFIG_HOTPLUG_CPU
180 mutex_unlock(&therm_cpu_lock);
181 #endif
183 return 0;
186 device_initcall(thermal_throttle_init_device);
187 #endif /* CONFIG_SYSFS */