Add global governor dropdown (hidden for default SD config)

This commit is contained in:
NGnius (Graham) 2023-02-02 20:20:16 -05:00
parent 286ad30378
commit e63310f62e
11 changed files with 67 additions and 18 deletions

2
backend/Cargo.lock generated
View file

@ -826,7 +826,7 @@ dependencies = [
[[package]]
name = "powertools-rs"
version = "1.1.0-beta5"
version = "1.1.0-beta6"
dependencies = [
"async-trait",
"limits_core",

View file

@ -1,6 +1,6 @@
[package]
name = "powertools-rs"
version = "1.1.0-beta5"
version = "1.1.0-beta6"
edition = "2021"
authors = ["NGnius (Graham) <ngniusness@gmail.com>"]
description = "Backend (superuser) functionality for PowerTools"

View file

@ -33,6 +33,7 @@ pub struct CpusLimits {
pub cpus: Vec<CpuLimits>,
pub count: usize,
pub smt_capable: bool,
pub governors: Vec<String>,
}
#[derive(Serialize, Deserialize)]

View file

@ -134,6 +134,7 @@ impl<C: AsMut<Cpu> + AsRef<Cpu> + TCpu + OnResume + OnSet> TCpus for Cpus<C> {
cpus: self.cpus.iter().map(|x| x.as_ref().limits()).collect(),
count: self.cpus.len(),
smt_capable: self.smt_capable,
governors: Vec::with_capacity(0),
}
}

View file

@ -155,6 +155,12 @@ impl TCpus for Cpus {
cpus: self.cpus.iter().map(|x| x.limits()).collect(),
count: self.cpus.len(),
smt_capable: self.smt_capable,
governors: if self.limits.global_governors {
self.cpus.iter()
.next()
.map(|x| x.governors())
.unwrap_or_else(|| Vec::with_capacity(0))
} else { Vec::with_capacity(0) },
}
}
@ -358,7 +364,7 @@ impl Cpu {
min: self.limits.clock_max.min,
max: self.limits.clock_max.max
}),
clock_step: 100,
clock_step: self.limits.clock_step,
governors: self.governors(),
}
}

View file

