Expand description
CPU local storage.
This module provides a mechanism to define CPU-local objects. Users can
define a statically-allocated CPU-local object by the macro
crate::cpu_local!
, or allocate a dynamically-allocated CPU-local
object with the function osdk_heap_allocator::alloc_cpu_local
.
The mechanism for statically-allocated CPU-local objects exploits the fact
that constant values of non-Copy
types can be bitwise copied. For
example, a Option<T>
object, though being not Copy
, have a constant
constructor Option::None
that produces a value that can be bitwise
copied to create a new instance. alloc::sync::Arc
however, donβt have
such a constructor, and thus cannot be directly used as a statically-
allocated CPU-local object. Wrapping it in a type that has a constant
constructor, like Option<T>
, can make it statically-allocated CPU-local.
Β§Implementation
These APIs are implemented by the methods as follows:
- For statically-allocated CPU-local objects, we place them in a special
section
.cpu_local
. The bootstrap processor (BSP) uses the objects linked in this section, and these objects are copied to dynamically allocated local storage of each application processors (AP) during the initialization process. - For dynamically-allocated CPU-local objects, we prepare a fixed-size chunk for each CPU. These per-CPU memory chunks are laid out contiguously in memory in the order of the CPU IDs. A dynamically-allocated CPU-local object can be allocated by occupying the same offset in each per-CPU memory chunk.
ModulesΒ§
- cell π
- The implementation of CPU-local variables that have inner mutability.
- dyn_
cpu_ πlocal - Dynamically-allocated CPU-local objects.
- is_used π
- This module tracks whether any statically-allocated CPU-local variables are used.
- single_
instr π - Extensions for CPU-local types that allows single-instruction operations.
- static_
cpu_ πlocal - Statically-allocated CPU-local objects.
StructsΒ§
- CpuLocal
- A CPU-local variable for type
T
, backed by a storage of typeS
. - CpuLocal
Cell - Inner mutable CPU-local objects.
- CpuLocal
Deref Guard - A guard for accessing the CPU-local object.
- DynCpu
Local Chunk - Manages dynamically-allocated CPU-local chunks.
StaticsΒ§
- CPU_
LOCAL_ πSTORAGES - The static CPU-local areas for APs.
TraitsΒ§
- AnyStorage
- A trait to abstract any type that can be used as a slot for a CPU-local
variable of type
T
.
FunctionsΒ§
- __
cpu_ π βlocal_ end - __
cpu_ π βlocal_ start - copy_
bsp_ π βfor_ ap - Copies the static CPU-local data on the bootstrap processor (BSP) for application processors (APs).
- get_ap π
- Gets the pointer to the static CPU-local storage for the given AP.
Type AliasesΒ§
- Dynamic
CpuLocal - Dynamically-allocated CPU-local objects.
- Static
CpuLocal - Statically-allocated CPU-local objects.