Skip to content

Commit

Permalink
Merge pull request #455 from nokyan/link-npu
Browse files Browse the repository at this point in the history
Display Link for NPUs
  • Loading branch information
nokyan authored Feb 21, 2025
2 parents 56e2e74 + e67b758 commit 4360abf
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 23 deletions.
9 changes: 9 additions & 0 deletions data/resources/ui/pages/npu.ui
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@
<property name="title" translatable="yes">Max Power Cap</property>
</object>
</child>
<child>
<object class="AdwActionRow" id="link"><!--Translators: "Link" refers to something like "PCIe 4.0 ×16"-->
<property name="title" translatable="yes">Link</property>
<style>
<class name="property"/>
</style>
<property name="subtitle-selectable">true</property>
</object>
</child>
</object>
</child>
</object>
Expand Down
13 changes: 6 additions & 7 deletions src/ui/pages/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ impl ResDrive {
imp.set_tab_detail_string(&drive_data.inner.block_device);
}

if let Ok(link) = drive.link() {
imp.link.set_subtitle(&link.to_string());
} else {
imp.link.set_subtitle(&i18n("N/A"));
}

imp.old_stats
.borrow_mut()
.clone_from(&drive_data.disk_stats);
Expand All @@ -283,7 +289,6 @@ impl ResDrive {
removable,
disk_stats,
capacity,
link,
} = drive_data;

let time_passed = SystemTime::now()
Expand Down Expand Up @@ -423,12 +428,6 @@ impl ResDrive {
imp.removable.set_subtitle(&i18n("N/A"));
}

if let Ok(link) = link {
imp.link.set_subtitle(&link.to_string());
} else {
imp.link.set_subtitle(&i18n("N/A"));
}

self.set_property(
"tab_usage_string",
// Translators: This is an abbreviation for "Read" and "Write". This is displayed in the sidebar so your
Expand Down
13 changes: 6 additions & 7 deletions src/ui/pages/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ impl ResGPU {
imp.encode_decode_usage.set_visible(true);
}

if let Ok(link) = gpu.link() {
imp.link.set_subtitle(&link.to_string());
} else {
imp.link.set_subtitle(&i18n("N/A"));
}

if let Ok(model_name) = gpu.name() {
imp.set_tab_detail_string(&model_name);
}
Expand Down Expand Up @@ -287,7 +293,6 @@ impl ResGPU {
power_usage,
power_cap,
power_cap_max,
link,
nvidia: _,
} = gpu_data;

Expand Down Expand Up @@ -430,12 +435,6 @@ impl ResGPU {
imp.temperature.set_subtitle(&i18n("N/A"));
}

if let Some(link) = link {
imp.link.set_subtitle(&link.to_string());
} else {
imp.link.set_subtitle(&i18n("N/A"));
}

self.set_property("tab_usage_string", &usage_percentage_string);
}
}
9 changes: 9 additions & 0 deletions src/ui/pages/npu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ mod imp {
pub driver_used: TemplateChild<adw::ActionRow>,
#[template_child]
pub max_power_cap: TemplateChild<adw::ActionRow>,
#[template_child]
pub link: TemplateChild<adw::ActionRow>,

#[property(get)]
uses_progress_bar: Cell<bool>,
Expand Down Expand Up @@ -99,6 +101,7 @@ mod imp {
pci_slot: Default::default(),
driver_used: Default::default(),
max_power_cap: Default::default(),
link: Default::default(),
uses_progress_bar: Cell::new(true),
main_graph_color: glib::Bytes::from_static(&super::ResNPU::MAIN_GRAPH_COLOR),
icon: RefCell::new(ThemedIcon::new("npu-symbolic").into()),
Expand Down Expand Up @@ -218,6 +221,12 @@ impl ResNPU {

imp.driver_used.set_subtitle(&npu.driver());

if let Ok(link) = npu.link() {
imp.link.set_subtitle(&link.to_string());
} else {
imp.link.set_subtitle(&i18n("N/A"));
}

if let Ok(model_name) = npu.name() {
imp.set_tab_detail_string(&model_name);
}
Expand Down
3 changes: 0 additions & 3 deletions src/utils/drive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub struct DriveData {
pub removable: Result<bool>,
pub disk_stats: HashMap<String, usize>,
pub capacity: Result<u64>,
pub link: Result<Link>,
}

impl DriveData {
Expand All @@ -49,7 +48,6 @@ impl DriveData {
let removable = inner.removable();
let disk_stats = inner.sys_stats().unwrap_or_default();
let capacity = inner.capacity();
let link = inner.link();

let drive_data = Self {
inner,
Expand All @@ -58,7 +56,6 @@ impl DriveData {
removable,
disk_stats,
capacity,
link,
};

trace!(
Expand Down
5 changes: 0 additions & 5 deletions src/utils/gpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ pub struct GpuData {
pub power_cap: Option<f64>,
pub power_cap_max: Option<f64>,

pub link: Option<Link>,

pub nvidia: bool,
}

Expand Down Expand Up @@ -82,8 +80,6 @@ impl GpuData {
let power_cap = gpu.power_cap().ok();
let power_cap_max = gpu.power_cap_max().ok();

let link = gpu.link().ok();

let nvidia = matches!(gpu, Gpu::Nvidia(_));

let gpu_data = Self {
Expand All @@ -99,7 +95,6 @@ impl GpuData {
power_usage,
power_cap,
power_cap_max,
link,
nvidia,
};

Expand Down
9 changes: 8 additions & 1 deletion src/utils/npu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use crate::{

use self::{intel::IntelNpu, other::OtherNpu};

use super::pci::Vendor;
use super::{
link::{Link, LinkData},
pci::Vendor,
};

pub const VID_INTEL: u16 = 0x8086;

Expand Down Expand Up @@ -389,4 +392,8 @@ impl Npu {
Npu::Other(npu) => npu.power_cap_max(),
}
}

pub fn link(&self) -> Result<Link> {
Ok(Link::Pcie(LinkData::from_pci_slot(&self.pci_slot())?))
}
}

0 comments on commit 4360abf

Please sign in to comment.