Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
#[cpu_local]
attribute and API for primitive types (these…
…us-os#1012) * The new `cls` crate offers a `#[cpu_local]` attribute that can be applied to a static variable to declare it as Cpu-Local Storage (CLS), much like `#[thread_local]` and Thread-Local Storage (TLS). * The `cls_macro` crate provides a procedural macro that implements the `#[cpu_local]` attribute. Currently, this only supports basic primitive types: `u8`, `u16`, `u32`, `u64`. More coming later. * The API for accessing CPU-local primitive types is quite simple: only `load`, `fetch_add`, `fetch_sub`. Note that these functions are implemented as atomic with respect to ONLY the single current CPU, not atomic with respect to all memory accesses across all other CPUs. This is intentional as it is more efficient, and CPU-local variables are only accessible to a single CPU and not by another "foreign" CPU. * Currently this is only used for the preemption counter on each CPU, but it will be used for more variables in future PRs. * This simplifies the implementation of `preemption` management, as we can rely on the `#[cpu_local]` API's semantics to be atomic with respect to the current CPU. * This also avoids a minor latent bug that existed in the old preemption implementation which made it theoretically possible for a task migration to occur between accessing the CPU-local preemption count and modifying that count. This wasn't a problem since Theseus does not yet perform task migration, but the new design makes this interleaving impossible and is thus future-proof for later task migration support. * Re-separate `preemption` and `cpu_local` into two different crates, as they previously were. This is possible because the preemption count now uses the new `#[cpu_local]` attribute, which allows `preemption` and `cpu_local` to not have cyclic dependencies on each other. * This is responsible for most of the changes in this PR: changing `cpu_local_preemption` back to `cpu_local` or `preemption`. * Another current limitation is that we must use the `#[cpu_local]` attribute to _manually_ specify the offset of each CPU-local variable from the start of the `PerCpuData` storage type. This will be removed in a future PR. Signed-off-by: Klimenty Tsoutsman <[email protected]> Co-authored-by: Kevin Boos <[email protected]>
- Loading branch information