A principle of synchronization regulates the orderly flow
of data into and out of structures and prevents resource contention.
Thus, in an MP system, thread A executing on Processor 1 must not
contend with thread B executing on Processor 2.
Three kinds of critical sections within the kernel require
mutual exclusion:
Between two interrupt service routines.
Between an interrupt service routine and a thread
of control.
Between two threads of control.
In a uniprocessor environment these contentions were easily
dealt with: Mutual exclusion was implemented for two interrupt service
routines or an interrupt service routine and a thread of control
by raising spl
levels to the highest priority interrupt service routine. To ensure
mutual exclusion between threads of control, no thread could be
preempted while running in kernel mode.
These protection mechanisms are inadequate for an MP environment.
The spl routines
were local in nature and affected only the interrupt protection
level of the calling CPU. Waiting for the current process to reach
a safe point, sleep, or exit the kernel failed to give the desired
parallelism and made for long, non-preemptable critical durations.
In HP-UX, kernel data structures are protected with software
semaphores, locks, and synchronization primitives. Kernel data structures
are then divided into sets, with a semaphore or lock guarding each
set. The granularity of the semaphores and locks are empirically
determined to minimize blocking of threads of control on the semaphores.