mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2025-02-25 18:55:26 -06:00
Add power cap adjustment
This commit is contained in:
parent
0c002452bf
commit
13fc0166bd
@ -133,6 +133,8 @@ pub struct GpuInfo {
|
||||
pub pci_slot: String,
|
||||
pub power_profile: Option<PowerProfile>,
|
||||
pub clocks_table: Option<ClocksTable>,
|
||||
pub power_cap: Option<i64>,
|
||||
pub power_cap_max: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
@ -213,6 +215,11 @@ impl GpuController {
|
||||
Err(_) => None,
|
||||
};
|
||||
|
||||
if let Some(hw_mon) = &self.hw_mon {
|
||||
info.power_cap = hw_mon.get_power_cap();
|
||||
info.power_cap_max = hw_mon.get_power_cap_max();
|
||||
}
|
||||
|
||||
info
|
||||
}
|
||||
|
||||
@ -317,6 +324,8 @@ impl GpuController {
|
||||
pci_slot,
|
||||
power_profile: None,
|
||||
clocks_table: None,
|
||||
power_cap: None,
|
||||
power_cap_max: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,6 +179,12 @@ impl App {
|
||||
.expect("Failed to set power profile");
|
||||
}
|
||||
|
||||
if let Some(cap) = app.root_stack.oc_page.get_power_cap() {
|
||||
app.daemon_connection
|
||||
.set_power_cap(gpu_id, cap)
|
||||
.expect("Failed to set power cap");
|
||||
}
|
||||
|
||||
app.set_info(gpu_id);
|
||||
});
|
||||
}
|
||||
@ -195,7 +201,7 @@ impl App {
|
||||
self.root_stack.info_page.set_info(&gpu_info);
|
||||
|
||||
log::trace!("Setting clocks");
|
||||
self.root_stack.oc_page.set_clocks(&gpu_info.clocks_table);
|
||||
self.root_stack.oc_page.set_info(&gpu_info);
|
||||
|
||||
log::trace!("Setting power profile {:?}", gpu_info.power_profile);
|
||||
self.root_stack
|
||||
|
@ -1,23 +1,25 @@
|
||||
mod clocks_frame;
|
||||
mod power_cap_frame;
|
||||
mod power_profile_frame;
|
||||
mod stats_grid;
|
||||
mod warning_frame;
|
||||
|
||||
use clocks_frame::ClocksSettings;
|
||||
use daemon::gpu_controller::{ClocksTable, GpuStats, PowerProfile};
|
||||
use daemon::gpu_controller::{GpuInfo, GpuStats, PowerProfile};
|
||||
use gtk::*;
|
||||
|
||||
use clocks_frame::ClocksFrame;
|
||||
use power_cap_frame::PowerCapFrame;
|
||||
use power_profile_frame::PowerProfileFrame;
|
||||
use stats_grid::StatsGrid;
|
||||
use warning_frame::WarningFrame;
|
||||
|
||||
use self::clocks_frame::ClocksFrame;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct OcPage {
|
||||
pub container: Box,
|
||||
stats_grid: StatsGrid,
|
||||
power_profile_frame: PowerProfileFrame,
|
||||
power_cap_frame: PowerCapFrame,
|
||||
clocks_frame: ClocksFrame,
|
||||
pub warning_frame: WarningFrame,
|
||||
}
|
||||
@ -34,6 +36,10 @@ impl OcPage {
|
||||
|
||||
container.pack_start(&stats_grid.container, false, true, 5);
|
||||
|
||||
let power_cap_frame = PowerCapFrame::new();
|
||||
|
||||
container.pack_start(&power_cap_frame.container, false, true, 0);
|
||||
|
||||
let power_profile_frame = PowerProfileFrame::new();
|
||||
|
||||
container.pack_start(&power_profile_frame.container, false, true, 0);
|
||||
@ -48,6 +54,7 @@ impl OcPage {
|
||||
power_profile_frame,
|
||||
clocks_frame,
|
||||
warning_frame,
|
||||
power_cap_frame,
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,10 +77,16 @@ impl OcPage {
|
||||
});
|
||||
}
|
||||
{
|
||||
let f = f.clone();
|
||||
self.clocks_frame.connect_clocks_changed(move || {
|
||||
f();
|
||||
})
|
||||
}
|
||||
{
|
||||
self.power_cap_frame.connect_cap_changed(move || {
|
||||
f();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_power_profile(&self, profile: &Option<PowerProfile>) {
|
||||
@ -93,14 +106,17 @@ impl OcPage {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_clocks(&self, clocks_table: &Option<ClocksTable>) {
|
||||
match clocks_table {
|
||||
pub fn set_info(&self, info: &GpuInfo) {
|
||||
match &info.clocks_table {
|
||||
Some(clocks_table) => {
|
||||
self.clocks_frame.show();
|
||||
self.clocks_frame.set_clocks(clocks_table);
|
||||
}
|
||||
None => self.clocks_frame.hide(),
|
||||
}
|
||||
|
||||
self.power_cap_frame
|
||||
.set_data(info.power_cap, info.power_cap_max);
|
||||
}
|
||||
|
||||
pub fn get_clocks(&self) -> Option<ClocksSettings> {
|
||||
@ -109,4 +125,8 @@ impl OcPage {
|
||||
false => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_power_cap(&self) -> Option<i64> {
|
||||
self.power_cap_frame.get_cap()
|
||||
}
|
||||
}
|
||||
|
84
gui/src/app/root_stack/oc_page/power_cap_frame.rs
Normal file
84
gui/src/app/root_stack/oc_page/power_cap_frame.rs
Normal file
@ -0,0 +1,84 @@
|
||||
use gtk::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PowerCapFrame {
|
||||
pub container: Frame,
|
||||
label: Label,
|
||||
adjustment: Adjustment,
|
||||
}
|
||||
|
||||
impl PowerCapFrame {
|
||||
pub fn new() -> Self {
|
||||
let container = Frame::new(None);
|
||||
|
||||
container.set_shadow_type(ShadowType::None);
|
||||
|
||||
container.set_label_widget(Some(&{
|
||||
let label = Label::new(None);
|
||||
label.set_markup("<span font_desc='11'><b>Power Usage Limit</b></span>");
|
||||
label
|
||||
}));
|
||||
container.set_label_align(0.2, 0.0);
|
||||
|
||||
let root_box = Box::new(Orientation::Horizontal, 0);
|
||||
|
||||
let label = Label::new(None);
|
||||
|
||||
root_box.pack_start(&label, false, true, 5);
|
||||
|
||||
let adjustment = Adjustment::new(0.0, 0.0, 0.0, 1.0, 10.0, 0.0);
|
||||
{
|
||||
let label = label.clone();
|
||||
adjustment.connect_value_changed(move |adj| {
|
||||
label.set_markup(&format!(
|
||||
"{}/{} W",
|
||||
adj.get_value().round(),
|
||||
adj.get_upper()
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
let scale = Scale::new(Orientation::Horizontal, Some(&adjustment));
|
||||
|
||||
scale.set_draw_value(false);
|
||||
|
||||
root_box.pack_start(&scale, true, true, 5);
|
||||
|
||||
container.add(&root_box);
|
||||
|
||||
Self {
|
||||
container,
|
||||
label,
|
||||
adjustment,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_data(&self, power_cap: Option<i64>, power_cap_max: Option<i64>) {
|
||||
if let Some(power_cap_max) = power_cap_max {
|
||||
self.adjustment.set_upper(power_cap_max as f64);
|
||||
} else {
|
||||
self.container.set_visible(false);
|
||||
}
|
||||
if let Some(power_cap) = power_cap {
|
||||
self.adjustment.set_value(power_cap as f64);
|
||||
} else {
|
||||
self.container.set_visible(false);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_cap(&self) -> Option<i64> {
|
||||
// Using match gives a warning that floats shouldn't be used in patterns
|
||||
let cap = self.adjustment.get_value();
|
||||
if cap == 0.0 {
|
||||
None
|
||||
} else {
|
||||
Some(cap as i64)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn connect_cap_changed<F: Fn() + 'static>(&self, f: F) {
|
||||
self.adjustment.connect_value_changed(move |_| {
|
||||
f();
|
||||
});
|
||||
}
|
||||
}
|
@ -50,7 +50,6 @@ impl PowerProfileFrame {
|
||||
}
|
||||
|
||||
container.add(&root_box);
|
||||
|
||||
Self {
|
||||
container,
|
||||
combo_box,
|
||||
|
Loading…
Reference in New Issue
Block a user