Skip to content

Commit

Permalink
Some initial structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywonchung committed Jul 8, 2024
1 parent e56164f commit 76207a5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion zeusd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ name = "zeusd"
[dependencies]
nvml-wrapper = "0.10"
actix-web = "4"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "fs"] }
thiserror = "1"
clap = { version = "4.5.4", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
Expand Down
47 changes: 47 additions & 0 deletions zeusd/src/devices/cpu/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! CPU power measurement with RAPL. Only supported on Linux.
use std::io::Read;

use tokio::io::AsyncReadExt;

pub struct FieldInfo {
pub name: String,
pub max_energy_uj: f64,
}

pub trait CpuManager {
fn get_available_fields(&self) -> Vec<FieldInfo>;
fn get_field_energy(&self, field_name: &str) -> f64;
}

static RAPL_DIR: &'static str = "/sys/class/powercap/intel-rapl";

pub struct RAPLCpuManager {
fields: Vec<FieldInfo>,
}

impl RAPLCpuManager {
pub fn new() -> Self {
let mut fields = Vec::with_capacity(2);

// The package domain is always present

// Look for subdomains and add to fields

Self { fields }
}
}

fn read_u64(path: &std::path::Path) -> f64 {
let mut file = std::fs::File::open(path).unwrap();
let mut buf = String::new();
file.read_to_string(&mut buf).unwrap();
buf.trim().parse().unwrap()
}

async fn read_u64_async(path: &std::path::Path) -> f64 {
let mut file = tokio::fs::File::open(path).await.unwrap();
let mut buf = String::new();
file.read_to_string(&mut buf).await.unwrap();
buf.trim().parse().unwrap()
}
1 change: 1 addition & 0 deletions zeusd/src/devices/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Interfaces for interacting with devices
pub mod gpu;
pub mod cpu;
2 changes: 1 addition & 1 deletion zeusd/src/routes/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::error::ZeusdError;
/// This macro takes
/// - the API name (set_power_limit, set_persistence_mode, etc.),
/// - the method and path for the request handler,
/// - and a list of `field name <type>` pairs of the corresponding `GpuCommand` variant.
/// - and a list of `field name: type` pairs of the corresponding `GpuCommand` variant.
///
/// Gien this, the macro generates
/// - a request payload struct named API name (e.g., SetPowerLimit) and all the
Expand Down

0 comments on commit 76207a5

Please sign in to comment.