From e1e897c9535bb233b90d731ed4b56af2865da6f8 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Fri, 17 Mar 2023 20:07:19 +0000 Subject: [PATCH] kernel: add per-cpu data section to kernel image --- arch/x86_64/layout.ld | 7 +++++++ include/socks/cpu.h | 13 +++++++++++++ include/socks/percpu.h | 15 +++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 include/socks/cpu.h create mode 100644 include/socks/percpu.h diff --git a/arch/x86_64/layout.ld b/arch/x86_64/layout.ld index 85f0c82..64ff918 100644 --- a/arch/x86_64/layout.ld +++ b/arch/x86_64/layout.ld @@ -31,6 +31,13 @@ SECTIONS { *(.data) } + .data.percpu ALIGN(4K) : AT(ADDR(.data.percpu) - KERNEL_VMA) + { + __percpu_start = .; + *(.data.percpu) + __percpu_end = .; + } + .initcall ALIGN(4K) : AT(ADDR(.initcall) - KERNEL_VMA) { __initcall0_start = .; *(.initcall0.init) diff --git a/include/socks/cpu.h b/include/socks/cpu.h new file mode 100644 index 0000000..6c3a339 --- /dev/null +++ b/include/socks/cpu.h @@ -0,0 +1,13 @@ +#ifndef SOCKS_CPU_H_ +#define SOCKS_CPU_H_ + +#include + +/* maximum number of processor cores that the kernel can support. + TODO move to build config option */ +#define CPU_MAX 128 + +DECLARE_BITMAP(cpu_available, CPU_MAX); +DECLARE_BITMAP(cpu_online, CPU_MAX); + +#endif diff --git a/include/socks/percpu.h b/include/socks/percpu.h new file mode 100644 index 0000000..f1cea7a --- /dev/null +++ b/include/socks/percpu.h @@ -0,0 +1,15 @@ +#ifndef SOCKS_PERCPU_H_ +#define SOCKS_PERCPU_H_ + +#include + +#define DEFINE_PERCPU_VAR(type, name) \ + __section(".data.percpu") type name + +#define percpu_get(var) __percpu_get(var) + +#define percpu_put(var) + +extern void *__percpu_get(void *var); + +#endif