const NAM_VERSION: &str = env!("CARGO_PKG_VERSION");
use std::sync::OnceLock;
static HOST_LIBRARY_VERSION: OnceLock<String> = OnceLock::new();
pub fn set_host_library_version(version: String) {
let _ = HOST_LIBRARY_VERSION.set(version);
}
#[derive(Debug, Clone)]
pub struct SystemSnapshot {
pub version: &'static str,
pub arch: &'static str,
pub os: &'static str,
pub kernel: String,
pub features: Vec<String>,
pub host_library_version: Option<String>,
}
impl SystemSnapshot {
pub fn capture() -> Self {
let kernel = read_kernel_version();
let features = detect_advanced_features();
Self {
version: NAM_VERSION,
arch: std::env::consts::ARCH,
os: std::env::consts::OS,
kernel,
features,
host_library_version: HOST_LIBRARY_VERSION.get().cloned(),
}
}
pub fn emit_irq_advisory(&self, core: usize) {
if core >= 64 {
return;
}
let mask = 0xFFFFFFFFFFFFFFFFu64 ^ (1u64 << core);
log::info!(
"💡 For minimum latency, isolate core {} from system IRQs (as sudo): echo {:X} > /proc/irq/default_smp_affinity",
core,
mask
);
}
}
fn read_kernel_version() -> String {
std::fs::read_to_string("/proc/version")
.ok()
.and_then(|v| {
v.split_whitespace().nth(2).map(String::from)
})
.unwrap_or_else(|| "unknown".to_string())
}
fn detect_advanced_features() -> Vec<String> {
let mut features = Vec::new();
if std::is_x86_feature_detected!("avx512f") {
features.push("avx512f".to_string());
}
if std::is_x86_feature_detected!("avx512bw") {
features.push("avx512bw".to_string());
}
if std::is_x86_feature_detected!("avx512dq") {
features.push("avx512dq".to_string());
}
if std::is_x86_feature_detected!("avx512vl") {
features.push("avx512vl".to_string());
}
if std::is_x86_feature_detected!("avx512vnni") {
features.push("avx512vnni".to_string());
}
if std::is_x86_feature_detected!("avx512bf16") {
features.push("avx512bf16".to_string());
}
features
}