SMP
This document describes the Symmetric Multi-Processing (SMP) support in the Kyronix kernel. It is the child of Process Management.
Source
kernel/proc/smp.c, kernel/proc/smp.h, kernel/proc/ap_trampoline.S
Overview
SMP support enables the kernel to run on multiple CPU cores. The BSP (Bootstrap Processor) discovers CPUs via the Limine SMP protocol and wakes APs (Application Processors) via a trampoline mechanism.
CPU Discovery (smp_init)
- Read
limine_smp_responsefrom bootloader - Set
g_cpu_countto reported CPU count - Identify BSP by its LAPIC ID, assign CPU ID 0
- Assign sequential IDs to APs (starting at 1)
- Store
&g_cpu_local[cid]in each CPU’sextra_argument
AP Boot Sequence (smp_boot_aps)
- Create idle process for each non-BSP CPU
- Write
ap_trampolineto each CPU’sgoto_address(Limine wake-up mechanism) - Wait until
g_aps_ready == g_cpu_count - 1
AP Trampoline (ap_trampoline)
The AP entry point in assembly:
cli– disable interrupts- Load
limine_smp_info.extra_argument(points tocpu_local_t) - Load
cpu_local_t.current(idle process) - Load
proc_t.kstack_topas RSP - Call
ap_init_cpu(cpu_local_t *)in C
AP Initialization (ap_init_cpu)
Each AP performs full initialization (in order):
- GDT:
gdt_ap_load(cpu_id)– per-CPU GDT + TSS - IDT:
idt_load_ap()– reload IDT - MSR setup: Write
IA32_GS_BASEandIA32_KERNEL_GS_BASE - SSE:
cpu_enable_sse() - SYSCALL MSRs: Configure SYSCALL/SYSRET (same as BSP)
- LAPIC: Enable spurious vector, mask LVT entries
- Signal readiness: Atomically increment
g_aps_ready - Wait for BSP: Spin on
g_kernel_ready - Start timer:
lapic_timer_start_periodic(250) - Enter
ap_sched_loop()
Per-CPU Data
Each CPU has a cpu_local_t structure accessed via GS:
| Offset | Field | Description |
|---|---|---|
| 0 | kernel_rsp | Kernel stack pointer |
| 8 | user_rsp | User stack pointer |
| 16 | cpu_id | CPU identifier |
| 32 | current | Current process |
| 40 | idle | Idle process |
Maximum supported CPUs is defined by MAX_CPUS.
Last reviewed: 2026-07-22