From 84a87641c07b57cf54ba1e51ec4115bd32911860 Mon Sep 17 00:00:00 2001 From: Ada Date: Mon, 2 Dec 2024 19:09:10 +0000 Subject: [PATCH] gpu: fix clippy issues --- src/data_collection.rs | 2 +- src/data_collection/amd.rs | 40 +++++++++++++++----------------------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/data_collection.rs b/src/data_collection.rs index 1c4e4023e..23a38a86b 100644 --- a/src/data_collection.rs +++ b/src/data_collection.rs @@ -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")] diff --git a/src/data_collection/amd.rs b/src/data_collection/amd.rs index 8f6386f09..fc4751960 100644 --- a/src/data_collection/amd.rs +++ b/src/data_collection/amd.rs @@ -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}, }; @@ -75,7 +75,7 @@ pub fn get_amd_devs() -> Option> { } } -pub fn get_amd_name(device_path: &PathBuf) -> Option { +pub fn get_amd_name(device_path: &Path) -> Option { // get revision and device ids from sysfs let rev_path = device_path.join("revision"); let dev_path = device_path.join("device"); @@ -107,17 +107,13 @@ pub fn get_amd_name(device_path: &PathBuf) -> Option { } // 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 { +pub fn get_amd_vram(device_path: &Path) -> Option { // 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"); @@ -140,13 +136,13 @@ pub fn get_amd_vram(device_path: &PathBuf) -> Option { return None; }; - return Some(AMDGPUMemory { + Some(AMDGPUMemory { total: vram_total, used: vram_used, - }); + }) } -pub fn get_amd_temp(device_path: &PathBuf) -> Option> { +pub fn get_amd_temp(device_path: &Path) -> Option> { let mut temperatures = Vec::new(); // get hardware monitoring sensor info from sysfs @@ -270,7 +266,7 @@ pub fn get_amdgpu_pid_fds(pid: u32, device_path: Vec) -> Option Option> { +pub fn get_amdgpu_drm(device_path: &Path) -> Option> { let mut drm_devices = Vec::new(); let drm_root = device_path.join("drm"); @@ -304,12 +300,10 @@ pub fn get_amdgpu_drm(device_path: &PathBuf) -> Option> { } } -pub fn get_amd_fdinfo(device_path: &PathBuf) -> Option> { +pub fn get_amd_fdinfo(device_path: &Path) -> Option> { 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; @@ -404,7 +398,7 @@ pub fn get_amd_fdinfo(device_path: &PathBuf) -> Option> } } - return Some(fdinfo); + Some(fdinfo) } #[inline] @@ -412,14 +406,12 @@ pub fn get_amd_vecs( temp_type: &TemperatureType, filter: &Option, widgets_to_harvest: &UsedWidgets, prev_time: Instant, ) -> Option { - 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 {