@ -222,20 +222,18 @@ impl OnResume for Gpu {
}
}
const PPT_DIVISOR: u64 = 1_000_000;
impl TGpu for Gpu {
fn limits(&self) -> crate::api::GpuLimits {
crate::api::GpuLimits {
fast_ppt_limits: Some(RangeLimit {
min: self.limits.fast_ppt.min / PPT_DIVISOR,
max: self.limits.fast_ppt.max / PPT_DIVISOR,
min: self.limits.fast_ppt.min / self.limits.ppt_divisor,
max: self.limits.fast_ppt.max / self.limits.ppt_divisor,
}),
slow_ppt_limits: Some(RangeLimit {
min: self.limits.slow_ppt.min / PPT_DIVISOR,
max: self.limits.slow_ppt.max / PPT_DIVISOR,
min: self.limits.slow_ppt.min / self.limits.ppt_divisor,
max: self.limits.slow_ppt.max / self.limits.ppt_divisor,
}),
ppt_step: 1,
ppt_step: self.limits.ppt_step,
tdp_limits: None,
tdp_boost_limits: None,
tdp_step: 42,
@ -247,7 +245,7 @@ impl TGpu for Gpu {
min: self.limits.clock_max.min,
max: self.limits.clock_max.max,
}),
clock_step: 100,
clock_step: self.limits.clock_step,
memory_control_capable: true,
}
}
@ -257,12 +255,12 @@ impl TGpu for Gpu {
}
fn ppt(&mut self, fast: Option<u64>, slow: Option<u64>) {
self.fast_ppt = fast.map(|x| x * PPT_DIVISOR);
self.slow_ppt = slow.map(|x| x * PPT_DIVISOR);
self.fast_ppt = fast.map(|x| x * self.limits.ppt_divisor);
self.slow_ppt = slow.map(|x| x * self.limits.ppt_divisor);
}
fn get_ppt(&self) -> (Option<u64>, Option<u64>) {
(self.fast_ppt.map(|x| x / PPT_DIVISOR), self.slow_ppt.map(|x| x / PPT_DIVISOR))
(self.fast_ppt.map(|x| x / self.limits.ppt_divisor), self.slow_ppt.map(|x| x / self.limits.ppt_divisor))
}
fn clock_limits(&mut self, limits: Option<MinMax<u64>>) {

View file

@ -66,12 +66,14 @@ impl Default for BatteryLimits {
#[derive(Serialize, Deserialize, Clone, Debug)]
pub(super) struct CpusLimits {
pub cpus: Vec<CpuLimits>,
pub global_governors: bool,
}
impl Default for CpusLimits {
fn default() -> Self {
Self {
cpus: [(); 8].iter().map(|_| CpuLimits::default()).collect()
cpus: [(); 8].iter().map(|_| CpuLimits::default()).collect(),
global_governors: false,
}
}
}
@ -80,13 +82,15 @@ impl Default for CpusLimits {
pub(super) struct CpuLimits {
pub clock_min: MinMax<u64>,
pub clock_max: MinMax<u64>,
pub clock_step: u64,
}
impl Default for CpuLimits {
fn default() -> Self {
Self {
clock_min: MinMax { min: 1400, max: 3500 },
clock_max: MinMax { min: 400, max: 3500 }
clock_max: MinMax { min: 400, max: 3500 },
clock_step: 100,
}
}
}
@ -95,8 +99,11 @@ impl Default for CpuLimits {
pub(super) struct GpuLimits {
pub fast_ppt: MinMax<u64>,
pub slow_ppt: MinMax<u64>,
pub ppt_divisor: u64,
pub ppt_step: u64,
pub clock_min: MinMax<u64>,
pub clock_max: MinMax<u64>,
pub clock_step: u64,
}
impl Default for GpuLimits {
@ -104,8 +111,11 @@ impl Default for GpuLimits {
Self {
fast_ppt: MinMax { min: 1000000, max: 30_000_000 },
slow_ppt: MinMax { min: 1000000, max: 29_000_000 },
ppt_divisor: 1_000_000,
ppt_step: 1,
clock_min: MinMax { min: 200, max: 1600 },
clock_max: MinMax { min: 200, max: 1600 }
clock_max: MinMax { min: 200, max: 1600 },
clock_step: 100,
}
}
}

View file

@ -138,6 +138,7 @@ impl TCpus for Cpus {
cpus: self.cpus.iter().map(|x| x.limits()).collect(),
count: self.cpus.len(),
smt_capable: self.smt_capable,
governors: Vec::with_capacity(0),
}
}

View file

@ -1,6 +1,6 @@
{
"name": "PowerTools",
"version": "1.1.0-beta5",
"version": "1.1.0-beta6",
"description": "Power tweaks for power users",
"scripts": {
"build": "shx rm -rf dist && rollup -c",

View file

@ -72,6 +72,7 @@ export type CpusLimits = {
cpus: CpuLimits[];
count: number;
smt_capable: boolean;
governors: string[];
};
export type GeneralLimits = {};

View file

@ -54,6 +54,11 @@ export class Cpus extends Component<{}, CpuState> {
label: <span>{elem}</span>,
};});
const governorGlobalOptions: SingleDropdownOption[] = (get_value(LIMITS_INFO) as backend.SettingsLimits).cpu.governors.map((elem) => {return {
data: elem,
label: <span>{elem}</span>,
};});
return (<Fragment>
{/* CPU */}
<div className={staticClasses.PanelSectionTitle}>
@ -215,6 +220,32 @@ export class Cpus extends Component<{}, CpuState> {
}}
/>}
</PanelSectionRow>}
{!advancedMode && governorGlobalOptions.length != 0 && <PanelSectionRow>
<Field
label={tr("Governor")}
>
<Dropdown
menuLabel={tr("Governor")}
rgOptions={governorGlobalOptions}
selectedOption={governorGlobalOptions.find((val: SingleDropdownOption, _index, _arr) => {
backend.log(backend.LogLevel.Debug, "POWERTOOLS: array item " + val.toString());
backend.log(backend.LogLevel.Debug, "POWERTOOLS: looking for data " + get_value(GOVERNOR_CPU)[0].toString());
return val.data == get_value(GOVERNOR_CPU)[0];
})}
strDefaultLabel={get_value(GOVERNOR_CPU)[0]}
onChange={(elem: SingleDropdownOption) => {
backend.log(backend.LogLevel.Debug, "Governor global dropdown selected " + elem.data.toString());
const governors = get_value(GOVERNOR_CPU);
for (let i = 0; i < total_cpus; i++) {
governors[i] = elem.data as string;
backend.resolve(backend.setCpuGovernor(i, elem.data as string), (_: string) => {});
}
set_value(GOVERNOR_CPU, governors);
reloadGUI("CPUGlobalGovernor");
}}
/>
</Field>
</PanelSectionRow>}
{/* CPU advanced mode */}
{advancedMode && <PanelSectionRow>
<SliderField