1
Fork 0
mirror of https://github.com/RGBCube/superfreq synced 2025-07-27 17:07:44 +00:00

engine: optimize turbo auto settings retrieval; improve validation errors

This commit is contained in:
NotAShelf 2025-05-18 05:03:34 +03:00
parent f1a5ad0b6c
commit d7d6398041
No known key found for this signature in database
GPG key ID: 29D95B64378DB4BF

View file

@ -300,10 +300,10 @@ fn manage_auto_turbo(
on_ac_power: bool,
) -> Result<(), EngineError> {
// Get the auto turbo settings from the config
let turbo_settings = config.turbo_auto_settings.clone();
let turbo_settings = &config.turbo_auto_settings;
// Validate the complete configuration to ensure it's usable
validate_turbo_auto_settings(&turbo_settings)?;
validate_turbo_auto_settings(turbo_settings)?;
// Get average CPU temperature and CPU load
let cpu_temp = report.cpu_global.average_temperature_celsius;
@ -440,25 +440,17 @@ fn manage_auto_turbo(
}
fn validate_turbo_auto_settings(settings: &TurboAutoSettings) -> Result<(), EngineError> {
// Validate load thresholds (0-100 % and high > low)
if settings.load_threshold_high <= settings.load_threshold_low
|| settings.load_threshold_high > 100.0
|| settings.load_threshold_low < 0.0
|| settings.load_threshold_low > 100.0
{
return Err(EngineError::ConfigurationError(
"Invalid turbo auto settings: load thresholds must be in 0-100% and high > low"
"Invalid turbo auto settings: load thresholds must be between 0 % and 100 % with high > low"
.to_string(),
));
}
// Validate range of load thresholds (should be 0-100%)
if settings.load_threshold_high > 100.0 || settings.load_threshold_low < 0.0 {
return Err(EngineError::ConfigurationError(
"Invalid turbo auto settings: load thresholds must be between 0% and 100%".to_string(),
));
}
// Validate temperature threshold (realistic range for CPU temps in Celsius)
// TODO: different CPUs have different temperature thresholds. While 110 is a good example
// "extreme" case, the upper barrier might be *lower* for some devices. We'll want to fix