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.

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.

Traits§

AnyStorage
A trait to abstract any type that can be used as a slot for a CPU-local variable of type T.

Type Aliases§

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