Skip to content

Commit

Permalink
gpu: fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
yretenai committed Dec 2, 2024
1 parent 6b22f86 commit 84a8764
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/data_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(feature = "nvidia")]
pub mod nvidia;

#[cfg(all(target_os = "linux"))]
#[cfg(target_os = "linux")]
pub mod amd;

#[cfg(feature = "battery")]
Expand Down
40 changes: 16 additions & 24 deletions src/data_collection/amd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use hashbrown::{HashMap, HashSet};
use std::{
fs,
fs::read_to_string,
path::PathBuf,
path::{Path, PathBuf},
sync::{LazyLock, Mutex},
time::{Duration, Instant},
};
Expand Down Expand Up @@ -75,7 +75,7 @@ pub fn get_amd_devs() -> Option<Vec<PathBuf>> {
}
}

pub fn get_amd_name(device_path: &PathBuf) -> Option<String> {
pub fn get_amd_name(device_path: &Path) -> Option<String> {
// get revision and device ids from sysfs
let rev_path = device_path.join("revision");
let dev_path = device_path.join("device");
Expand Down Expand Up @@ -107,17 +107,13 @@ pub fn get_amd_name(device_path: &PathBuf) -> Option<String> {
}

// if it exists in our local database, use that name
if let Some(tuple) = amdgpu_marketing::AMDGPU_MARKETING_NAME
amdgpu_marketing::AMDGPU_MARKETING_NAME
.iter()
.find(|(did, rid, _)| (did, rid) == (&device_id, &revision_id))
{
Some(tuple.2.to_string())
} else {
None
}
.map(|tuple| tuple.2.to_string())
}

pub fn get_amd_vram(device_path: &PathBuf) -> Option<AMDGPUMemory> {
pub fn get_amd_vram(device_path: &Path) -> Option<AMDGPUMemory> {
// get vram memory info from sysfs
let vram_total_path = device_path.join("mem_info_vram_total");
let vram_used_path = device_path.join("mem_info_vram_used");
Expand All @@ -140,13 +136,13 @@ pub fn get_amd_vram(device_path: &PathBuf) -> Option<AMDGPUMemory> {
return None;
};

return Some(AMDGPUMemory {
Some(AMDGPUMemory {
total: vram_total,
used: vram_used,
});
})
}

pub fn get_amd_temp(device_path: &PathBuf) -> Option<Vec<AMDGPUTemperature>> {
pub fn get_amd_temp(device_path: &Path) -> Option<Vec<AMDGPUTemperature>> {
let mut temperatures = Vec::new();

// get hardware monitoring sensor info from sysfs
Expand Down Expand Up @@ -270,7 +266,7 @@ pub fn get_amdgpu_pid_fds(pid: u32, device_path: Vec<PathBuf>) -> Option<Vec<u32
}
}

pub fn get_amdgpu_drm(device_path: &PathBuf) -> Option<Vec<PathBuf>> {
pub fn get_amdgpu_drm(device_path: &Path) -> Option<Vec<PathBuf>> {
let mut drm_devices = Vec::new();
let drm_root = device_path.join("drm");

Expand Down Expand Up @@ -304,12 +300,10 @@ pub fn get_amdgpu_drm(device_path: &PathBuf) -> Option<Vec<PathBuf>> {
}
}

pub fn get_amd_fdinfo(device_path: &PathBuf) -> Option<HashMap<u32, AMDGPUProc>> {
pub fn get_amd_fdinfo(device_path: &Path) -> Option<HashMap<u32, AMDGPUProc>> {
let mut fdinfo = HashMap::new();

let Some(drm_paths) = get_amdgpu_drm(device_path) else {
return None;
};
let drm_paths = get_amdgpu_drm(device_path)?;

let Ok(proc_dir) = fs::read_dir("/proc") else {
return None;
Expand Down Expand Up @@ -404,22 +398,20 @@ pub fn get_amd_fdinfo(device_path: &PathBuf) -> Option<HashMap<u32, AMDGPUProc>>
}
}

return Some(fdinfo);
Some(fdinfo)
}

#[inline]
pub fn get_amd_vecs(
temp_type: &TemperatureType, filter: &Option<Filter>, widgets_to_harvest: &UsedWidgets,
prev_time: Instant,
) -> Option<AMDGPUData> {
let Some(device_path_list) = get_amd_devs() else {
return None;
};
let device_path_list = get_amd_devs()?;
let interval = Instant::now().duration_since(prev_time);
let num_gpu = device_path_list.len();
let mut temp_vec = Vec::with_capacity(num_gpu as usize);
let mut mem_vec = Vec::with_capacity(num_gpu as usize);
let mut proc_vec = Vec::with_capacity(num_gpu as usize);
let mut temp_vec = Vec::with_capacity(num_gpu);
let mut mem_vec = Vec::with_capacity(num_gpu);
let mut proc_vec = Vec::with_capacity(num_gpu);
let mut total_mem = 0;

for device_path in device_path_list {
Expand Down

0 comments on commit 84a8764

Please sign in to comment.