DTRACE_LOCKSTAT(4)
πΈ NAME πΈ
dtrace_lockstat β a DTrace provider for tracing kernel locking events. This is the DTRACE_LOCKSTAT(4) page from the Kernel Interfaces Manual, and bestie, it's lowkey iconic because it's literally the map of kernel lock events π
β¨ SYNOPSIS β¨
lockstat:::adaptive-acquire(struct mtx *);
lockstat:::adaptive-release(struct mtx *);
lockstat:::adaptive-spin(struct mtx *, uint64_t);
lockstat:::adaptive-block(struct mtx *, uint64_t);
lockstat:::spin-acquire(struct mtx *);
lockstat:::spin-release(struct mtx *);
lockstat:::spin-spin(struct mtx *, uint64_t);
lockstat:::rw-acquire(struct rwlock *, int);
lockstat:::rw-release(struct rwlock *, int);
lockstat:::rw-block(struct rwlock *, uint64_t, int, int, int);
lockstat:::rw-spin(struct rwlock *, uint64_t);
lockstat:::rw-upgrade(struct rwlock *);
lockstat:::rw-downgrade(struct rwlock *);
lockstat:::sx-acquire(struct sx *, int);
lockstat:::sx-release(struct sx *, int);
lockstat:::sx-block(struct sx *, uint64_t, int, int, int);
lockstat:::sx-spin(struct sx *, uint64_t);
lockstat:::sx-upgrade(struct sx *);
lockstat:::sx-downgrade(struct sx *);
lockstat:::lockmgr-acquire(struct lock *, int);
lockstat:::lockmgr-release(struct lock *, int);
lockstat:::lockmgr-disown(struct lock *, int);
lockstat:::lockmgr-block(struct lock *, uint64_t, int, int, int);
lockstat:::lockmgr-upgrade(struct lock *);
lockstat:::lockmgr-downgrade(struct lock *);
lockstat:::thread-spin(struct mtx *, uint64);
π¦ DESCRIPTION π¦
Okay so the DTrace lockstat provider lets you trace events related to locking on FreeBSD. No cap.
The dtrace_lockstat provider is packed with DTrace probes for inspecting kernel lock state transitions. Probes exist for the lockmgr(9), mutex(9), rwlock(9), and sx(9) lock types. The lockstat(1) utility can be used to collect and display data collected from the dtrace_lockstat provider. Each type of lock has acquire() and release() probes that expose the lock structure being operated upon, plus probes that fire when a thread contends with other threads for ownership of a lock. Periodt.
lockstat:::adaptive-acquire()andlockstat:::adaptive-release()β fire when anMTX_DEFmutex(9)is acquired and released, respectively. The only argument is a pointer to the lock structure which describes the lock being acquired or released.lockstat:::adaptive-spin()β fires when a thread spins while waiting for anMTX_DEFmutex(9)to be released by another thread. First arg: pointer to the lock structure that describes the lock. Second arg: the amount of time, in nanoseconds, that the mutex spent spinning.lockstat:::adaptive-block()β fires when a thread takes itself off the CPU while trying to acquire anMTX_DEFmutex(9)that is owned by another thread. First arg: pointer to the lock structure that describes the lock. Second arg: the length of time, in nanoseconds, that the waiting thread was blocked. Also highkey important:lockstat:::adaptive-block()andlockstat:::adaptive-spin()fire only after the lock has been successfully acquired, and in particular, after thelockstat:::adaptive-acquire()probe fires. πlockstat:::spin-acquire()andlockstat:::spin-release()β fire when anMTX_SPINmutex(9)is acquired or released, respectively. The only argument is a pointer to the lock structure which describes the lock being acquired or released.lockstat:::spin-spin()β fires when a thread spins while waiting for anMTX_SPINmutex(9)to be released by another thread. First arg: pointer to the lock structure that describes the lock. Second arg: the length of the time spent spinning, in nanoseconds. It fires only after the lock has been successfully acquired, and in particular, after thelockstat:::spin-acquire()probe fires.lockstat:::rw-acquire()andlockstat:::rw-release()β fire when arwlock(9)is acquired or released, respectively. First arg: pointer to the structure which describes the lock being acquired. Second arg:0if the lock is being acquired or released as a writer, and1if it is being acquired or released as a reader. Thelockstat:::sx-acquire()andlockstat:::sx-release(), andlockstat:::lockmgr-acquire()andlockstat:::lockmgr-release()probes fire upon the corresponding events forsx(9)andlockmgr(9)locks, respectively. Thelockstat:::lockmgr-disown()probe fires when alockmgr(9)exclusive lock is disowned. In this state, the lock remains exclusively held, but may be released by a different thread. Thelockstat:::lockmgr-release()probe does not fire when releasing a disowned lock. The first argument is a pointer to the structure which describes the lock being disowned. The second argument is0, for compatibility withlockstat:::lockmgr-release(). π«Άlockstat:::rw-block(),lockstat:::sx-block(), andlockstat:::lockmgr-block()β fire when a thread removes itself from the CPU while waiting to acquire a lock of the corresponding type.lockstat:::rw-spin()andlockstat:::sx-spin()β fire when a thread spins while waiting to acquire a lock of the corresponding type. All probes take the same set of arguments. First arg: pointer to the lock structure that describes the lock. Second arg: the length of time, in nanoseconds, that the waiting thread was off the CPU or spinning for the lock. Third arg:0if the thread is attempting to acquire the lock as a writer, and1if the thread is attempting to acquire the lock as a reader. Fourth arg:0if the thread is waiting for a reader to release the lock, and1if the thread is waiting for a writer to release the lock. Fifth arg: the number of readers that held the lock when the thread first attempted to acquire the lock. This argument will be0if the fourth argument is1. Slay, that's the whole arg list πlockstat:::lockmgr-upgrade(),lockstat:::rw-upgrade(), andlockstat:::sx-upgrade()β fire when a thread successfully upgrades a heldlockmgr(9),rwlock(9), orsx(9)shared/reader lock to an exclusive/writer lock. The only argument is a pointer to the structure which describes the lock being acquired.lockstat:::lockmgr-downgrade(),lockstat:::rw-downgrade(), andlockstat:::sx-downgrade()β fire when a thread downgrades a heldlockmgr(9),rwlock(9), orsx(9)exclusive/writer lock to a shared/reader lock.lockstat:::thread-spin()β fires when a thread spins on a thread lock, which is a specializedMTX_SPINmutex(9). First arg: pointer to the structure that describes the lock. Second arg: the length of time, in nanoseconds, that the thread was spinning.
π SEE ALSO π
Go read these too, bestie: dtrace(1), lockstat(1), locking(9), mutex(9), rwlock(9), SDT(9), sx(9).
π°οΈ HISTORY π°οΈ
The dtrace_lockstat provider first appeared in Solaris. The FreeBSD implementation of the dtrace_lockstat provider first appeared in FreeBSD 9. History check, iconic.
π AUTHORS π
This manual page was written by George V. Neville-Neil <gnn@FreeBSD.org> and Mark Johnston <markj@FreeBSD.org>. Obsessed with the way they put this together, ngl π
π BUGS π
Probes for rmlock(9) locks have not yet been added. Not yet, bestie π
mwah π β this page is from Debian, dated September 3, 2025, for DTRACE_LOCKSTAT(4). periodt.
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2017 George V. Neville-Neil <gnn@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms