Kernel correctness is incredibly important, so kernel authors build extensive debugging and self-checking infrastructure into their systems. But kernels are deployed in challenging situations, so debugging tools designed more for simple, user-level processes don’t always apply. We can add a lot to our debugging toolboxes by considering how kernel designers make their systems more robust. Today, we consider the spinlock subsystem.
Part 1: Survey
In the first part, check out other operating systems’ spinlocks. Your goal is to characterize their debugging and robustness features, and differences from Chickadee’s spinlocks.
Every group will want to familiarize themselves with Chickadee’s k-lock.hh. Then each group should choose an operating system. Here’s a selection of two teaching operating systems and two real operating systems; the real OSes’ implementations are far more complex. Are the teaching OS features mirrored in the real OS? Does the real OS have more features? What features?
OS/161 teaching operating system
- https://github.com/CS161/os161/blob/master/kern/include/spinlock.h
- https://github.com/CS161/os161/blob/master/kern/thread/spinlock.c
xv6 teaching operating system
- Function prototypes
- https://github.com/mit-pdos/xv6-public/blob/master/spinlock.h
- https://github.com/mit-pdos/xv6-public/blob/master/spinlock.c
FreeBSD operating system
- Locking manual page
- Lock profiling support
- Lock validation facility
- https://github.com/freebsd/freebsd/blob/master/sys/sys/lock.h
- https://github.com/freebsd/freebsd/blob/master/sys/kern/kern_lock.c
- https://github.com/freebsd/freebsd/blob/master/sys/kern/subr_witness.c
Linux operating system
- Locking in the Linux kernel
- Linus’s spin_lock tutorial
- Runtime locking correctness validator, “lockdep”
- Kernel Lock Torture Test
- https://github.com/torvalds/linux/blob/master/include/linux/spinlock.h
- https://github.com/torvalds/linux/blob/master/include/linux/spinlock_types.h
- https://github.com/torvalds/linux/blob/master/include/linux/spinlock_api_smp.h
- https://github.com/torvalds/linux/blob/master/arch/x86/include/asm/spinlock.h
- https://github.com/torvalds/linux/blob/master/arch/x86/include/asm/spinlock_types.h
- https://github.com/torvalds/linux/tree/master/kernel/locking — directory containing lock implementations
- https://github.com/torvalds/linux/blob/master/kernel/locking/spinlock.c
- https://github.com/torvalds/linux/blob/master/kernel/locking/spinlock_debug.c
- see also the
lockdep
files in https://github.com/torvalds/linux/tree/master/kernel/locking
Part 2: Recommendations
Look at code (possibly dividing the work among the group) and discuss about
what you see. Develop a proposal for changes to Chickadee’s k-lock.hh
file
to make it more debuggable. Mention features you found in the other operating
systems that should not be ported to Chickadee, as well as features that
should. Outline implementations if you can.
Part 3: Presentations and discussion
In the last half hour of class, each group will present their ideas; we’ll discuss and conclude.