Lines Matching +full:int +full:- +full:threshold
1 // SPDX-License-Identifier: GPL-2.0-only
45 * struct _thermal_state - Represent the current thermal event state
48 * @last_interrupt_time: Stores the timestamp for the last threshold
52 * or power threshold interrupts.
54 * or power threshold interrupts.
57 * threshold high to low state.
61 * This is used for the purpose of rate-control.
72 * @baseline_temp: Temperature at which thermal threshold high
109 /* Callback to handle core threshold interrupts */
110 int (*platform_thermal_notify)(__u64 msr_val);
114 int (*platform_thermal_package_notify)(__u64 msr_val);
142 unsigned int cpu = dev->id; \
206 * "Table 2-2. IA-32 Architectural MSRs", MSR 0x19C in thermal_intr_init_core_clear_mask()
217 * Bit 7 and 9: Thermal Threshold #1 and #2 log in thermal_intr_init_core_clear_mask()
242 * "Table 2-2. IA-32 Architectural MSRs", MSR 0x1B1 in thermal_intr_init_pkg_clear_mask()
262 void thermal_clear_package_intr_status(int level, u64 bit_mask) in thermal_clear_package_intr_status()
265 int msr; in thermal_clear_package_intr_status()
280 static void get_therm_status(int level, bool *proc_hot, u8 *temp) in get_therm_status()
282 int msr; in get_therm_status()
303 unsigned int i, avg, this_cpu = smp_processor_id(); in throttle_active_work()
308 get_therm_status(state->level, &hot, &temp); in throttle_active_work()
310 if (!hot && temp > state->baseline_temp) { in throttle_active_work()
311 if (state->rate_control_active) in throttle_active_work()
314 state->level == CORE_LEVEL ? "Core" : "Package", in throttle_active_work()
315 state->count); in throttle_active_work()
317 state->rate_control_active = false; in throttle_active_work()
321 if (time_before64(now, state->next_check) && in throttle_active_work()
322 state->rate_control_active) in throttle_active_work()
325 state->next_check = now + CHECK_INTERVAL; in throttle_active_work()
327 if (state->count != state->last_count) { in throttle_active_work()
329 state->last_count = state->count; in throttle_active_work()
330 state->average = 0; in throttle_active_work()
331 state->sample_count = 0; in throttle_active_work()
332 state->sample_index = 0; in throttle_active_work()
335 state->temp_samples[state->sample_index] = temp; in throttle_active_work()
336 state->sample_count++; in throttle_active_work()
337 state->sample_index = (state->sample_index + 1) % ARRAY_SIZE(state->temp_samples); in throttle_active_work()
338 if (state->sample_count < ARRAY_SIZE(state->temp_samples)) in throttle_active_work()
342 for (i = 0; i < ARRAY_SIZE(state->temp_samples); ++i) in throttle_active_work()
343 avg += state->temp_samples[i]; in throttle_active_work()
345 avg /= ARRAY_SIZE(state->temp_samples); in throttle_active_work()
347 if (state->average > avg) { in throttle_active_work()
348 pr_warn("CPU%d: %s temperature is above threshold, cpu clock is throttled (total events = %lu)\n", in throttle_active_work()
350 state->level == CORE_LEVEL ? "Core" : "Package", in throttle_active_work()
351 state->count); in throttle_active_work()
352 state->rate_control_active = true; in throttle_active_work()
355 state->average = avg; in throttle_active_work()
358 thermal_clear_package_intr_status(state->level, THERM_STATUS_PROCHOT_LOG); in throttle_active_work()
359 schedule_delayed_work_on(this_cpu, &state->therm_work, THERM_THROT_POLL_INTERVAL); in throttle_active_work()
363 * therm_throt_process - Process thermal throttling event from interrupt
373 static void therm_throt_process(bool new_event, int event, int level) in therm_throt_process()
376 unsigned int this_cpu = smp_processor_id(); in therm_throt_process()
384 state = &pstate->core_throttle; in therm_throt_process()
386 state = &pstate->core_power_limit; in therm_throt_process()
391 state = &pstate->package_throttle; in therm_throt_process()
393 state = &pstate->package_power_limit; in therm_throt_process()
399 old_event = state->new_event; in therm_throt_process()
400 state->new_event = new_event; in therm_throt_process()
403 state->count++; in therm_throt_process()
408 if (new_event && !state->last_interrupt_time) { in therm_throt_process()
412 get_therm_status(state->level, &hot, &temp); in therm_throt_process()
416 * already dropped from the high threshold temperature. in therm_throt_process()
421 state->baseline_temp = temp; in therm_throt_process()
422 state->last_interrupt_time = now; in therm_throt_process()
423 schedule_delayed_work_on(this_cpu, &state->therm_work, THERM_THROT_POLL_INTERVAL); in therm_throt_process()
424 } else if (old_event && state->last_interrupt_time) { in therm_throt_process()
427 throttle_time = jiffies_delta_to_msecs(now - state->last_interrupt_time); in therm_throt_process()
428 if (throttle_time > state->max_time_ms) in therm_throt_process()
429 state->max_time_ms = throttle_time; in therm_throt_process()
430 state->total_time_ms += throttle_time; in therm_throt_process()
431 state->last_interrupt_time = 0; in therm_throt_process()
435 static int thresh_event_valid(int level, int event) in thresh_event_valid()
438 unsigned int this_cpu = smp_processor_id(); in thresh_event_valid()
443 state = (event == 0) ? &pstate->pkg_thresh0 : in thresh_event_valid()
444 &pstate->pkg_thresh1; in thresh_event_valid()
446 state = (event == 0) ? &pstate->core_thresh0 : in thresh_event_valid()
447 &pstate->core_thresh1; in thresh_event_valid()
449 if (time_before64(now, state->next_check)) in thresh_event_valid()
452 state->next_check = now + CHECK_INTERVAL; in thresh_event_valid()
458 static int __init int_pln_enable_setup(char *s) in int_pln_enable_setup()
468 static int thermal_throttle_add_dev(struct device *dev, unsigned int cpu) in thermal_throttle_add_dev()
470 int err; in thermal_throttle_add_dev()
473 err = sysfs_create_group(&dev->kobj, &thermal_attr_group); in thermal_throttle_add_dev()
478 err = sysfs_add_file_to_group(&dev->kobj, in thermal_throttle_add_dev()
486 err = sysfs_add_file_to_group(&dev->kobj, in thermal_throttle_add_dev()
492 err = sysfs_add_file_to_group(&dev->kobj, in thermal_throttle_add_dev()
498 err = sysfs_add_file_to_group(&dev->kobj, in thermal_throttle_add_dev()
505 err = sysfs_add_file_to_group(&dev->kobj, in thermal_throttle_add_dev()
516 sysfs_remove_group(&dev->kobj, &thermal_attr_group); in thermal_throttle_add_dev()
523 sysfs_remove_group(&dev->kobj, &thermal_attr_group); in thermal_throttle_remove_dev()
527 static int thermal_throttle_online(unsigned int cpu) in thermal_throttle_online()
533 state->package_throttle.level = PACKAGE_LEVEL; in thermal_throttle_online()
534 state->core_throttle.level = CORE_LEVEL; in thermal_throttle_online()
536 INIT_DELAYED_WORK(&state->package_throttle.therm_work, throttle_active_work); in thermal_throttle_online()
537 INIT_DELAYED_WORK(&state->core_throttle.therm_work, throttle_active_work); in thermal_throttle_online()
553 static int thermal_throttle_offline(unsigned int cpu) in thermal_throttle_offline()
565 cancel_delayed_work_sync(&state->package_throttle.therm_work); in thermal_throttle_offline()
566 cancel_delayed_work_sync(&state->core_throttle.therm_work); in thermal_throttle_offline()
568 state->package_throttle.rate_control_active = false; in thermal_throttle_offline()
569 state->core_throttle.rate_control_active = false; in thermal_throttle_offline()
575 static __init int thermal_throttle_init_device(void) in thermal_throttle_init_device()
577 int ret; in thermal_throttle_init_device()
601 /* lower threshold check */ in notify_package_thresholds()
604 /* higher threshold check */ in notify_package_thresholds()
618 /* lower threshold reached */ in notify_package_thresholds()
621 /* higher threshold reached */ in notify_package_thresholds()
634 /* lower threshold reached */ in notify_thresholds()
638 /* higher threshold reached */ in notify_thresholds()
691 static int intel_thermal_supported(struct cpuinfo_x86 *c) in intel_thermal_supported()
718 unsigned int cpu = smp_processor_id(); in intel_init_thermal()
719 int tm2 = 0; in intel_init_thermal()
735 * 0x10000 because APs are woken up by BSP issuing INIT-SIPI-SIPI in intel_init_thermal()
755 if (c->x86 == 6 && (c->x86_model == 9 || c->x86_model == 13)) { in intel_init_thermal()