lockstat Spin Lock Probes

Threads cannot block in some contexts in the kernel, such as high-level interrupt context and any context manipulating dispatcher state. In such contexts, you cannot use adaptive locks. Instead you must use spin locks to effect mutual exclusion to critical sections. As the name implies, the behavior of spin locks in the presence of contention is to spin until the lock is released by the owning thread. The following describes the probes related to spin locks.

spin-acquire

Hold-event probe that fires immediately after a spin lock is acquired.

spin-release

Hold-event probe that fires immediately after a spin lock is released.

spin-spin

Contention-event probe that fires after a thread that has spun on a held spin lock has successfully acquired the spin lock. If both are enabled, spin-spin fires before spin-acquire. arg1 for spin-spin contains the spin time. Spin time is the number of nanoseconds that were spent in the spin loop before the lock was acquired.

Adaptive locks are much more common than spin locks. The following script displays the total count for the adaptive and spin lock types to provide data to support this observation.

lockstat:::adaptive-acquire
/execname == "date"/
{
        @locks["adaptive"] = count();
}

lockstat:::spin-acquire
/execname == "date"/
{
        @locks["spin"] = count();
}

Run this script in one window, and the date command in another window. When you terminate the DTrace script, you will see output similar to the following example:

# dtrace -s ./whatlock.d
dtrace: script './whatlock.d' matched 5 probes 
^C
spin                                                             26
adaptive                                                       2981

As this output indicates, over 99 percent of the locks acquired in running the date command are adaptive locks. It may be surprising that so many locks are acquired in doing something as simple as a date. The large number of locks is a natural artifact of the fine-grained locking required of an extremely scalable system like the Oracle Solaris kernel.