SMP & Kernel Threads for egos-2k+
16 harts · 120,000 threads in one run
Took a RISC-V teaching OS from a single hart to 16, then added kernel threads and a pthreads-style library on top.
- C
- RISC-V
- QEMU
[+] details [-] hide details
- Extended egos-2k+, a RISC-V teaching OS, from a single hart to 16. Each hart gets its own boot and trap setup, the trap entry path takes a big kernel lock acquired with
amoswap, and idle harts park inwfi. - Implemented kernel-level threads as process-table entries that share the parent's page table, with per-thread stacks and syscall pages located through the
tpregister. - Built a pthreads-style library with create, join, and exit, plus mutexes, semaphores, and condition variables, and measured a contended mutex at 57× the per-increment cost of per-thread counters.
- Debugged multicore races such as a torn 64-bit
mtimecmpwrite that left harts asleep forever, and stress-tested 120,000 threads in one run with an exact final count under QEMU multi-threaded TCG.



