diff options
author | sigsegv7 <ian@vegaa.systems> | 2023-10-04 19:28:31 -0400 |
---|---|---|
committer | sigsegv7 <ian@vegaa.systems> | 2023-10-04 19:28:31 -0400 |
commit | e6f471fb01a3f49660840ed9801fd30057c3f2ec (patch) | |
tree | 577cfb07b57758e5fdc7e007388c2f16d4081fe4 /sys | |
parent | ccf6421ebfd30808a24b1a08aa6dbf963de1f24d (diff) |
kernel/amd64: Add spinlock to cpu_info
Signed-off-by: sigsegv7 <ian@vegaa.systems>
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/amd64/lapic.c | 4 | ||||
-rw-r--r-- | sys/include/arch/amd64/cpu.h | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/sys/arch/amd64/lapic.c b/sys/arch/amd64/lapic.c index 53a4fd5..76b0f87 100644 --- a/sys/arch/amd64/lapic.c +++ b/sys/arch/amd64/lapic.c @@ -249,10 +249,11 @@ lapic_init(void) /* Register the timer for scheduler usage */ register_timer(TIMER_SCHED, &lapic_timer); - /* Get the current processor, and calibrate LAPIC timer */ + /* Get the current processor, and lock its structure */ cur_cpu = this_cpu(); CPU_INFO_LOCK(cur_cpu); + /* Calibrate timer */ lapic_timer_init(&tmr_freq); cur_cpu->lapic_tmr_freq = tmr_freq; @@ -260,5 +261,6 @@ lapic_init(void) cur_cpu->lapic_id = lapic_get_id(); BSP_KINFO("BSP Local APIC ID: %d\n", cur_cpu->lapic_id); + CPU_INFO_UNLOCK(cur_cpu); } diff --git a/sys/include/arch/amd64/cpu.h b/sys/include/arch/amd64/cpu.h index b63d6e9..dfc4054 100644 --- a/sys/include/arch/amd64/cpu.h +++ b/sys/include/arch/amd64/cpu.h @@ -31,14 +31,25 @@ #define _AMD64_CPU_H_ #include <sys/types.h> +#include <sys/spinlock.h> #define this_cpu() amd64_this_cpu() #define get_bsp() amd64_get_bsp() +#define CPU_INFO_LOCK(info) spinlock_acquire(&(info->lock)) +#define CPU_INFO_UNLOCK(info) spinlock_release(&(info->lock)) +/* + * Info about a specific processor. + * + * XXX: Spinlock must be acquired outside of this module! + * None of these module's internal functions should + * acquire the spinlock themselves! + */ struct cpu_info { void *pmap; /* Current pmap */ uint32_t lapic_id; volatile size_t lapic_tmr_freq; + struct spinlock lock; }; struct cpu_info *amd64_this_cpu(void); |