9#define PERCPU_MAX_SECTIONS 128
13typedef struct percpu_section
46 if (
offset == allocated.length)
56 memset((
void*)addr, 0, size);
81 if (def->ctor !=
NULL)
92 if (def->dtor !=
NULL)
137 panic(
NULL,
"failed to allocate percpu variable");
150 section->
dying =
false;
181 target->
dying =
true;
187 bool allAcked =
false;
#define assert(expression)
void percpu_update(void)
Update percpu sections on the current CPU.
void percpu_free(percpu_t ptr, size_t size)
Frees a percpu variable.
#define PERCPU_DEFINE(type, name,...)
Macro to define 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.
#define PERCPU_ALIGNMENT
The PERCPU_ALIGNMENT constant defines the alignment for per-CPU variables.
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.
#define CPU_PTR(id, ptr)
Macro to get a pointer to a percpu variable on a specific CPU.
size_t percpu_t
The type that the compiler uses to store per-CPU variables.
#define CPU_FOR_EACH(cpu)
Macro to iterate over all CPUs.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
#define LOCK_CREATE()
Create a lock initializer.
#define LOCK_SCOPE(lock)
Acquires a lock for the reminder of the current scope.
static void lock_release(lock_t *lock)
Releases a lock.
static void lock_acquire(lock_t *lock)
Acquires a lock, blocking until it is available.
#define CONFIG_PERCPU_SIZE
Per-CPU data size configuration.
#define ENOMEM
Out of memory.
#define errno
Error number variable.
#define BITMAP_CREATE_ZERO(name, bits)
Define and create a zero-initialized bitmap and its buffer.
static uint64_t bitmap_find_clear_region_and_set(bitmap_t *map, uint64_t minIdx, uintptr_t maxIdx, uint64_t length, uint64_t alignment)
Find a clear region of specified length and alignment, and set it.
static void bitmap_clear_range(bitmap_t *map, uint64_t low, uint64_t high)
Clear a range of bits in the bitmap.
#define ASM(...)
Inline assembly macro.
#define ROUND_UP(number, multiple)
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define PERCPU_MAX_SECTIONS
static void percpu_run_ctors(percpu_section_t *section)
static void percpu_run_dtors(percpu_section_t *section)
static size_t sectionCount
static percpu_section_t sections[PERCPU_MAX_SECTIONS]
We cant do memory allocation during early boot so we have to statically allocate the percpu sections.
static uint64_t globalAck
static uint64_t globalGeneration
static void msr_write(uint32_t msr, uint64_t value)
#define MSR_KERNEL_GS_BASE
#define offsetof(type, member)
__UINTPTR_TYPE__ uintptr_t
_PUBLIC void * memmove(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_PUBLIC void * memset(void *s, int c, size_t n)
A simple ticket lock implementation.
Structure to define a percpu variable.