forked from NG-SD-Plugins/PowerTools
Fix incorrect CPU defaults loaded by defaults button
This commit is contained in:
parent
aff5005ca9
commit
ea89de01d7
8 changed files with 58 additions and 18 deletions
|
@ -122,6 +122,27 @@ pub fn set_smt(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_smt(
|
||||||
|
sender: Sender<ApiMessage>,
|
||||||
|
) -> impl AsyncCallable {
|
||||||
|
let sender = Arc::new(Mutex::new(sender)); // Sender is not Sync; this is required for safety
|
||||||
|
let getter = move || {
|
||||||
|
let sender2 = sender.clone();
|
||||||
|
move || {
|
||||||
|
let (tx, rx) = mpsc::channel();
|
||||||
|
let callback = move |value: bool| tx.send(value).expect("get_smt callback send failed");
|
||||||
|
sender2.lock().unwrap().send(ApiMessage::Cpu(CpuMessage::GetSmt(Box::new(callback)))).expect("get_smt send failed");
|
||||||
|
rx.recv().expect("get_smt callback recv failed")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
super::async_utils::AsyncIshGetter {
|
||||||
|
set_get: getter,
|
||||||
|
trans_getter: |result| {
|
||||||
|
vec![result.into()]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_cpus_online(
|
pub fn get_cpus_online(
|
||||||
sender: Sender<ApiMessage>,
|
sender: Sender<ApiMessage>,
|
||||||
) -> impl AsyncCallable {
|
) -> impl AsyncCallable {
|
||||||
|
|
|
@ -57,6 +57,7 @@ pub enum CpuMessage {
|
||||||
SetCpuOnline(usize, bool),
|
SetCpuOnline(usize, bool),
|
||||||
SetCpusOnline(Vec<bool>),
|
SetCpusOnline(Vec<bool>),
|
||||||
SetSmt(bool, Callback<Vec<bool>>),
|
SetSmt(bool, Callback<Vec<bool>>),
|
||||||
|
GetSmt(Callback<bool>),
|
||||||
GetCpusOnline(Callback<Vec<bool>>),
|
GetCpusOnline(Callback<Vec<bool>>),
|
||||||
SetClockLimits(usize, Option<MinMax<u64>>),
|
SetClockLimits(usize, Option<MinMax<u64>>),
|
||||||
GetClockLimits(usize, Callback<Option<MinMax<u64>>>),
|
GetClockLimits(usize, Callback<Option<MinMax<u64>>>),
|
||||||
|
@ -113,7 +114,10 @@ impl CpuMessage {
|
||||||
result.push(*settings.cpus()[i].online());
|
result.push(*settings.cpus()[i].online());
|
||||||
}
|
}
|
||||||
cb(result);
|
cb(result);
|
||||||
}
|
},
|
||||||
|
Self::GetSmt(cb) => {
|
||||||
|
cb(*settings.smt());
|
||||||
|
},
|
||||||
Self::GetCpusOnline(cb) => {
|
Self::GetCpusOnline(cb) => {
|
||||||
let mut result = Vec::with_capacity(settings.len());
|
let mut result = Vec::with_capacity(settings.len());
|
||||||
for cpu in settings.cpus() {
|
for cpu in settings.cpus() {
|
||||||
|
|
|
@ -125,6 +125,10 @@ fn main() -> Result<(), ()> {
|
||||||
"CPU_set_smt",
|
"CPU_set_smt",
|
||||||
api::cpu::set_smt(api_sender.clone())
|
api::cpu::set_smt(api_sender.clone())
|
||||||
)
|
)
|
||||||
|
.register_async(
|
||||||
|
"CPU_get_smt",
|
||||||
|
api::cpu::get_smt(api_sender.clone())
|
||||||
|
)
|
||||||
.register(
|
.register(
|
||||||
"CPU_set_clock_limits",
|
"CPU_set_clock_limits",
|
||||||
api::cpu::set_clock_limits(api_sender.clone())
|
api::cpu::set_clock_limits(api_sender.clone())
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl Cpus {
|
||||||
if let Some(max_cpu) = Self::cpu_count() {
|
if let Some(max_cpu) = Self::cpu_count() {
|
||||||
let mut sys_cpus = Vec::with_capacity(max_cpu);
|
let mut sys_cpus = Vec::with_capacity(max_cpu);
|
||||||
for i in 0..max_cpu {
|
for i in 0..max_cpu {
|
||||||
sys_cpus.push(Cpu::from_sys(i, oc_limits.cpus.get(i).map(|x| x.to_owned()).unwrap_or_default()));
|
sys_cpus.push(Cpu::system_default(i, oc_limits.cpus.get(i).map(|x| x.to_owned()).unwrap_or_default()));
|
||||||
}
|
}
|
||||||
let (_, can_smt) = Self::system_smt_capabilities();
|
let (_, can_smt) = Self::system_smt_capabilities();
|
||||||
Self {
|
Self {
|
||||||
|
@ -325,7 +325,7 @@ impl Cpu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_sys(cpu_index: usize, oc_limits: CpuLimits) -> Self {
|
/*fn from_sys(cpu_index: usize, oc_limits: CpuLimits) -> Self {
|
||||||
Self {
|
Self {
|
||||||
online: usdpl_back::api::files::read_single(cpu_online_path(cpu_index)).unwrap_or(1u8) != 0,
|
online: usdpl_back::api::files::read_single(cpu_online_path(cpu_index)).unwrap_or(1u8) != 0,
|
||||||
clock_limits: None,
|
clock_limits: None,
|
||||||
|
@ -335,6 +335,17 @@ impl Cpu {
|
||||||
index: cpu_index,
|
index: cpu_index,
|
||||||
state: crate::state::steam_deck::Cpu::default(),
|
state: crate::state::steam_deck::Cpu::default(),
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
fn system_default(cpu_index: usize, oc_limits: CpuLimits) -> Self {
|
||||||
|
Self {
|
||||||
|
online: true,
|
||||||
|
clock_limits: None,
|
||||||
|
governor: "schedutil".to_owned(),
|
||||||
|
limits: oc_limits,
|
||||||
|
index: cpu_index,
|
||||||
|
state: crate::state::steam_deck::Cpu::default(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn limits(&self) -> crate::api::CpuLimits {
|
fn limits(&self) -> crate::api::CpuLimits {
|
||||||
|
|
|
@ -132,6 +132,10 @@ export async function setCpuSmt(status: boolean): Promise<boolean[]> {
|
||||||
return await call_backend("CPU_set_smt", [status]);
|
return await call_backend("CPU_set_smt", [status]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getCpuSmt(): Promise<boolean> {
|
||||||
|
return await call_backend("CPU_get_smt", []);
|
||||||
|
}
|
||||||
|
|
||||||
/*export async function getCpuCount(): Promise<number> {
|
/*export async function getCpuCount(): Promise<number> {
|
||||||
return (await call_backend("CPU_count", []))[0];
|
return (await call_backend("CPU_count", []))[0];
|
||||||
}*/
|
}*/
|
||||||
|
|
|
@ -25,33 +25,28 @@ import { set_value, get_value } from "usdpl-front";
|
||||||
|
|
||||||
interface CpuState {
|
interface CpuState {
|
||||||
reloadThingy: string;
|
reloadThingy: string;
|
||||||
advancedCpu: number;
|
|
||||||
advancedMode: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let advancedMode = false;
|
||||||
|
let advancedCpu = 1;
|
||||||
|
|
||||||
export class Cpus extends Component<{}, CpuState> {
|
export class Cpus extends Component<{}, CpuState> {
|
||||||
constructor(props: {}) {
|
constructor(props: {}) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
reloadThingy: "/shrug",
|
reloadThingy: "/shrug",
|
||||||
advancedCpu: 1,
|
|
||||||
advancedMode: false,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const reloadGUI = (x: string) => this.setState((state) => {
|
const reloadGUI = (x: string) => this.setState((_state) => {
|
||||||
return {
|
return {
|
||||||
reloadThingy: x,
|
reloadThingy: x,
|
||||||
advancedCpu: state.advancedCpu,
|
|
||||||
advancedMode: state.advancedMode,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const total_cpus = (get_value(LIMITS_INFO) as backend.SettingsLimits | null)?.cpu.count ?? 8;
|
const total_cpus = (get_value(LIMITS_INFO) as backend.SettingsLimits | null)?.cpu.count ?? 8;
|
||||||
const advancedCpuIndex = this.state.advancedCpu - 1;
|
const advancedCpuIndex = advancedCpu - 1;
|
||||||
const advancedCpu = this.state.advancedCpu;
|
|
||||||
const advancedMode = this.state.advancedMode;
|
|
||||||
const smtAllowed = (get_value(LIMITS_INFO) as backend.SettingsLimits | null)?.cpu.smt_capable ?? true;
|
const smtAllowed = (get_value(LIMITS_INFO) as backend.SettingsLimits | null)?.cpu.smt_capable ?? true;
|
||||||
|
|
||||||
const governorOptions: SingleDropdownOption[] = (get_value(LIMITS_INFO) as backend.SettingsLimits).cpu.cpus[advancedCpuIndex].governors.map((elem) => {return {
|
const governorOptions: SingleDropdownOption[] = (get_value(LIMITS_INFO) as backend.SettingsLimits).cpu.cpus[advancedCpuIndex].governors.map((elem) => {return {
|
||||||
|
@ -70,12 +65,10 @@ export class Cpus extends Component<{}, CpuState> {
|
||||||
label={tr("Advanced")}
|
label={tr("Advanced")}
|
||||||
description={tr("Enables per-thread configuration")}
|
description={tr("Enables per-thread configuration")}
|
||||||
onChange={(advanced: boolean) => {
|
onChange={(advanced: boolean) => {
|
||||||
//advancedMode = advanced;
|
advancedMode = advanced;
|
||||||
this.setState((state) => {
|
this.setState((state) => {
|
||||||
return {
|
return {
|
||||||
reloadThingy: state.reloadThingy,
|
reloadThingy: state.reloadThingy,
|
||||||
advancedCpu: state.advancedCpu,
|
|
||||||
advancedMode: advanced,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
@ -232,11 +225,10 @@ export class Cpus extends Component<{}, CpuState> {
|
||||||
min={1}
|
min={1}
|
||||||
showValue={true}
|
showValue={true}
|
||||||
onChange={(cpuNum: number) => {
|
onChange={(cpuNum: number) => {
|
||||||
|
advancedCpu = cpuNum;
|
||||||
this.setState((state) => {
|
this.setState((state) => {
|
||||||
return {
|
return {
|
||||||
reloadThingy: state.reloadThingy,
|
reloadThingy: state.reloadThingy,
|
||||||
advancedCpu: cpuNum,
|
|
||||||
advancedMode: state.advancedMode,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -117,6 +117,9 @@ const reload = function() {
|
||||||
set_value(ONLINE_CPUS, count);
|
set_value(ONLINE_CPUS, count);
|
||||||
set_value(SMT_CPU, statii.length > 3 && statii[0] == statii[1] && statii[2] == statii[3]);
|
set_value(SMT_CPU, statii.length > 3 && statii[0] == statii[1] && statii[2] == statii[3]);
|
||||||
});
|
});
|
||||||
|
backend.resolve(backend.getCpuSmt(), (smt: boolean) => {
|
||||||
|
set_value(SMT_CPU, smt);
|
||||||
|
});
|
||||||
backend.resolve(backend.getCpuClockLimits(0), (limits: number[]) => {
|
backend.resolve(backend.getCpuClockLimits(0), (limits: number[]) => {
|
||||||
set_value(CLOCK_MIN_CPU, limits[0]);
|
set_value(CLOCK_MIN_CPU, limits[0]);
|
||||||
set_value(CLOCK_MAX_CPU, limits[1]);
|
set_value(CLOCK_MAX_CPU, limits[1]);
|
||||||
|
|
1
translations/fr-FR.mo
Symbolic link
1
translations/fr-FR.mo
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
fr-CA.mo
|
Loading…
Reference in a new issue