Skip to content

Commit 9e76a97

Browse files
durgadossH. Peter Anvin
authored andcommitted
x86, hwmon: Add core threshold notification to therm_throt.c
This patch adds code to therm_throt.c to notify core thermal threshold events. These thresholds are supported by the IA32_THERM_INTERRUPT register. The status/log for the same is monitored using the IA32_THERM_STATUS register. The necessary #defines are in msr-index.h. A call back is added to mce.h, to further notify the thermal stack, about the threshold events. Signed-off-by: Durgadoss R <[email protected]> LKML-Reference: <D6D887BA8C9DFF48B5233887EF04654105C1251710@bgsmsx502.gar.corp.intel.com> Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 387c31c commit 9e76a97

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

arch/x86/include/asm/mce.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ void intel_init_thermal(struct cpuinfo_x86 *c);
223223

224224
void mce_log_therm_throt_event(__u64 status);
225225

226+
/* Interrupt Handler for core thermal thresholds */
227+
extern int (*platform_thermal_notify)(__u64 msr_val);
228+
226229
#ifdef CONFIG_X86_THERMAL_VECTOR
227230
extern void mcheck_intel_therm_init(void);
228231
#else

arch/x86/include/asm/msr-index.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,18 @@
253253
#define PACKAGE_THERM_INT_LOW_ENABLE (1 << 1)
254254
#define PACKAGE_THERM_INT_PLN_ENABLE (1 << 24)
255255

256+
/* Thermal Thresholds Support */
257+
#define THERM_INT_THRESHOLD0_ENABLE (1 << 15)
258+
#define THERM_SHIFT_THRESHOLD0 8
259+
#define THERM_MASK_THRESHOLD0 (0x7f << THERM_SHIFT_THRESHOLD0)
260+
#define THERM_INT_THRESHOLD1_ENABLE (1 << 23)
261+
#define THERM_SHIFT_THRESHOLD1 16
262+
#define THERM_MASK_THRESHOLD1 (0x7f << THERM_SHIFT_THRESHOLD1)
263+
#define THERM_STATUS_THRESHOLD0 (1 << 6)
264+
#define THERM_LOG_THRESHOLD0 (1 << 7)
265+
#define THERM_STATUS_THRESHOLD1 (1 << 8)
266+
#define THERM_LOG_THRESHOLD1 (1 << 9)
267+
256268
/* MISC_ENABLE bits: architectural */
257269
#define MSR_IA32_MISC_ENABLE_FAST_STRING (1ULL << 0)
258270
#define MSR_IA32_MISC_ENABLE_TCC (1ULL << 1)

arch/x86/kernel/cpu/mcheck/therm_throt.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ struct thermal_state {
5353
struct _thermal_state core_power_limit;
5454
struct _thermal_state package_throttle;
5555
struct _thermal_state package_power_limit;
56+
struct _thermal_state core_thresh0;
57+
struct _thermal_state core_thresh1;
5658
};
5759

60+
/* Callback to handle core threshold interrupts */
61+
int (*platform_thermal_notify)(__u64 msr_val);
62+
5863
static DEFINE_PER_CPU(struct thermal_state, thermal_state);
5964

6065
static atomic_t therm_throt_en = ATOMIC_INIT(0);
@@ -200,6 +205,22 @@ static int therm_throt_process(bool new_event, int event, int level)
200205
return 0;
201206
}
202207

208+
static int thresh_event_valid(int event)
209+
{
210+
struct _thermal_state *state;
211+
unsigned int this_cpu = smp_processor_id();
212+
struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu);
213+
u64 now = get_jiffies_64();
214+
215+
state = (event == 0) ? &pstate->core_thresh0 : &pstate->core_thresh1;
216+
217+
if (time_before64(now, state->next_check))
218+
return 0;
219+
220+
state->next_check = now + CHECK_INTERVAL;
221+
return 1;
222+
}
223+
203224
#ifdef CONFIG_SYSFS
204225
/* Add/Remove thermal_throttle interface for CPU device: */
205226
static __cpuinit int thermal_throttle_add_dev(struct sys_device *sys_dev,
@@ -313,6 +334,22 @@ device_initcall(thermal_throttle_init_device);
313334
#define PACKAGE_THROTTLED ((__u64)2 << 62)
314335
#define PACKAGE_POWER_LIMIT ((__u64)3 << 62)
315336

337+
static void notify_thresholds(__u64 msr_val)
338+
{
339+
/* check whether the interrupt handler is defined;
340+
* otherwise simply return
341+
*/
342+
if (!platform_thermal_notify)
343+
return;
344+
345+
/* lower threshold reached */
346+
if ((msr_val & THERM_LOG_THRESHOLD0) && thresh_event_valid(0))
347+
platform_thermal_notify(msr_val);
348+
/* higher threshold reached */
349+
if ((msr_val & THERM_LOG_THRESHOLD1) && thresh_event_valid(1))
350+
platform_thermal_notify(msr_val);
351+
}
352+
316353
/* Thermal transition interrupt handler */
317354
static void intel_thermal_interrupt(void)
318355
{
@@ -321,6 +358,9 @@ static void intel_thermal_interrupt(void)
321358

322359
rdmsrl(MSR_IA32_THERM_STATUS, msr_val);
323360

361+
/* Check for violation of core thermal thresholds*/
362+
notify_thresholds(msr_val);
363+
324364
if (therm_throt_process(msr_val & THERM_STATUS_PROCHOT,
325365
THERMAL_THROTTLING_EVENT,
326366
CORE_LEVEL) != 0)

0 commit comments

Comments
 (0)