mirror of
https://codeberg.org/icewind/palantir.git
synced 2026-06-03 10:14:09 +02:00
better handling of gpu power
This commit is contained in:
parent
84f9593465
commit
1df1369165
2 changed files with 14 additions and 4 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
use crate::data::{GpuMemory, GpuUsage};
|
use crate::data::{GpuMemory, GpuUsage};
|
||||||
use crate::linux::hwmon::FileSource;
|
use crate::linux::hwmon::FileSource;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fs::read_to_string;
|
use std::fs::{read_dir, read_to_string};
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::atomic::{AtomicU64, Ordering};
|
use std::sync::atomic::{AtomicU64, Ordering};
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
@ -60,10 +61,18 @@ fn get_gpu_power_elapsed() -> Option<Duration> {
|
||||||
elapsed
|
elapsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn find_gpu_sensor() -> Option<PathBuf> {
|
||||||
|
read_dir("/sys/class/drm/card0/device/hwmon")
|
||||||
|
.ok()?
|
||||||
|
.flatten()
|
||||||
|
.find_map(|hwmon| {
|
||||||
|
let path = hwmon.path().join("power1_average");
|
||||||
|
path.exists().then_some(path)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_gpu_power() {
|
pub fn update_gpu_power() {
|
||||||
if let Ok(mut file) =
|
if let Some(Ok(mut file)) = find_gpu_sensor().map(FileSource::open) {
|
||||||
FileSource::open("/sys/class/drm/card0/device/hwmon/hwmon0/power1_average")
|
|
||||||
{
|
|
||||||
loop {
|
loop {
|
||||||
if let Some(elapsed) = get_gpu_power_elapsed() {
|
if let Some(elapsed) = get_gpu_power_elapsed() {
|
||||||
let current_power: u64 = match file.read() {
|
let current_power: u64 = match file.read() {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue