#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CpuGovernor {
Performance,
Powersave,
Ondemand,
Conservative,
Schedutil,
Userspace,
Unknown,
}
const GOVERNOR_SPECS: &[(CpuGovernor, &str)] = &[
(CpuGovernor::Performance, "performance"),
(CpuGovernor::Powersave, "powersave"),
(CpuGovernor::Ondemand, "ondemand"),
(CpuGovernor::Conservative, "conservative"),
(CpuGovernor::Schedutil, "schedutil"),
(CpuGovernor::Userspace, "userspace"),
];
impl CpuGovernor {
pub fn name(&self) -> &'static str {
GOVERNOR_SPECS
.iter()
.find(|(v, _)| v == self)
.map(|(_, n)| *n)
.unwrap_or("unknown")
}
pub fn parse(s: &str) -> Self {
let lower = s.trim().to_lowercase();
GOVERNOR_SPECS
.iter()
.find(|(_, n)| *n == lower)
.map(|(v, _)| *v)
.unwrap_or(Self::Unknown)
}
pub fn is_deterministic(&self) -> bool {
matches!(self, Self::Performance | Self::Powersave | Self::Userspace)
}
}