Part 8 · 1 chapters · ~8 min

Capstone: xv6 and Extending the BYO Kernel

Reading xv6, MIT's small teaching Unix for RISC-V (processes, the scheduler, traps and system calls, virtual memory, the file system), the labs worth doing, and extending the Build Your Own course's kernel simulator with a new system call and copy-on-write fork.

16

Reading xv6

code
git clone https://github.com/mit-pdos/xv6-riscv && cd xv6-riscv
make qemu                      # boots in the QEMU emulator; needs a RISC-V toolchain

where to read, in order (about 6,000 lines of C in total)
kernel/proc.c       processes, fork, exit, wait, the scheduler loop
kernel/trap.c       traps: system calls, interrupts, faults
kernel/syscall.c    system call dispatch table
kernel/vm.c         page tables, mapping, copyin/copyout
kernel/fs.c, log.c  inodes, directories, the write-ahead log for crash consistency
kernel/spinlock.c, sleeplock.c   locks

MIT 6.1810 labs worth doing: system calls (trace), page tables, traps (alarm), copy-on-write fork, locks, file system (large files, symlinks)
extending the BYO kernel (modules/byo/repos/kernel)
  1. Add a getppid system call end to end (table entry, handler, a user program that calls it, a test).
  2. Implement copy-on-write fork in its memory model: share pages read-only, copy on the first write fault.
  3. Add a sleep queue so blocked processes stop consuming scheduler time.
  4. Measure: compare fork time and memory before and after copy-on-write.