Skip to content

Commit

Permalink
lib: stop reading hwmon and gpu_metrics sysfs for pci power state
Browse files Browse the repository at this point in the history
  • Loading branch information
Umio-Yasuno committed Jul 15, 2024
1 parent 7aae6e7 commit f936241
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
13 changes: 4 additions & 9 deletions crates/libamdgpu_top/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,10 @@ impl AppAmdgpuTop {

if self.amdgpu_dev.is_none() {
if let Some(ref mut sensors) = self.stat.sensors {
sensors.update_without_device_handle();
sensors.sclk = None;
sensors.mclk = None;
sensors.vddnb = None;
sensors.vddgfx = None;
}

if self.stat.metrics.is_some() {
self.stat.metrics = GpuMetrics::get_from_sysfs_path(&self.device_info.sysfs_path).ok();
sensors.update_for_idle();
}

self.stat.metrics = None;
return;
};

Expand All @@ -182,6 +175,8 @@ impl AppAmdgpuTop {

if let Some(ref mut sensors) = self.stat.sensors {
sensors.update(dev);
} else {
self.stat.sensors = Sensors::new(dev, &self.device_info.pci_bus, &self.device_info.ext_info);
}
}

Expand Down
26 changes: 24 additions & 2 deletions crates/libamdgpu_top/src/stat/sensors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,34 @@ impl Sensors {
}

self.fan_rpm = parse_hwmon(self.hwmon_path.join("fan1_input"));
self.pci_power_state = std::fs::read_to_string(self.gpu_port_path.join("power_state")).ok()
self.power_profile = PowerProfile::get_current_profile_from_sysfs(&self.sysfs_path);
self.update_pci_power_state();
}

pub fn update_for_idle(&mut self) {
self.current_link = None;
self.edge_temp = None;
self.junction_temp = None;
self.memory_temp = None;
self.average_power = None;
self.input_power = None;
self.sclk = None;
self.mclk = None;
self.vddnb = None;
self.vddgfx = None;
self.fan_rpm = None;
self.power_profile = None;

self.update_pci_power_state();
}

pub fn update_pci_power_state(&mut self) {
self.pci_power_state = std::fs::read_to_string(self.gpu_port_path.join("power_state"))
.ok()
.map(|mut s| {
s.pop(); // trim `\n`
s
});
self.power_profile = PowerProfile::get_current_profile_from_sysfs(&self.sysfs_path);
}

pub fn update(&mut self, amdgpu_dev: &DeviceHandle) {
Expand Down

0 comments on commit f936241

Please sign in to comment.