Add new API calls to front-end for #44 and #48 and improve resolve's type '''safety'''

This commit is contained in:
NGnius (Graham) 2022-11-13 12:41:45 -05:00
parent 1a49516d51
commit d6196c6dad
2 changed files with 20 additions and 16 deletions

View file

@ -4,7 +4,7 @@ const USDPL_PORT: number = 44443;
// Utility // Utility
export function resolve(promise: Promise<any>, setter: any) { export function resolve<T>(promise: Promise<T>, setter: (t: T) => void) {
(async function () { (async function () {
let data = await promise; let data = await promise;
if (data != null) { if (data != null) {
@ -62,7 +62,7 @@ export async function unsetBatteryChargeRate(): Promise<any[]> {
// CPU // CPU
export async function setCpuSmt(status: boolean): Promise<number> { export async function setCpuSmt(status: boolean): Promise<boolean> {
return (await call_backend("CPU_set_smt", [status]))[0]; return (await call_backend("CPU_set_smt", [status]))[0];
} }
@ -158,7 +158,7 @@ export async function loadGeneralSystemSettings(): Promise<boolean> {
return (await call_backend("GENERAL_load_system_settings", []))[0]; return (await call_backend("GENERAL_load_system_settings", []))[0];
} }
export async function getGeneralSettingsName(): Promise<boolean> { export async function getGeneralSettingsName(): Promise<string> {
return (await call_backend("GENERAL_get_name", []))[0]; return (await call_backend("GENERAL_get_name", []))[0];
} }

View file

@ -29,7 +29,6 @@ var startHook: any = null;
var usdplReady = false; var usdplReady = false;
var smtAllowed = true; var smtAllowed = true;
var smtGlobal = smtAllowed;
// usdpl persistent store keys // usdpl persistent store keys
@ -43,6 +42,7 @@ const CHARGE_DESIGN_BATT = "BATTERY_charge_design"
const TOTAL_CPUS = "CPUs_total"; const TOTAL_CPUS = "CPUs_total";
const ONLINE_CPUS = "CPUs_online"; const ONLINE_CPUS = "CPUs_online";
const SMT_CPU = "CPUs_SMT";
const CLOCK_MIN_CPU = "CPUs_min_clock"; const CLOCK_MIN_CPU = "CPUs_min_clock";
const CLOCK_MAX_CPU = "CPUs_max_clock"; const CLOCK_MAX_CPU = "CPUs_max_clock";
const GOVERNOR_CPU = "CPUs_governor"; const GOVERNOR_CPU = "CPUs_governor";
@ -80,7 +80,7 @@ const reload = function() {
// TODO: allow for per-core control of online status // TODO: allow for per-core control of online status
const count = countCpus(statii); const count = countCpus(statii);
set_value(ONLINE_CPUS, count); set_value(ONLINE_CPUS, count);
smtGlobal = statii.length > 3 && statii[0] == statii[1] && statii[2] == statii[3] && smtAllowed; set_value(SMT_CPU, statii.length > 3 && statii[0] == statii[1] && statii[2] == statii[3] && smtAllowed);
}); });
// TODO: allow for per-core control of clock limits // TODO: allow for per-core control of clock limits
backend.resolve(backend.getCpuClockLimits(0), (limits: number[]) => { backend.resolve(backend.getCpuClockLimits(0), (limits: number[]) => {
@ -181,18 +181,21 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
</div> </div>
{smtAllowed && <PanelSectionRow> {smtAllowed && <PanelSectionRow>
<ToggleField <ToggleField
checked={smtGlobal} checked={get_value(SMT_CPU)}
label="SMT" label="SMT"
description="Enables odd-numbered CPUs" description="Enables odd-numbered CPUs"
onChange={(smt: boolean) => { onChange={(smt: boolean) => {
console.debug("SMT is now " + smt.toString()); console.debug("SMT is now " + smt.toString());
const cpus = get_value(ONLINE_CPUS); const cpus = get_value(ONLINE_CPUS);
smtGlobal = smt && smtAllowed; const smtNow = smt && smtAllowed
// TODO: move SMT setting logic back to back-end // TODO: move SMT setting logic back to back-end
backend.resolve(backend.setCpuSmt(smtNow), (newVal: boolean) => {
set_value(SMT_CPU, newVal);
});
let onlines: boolean[] = []; let onlines: boolean[] = [];
for (let i = 0; i < total_cpus; i++) { for (let i = 0; i < total_cpus; i++) {
const online = (smtGlobal? i < cpus : (i % 2 == 0) && (i < cpus * 2)) const online = (smtNow? i < cpus : (i % 2 == 0) && (i < cpus * 2))
|| (!smtGlobal && cpus == 4); || (!smtNow && cpus == 4);
onlines.push(online); onlines.push(online);
} }
backend.resolve(backend.setCpuOnlines(onlines), (statii: boolean[]) => { backend.resolve(backend.setCpuOnlines(onlines), (statii: boolean[]) => {
@ -209,7 +212,7 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
label="Threads" label="Threads"
value={get_value(ONLINE_CPUS)} value={get_value(ONLINE_CPUS)}
step={1} step={1}
max={smtGlobal? total_cpus : total_cpus/2} max={get_value(SMT_CPU)? total_cpus : total_cpus/2}
min={1} min={1}
showValue={true} showValue={true}
onChange={(cpus: number) => { onChange={(cpus: number) => {
@ -217,9 +220,10 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
const onlines = get_value(ONLINE_CPUS); const onlines = get_value(ONLINE_CPUS);
if (cpus != onlines) { if (cpus != onlines) {
set_value(ONLINE_CPUS, cpus); set_value(ONLINE_CPUS, cpus);
const smtNow = get_value(SMT_CPU);
let onlines: boolean[] = []; let onlines: boolean[] = [];
for (let i = 0; i < total_cpus; i++) { for (let i = 0; i < total_cpus; i++) {
const online = smtGlobal? i < cpus : (i % 2 == 0) && (i < cpus * 2); const online = smtNow? i < cpus : (i % 2 == 0) && (i < cpus * 2);
onlines.push(online); onlines.push(online);
} }
backend.resolve(backend.setCpuOnlines(onlines), (statii: boolean[]) => { backend.resolve(backend.setCpuOnlines(onlines), (statii: boolean[]) => {
@ -249,7 +253,7 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
for (let i = 0; i < total_cpus; i++) { for (let i = 0; i < total_cpus; i++) {
backend.resolve(backend.unsetCpuClockLimits(i), (_idc: any[]) => {}); backend.resolve(backend.unsetCpuClockLimits(i), (_idc: any[]) => {});
} }
backend.resolve(backend.waitForComplete(), (_: boolean[]) => { backend.resolve(backend.waitForComplete(), (_: boolean) => {
reloadGUI("CPUUnsetFreq"); reloadGUI("CPUUnsetFreq");
}); });
} }
@ -277,7 +281,7 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
set_value(CLOCK_MAX_CPU, limits[1]); set_value(CLOCK_MAX_CPU, limits[1]);
}); });
} }
backend.resolve(backend.waitForComplete(), (_: boolean[]) => { backend.resolve(backend.waitForComplete(), (_: boolean) => {
reloadGUI("CPUMinFreq"); reloadGUI("CPUMinFreq");
}); });
reloadGUI("CPUMinFreqImmediate"); reloadGUI("CPUMinFreqImmediate");
@ -306,7 +310,7 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
set_value(CLOCK_MAX_CPU, limits[1]); set_value(CLOCK_MAX_CPU, limits[1]);
}); });
} }
backend.resolve(backend.waitForComplete(), (_: boolean[]) => { backend.resolve(backend.waitForComplete(), (_: boolean) => {
reloadGUI("CPUMaxFreq"); reloadGUI("CPUMaxFreq");
}); });
reloadGUI("CPUMaxFreqImmediate"); reloadGUI("CPUMaxFreqImmediate");
@ -621,9 +625,9 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
backend.setGeneralPersistent(false), backend.setGeneralPersistent(false),
(val: boolean) => { (val: boolean) => {
set_value(PERSISTENT_GEN, val); set_value(PERSISTENT_GEN, val);
backend.resolve(backend.loadGeneralDefaultSettings(), (_: any[]) => { backend.resolve(backend.loadGeneralSystemSettings(), (_) => {
reload(); reload();
backend.resolve(backend.waitForComplete(), (_: any[]) => {reloadGUI("LoadDefaults")}); backend.resolve(backend.waitForComplete(), (_) => {reloadGUI("LoadSystemDefaults")});
}); });
} }
); );