From 8c763f241f8f0be9d63bc4ce44c23b66c0f2fcfc Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Thu, 5 Jan 2023 21:35:53 -0500 Subject: [PATCH] Improve SMT heuristic when loading from saved --- backend/src/settings/generic/cpu.rs | 7 +++---- backend/src/settings/mod.rs | 1 + backend/src/settings/steam_deck/cpu.rs | 5 ++--- backend/src/settings/unknown/cpu.rs | 5 ++--- backend/src/settings/util.rs | 7 +++++++ 5 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 backend/src/settings/util.rs diff --git a/backend/src/settings/generic/cpu.rs b/backend/src/settings/generic/cpu.rs index a2fe995..b4bba83 100644 --- a/backend/src/settings/generic/cpu.rs +++ b/backend/src/settings/generic/cpu.rs @@ -101,7 +101,7 @@ impl + AsRef + TCpu + FromGenericCpuInfo> Cpus { let (_, can_smt) = Self::system_smt_capabilities(); let mut result = Vec::with_capacity(other.len()); let max_cpus = Self::cpu_count(); - let mut smt_disabled = false; + let smt_guess = crate::settings::util::guess_smt(&other) && can_smt; for (i, cpu) in other.drain(..).enumerate() { // prevent having more CPUs than available if let Some(max_cpus) = max_cpus { @@ -109,8 +109,7 @@ impl + AsRef + TCpu + FromGenericCpuInfo> Cpus { break; } } - let mut new_cpu = C::from_json_and_limits(cpu, version, i, limits.clone()); - smt_disabled &= *new_cpu.online() as usize != i % 2; + let new_cpu = C::from_json_and_limits(cpu, version, i, limits.clone()); result.push(new_cpu); } if let Some(max_cpus) = max_cpus { @@ -123,7 +122,7 @@ impl + AsRef + TCpu + FromGenericCpuInfo> Cpus { } Self { cpus: result, - smt: !smt_disabled, + smt: smt_guess, smt_capable: can_smt, } } diff --git a/backend/src/settings/mod.rs b/backend/src/settings/mod.rs index a24b57e..3541526 100644 --- a/backend/src/settings/mod.rs +++ b/backend/src/settings/mod.rs @@ -4,6 +4,7 @@ mod error; mod general; mod min_max; mod traits; +mod util; pub mod generic; pub mod generic_amd; diff --git a/backend/src/settings/steam_deck/cpu.rs b/backend/src/settings/steam_deck/cpu.rs index 7ae9630..83a1909 100644 --- a/backend/src/settings/steam_deck/cpu.rs +++ b/backend/src/settings/steam_deck/cpu.rs @@ -120,7 +120,7 @@ impl Cpus { let (_, can_smt) = Self::system_smt_capabilities(); let mut result = Vec::with_capacity(other.len()); let max_cpus = Self::cpu_count(); - let mut smt_disabled = false; + let smt_guess = crate::settings::util::guess_smt(&other) && can_smt; for (i, cpu) in other.drain(..).enumerate() { // prevent having more CPUs than available if let Some(max_cpus) = max_cpus { @@ -129,7 +129,6 @@ impl Cpus { } } let new_cpu = Cpu::from_json(cpu, version, i, oc_limits.cpus.get(i).map(|x| x.to_owned()).unwrap_or_default()); - smt_disabled &= new_cpu.online as usize != i % 2; result.push(new_cpu); } if let Some(max_cpus) = max_cpus { @@ -142,7 +141,7 @@ impl Cpus { } Self { cpus: result, - smt: !smt_disabled, + smt: smt_guess, smt_capable: can_smt, limits: oc_limits, driver_mode: driver, diff --git a/backend/src/settings/unknown/cpu.rs b/backend/src/settings/unknown/cpu.rs index 76982f4..909c746 100644 --- a/backend/src/settings/unknown/cpu.rs +++ b/backend/src/settings/unknown/cpu.rs @@ -105,7 +105,7 @@ impl Cpus { let (_, can_smt) = Self::system_smt_capabilities(); let mut result = Vec::with_capacity(other.len()); let max_cpus = Self::cpu_count(); - let mut smt_disabled = false; + let smt_guess = crate::settings::util::guess_smt(&other) && can_smt; for (i, cpu) in other.drain(..).enumerate() { // prevent having more CPUs than available if let Some(max_cpus) = max_cpus { @@ -114,7 +114,6 @@ impl Cpus { } } let new_cpu = Cpu::from_json(cpu, version, i); - smt_disabled &= new_cpu.online as usize != i % 2; result.push(new_cpu); } if let Some(max_cpus) = max_cpus { @@ -127,7 +126,7 @@ impl Cpus { } Self { cpus: result, - smt: !smt_disabled, + smt: smt_guess, smt_capable: can_smt, } } diff --git a/backend/src/settings/util.rs b/backend/src/settings/util.rs new file mode 100644 index 0000000..83f032d --- /dev/null +++ b/backend/src/settings/util.rs @@ -0,0 +1,7 @@ +pub fn guess_smt(cpus: &Vec) -> bool { + let mut guess = true; + for i in (0..cpus.len()).step_by(2) { + guess &= cpus[i].online == cpus[i+1].online; + } + guess +}