From ea89de01d7de5ef32d30015970e208bc6c39f9b8 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Wed, 18 Jan 2023 21:05:04 -0500 Subject: [PATCH] Fix incorrect CPU defaults loaded by defaults button --- backend/src/api/cpu.rs | 21 +++++++++++++++++++++ backend/src/api/handler.rs | 6 +++++- backend/src/main.rs | 4 ++++ backend/src/settings/steam_deck/cpu.rs | 15 +++++++++++++-- src/backend.ts | 4 ++++ src/components/cpus.tsx | 22 +++++++--------------- src/index.tsx | 3 +++ translations/fr-FR.mo | 1 + 8 files changed, 58 insertions(+), 18 deletions(-) create mode 120000 translations/fr-FR.mo diff --git a/backend/src/api/cpu.rs b/backend/src/api/cpu.rs index 1c4d35f..e1f8aa6 100644 --- a/backend/src/api/cpu.rs +++ b/backend/src/api/cpu.rs @@ -122,6 +122,27 @@ pub fn set_smt( } } +pub fn get_smt( + sender: Sender, +) -> 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( sender: Sender, ) -> impl AsyncCallable { diff --git a/backend/src/api/handler.rs b/backend/src/api/handler.rs index 48a4962..f339ff8 100644 --- a/backend/src/api/handler.rs +++ b/backend/src/api/handler.rs @@ -57,6 +57,7 @@ pub enum CpuMessage { SetCpuOnline(usize, bool), SetCpusOnline(Vec), SetSmt(bool, Callback>), + GetSmt(Callback), GetCpusOnline(Callback>), SetClockLimits(usize, Option>), GetClockLimits(usize, Callback>>), @@ -113,7 +114,10 @@ impl CpuMessage { result.push(*settings.cpus()[i].online()); } cb(result); - } + }, + Self::GetSmt(cb) => { + cb(*settings.smt()); + }, Self::GetCpusOnline(cb) => { let mut result = Vec::with_capacity(settings.len()); for cpu in settings.cpus() { diff --git a/backend/src/main.rs b/backend/src/main.rs index 43e9696..0603a24 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -125,6 +125,10 @@ fn main() -> Result<(), ()> { "CPU_set_smt", api::cpu::set_smt(api_sender.clone()) ) + .register_async( + "CPU_get_smt", + api::cpu::get_smt(api_sender.clone()) + ) .register( "CPU_set_clock_limits", api::cpu::set_clock_limits(api_sender.clone()) diff --git a/backend/src/settings/steam_deck/cpu.rs b/backend/src/settings/steam_deck/cpu.rs index 539a5f4..038558b 100644 --- a/backend/src/settings/steam_deck/cpu.rs +++ b/backend/src/settings/steam_deck/cpu.rs @@ -91,7 +91,7 @@ impl Cpus { if let Some(max_cpu) = Self::cpu_count() { let mut sys_cpus = Vec::with_capacity(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(); 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 { online: usdpl_back::api::files::read_single(cpu_online_path(cpu_index)).unwrap_or(1u8) != 0, clock_limits: None, @@ -335,6 +335,17 @@ impl Cpu { index: cpu_index, 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 { diff --git a/src/backend.ts b/src/backend.ts index 26d88f4..f3dfbd5 100644 --- a/src/backend.ts +++ b/src/backend.ts @@ -132,6 +132,10 @@ export async function setCpuSmt(status: boolean): Promise { return await call_backend("CPU_set_smt", [status]); } +export async function getCpuSmt(): Promise { + return await call_backend("CPU_get_smt", []); +} + /*export async function getCpuCount(): Promise { return (await call_backend("CPU_count", []))[0]; }*/ diff --git a/src/components/cpus.tsx b/src/components/cpus.tsx index fcc73dc..9089dac 100644 --- a/src/components/cpus.tsx +++ b/src/components/cpus.tsx @@ -25,33 +25,28 @@ import { set_value, get_value } from "usdpl-front"; interface CpuState { reloadThingy: string; - advancedCpu: number; - advancedMode: boolean; } +let advancedMode = false; +let advancedCpu = 1; + export class Cpus extends Component<{}, CpuState> { constructor(props: {}) { super(props); this.state = { reloadThingy: "/shrug", - advancedCpu: 1, - advancedMode: false, }; } render() { - const reloadGUI = (x: string) => this.setState((state) => { + const reloadGUI = (x: string) => this.setState((_state) => { return { reloadThingy: x, - advancedCpu: state.advancedCpu, - advancedMode: state.advancedMode, }; }); const total_cpus = (get_value(LIMITS_INFO) as backend.SettingsLimits | null)?.cpu.count ?? 8; - const advancedCpuIndex = this.state.advancedCpu - 1; - const advancedCpu = this.state.advancedCpu; - const advancedMode = this.state.advancedMode; + const advancedCpuIndex = advancedCpu - 1; 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 { @@ -70,12 +65,10 @@ export class Cpus extends Component<{}, CpuState> { label={tr("Advanced")} description={tr("Enables per-thread configuration")} onChange={(advanced: boolean) => { - //advancedMode = advanced; + advancedMode = advanced; this.setState((state) => { return { reloadThingy: state.reloadThingy, - advancedCpu: state.advancedCpu, - advancedMode: advanced, }; }); }} @@ -232,11 +225,10 @@ export class Cpus extends Component<{}, CpuState> { min={1} showValue={true} onChange={(cpuNum: number) => { + advancedCpu = cpuNum; this.setState((state) => { return { reloadThingy: state.reloadThingy, - advancedCpu: cpuNum, - advancedMode: state.advancedMode, }; }); }} diff --git a/src/index.tsx b/src/index.tsx index 4ad0757..56cf799 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -117,6 +117,9 @@ const reload = function() { set_value(ONLINE_CPUS, count); 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[]) => { set_value(CLOCK_MIN_CPU, limits[0]); set_value(CLOCK_MAX_CPU, limits[1]); diff --git a/translations/fr-FR.mo b/translations/fr-FR.mo new file mode 120000 index 0000000..303685b --- /dev/null +++ b/translations/fr-FR.mo @@ -0,0 +1 @@ +fr-CA.mo \ No newline at end of file