[PATCH] x86: Refactor thermal throttle processing
[pandora-kernel.git] / arch / i386 / kernel / cpu / mcheck / therm_throt.c
1 /*
2  * linux/arch/i386/kerne/cpu/mcheck/therm_throt.c
3  *
4  * Thermal throttle event support code.
5  *
6  * Author: Dmitriy Zavin (dmitriyz@google.com)
7  *
8  * Credits: Adapted from Zwane Mwaikambo's original code in mce_intel.c.
9  *
10  */
11
12 #include <linux/percpu.h>
13 #include <linux/cpu.h>
14 #include <asm/cpu.h>
15 #include <linux/notifier.h>
16 #include <asm/therm_throt.h>
17
18 /* How long to wait between reporting thermal events */
19 #define CHECK_INTERVAL              (300 * HZ)
20
21 static DEFINE_PER_CPU(unsigned long, next_check);
22
23 /***
24  * therm_throt_process - Process thermal throttling event
25  * @curr: Whether the condition is current or not (boolean), since the
26  *        thermal interrupt normally gets called both when the thermal
27  *        event begins and once the event has ended.
28  *
29  * This function is normally called by the thermal interrupt after the
30  * IRQ has been acknowledged.
31  *
32  * It will take care of rate limiting and printing messages to the syslog.
33  *
34  * Returns: 0 : Event should NOT be further logged, i.e. still in
35  *              "timeout" from previous log message.
36  *          1 : Event should be logged further, and a message has been
37  *              printed to the syslog.
38  */
39 int therm_throt_process(int curr)
40 {
41         unsigned int cpu = smp_processor_id();
42
43         if (time_before(jiffies, __get_cpu_var(next_check)))
44                 return 0;
45
46         __get_cpu_var(next_check) = jiffies + CHECK_INTERVAL;
47
48         /* if we just entered the thermal event */
49         if (curr) {
50                 printk(KERN_CRIT "CPU%d: Temperature above threshold, "
51                        "cpu clock throttled\n", cpu);
52                 add_taint(TAINT_MACHINE_CHECK);
53         } else {
54                 printk(KERN_CRIT "CPU%d: Temperature/speed normal\n", cpu);
55         }
56
57         return 1;
58 }