Module local

Source
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:

  1. 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.
  2. 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 type S.
CpuLocalCell
Inner mutable CPU-local objects.
CpuLocalDerefGuard
A guard for accessing the CPU-local object.
DynCpuLocalChunk
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Β§

DynamicCpuLocal
Dynamically-allocated CPU-local objects.
StaticCpuLocal
Statically-allocated CPU-local objects.