rust/kernel/cpufreq.rs
Source file repositories/reference/linux-study-clean/rust/kernel/cpufreq.rs
File Facts
- System
- Linux kernel
- Corpus path
rust/kernel/cpufreq.rs- Extension
.rs- Size
- 46214 bytes
- Lines
- 1400
- Domain
- Rust Kernel Layer
- Bucket
- Rust API Membrane
- Inferred role
- Rust Kernel Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.
- Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function freqfunction generic_suspendfunction freq_tablefunction Somefunction Okfunction dereffunction exitfunction setpolicyfunction Okfunction drop
Annotated Snippet
pub fn register_em_opp(&mut self) {
// SAFETY: By the type invariant, the pointer stored in `self` is valid.
unsafe { bindings::cpufreq_register_em_with_opp(self.as_mut_ref()) };
}
/// Gets [`cpumask::Cpumask`] for a cpufreq [`Policy`].
#[inline]
pub fn cpus(&mut self) -> &mut cpumask::Cpumask {
// SAFETY: The pointer to `cpus` is valid for writing and remains valid for the lifetime of
// the returned reference.
unsafe { cpumask::CpumaskVar::from_raw_mut(&mut self.as_mut_ref().cpus) }
}
/// 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.
#[cfg(CONFIG_COMMON_CLK)]
pub unsafe fn set_clk(&mut self, dev: &Device, name: Option<&CStr>) -> Result<Clk> {
let clk = Clk::get(dev, name)?;
self.as_mut_ref().clk = clk.as_raw();
Ok(clk)
}
/// Allows / disallows frequency switching code to run on any CPU.
#[inline]
pub fn set_dvfs_possible_from_any_cpu(&mut self, val: bool) -> &mut Self {
self.as_mut_ref().dvfs_possible_from_any_cpu = val;
self
}
/// Returns if fast switching of frequencies is possible or not.
#[inline]
pub fn fast_switch_possible(&self) -> bool {
self.as_ref().fast_switch_possible
}
/// Enables / disables fast frequency switching.
#[inline]
pub fn set_fast_switch_possible(&mut self, val: bool) -> &mut Self {
self.as_mut_ref().fast_switch_possible = val;
self
}
/// Sets transition latency (in nanoseconds) for the [`Policy`].
#[inline]
pub fn set_transition_latency_ns(&mut self, latency_ns: u32) -> &mut Self {
self.as_mut_ref().cpuinfo.transition_latency = latency_ns;
self
}
/// Sets cpuinfo `min_freq`.
#[inline]
pub fn set_cpuinfo_min_freq(&mut self, min_freq: Hertz) -> &mut Self {
self.as_mut_ref().cpuinfo.min_freq = min_freq.as_khz() as u32;
self
}
/// Sets cpuinfo `max_freq`.
#[inline]
pub fn set_cpuinfo_max_freq(&mut self, max_freq: Hertz) -> &mut Self {
self.as_mut_ref().cpuinfo.max_freq = max_freq.as_khz() as u32;
self
}
/// Set `transition_delay_us`, i.e. the minimum time between successive frequency change
/// requests.
#[inline]
pub fn set_transition_delay_us(&mut self, transition_delay_us: u32) -> &mut Self {
self.as_mut_ref().transition_delay_us = transition_delay_us;
self
}
/// Returns reference to the CPU frequency [`Table`] for the [`Policy`].
pub fn freq_table(&self) -> Result<&Table> {
if self.as_ref().freq_table.is_null() {
return Err(EINVAL);
}
// SAFETY: The `freq_table` is guaranteed to be valid for reading and remains valid for the
// lifetime of the returned reference.
Ok(unsafe { Table::from_raw(self.as_ref().freq_table) })
}
/// Sets the CPU frequency [`Table`] for the [`Policy`].
///
/// # Safety
///
Annotation
- Detected declarations: `function freq`, `function generic_suspend`, `function freq_table`, `function Some`, `function Ok`, `function deref`, `function exit`, `function setpolicy`, `function Ok`, `function drop`.
- Atlas domain: Rust Kernel Layer / Rust API Membrane.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.