Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with gpu devices with no valid subdevice name #151

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ impl GeneralReadout for LinuxGeneralReadout {
continue;
};

if let Some(sub_device_name) = device.get_sub_device_name(&db) {
if let Some(sub_device_name) = device.get_device_name(&db) {
gpus.push(sub_device_name);
};
}
Expand Down
12 changes: 5 additions & 7 deletions src/linux/pci_devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl PciDevice {
}
}

pub fn get_sub_device_name(&self, db: &Database) -> Option<String> {
pub fn get_device_name(&self, db: &Database) -> Option<String> {
let vendor_value = self.read_value(PciDeviceReadableValues::Vendor);
let sub_vendor_value = self.read_value(PciDeviceReadableValues::SubVendor);
let device_value = self.read_value(PciDeviceReadableValues::Device);
Expand All @@ -75,6 +75,8 @@ impl PciDevice {
let Some(device) = vendor.devices.get(&device_value) else {
return None;
};
// To return device name if no valid subdevice name is found
let device_name = device.name.to_owned();

let sub_device_id = SubDeviceId {
subvendor: sub_vendor_value,
Expand All @@ -84,20 +86,16 @@ impl PciDevice {
if let Some(sub_device) = device.subdevices.get(&sub_device_id) {
let start = match sub_device.find('[') {
Some(i) => i + 1,
_ => panic!(
"Could not find opening square bracket for sub device: {}",
sub_device
),
_ => return Some(device_name),
};
let end = sub_device.len() - 1;

Some(sub_device.chars().take(end).skip(start).collect::<String>())
} else {
None
Some(device_name)
}
}
}

pub fn get_pci_devices() -> Result<Vec<PciDevice>, io::Error> {
let devices_dir = read_dir("/sys/bus/pci/devices/")?;

Expand Down