#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum PowerManagement
{
Physical,
KernelVirtualMachine,
}
impl PowerManagement
{
#[inline(always)]
pub fn current() -> Option<Self>
{
use self::power_management_env::*;
use self::PowerManagement::*;
match unsafe { rte_power_get_env() }
{
PM_ENV_NOT_SET => None,
PM_ENV_ACPI_CPUFREQ => Some(Physical),
PM_ENV_KVM_VM => Some(KernelVirtualMachine),
}
}
#[inline(always)]
pub fn start(&self) -> Result<(), i32>
{
use self::PowerManagement::*;
use self::power_management_env::*;
let environment = match *self
{
Physical => PM_ENV_ACPI_CPUFREQ,
KernelVirtualMachine => PM_ENV_KVM_VM,
};
match unsafe { rte_power_set_env(environment) }
{
0 => Ok(()),
x if x < 0 => Err(x),
illegal @ _ => panic!("rte_power_set_env() returned an invalid positive return code of '{}'", illegal),
}
}
#[inline(always)]
pub fn stop()
{
unsafe { rte_power_unset_env() }
}
}