Update non-static info in GpuInfo on get_info()

This commit is contained in:
Ilya Zlobintsev
2021-02-10 12:14:36 +02:00
parent 4134a3d4b6
commit dbd8f5e0d3
3 changed files with 26 additions and 20 deletions

View File

@@ -137,7 +137,7 @@ pub struct GpuInfo {
pub struct GpuController {
pub hw_path: PathBuf,
hw_mon: Option<HWMon>,
pub gpu_info: GpuInfo,
gpu_info: GpuInfo,
config: GpuConfig,
}
@@ -150,7 +150,7 @@ impl GpuController {
gpu_info: GpuInfo::default(),
};
controller.gpu_info = controller.get_info();
controller.gpu_info = controller.get_info_initial();
controller.load_config(&config);
@@ -199,8 +199,24 @@ impl GpuController {
path: self.hw_path.clone(),
}
}
pub fn get_info(&self) -> GpuInfo {
let mut info = self.gpu_info.clone();
info.power_profile = match self.get_power_profile() {
Ok(p) => Some(p),
Err(_) => None,
};
fn get_info(&self) -> GpuInfo {
info.clocks_table = match self.get_clocks_table() {
Ok(t) => Some(t),
Err(_) => None,
};
info
}
fn get_info_initial(&self) -> GpuInfo {
let uevent =
fs::read_to_string(self.hw_path.join("uevent")).expect("Failed to read uevent");
@@ -262,16 +278,6 @@ impl GpuController {
let vulkan_info = GpuController::get_vulkan_info(&model_id);
let power_profile = match self.get_power_profile() {
Ok(p) => Some(p),
Err(_) => None,
};
let clocks_table = match self.get_clocks_table() {
Ok(t) => Some(t),
Err(_) => None,
};
let vendor_data =
match VendorData::from_ids(&vendor_id, &model_id, &card_vendor_id, &card_model_id) {
Ok(data) => data,
@@ -291,8 +297,8 @@ impl GpuController {
link_width,
vulkan_info,
pci_slot,
power_profile,
clocks_table,
power_profile: None,
clocks_table: None,
}
}

View File

@@ -98,7 +98,7 @@ impl Daemon {
log::info!("Initializing {:?}", entry.path());
let mut controller = GpuController::new(entry.path().join("device"), GpuConfig::new());
let gpu_info = &controller.gpu_info;
let gpu_info = &controller.get_info();
for (id, (gpu_identifier, gpu_config)) in &config.gpu_configs {
if gpu_info.pci_slot == gpu_identifier.pci_id && gpu_info.vendor_data.card_model == gpu_identifier.card_model && gpu_info.vendor_data.gpu_model == gpu_identifier.gpu_model {
@@ -163,19 +163,19 @@ impl Daemon {
Action::GetGpus => {
let mut gpus: HashMap<u32, Option<String>> = HashMap::new();
for (id, controller) in &self.gpu_controllers {
gpus.insert(*id, controller.gpu_info.vendor_data.gpu_model.clone());
gpus.insert(*id, controller.get_info().vendor_data.gpu_model.clone());
}
Ok(DaemonResponse::Gpus(gpus))
},
Action::GetStats(i) => match self.gpu_controllers.get(&i) {
Some(controller) => match controller.get_stats() {
Ok(stats) => Ok(DaemonResponse::GpuStats(stats)),
Err(e) => Err(DaemonError::HWMonError),
Err(_) => Err(DaemonError::HWMonError),
},
None => Err(DaemonError::InvalidID),
},
Action::GetInfo(i) => match self.gpu_controllers.get(&i) {
Some(controller) => Ok(DaemonResponse::GpuInfo(controller.gpu_info.clone())),
Some(controller) => Ok(DaemonResponse::GpuInfo(controller.get_info().clone())),
None => Err(DaemonError::InvalidID),
},
Action::StartFanControl(i) => match self.gpu_controllers.get_mut(&i) {

View File

@@ -1,4 +1,4 @@
use daemon::{config::GpuConfig, gpu_controller::PowerProfile};
use daemon::gpu_controller::PowerProfile;
use gtk::*;
use prelude::ComboBoxExtManual;