Improve SMT heuristic when loading from saved

This commit is contained in:
NGnius (Graham) 2023-01-05 21:35:53 -05:00
parent fbb68e0d51
commit 8c763f241f
5 changed files with 15 additions and 10 deletions

View file

@ -101,7 +101,7 @@ impl<C: AsMut<Cpu> + AsRef<Cpu> + TCpu + FromGenericCpuInfo> Cpus<C> {
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<C: AsMut<Cpu> + AsRef<Cpu> + TCpu + FromGenericCpuInfo> Cpus<C> {
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<C: AsMut<Cpu> + AsRef<Cpu> + TCpu + FromGenericCpuInfo> Cpus<C> {
}
Self {
cpus: result,
smt: !smt_disabled,
smt: smt_guess,
smt_capable: can_smt,
}
}

View file

@ -4,6 +4,7 @@ mod error;
mod general;
mod min_max;
mod traits;
mod util;
pub mod generic;
pub mod generic_amd;

View file

@ -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,

View file

@ -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,
}
}

View file

@ -0,0 +1,7 @@
pub fn guess_smt(cpus: &Vec<crate::persist::CpuJson>) -> bool {
let mut guess = true;
for i in (0..cpus.len()).step_by(2) {
guess &= cpus[i].online == cpus[i+1].online;
}
guess
}