Improve SMT heuristic when loading from saved
This commit is contained in:
parent
fbb68e0d51
commit
8c763f241f
5 changed files with 15 additions and 10 deletions
|
@ -101,7 +101,7 @@ impl<C: AsMut<Cpu> + AsRef<Cpu> + TCpu + FromGenericCpuInfo> Cpus<C> {
|
||||||
let (_, can_smt) = Self::system_smt_capabilities();
|
let (_, can_smt) = Self::system_smt_capabilities();
|
||||||
let mut result = Vec::with_capacity(other.len());
|
let mut result = Vec::with_capacity(other.len());
|
||||||
let max_cpus = Self::cpu_count();
|
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() {
|
for (i, cpu) in other.drain(..).enumerate() {
|
||||||
// prevent having more CPUs than available
|
// prevent having more CPUs than available
|
||||||
if let Some(max_cpus) = max_cpus {
|
if let Some(max_cpus) = max_cpus {
|
||||||
|
@ -109,8 +109,7 @@ impl<C: AsMut<Cpu> + AsRef<Cpu> + TCpu + FromGenericCpuInfo> Cpus<C> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut new_cpu = C::from_json_and_limits(cpu, version, i, limits.clone());
|
let new_cpu = C::from_json_and_limits(cpu, version, i, limits.clone());
|
||||||
smt_disabled &= *new_cpu.online() as usize != i % 2;
|
|
||||||
result.push(new_cpu);
|
result.push(new_cpu);
|
||||||
}
|
}
|
||||||
if let Some(max_cpus) = max_cpus {
|
if let Some(max_cpus) = max_cpus {
|
||||||
|
@ -123,7 +122,7 @@ impl<C: AsMut<Cpu> + AsRef<Cpu> + TCpu + FromGenericCpuInfo> Cpus<C> {
|
||||||
}
|
}
|
||||||
Self {
|
Self {
|
||||||
cpus: result,
|
cpus: result,
|
||||||
smt: !smt_disabled,
|
smt: smt_guess,
|
||||||
smt_capable: can_smt,
|
smt_capable: can_smt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ mod error;
|
||||||
mod general;
|
mod general;
|
||||||
mod min_max;
|
mod min_max;
|
||||||
mod traits;
|
mod traits;
|
||||||
|
mod util;
|
||||||
|
|
||||||
pub mod generic;
|
pub mod generic;
|
||||||
pub mod generic_amd;
|
pub mod generic_amd;
|
||||||
|
|
|
@ -120,7 +120,7 @@ impl Cpus {
|
||||||
let (_, can_smt) = Self::system_smt_capabilities();
|
let (_, can_smt) = Self::system_smt_capabilities();
|
||||||
let mut result = Vec::with_capacity(other.len());
|
let mut result = Vec::with_capacity(other.len());
|
||||||
let max_cpus = Self::cpu_count();
|
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() {
|
for (i, cpu) in other.drain(..).enumerate() {
|
||||||
// prevent having more CPUs than available
|
// prevent having more CPUs than available
|
||||||
if let Some(max_cpus) = max_cpus {
|
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());
|
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);
|
result.push(new_cpu);
|
||||||
}
|
}
|
||||||
if let Some(max_cpus) = max_cpus {
|
if let Some(max_cpus) = max_cpus {
|
||||||
|
@ -142,7 +141,7 @@ impl Cpus {
|
||||||
}
|
}
|
||||||
Self {
|
Self {
|
||||||
cpus: result,
|
cpus: result,
|
||||||
smt: !smt_disabled,
|
smt: smt_guess,
|
||||||
smt_capable: can_smt,
|
smt_capable: can_smt,
|
||||||
limits: oc_limits,
|
limits: oc_limits,
|
||||||
driver_mode: driver,
|
driver_mode: driver,
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl Cpus {
|
||||||
let (_, can_smt) = Self::system_smt_capabilities();
|
let (_, can_smt) = Self::system_smt_capabilities();
|
||||||
let mut result = Vec::with_capacity(other.len());
|
let mut result = Vec::with_capacity(other.len());
|
||||||
let max_cpus = Self::cpu_count();
|
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() {
|
for (i, cpu) in other.drain(..).enumerate() {
|
||||||
// prevent having more CPUs than available
|
// prevent having more CPUs than available
|
||||||
if let Some(max_cpus) = max_cpus {
|
if let Some(max_cpus) = max_cpus {
|
||||||
|
@ -114,7 +114,6 @@ impl Cpus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let new_cpu = Cpu::from_json(cpu, version, i);
|
let new_cpu = Cpu::from_json(cpu, version, i);
|
||||||
smt_disabled &= new_cpu.online as usize != i % 2;
|
|
||||||
result.push(new_cpu);
|
result.push(new_cpu);
|
||||||
}
|
}
|
||||||
if let Some(max_cpus) = max_cpus {
|
if let Some(max_cpus) = max_cpus {
|
||||||
|
@ -127,7 +126,7 @@ impl Cpus {
|
||||||
}
|
}
|
||||||
Self {
|
Self {
|
||||||
cpus: result,
|
cpus: result,
|
||||||
smt: !smt_disabled,
|
smt: smt_guess,
|
||||||
smt_capable: can_smt,
|
smt_capable: can_smt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
7
backend/src/settings/util.rs
Normal file
7
backend/src/settings/util.rs
Normal 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
|
||||||
|
}
|
Loading…
Reference in a new issue