Struct Policy

Source
pub struct Policy(/* private fields */);
Expand description

CPU frequency policy.

Rust abstraction for the C struct cpufreq_policy.

§Invariants

A Policy instance always corresponds to a valid C struct cpufreq_policy.

The callers must ensure that the struct cpufreq_policy is valid for access and remains valid for the lifetime of the returned reference.

§Examples

The following example demonstrates how to create a CPU frequency table.

use kernel::cpufreq::{ETERNAL_LATENCY_NS, Policy};

fn update_policy(policy: &mut Policy) {
    policy
        .set_dvfs_possible_from_any_cpu(true)
        .set_fast_switch_possible(true)
        .set_transition_latency_ns(ETERNAL_LATENCY_NS);

    pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur()));
}

Implementations§

Source§

impl Policy

Source

pub unsafe fn from_raw<'a>(ptr: *const cpufreq_policy) -> &'a Self

Creates a reference to an existing struct cpufreq_policy pointer.

§Safety

The caller must ensure that ptr is valid for reading and remains valid for the lifetime of the returned reference.

Source

pub unsafe fn from_raw_mut<'a>(ptr: *mut cpufreq_policy) -> &'a mut Self

Creates a mutable reference to an existing struct cpufreq_policy pointer.

§Safety

The caller must ensure that ptr is valid for writing and remains valid for the lifetime of the returned reference.

Source

pub fn cpu(&self) -> u32

Returns the primary CPU for the Policy.

Source

pub fn min(&self) -> Hertz

Returns the minimum frequency for the Policy.

Source

pub fn set_min(&mut self, min: Hertz) -> &mut Self

Set the minimum frequency for the Policy.

Source

pub fn max(&self) -> Hertz

Returns the maximum frequency for the Policy.

Source

pub fn set_max(&mut self, max: Hertz) -> &mut Self

Set the maximum frequency for the Policy.

Source

pub fn cur(&self) -> Hertz

Returns the current frequency for the Policy.

Source

pub fn suspend_freq(&self) -> Hertz

Returns the suspend frequency for the Policy.

Source

pub fn set_suspend_freq(&mut self, freq: Hertz) -> &mut Self

Sets the suspend frequency for the Policy.

Source

pub fn generic_suspend(&mut self) -> Result<()>

Provides a wrapper to the generic suspend routine.

Source

pub fn generic_get(&self) -> Result<u32>

Provides a wrapper to the generic get routine.

Source

pub fn register_em_opp(&mut self)

Provides a wrapper to the register with energy model using the OPP core.

Source

pub fn cpus(&mut self) -> &mut Cpumask

Gets cpumask::Cpumask for a cpufreq Policy.

Source

pub unsafe fn set_clk( &mut self, dev: &Device, name: Option<&CStr>, ) -> Result<Clk>

Sets clock for the Policy.

§Safety

The caller must guarantee that the returned Clk is not dropped while it is getting used by the C code.

Source

pub fn set_dvfs_possible_from_any_cpu(&mut self, val: bool) -> &mut Self

Allows / disallows frequency switching code to run on any CPU.

Source

pub fn fast_switch_possible(&self) -> bool

Returns if fast switching of frequencies is possible or not.

Source

pub fn set_fast_switch_possible(&mut self, val: bool) -> &mut Self

Enables / disables fast frequency switching.

Source

pub fn set_transition_latency_ns(&mut self, latency_ns: u32) -> &mut Self

Sets transition latency (in nanoseconds) for the Policy.

Source

pub fn set_cpuinfo_min_freq(&mut self, min_freq: Hertz) -> &mut Self

Sets cpuinfo min_freq.

Source

pub fn set_cpuinfo_max_freq(&mut self, max_freq: Hertz) -> &mut Self

Sets cpuinfo max_freq.

Source

pub fn set_transition_delay_us(&mut self, transition_delay_us: u32) -> &mut Self

Set transition_delay_us, i.e. the minimum time between successive frequency change requests.

Source

pub fn freq_table(&self) -> Result<&Table>

Returns reference to the CPU frequency Table for the Policy.

Source

pub unsafe fn set_freq_table(&mut self, table: &Table) -> &mut Self

Sets the CPU frequency Table for the Policy.

§Safety

The caller must guarantee that the Table is not dropped while it is getting used by the C code.

Source

pub fn data<T: ForeignOwnable>(&mut self) -> Option<T::Borrowed<'_>>

Returns the Policy’s private data.

Auto Trait Implementations§

§

impl !Freeze for Policy

§

impl !RefUnwindSafe for Policy

§

impl !Send for Policy

§

impl !Sync for Policy

§

impl !Unpin for Policy

§

impl UnwindSafe for Policy

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, E> Init<T, E> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, E> PinInit<T, E> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.