mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2025-02-25 18:55:26 -06:00
adopt new pciid-parser
This commit is contained in:
parent
41fed9d272
commit
0b6c41b49c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
Cargo.lock
|
|
||||||
*.glade\~
|
*.glade\~
|
||||||
|
2052
Cargo.lock
generated
Normal file
2052
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -15,6 +15,6 @@ log = "0.4"
|
|||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
signal-hook = "0.3"
|
signal-hook = "0.3"
|
||||||
pciid-parser = { git = "https://github.com/ilyazzz/pci-id-parser.git" }
|
|
||||||
reqwest = { version = "0.11", features = ["blocking", "json"] }
|
reqwest = { version = "0.11", features = ["blocking", "json"] }
|
||||||
nix = "0.23"
|
nix = "0.23"
|
||||||
|
pciid-parser = { version = "0.6.0", features = ["online"] }
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use crate::hw_mon::{HWMon, HWMonError};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{GpuConfig, GpuIdentifier},
|
config::{GpuConfig, GpuIdentifier},
|
||||||
hw_mon::Temperature,
|
hw_mon::{HWMon, HWMonError, Temperature},
|
||||||
};
|
};
|
||||||
use pciid_parser::{PciDatabase, VendorData};
|
use pciid_parser::{schema::DeviceInfo, Database};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@ -141,6 +140,25 @@ pub struct GpuInfo {
|
|||||||
pub power_cap_max: Option<i64>,
|
pub power_cap_max: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||||
|
pub struct VendorData {
|
||||||
|
pub gpu_vendor: Option<String>,
|
||||||
|
pub gpu_model: Option<String>,
|
||||||
|
pub card_vendor: Option<String>,
|
||||||
|
pub card_model: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<DeviceInfo<'_>> for VendorData {
|
||||||
|
fn from(info: DeviceInfo) -> Self {
|
||||||
|
Self {
|
||||||
|
gpu_vendor: info.vendor_name.map(str::to_owned),
|
||||||
|
gpu_model: info.device_name.map(str::to_owned),
|
||||||
|
card_vendor: info.subvendor_name.map(str::to_owned),
|
||||||
|
card_model: info.subdevice_name.map(str::to_owned),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct GpuController {
|
pub struct GpuController {
|
||||||
pub hw_path: PathBuf,
|
pub hw_path: PathBuf,
|
||||||
@ -150,7 +168,7 @@ pub struct GpuController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GpuController {
|
impl GpuController {
|
||||||
pub fn new(hw_path: PathBuf, config: GpuConfig, pci_db: &Option<PciDatabase>) -> Self {
|
pub fn new(hw_path: PathBuf, config: GpuConfig, pci_db: &Option<Database>) -> Self {
|
||||||
let mut controller = GpuController {
|
let mut controller = GpuController {
|
||||||
hw_path: hw_path.clone(),
|
hw_path: hw_path.clone(),
|
||||||
hw_mon: None,
|
hw_mon: None,
|
||||||
@ -227,7 +245,7 @@ impl GpuController {
|
|||||||
info
|
info
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_info_initial(&self, pci_db: &Option<PciDatabase>) -> GpuInfo {
|
fn get_info_initial(&self, pci_db: &Option<Database>) -> GpuInfo {
|
||||||
let uevent =
|
let uevent =
|
||||||
fs::read_to_string(self.hw_path.join("uevent")).expect("Failed to read uevent");
|
fs::read_to_string(self.hw_path.join("uevent")).expect("Failed to read uevent");
|
||||||
|
|
||||||
@ -290,19 +308,13 @@ impl GpuController {
|
|||||||
let vulkan_info = GpuController::get_vulkan_info(&model_id);
|
let vulkan_info = GpuController::get_vulkan_info(&model_id);
|
||||||
|
|
||||||
let vendor_data = match pci_db {
|
let vendor_data = match pci_db {
|
||||||
Some(db) => {
|
Some(db) => db
|
||||||
match db.get_by_ids(&vendor_id, &model_id, &card_vendor_id, &card_model_id) {
|
.get_device_info(&vendor_id, &model_id, &card_vendor_id, &card_model_id)
|
||||||
Ok(data) => data,
|
.into(),
|
||||||
Err(_) => VendorData::default(),
|
None => match Database::read() {
|
||||||
}
|
Ok(db) => db
|
||||||
}
|
.get_device_info(&vendor_id, &model_id, &card_vendor_id, &card_model_id)
|
||||||
None => match PciDatabase::read() {
|
.into(),
|
||||||
Ok(db) => {
|
|
||||||
match db.get_by_ids(&vendor_id, &model_id, &card_vendor_id, &card_model_id) {
|
|
||||||
Ok(data) => data,
|
|
||||||
Err(_) => VendorData::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!(
|
println!(
|
||||||
"{:?} pci.ids not found! Make sure you have 'hwdata' installed",
|
"{:?} pci.ids not found! Make sure you have 'hwdata' installed",
|
||||||
|
@ -5,7 +5,7 @@ pub mod hw_mon;
|
|||||||
|
|
||||||
use config::{Config, GpuConfig};
|
use config::{Config, GpuConfig};
|
||||||
use gpu_controller::PowerProfile;
|
use gpu_controller::PowerProfile;
|
||||||
use pciid_parser::PciDatabase;
|
use pciid_parser::Database;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@ -99,7 +99,7 @@ impl Daemon {
|
|||||||
|
|
||||||
fn load_gpu_controllers(config: &mut Config) -> HashMap<u32, GpuController> {
|
fn load_gpu_controllers(config: &mut Config) -> HashMap<u32, GpuController> {
|
||||||
let pci_db = match config.allow_online_update {
|
let pci_db = match config.allow_online_update {
|
||||||
Some(true) => match Self::get_pci_db_online() {
|
Some(true) => match Database::get_online() {
|
||||||
Ok(db) => Some(db),
|
Ok(db) => Some(db),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::info!("Error updating PCI db: {:?}", e);
|
log::info!("Error updating PCI db: {:?}", e);
|
||||||
@ -165,17 +165,6 @@ impl Daemon {
|
|||||||
gpu_controllers
|
gpu_controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_pci_db_online() -> Result<PciDatabase, reqwest::Error> {
|
|
||||||
let client = reqwest::blocking::Client::builder()
|
|
||||||
.user_agent("LACT")
|
|
||||||
.build()?;
|
|
||||||
let vendors = client
|
|
||||||
.get("https://pci.endpoint.ml/devices.json")
|
|
||||||
.send()?
|
|
||||||
.json()?;
|
|
||||||
Ok(PciDatabase { vendors })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn listen(mut self) {
|
pub fn listen(mut self) {
|
||||||
loop {
|
loop {
|
||||||
let stream = nix::sys::socket::accept(self.listener).expect("Accept failed");
|
let stream = nix::sys::socket::accept(self.listener).expect("Accept failed");
|
||||||
@ -475,6 +464,8 @@ pub enum DaemonError {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::gpu_controller::VendorData;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn init() {
|
fn init() {
|
||||||
@ -485,9 +476,9 @@ mod tests {
|
|||||||
fn recognize_polaris() {
|
fn recognize_polaris() {
|
||||||
init();
|
init();
|
||||||
|
|
||||||
let db = Daemon::get_pci_db_online().unwrap();
|
let db = Database::get_online().unwrap();
|
||||||
|
|
||||||
let vendor_data = db.get_by_ids("1002", "67df", "1da2", "e387").unwrap();
|
let vendor_data: VendorData = db.get_device_info("1002", "67df", "1da2", "e387").into();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
vendor_data.gpu_vendor,
|
vendor_data.gpu_vendor,
|
||||||
|
Loading…
Reference in New Issue
Block a user