SimpleKernel 1.17.0
Loading...
Searching...
No Matches
per_cpu.hpp
Go to the documentation of this file.
5#pragma once
7#include <cpu_io.h>
8#include <etl/singleton.h>
9#include <unistd.h>
10
11#include <array>
12#include <atomic>
13#include <cstddef>
14#include <cstdint>
15#include <cstdlib>
20namespace per_cpu {
21
23struct PerCpu {
25 size_t core_id{0};
26
33
36 explicit PerCpu(size_t id) : core_id(id) {}
37
38 PerCpu() = default;
39 PerCpu(const PerCpu&) = default;
40 PerCpu(PerCpu&&) = default;
41 auto operator=(const PerCpu&) -> PerCpu& = default;
42 auto operator=(PerCpu&&) -> PerCpu& = default;
43 ~PerCpu() = default;
45} __attribute__((aligned(SIMPLEKERNEL_PER_CPU_ALIGN_SIZE)));
46
47static_assert(sizeof(PerCpu) <= SIMPLEKERNEL_PER_CPU_ALIGN_SIZE,
48 "PerCpu size should not exceed cache line size");
49
52 etl::singleton<std::array<PerCpu, SIMPLEKERNEL_MAX_CORE_COUNT>>;
53
55static __always_inline auto GetCurrentCore() -> PerCpu& {
56 return PerCpuArraySingleton::instance()[cpu_io::GetCurrentCoreId()];
57}
58
59} // namespace per_cpu
auto GetCurrentCoreId() -> size_t
Definition cpu_io.h:26
etl::singleton< std::array< PerCpu, SIMPLEKERNEL_MAX_CORE_COUNT > > PerCpuArraySingleton
PerCpu 数组单例类型
Definition per_cpu.hpp:52
struct per_cpu::PerCpu __attribute__((aligned(SIMPLEKERNEL_PER_CPU_ALIGN_SIZE)))
static __always_inline auto GetCurrentCore() -> PerCpu &
获取当前核心的 PerCpu 数据
Definition per_cpu.hpp:55
每个核心的调度数据 (RunQueue)
任务控制块,管理进程/线程的核心数据结构
每个 CPU 核心的局部数据
Definition per_cpu.hpp:23
PerCpu(size_t id)
Definition per_cpu.hpp:36
PerCpu(PerCpu &&)=default
TaskControlBlock * running_task
当前运行的任务
Definition per_cpu.hpp:28
CpuSchedData * sched_data
调度数据 (RunQueue) 指针
Definition per_cpu.hpp:32
auto operator=(PerCpu &&) -> PerCpu &=default
TaskControlBlock * idle_task
空闲任务
Definition per_cpu.hpp:30
auto operator=(const PerCpu &) -> PerCpu &=default
size_t core_id
核心 ID
Definition per_cpu.hpp:25
~PerCpu()=default
PerCpu(const PerCpu &)=default
PerCpu()=default