xps 13 3980

This commit is contained in:
2026-02-26 13:37:04 +01:00
commit d6ac8e5931
21 changed files with 4562 additions and 0 deletions

103
src/sal/traits.rs Normal file
View File

@@ -0,0 +1,103 @@
use anyhow::Result;
use thiserror::Error;
use miette::Diagnostic;
use std::sync::Arc;
#[derive(Error, Diagnostic, Debug, Clone)]
pub enum AuditError {
#[error("Missing root privileges.")]
#[diagnostic(code(ember_tune::root_required), severity(error))]
#[help("ember-tune requires direct hardware access (MSRs, sysfs). Please run with 'sudo'.")]
RootRequired,
#[error("Missing kernel parameter: {0}")]
#[diagnostic(code(ember_tune::missing_kernel_param), severity(error))]
#[help("Add '{0}' to your GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub, then run 'sudo update-grub' and reboot.")]
MissingKernelParam(String),
#[error("System is running on battery: {0}")]
#[diagnostic(code(ember_tune::ac_power_missing), severity(error))]
#[help("Thermal benchmarking requires a stable AC power source to ensure consistent PL limits. Please plug in your charger.")]
AcPowerMissing(String),
#[error("Incompatible kernel version: {0}")]
#[diagnostic(code(ember_tune::kernel_incompatible), severity(error))]
#[help("Your kernel version '{0}' may not support the required RAPL or SMM interfaces. Please upgrade to a recent LTS kernel (6.1+).")]
KernelIncompatible(String),
#[error("Required tool missing: {0}")]
#[diagnostic(code(ember_tune::tool_missing), severity(error))]
#[help("The utility '{0}' is required for this SAL. Please install it using your package manager (e.g., 'sudo apt install {0}').")]
ToolMissing(String),
}
pub struct AuditStep {
pub description: String,
pub outcome: Result<(), AuditError>,
}
/// Evaluates immutable system states (e.g., kernel bootline parameters, AC power status).
pub trait PreflightAuditor: Send + Sync {
fn audit(&self) -> Box<dyn Iterator<Item = AuditStep> + '_>;
}
impl<T: PreflightAuditor + ?Sized> PreflightAuditor for Arc<T> {
fn audit(&self) -> Box<dyn Iterator<Item = AuditStep> + '_> {
(**self).audit()
}
}
/// Suppresses conflicting daemons (tlp, thermald).
pub trait EnvironmentGuard {
fn suppress(&mut self) -> Result<()>;
fn restore(&mut self) -> Result<()>;
}
/// Read-only interface for standardized metrics.
pub trait SensorBus {
fn get_temp(&self) -> Result<f32>;
fn get_power_w(&self) -> Result<f32>;
fn get_fan_rpm(&self) -> Result<u32>;
}
impl<T: SensorBus + ?Sized> SensorBus for Arc<T> {
fn get_temp(&self) -> Result<f32> {
(**self).get_temp()
}
fn get_power_w(&self) -> Result<f32> {
(**self).get_power_w()
}
fn get_fan_rpm(&self) -> Result<u32> {
(**self).get_fan_rpm()
}
}
/// Write-only interface for hardware commands.
pub trait ActuatorBus {
fn set_fan_mode(&self, mode: &str) -> Result<()>;
fn set_sustained_power_limit(&self, watts: f32) -> Result<()>;
fn set_burst_power_limit(&self, watts: f32) -> Result<()>;
}
impl<T: ActuatorBus + ?Sized> ActuatorBus for Arc<T> {
fn set_fan_mode(&self, mode: &str) -> Result<()> {
(**self).set_fan_mode(mode)
}
fn set_sustained_power_limit(&self, watts: f32) -> Result<()> {
(**self).set_sustained_power_limit(watts)
}
fn set_burst_power_limit(&self, watts: f32) -> Result<()> {
(**self).set_burst_power_limit(watts)
}
}
/// Concurrent monitor for catastrophic states.
pub trait HardwareWatchdog {
fn check_emergency(&self) -> Result<bool>;
}
impl<T: HardwareWatchdog + ?Sized> HardwareWatchdog for Arc<T> {
fn check_emergency(&self) -> Result<bool> {
(**self).check_emergency()
}
}