52#define PERCPU_ALIGNMENT 64
75#define PERCPU __seg_gs*
85#define SELF ((cpu_t PERCPU)0)
93#define SELF_PTR(ptr) ((void*)((uintptr_t)(SELF->self->percpu) + ((uintptr_t)(ptr) - offsetof(cpu_t, percpu))))
102#define CPU_PTR(id, ptr) \
103 ((void*)((uintptr_t)(cpu_get_by_id(id)->percpu) + ((uintptr_t)(ptr) - offsetof(cpu_t, percpu))))
115#define PERCPU_DEFINE(type, name, ...) \
117 static const percpu_def_t __attribute__((used, section("._percpu"))) _percpu##name = {.ptr = (percpu_t*)&(name), \
118 .size = sizeof(typeof(*name)), \
130#define PERCPU_DEFINE_CTOR(type, name) \
131 static void name##_ctor(void); \
132 PERCPU_DEFINE(type, name, .ctor = name##_ctor, .dtor = NULL); \
133 static void name##_ctor(void)
144#define PERCPU_DEFINE_DTOR(type, name) \
145 static void name##_dtor(void); \
146 PERCPU_DEFINE(type, name, .ctor = NULL, .dtor = name##_dtor); \
147 static void name##_dtor(void)
194#define PERCPU_INIT() \
197 extern percpu_def_t _percpu_start; \
198 extern percpu_def_t _percpu_end; \
199 percpu_section_init(&_percpu_start, &_percpu_end); \
205#define PERCPU_DEINIT() \
208 extern percpu_def_t _percpu_start; \
209 extern percpu_def_t _percpu_end; \
210 percpu_section_deinit(&_percpu_start, &_percpu_end); \
void percpu_update(void)
Update percpu sections on the current CPU.
void percpu_free(percpu_t ptr, size_t size)
Frees a percpu variable.
void percpu_init(cpu_t *cpu)
Initialize the percpu system.
void percpu_section_deinit(percpu_def_t *start, percpu_def_t *end)
Unregister a percpu section and run destructors.
void percpu_section_init(percpu_def_t *start, percpu_def_t *end)
Register a percpu section and run constructors.
percpu_t percpu_alloc(size_t size)
Allocates a percpu variable.
size_t percpu_t
The type that the compiler uses to store per-CPU variables.
Structure to define a percpu variable.