- kernel detects CPUs by searching ACPI tables for local apic nodes - each CPU has its own TSS that points to its own stack. All cpus boot on the same boot stack (in sequence) but switch to its private stack as soon as they can. - final booting code in main() placed in bsp_finish_booting() which is executed only after the BSP switches to its final stack - apic functions to send startup interrupts - assembler functions to handle CPU features not needed for single cpu mode like memory barries, HT detection etc. - new files kernel/smp.[ch], kernel/arch/i386/arch_smp.c and kernel/arch/i386/include/arch_smp.h - 16-bit trampoline code for the APs. It is executed by each AP after receiving startup IPIs it brings up the CPUs to 32bit mode and let them spin in an infinite loop so they don't do any damage. - implementation of kernel spinlock - CONFIG_SMP and CONFIG_MAX_CPUS set by the build system
38 lines
830 B
C
38 lines
830 B
C
#ifndef __SPINLOCK_H__
|
|
#define __SPINLOCK_H__
|
|
|
|
#include "kernel.h"
|
|
|
|
typedef struct spinlock {
|
|
atomic_t val;
|
|
} spinlock_t;
|
|
|
|
#ifndef CONFIG_SMP
|
|
|
|
#define SPINLOCK_DEFINE(name)
|
|
#define PRIVATE_SPINLOCK_DEFINE(name)
|
|
#define SPINLOCK_DECLARE(name)
|
|
#define spinlock_init(sl)
|
|
#define spinlock_lock(sl)
|
|
#define spinlock_unlock(sl)
|
|
|
|
#else
|
|
|
|
/* SMP */
|
|
#define SPINLOCK_DEFINE(name) spinlock_t name;
|
|
#define PRIVATE_SPINLOCK_DEFINE(name) PRIVATE SPINLOCK_DEFINE(name)
|
|
#define SPINLOCK_DECLARE(name) extern SPINLOCK_DEFINE(name)
|
|
#define spinlock_init(sl) do { (sl)->val = 0; } while (0)
|
|
#if CONFIG_MAX_CPUS == 1
|
|
#define spinlock_lock(sl)
|
|
#define spinlock_unlock(sl)
|
|
#else
|
|
#define spinlock_lock(sl) arch_spinlock_lock((atomic_t*) sl)
|
|
#define spinlock_unlock(sl) arch_spinlock_unlock((atomic_t*) sl)
|
|
#endif
|
|
|
|
|
|
#endif
|
|
|
|
#endif /* __SPINLOCK_H__ */
|