Lines Matching +full:avg +full:- +full:samples
1 // SPDX-License-Identifier: GPL-2.0-only
44 * struct _thermal_state - Represent the current thermal event state
60 * This is used for the purpose of rate-control.
68 * @sample_count: Total number of samples collected in the buffer
70 * @average: The last moving average of temperature samples
73 * @temp_samples: Storage for temperature samples to calculate
141 unsigned int cpu = dev->id; \
242 unsigned int i, avg, this_cpu = smp_processor_id(); in throttle_active_work() local
247 get_therm_status(state->level, &hot, &temp); in throttle_active_work()
249 if (!hot && temp > state->baseline_temp) { in throttle_active_work()
250 if (state->rate_control_active) in throttle_active_work()
253 state->level == CORE_LEVEL ? "Core" : "Package", in throttle_active_work()
254 state->count); in throttle_active_work()
256 state->rate_control_active = false; in throttle_active_work()
260 if (time_before64(now, state->next_check) && in throttle_active_work()
261 state->rate_control_active) in throttle_active_work()
264 state->next_check = now + CHECK_INTERVAL; in throttle_active_work()
266 if (state->count != state->last_count) { in throttle_active_work()
268 state->last_count = state->count; in throttle_active_work()
269 state->average = 0; in throttle_active_work()
270 state->sample_count = 0; in throttle_active_work()
271 state->sample_index = 0; in throttle_active_work()
274 state->temp_samples[state->sample_index] = temp; in throttle_active_work()
275 state->sample_count++; in throttle_active_work()
276 state->sample_index = (state->sample_index + 1) % ARRAY_SIZE(state->temp_samples); in throttle_active_work()
277 if (state->sample_count < ARRAY_SIZE(state->temp_samples)) in throttle_active_work()
280 avg = 0; in throttle_active_work()
281 for (i = 0; i < ARRAY_SIZE(state->temp_samples); ++i) in throttle_active_work()
282 avg += state->temp_samples[i]; in throttle_active_work()
284 avg /= ARRAY_SIZE(state->temp_samples); in throttle_active_work()
286 if (state->average > avg) { in throttle_active_work()
289 state->level == CORE_LEVEL ? "Core" : "Package", in throttle_active_work()
290 state->count); in throttle_active_work()
291 state->rate_control_active = true; in throttle_active_work()
294 state->average = avg; in throttle_active_work()
297 clear_therm_status_log(state->level); in throttle_active_work()
298 schedule_delayed_work_on(this_cpu, &state->therm_work, THERM_THROT_POLL_INTERVAL); in throttle_active_work()
302 * therm_throt_process - Process thermal throttling event from interrupt
323 state = &pstate->core_throttle; in therm_throt_process()
325 state = &pstate->core_power_limit; in therm_throt_process()
330 state = &pstate->package_throttle; in therm_throt_process()
332 state = &pstate->package_power_limit; in therm_throt_process()
338 old_event = state->new_event; in therm_throt_process()
339 state->new_event = new_event; in therm_throt_process()
342 state->count++; in therm_throt_process()
347 if (new_event && !state->last_interrupt_time) { in therm_throt_process()
351 get_therm_status(state->level, &hot, &temp); in therm_throt_process()
360 state->baseline_temp = temp; in therm_throt_process()
361 state->last_interrupt_time = now; in therm_throt_process()
362 schedule_delayed_work_on(this_cpu, &state->therm_work, THERM_THROT_POLL_INTERVAL); in therm_throt_process()
363 } else if (old_event && state->last_interrupt_time) { in therm_throt_process()
366 throttle_time = jiffies_delta_to_msecs(now - state->last_interrupt_time); in therm_throt_process()
367 if (throttle_time > state->max_time_ms) in therm_throt_process()
368 state->max_time_ms = throttle_time; in therm_throt_process()
369 state->total_time_ms += throttle_time; in therm_throt_process()
370 state->last_interrupt_time = 0; in therm_throt_process()
382 state = (event == 0) ? &pstate->pkg_thresh0 : in thresh_event_valid()
383 &pstate->pkg_thresh1; in thresh_event_valid()
385 state = (event == 0) ? &pstate->core_thresh0 : in thresh_event_valid()
386 &pstate->core_thresh1; in thresh_event_valid()
388 if (time_before64(now, state->next_check)) in thresh_event_valid()
391 state->next_check = now + CHECK_INTERVAL; in thresh_event_valid()
412 err = sysfs_create_group(&dev->kobj, &thermal_attr_group); in thermal_throttle_add_dev()
417 err = sysfs_add_file_to_group(&dev->kobj, in thermal_throttle_add_dev()
425 err = sysfs_add_file_to_group(&dev->kobj, in thermal_throttle_add_dev()
431 err = sysfs_add_file_to_group(&dev->kobj, in thermal_throttle_add_dev()
437 err = sysfs_add_file_to_group(&dev->kobj, in thermal_throttle_add_dev()
444 err = sysfs_add_file_to_group(&dev->kobj, in thermal_throttle_add_dev()
455 sysfs_remove_group(&dev->kobj, &thermal_attr_group); in thermal_throttle_add_dev()
462 sysfs_remove_group(&dev->kobj, &thermal_attr_group); in thermal_throttle_remove_dev()
472 state->package_throttle.level = PACKAGE_LEVEL; in thermal_throttle_online()
473 state->core_throttle.level = CORE_LEVEL; in thermal_throttle_online()
475 INIT_DELAYED_WORK(&state->package_throttle.therm_work, throttle_active_work); in thermal_throttle_online()
476 INIT_DELAYED_WORK(&state->core_throttle.therm_work, throttle_active_work); in thermal_throttle_online()
495 cancel_delayed_work_sync(&state->package_throttle.therm_work); in thermal_throttle_offline()
496 cancel_delayed_work_sync(&state->core_throttle.therm_work); in thermal_throttle_offline()
498 state->package_throttle.rate_control_active = false; in thermal_throttle_offline()
499 state->core_throttle.rate_control_active = false; in thermal_throttle_offline()
666 * 0x10000 because APs are woken up by BSP issuing INIT-SIPI-SIPI in intel_init_thermal()
686 if (c->x86 == 6 && (c->x86_model == 9 || c->x86_model == 13)) { in intel_init_thermal()