CVSROOT: /cvs Module name: src Changes by: v...@cvs.openbsd.org 2025/04/14 03:14:51
Modified files: sys/kern : subr_witness.c sys/sys : _lock.h witness.h Log message: witness: Improve handling of lock nesting Add an option to specify a parent/child lock relation for a lock object. This lets witness(4) handle the nesting of locks that have the same type without using LO_DUPOK or LOP_DUPOK. An example: The states of objects o1 and o2 are protected by locks o1->o_mtx and o2->o_mtx, respectively. The objects are hierarchical and there is an operation that requires keeping them both locked at the same time. Assume the hierarchy mandates that o1 is locked first. The duplicate locking error can now be avoided by using WITNESS_SETCHILD(&o1->o_mtx.lock_object, &o2->o_mtx.lock_object) or WITNESS_SETPARENT(&o2->o_mtx.lock_object, &o1->o_mtx.lock_object) after the lock initializer. The choice between WITNESS_SETCHILD() and WITNESS_SETPARENT() depends on whether the object access pattern is many-to-one or one-to-many from locking perspective; the implementation allows only one predefined parent/child relation per lock. OK mpi@, claudio@ (earlier version)