L4/Darwin: Evolving UNIX Charles Gray Research Engineer, National ICT Australia charles.gray@nicta.com.au
Outline 1. Project Overview 2. BSD on the Mach microkernel 3. Porting Darwin to the L4 microkernel 4. Project Status 2
Darbat Overview Para-virtualised Darwin kernel L4 μ-kernel hypervisor Isolated kernel and device drivers Standard virtualisation benefits 3
Why? Virtualisation Flexibility Robustness Code size 4
Linux Size (LoC) 7,000,000 6,000,000 5,000,000 4,000,000 3,000,000 2,000,000 1,000,000 0 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 5
Mach Once a hot research topic Application Application Many attempts at BSD on Mach Darwin is a monolithic Mach kernel Gave microkernels a bad name Process Mgr Disk File System Network Mach 6
What s in a kernel? XML parser Decompression algorithms Linker Network routing Device drivers Strings 7
Mac OS X Architecture Darwin OS X App launchd UNIX App Aqua GUI xnu 8
Darwin UNIX App OS X App BSD Mach I/O Kit Unique kernel design Mach 3.0 μ-kernel 4.4 BSD derivative I/O Kit device drivers Mac OS X applications Full FreeBSD 5 UNIX environment 9
BSD Layer BSD fork() mmap() listen() HFS+ TCP UFS Threads Process UBC Scheduler VM Disk Network Mach PCI Bus I/O Kit interrupt 10
The I/O Kit mach_msg() BSD paging HFS+ Partition0 Partition1 Client Disk0 Disk1 Keyboard ATA NIC UHCI interrupt Mach PCI Bus I/O Kit 11
BSD and I/O Kit BSD HFS+ read() ioctl() bdevsw Partition0 Partition1 Disk0 Disk1 SCSI ATA I/O Kit 12
L4 2nd generation u-kernel Learn from mistakes of Mach Pay attention to cache, TLB, complexity Make microkernels work 10-20x performance improvement over Mach 13
L4 μ-kernel OS Application Application IPC Threads Address Spaces Scheduler interrupt page-fault / exception L4 14 not to scale
Darbat Decompose Darwin kernel Tackle complexity problem Add flexibility Maintain (or improve) performance All with binary compatibility 15
Darbat Model UNIX App OS X App BSD BSD Mach Mach timer Drv. Stub Drv. Stub L4 BSD stub BSD stub I/O Kit I/O Kit xnuglue xnuglue interrupt 16
XNU on L4 page faults syscalls timer int. mask exception I/O Kit ISR Thread Work-loop Thread Mach 17
Server Consolidation xnu xnu I/O Kit L4 Multiple OS instances support Simplified driver model 18
Crashable Drivers Drivers crash Holding locks Hogging resources Can isolate drivers and keep performance Some devices still critical xnu Network Disk Stack Stack L4 19
VM Aware Scheduling Application Application priority Application Application Application xnu xnu xnu L4 20
Reliable Servers xnu Key Mgr. Microkernel is very resilient I/O Kit Watchdog L4 Protect data from 3rd party modules Ensure reliable execution of code Cheaper software solutions 21
Heterogeneous Systems L4 is OS (everything?) agnostic Linux *BSD Share devices Share file systems Wombat Linux L4 xnu I/O Kit 22
System Call Performance Mac OS X 10.4.7 Darbat 0.2 UNIX App ~2500 cycles UNIX App ~2400 cycles xnu xnu L4 mach_msg null operation 23
In-task Synchronisation Mac OS X 10.4.7 UNIX App Darbat UNIX App xnu ~17,000 cycles ~6,500 cycles L4 pthreads synchronisation 24
IPC Optimisation OS X App OS X App L4 IPC is a subset of Mach IPC Applications rely on Mach semantics Optimisation for some messages xnu L4 25
Scripting Sometimes you just need a hack In-kernel scripts get messy Scheduling and locks are a pain Don t compromise the whole system xnu Python I/O Kit L4 26
Lessons So Far Darwin modularity Binary compatibility Mac OS X has bugs Performance Debugging 27
Future Work? Further decomposition Improved xnu and I/O Kit bindings Usable system! Experiment with features System benchmarks 28
Summary UNIX kernels are feature-packed L4 is one option to address this problem Extend UNIX kernel to meet modern usage Questions? 29