Skip to content
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
3 changes: 3 additions & 0 deletions crates/cardwire-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ pub struct GpuAction {

#[arg(long, help = "Unblock a specific gpu")]
pub unblock: bool,

#[arg(long, help = "Get gpu status")]
pub status: bool,
}
3 changes: 3 additions & 0 deletions crates/cardwire-cli/src/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ impl<'a> DaemonClient<'a> {
pub async fn set_gpu_block(&self, id: u32, blocked: bool) -> zbus::Result<()> {
self.proxy.call("SetGpuBlock", &(id, blocked)).await
}
pub async fn get_status(&self, id: u32) -> zbus::Result<String> {
self.proxy.call("GetStatus", &id).await
}
}
23 changes: 19 additions & 4 deletions crates/cardwire-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,25 @@ async fn main() -> anyhow::Result<()> {
}
}
Commands::Gpu { id, action } => {
match client.set_gpu_block(id, action.block).await {
Ok(_) => println!("Mode has been set to {} on GPU {}", action.block, id),
Err(e) => handle_error(e),
};
if action.status {
// Handle --status
match client.get_status(id).await {
Ok(status) => println!("GPU {} status: {}", id, status),
Err(e) => handle_error(e),
};
} else if action.block {
// Handle --block
match client.set_gpu_block(id, true).await {
Ok(_) => println!("GPU {} has been blocked", id),
Err(e) => handle_error(e),
};
} else if action.unblock {
// Handle --unblock
match client.set_gpu_block(id, false).await {
Ok(_) => println!("GPU {} has been unblocked", id),
Err(e) => handle_error(e),
};
}
}
_ => {}
}
Expand Down
17 changes: 17 additions & 0 deletions crates/cardwire-daemon/src/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cardwire_core::{
gpu::{DbusGpuDevice, block_gpu, is_gpu_blocked}, pci::DbusPciDevice
};
use log::{error, info, warn};
use tokio::fs;
use zbus::{fdo, interface};

#[interface(name = "com.github.opengamingcollective.cardwire")]
Expand Down Expand Up @@ -186,4 +187,20 @@ impl Daemon {

Ok(dbus_list)
}

pub async fn get_status(&self, gpu_id: u32) -> fdo::Result<String> {
let gpu = self
.state
.gpu_list
.get(&(gpu_id as usize))
.ok_or_else(|| fdo::Error::InvalidArgs(format!("Unknown GPU id: {}", gpu_id)))?;
let gpu_pci = gpu.pci.pci_address();
let power_state =
fs::read_to_string(format!("/sys/bus/pci/devices/{gpu_pci}/power_state")).await;
if let Ok(state) = power_state {
Ok(state)
} else {
Err(fdo::Error::Failed("Couldn't read power_state".to_string()))
}
}
}