Links from today's lecture: http://www.infoq.com/presentations/click-crash-course-modern-hardware -- at 36min mark memory cache details start http://www.cs.fsu.edu/~xyuan/cop5611/spinlock.html -- explanations of Linux spinlocks http://lxr.linux.no/#linux-bk+v2.6.11.5/include/asm-i386/spinlock.h -- actual code of Linux spinlock in 2.6.11.5 kernel. Observe the preemptable kernel #ifdefs Info on preemptable kernels: Intro: http://www.linuxjournal.com/article/5600 Driver details: http://lwn.net/Articles/22912/ Per-CPU variables: http://lxr.linux.no/#linux+v2.6.32/include/linux/preempt.h -- find your way through the macros that must be used to create a per-CPU variable and safely access it from a preemtible kernel. Recall that pre-emption may occur between two threads on the *same* CPU. Suggestion: explore the handling of spinlocks by preemption code -- how is same-CPU safety of a spinlock achieved? ==== OpenSolaris approach ==== Read Chapter 17 of the textbook. Mutex implementation (with "polymorphism" of the mutex_{enter,exit} methods) between spinlocks and adaptive locks: http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/intel/sys/mutex_impl.h#40 -- comment and union, then access macros http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/os/mutex.c#26 -- "Big Theory Statement" then mutex_vector_enter (line 337) Details on cli/sti: http://en.wikipedia.org/wiki/IF_(x86_flag) Actual x86 assembly routines: http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/intel/ia32/ml/lock_prim.s (see the beginning of 2009/l6.txt for more details)