From 0483ee1617541800eac7febe5c5deb5e5dc26630 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Tue, 14 Feb 2023 21:59:05 -0500 Subject: [PATCH] Fix SMT toggle always reenabling (fix #73) --- backend/src/settings/mod.rs | 2 +- backend/src/settings/steam_deck/cpu.rs | 1 + backend/src/settings/util.rs | 42 ++++++++++++++++++++++++++ src/backend.ts | 2 +- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/backend/src/settings/mod.rs b/backend/src/settings/mod.rs index 3541526..115f42d 100644 --- a/backend/src/settings/mod.rs +++ b/backend/src/settings/mod.rs @@ -23,7 +23,7 @@ pub use traits::{OnResume, OnSet, SettingsRange, TGeneral, TGpu, TCpus, TBattery mod tests { #[test] fn system_defaults_test() { - let settings = super::Settings::system_default("idc".into()); + let settings = super::Settings::system_default("idc".into(), "Cool name".into()); println!("Loaded system settings: {:?}", settings); } } diff --git a/backend/src/settings/steam_deck/cpu.rs b/backend/src/settings/steam_deck/cpu.rs index 2fe0480..909b3a7 100644 --- a/backend/src/settings/steam_deck/cpu.rs +++ b/backend/src/settings/steam_deck/cpu.rs @@ -176,6 +176,7 @@ impl TCpus for Cpus { } fn smt(&mut self) -> &'_ mut bool { + log::debug!("CPU driver thinks SMT is {}", self.smt); &mut self.smt } diff --git a/backend/src/settings/util.rs b/backend/src/settings/util.rs index 83f032d..bb05f80 100644 --- a/backend/src/settings/util.rs +++ b/backend/src/settings/util.rs @@ -5,3 +5,45 @@ pub fn guess_smt(cpus: &Vec) -> bool { } guess } + +#[cfg(test)] +mod test { + use super::*; + + use crate::persist::CpuJson; + + #[test] + fn smt_guess_test() { + let input = vec![ + cpu_with_online(true), + cpu_with_online(true), + cpu_with_online(true), + cpu_with_online(true), + cpu_with_online(true), + cpu_with_online(true), + cpu_with_online(true), + cpu_with_online(true), + ]; + assert_eq!(guess_smt(&input), true); + + let input = vec![ + cpu_with_online(true), + cpu_with_online(false), + cpu_with_online(true), + cpu_with_online(false), + cpu_with_online(true), + cpu_with_online(false), + cpu_with_online(true), + cpu_with_online(false), + ]; + assert_eq!(guess_smt(&input), false); + } + + fn cpu_with_online(status: bool) -> CpuJson { + CpuJson { + online: status, + clock_limits: None, + governor: "schedutil".to_owned(), + } + } +} diff --git a/src/backend.ts b/src/backend.ts index f1bada4..801b8e5 100644 --- a/src/backend.ts +++ b/src/backend.ts @@ -146,7 +146,7 @@ export async function setCpuSmt(status: boolean): Promise { } export async function getCpuSmt(): Promise { - return await call_backend("CPU_get_smt", []); + return (await call_backend("CPU_get_smt", []))[0]; } /*export async function getCpuCount(): Promise {