mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2025-02-25 18:55:26 -06:00
Basic error handling support and resctructuring
This commit is contained in:
parent
7f8d4e1372
commit
7fb485de50
@ -57,7 +57,7 @@ impl Daemon {
|
||||
|
||||
let response: Vec<u8> = match action {
|
||||
Action::GetStats => bincode::serialize(&self.gpu_controller.get_stats()).unwrap(),
|
||||
Action::GetInfo => bincode::serialize(&self.gpu_controller.get_info()).unwrap(),
|
||||
Action::GetInfo => bincode::serialize(&self.gpu_controller.gpu_info).unwrap(),
|
||||
};
|
||||
stream.write_all(&response).expect("Failed writing response");
|
||||
|
||||
|
@ -13,9 +13,10 @@ pub struct GpuStats {
|
||||
pub struct GpuController {
|
||||
hw_path: PathBuf,
|
||||
fan_controller: FanController,
|
||||
pub gpu_info: GpuInfo,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
pub struct GpuInfo {
|
||||
pub gpu_vendor: String,
|
||||
pub gpu_model: String,
|
||||
@ -26,16 +27,20 @@ pub struct GpuInfo {
|
||||
}
|
||||
|
||||
impl GpuController {
|
||||
pub fn new(hw_path: &str) -> GpuController {
|
||||
pub fn new(hw_path: &str) -> Self {
|
||||
let gpu_info = GpuController::get_info(PathBuf::from(hw_path));
|
||||
println!("Initializing for {:?}", gpu_info);
|
||||
|
||||
GpuController {
|
||||
hw_path: PathBuf::from(hw_path),
|
||||
fan_controller: FanController::new(hw_path),
|
||||
gpu_info,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_info(self) -> GpuInfo {
|
||||
fn get_info(hw_path: PathBuf) -> GpuInfo {
|
||||
let uevent =
|
||||
fs::read_to_string(self.hw_path.join("uevent")).expect("Failed to read uevent");
|
||||
fs::read_to_string(hw_path.join("uevent")).expect("Failed to read uevent");
|
||||
|
||||
//caps for raw values, lowercase for parsed
|
||||
let mut driver = String::new();
|
||||
@ -72,8 +77,13 @@ impl GpuController {
|
||||
//some weird space character, don't touch
|
||||
let pci_id_line = format!(" {}", MODEL_ID.to_lowercase());
|
||||
let card_ids_line = format!(" {} {}", CARD_VENDOR_ID.to_lowercase(), CARD_MODEL_ID.to_lowercase());
|
||||
println!("looking for {}", pci_id_line);
|
||||
|
||||
for line in full_hwid_list.split('\n') {
|
||||
if line.len() > CARD_VENDOR_ID.len() {
|
||||
if line[0..CARD_VENDOR_ID.len()] == CARD_VENDOR_ID.to_lowercase() {
|
||||
card_vendor = line.splitn(2, ' ').collect::<Vec<&str>>()[1].trim_start().to_string();
|
||||
}
|
||||
}
|
||||
if line.contains(&pci_id_line) {
|
||||
model = line[pci_id_line.len()..].trim_start().to_string();
|
||||
}
|
||||
@ -82,13 +92,13 @@ impl GpuController {
|
||||
}
|
||||
}
|
||||
|
||||
let vbios_version = fs::read_to_string(self.hw_path.join("vbios_version"))
|
||||
.expect("Failed to read vbios_info");
|
||||
let vbios_version = fs::read_to_string(hw_path.join("vbios_version"))
|
||||
.expect("Failed to read vbios_info").trim().to_string();
|
||||
|
||||
GpuInfo {
|
||||
gpu_vendor: vendor,
|
||||
gpu_model: model,
|
||||
card_vendor: String::new(),
|
||||
card_vendor,
|
||||
card_model,
|
||||
driver,
|
||||
vbios_version,
|
||||
|
@ -9,6 +9,10 @@ pub mod gpu_controller;
|
||||
|
||||
pub const SOCK_PATH: &str = "/tmp/amdgpu-configurator.sock";
|
||||
|
||||
pub enum DaemonError {
|
||||
ConnectionFailed,
|
||||
}
|
||||
|
||||
pub fn get_gpu_stats() -> GpuStats{
|
||||
let mut stream = UnixStream::connect(SOCK_PATH).expect("Failed to connect to daemon");
|
||||
stream.write_all(&bincode::serialize(&daemon::Action::GetStats).unwrap()).unwrap();
|
||||
@ -20,13 +24,18 @@ pub fn get_gpu_stats() -> GpuStats{
|
||||
bincode::deserialize(&buffer).unwrap()
|
||||
}
|
||||
|
||||
pub fn get_gpu_info() -> GpuInfo {
|
||||
let mut stream = UnixStream::connect(SOCK_PATH).expect("Failed to connect to daemon");
|
||||
stream.write_all(&bincode::serialize(&daemon::Action::GetInfo).unwrap()).unwrap();
|
||||
stream.shutdown(std::net::Shutdown::Write).expect("Could not shut down");
|
||||
|
||||
let mut buffer = Vec::<u8>::new();
|
||||
stream.read_to_end(&mut buffer).unwrap();
|
||||
pub fn get_gpu_info() -> Result<GpuInfo, DaemonError> {
|
||||
match UnixStream::connect(SOCK_PATH) {
|
||||
Ok(mut s) => {
|
||||
|
||||
s.write_all(&bincode::serialize(&daemon::Action::GetInfo).unwrap()).unwrap();
|
||||
s.shutdown(std::net::Shutdown::Write).expect("Could not shut down");
|
||||
|
||||
let mut buffer = Vec::<u8>::new();
|
||||
s.read_to_end(&mut buffer).unwrap();
|
||||
|
||||
bincode::deserialize(&buffer).unwrap()
|
||||
Ok(bincode::deserialize(&buffer).unwrap())
|
||||
},
|
||||
Err(_) => Err(DaemonError::ConnectionFailed),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user