LOCKING(9): Update to current FreeBSD version

This commit is contained in:
Sebastian Huber 2017-11-14 13:06:39 +01:00
parent b03a1c0b59
commit 9c1490aac3
4 changed files with 115 additions and 81 deletions

View File

@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from BSDI $Id: mutex.h,v 2.7.2.35 2000/04/27 03:10:26 cp Exp $
* from BSDI Id: mutex.h,v 2.7.2.35 2000/04/27 03:10:26 cp
* $FreeBSD$
*/
@ -34,6 +34,7 @@
#include <sys/queue.h>
#include <sys/_lock.h>
#include <sys/ktr_class.h>
struct lock_list_entry;
struct thread;
@ -58,11 +59,12 @@ struct thread;
struct lock_class {
const char *lc_name;
unsigned int lc_flags;
void (*lc_assert)(struct lock_object *lock, int what);
void (*lc_ddb_show)(struct lock_object *lock);
void (*lc_lock)(struct lock_object *lock, int how);
int (*lc_owner)(struct lock_object *lock, struct thread **owner);
int (*lc_unlock)(struct lock_object *lock);
void (*lc_assert)(const struct lock_object *lock, int what);
void (*lc_ddb_show)(const struct lock_object *lock);
void (*lc_lock)(struct lock_object *lock, __uintptr_t how);
int (*lc_owner)(const struct lock_object *lock,
struct thread **owner);
__uintptr_t (*lc_unlock)(struct lock_object *lock);
};
#define LC_SLEEPLOCK 0x00000001 /* Sleep lock. */
@ -79,8 +81,10 @@ struct lock_class {
#define LO_SLEEPABLE 0x00100000 /* Lock may be held while sleeping. */
#define LO_UPGRADABLE 0x00200000 /* Lock may be upgraded/downgraded. */
#define LO_DUPOK 0x00400000 /* Don't check for duplicate acquires */
#define LO_IS_VNODE 0x00800000 /* Tell WITNESS about a VNODE lock */
#define LO_CLASSMASK 0x0f000000 /* Class index bitmask. */
#define LO_NOPROFILE 0x10000000 /* Don't profile this lock */
#define LO_NEW 0x20000000 /* Don't check for double-init */
/*
* Lock classes are statically assigned an index into the gobal lock_classes
@ -121,7 +125,8 @@ struct lock_class {
* calling conventions for this debugging code in modules so that modules can
* work with both debug and non-debug kernels.
*/
#if defined(KLD_MODULE) || defined(WITNESS) || defined(INVARIANTS) || defined(INVARIANT_SUPPORT) || defined(KTR) || defined(LOCK_PROFILING)
#if defined(KLD_MODULE) || defined(WITNESS) || defined(INVARIANTS) || \
defined(LOCK_PROFILING) || defined(KTR)
#define LOCK_DEBUG 1
#else
#define LOCK_DEBUG 0
@ -150,21 +155,26 @@ struct lock_class {
* file - file name
* line - line number
*/
#if LOCK_DEBUG > 0
#define LOCK_LOG_TEST(lo, flags) \
(((flags) & LOP_QUIET) == 0 && ((lo)->lo_flags & LO_QUIET) == 0)
#else
#define LOCK_LOG_TEST(lo, flags) 0
#endif
#define LOCK_LOG_LOCK(opname, lo, flags, recurse, file, line) do { \
if (LOCK_LOG_TEST((lo), (flags))) \
CTR6(KTR_LOCK, opname " (%s) %s %p r = %d at %s:%d", \
LOCK_CLASS(lo)->lc_name, (lo)->lo_name, \
(lo), (u_int)(recurse), (file), (line)); \
(lo), (unsigned int)(recurse), (file), (line)); \
} while (0)
#define LOCK_LOG_TRY(opname, lo, flags, result, file, line) do { \
if (LOCK_LOG_TEST((lo), (flags))) \
CTR6(KTR_LOCK, "TRY_" opname " (%s) %s %p result=%d at %s:%d",\
LOCK_CLASS(lo)->lc_name, (lo)->lo_name, \
(lo), (u_int)(result), (file), (line)); \
(lo), (unsigned int)(result), (file), (line)); \
} while (0)
#define LOCK_LOG_INIT(lo, flags) do { \
@ -192,13 +202,42 @@ extern struct lock_class lock_class_mtx_spin;
extern struct lock_class lock_class_sx;
extern struct lock_class lock_class_rw;
extern struct lock_class lock_class_rm;
extern struct lock_class lock_class_rm_sleepable;
extern struct lock_class lock_class_lockmgr;
extern struct lock_class *lock_classes[];
struct lock_delay_config {
unsigned int base;
unsigned int max;
};
struct lock_delay_arg {
struct lock_delay_config *config;
unsigned int delay;
unsigned int spin_cnt;
};
static inline void
lock_delay_arg_init(struct lock_delay_arg *la, struct lock_delay_config *lc)
{
la->config = lc;
la->delay = lc->base;
la->spin_cnt = 0;
}
#define LOCK_DELAY_SYSINIT(func) \
SYSINIT(func##_ld, SI_SUB_LOCK, SI_ORDER_ANY, func, NULL)
#define LOCK_DELAY_SYSINIT_DEFAULT(lc) \
SYSINIT(lock_delay_##lc##_ld, SI_SUB_LOCK, SI_ORDER_ANY, \
lock_delay_default_init, &lc)
void lock_init(struct lock_object *, struct lock_class *,
const char *, const char *, int);
void lock_destroy(struct lock_object *);
void lock_delay(struct lock_delay_arg *);
void lock_delay_default_init(struct lock_delay_config *);
void spinlock_enter(void);
void spinlock_exit(void);
void witness_init(struct lock_object *, const char *);
@ -215,7 +254,7 @@ void witness_restore(struct lock_object *, const char *, int);
int witness_list_locks(struct lock_list_entry **,
int (*)(const char *, ...));
int witness_warn(int, struct lock_object *, const char *, ...);
void witness_assert(struct lock_object *, int, const char *, int);
void witness_assert(const struct lock_object *, int, const char *, int);
void witness_display_spinlock(struct lock_object *, struct thread *,
int (*)(const char *, ...));
int witness_line(struct lock_object *);
@ -304,16 +343,5 @@ void witness_thread_exit(struct thread *);
#define WITNESS_LINE(lock) (0)
#endif /* WITNESS */
/*
* Helper macros to allow developers to add explicit lock order checks
* wherever they please without having to actually grab a lock to do so.
*/
#define witness_check(l) \
WITNESS_CHECKORDER(&(l)->lock_object, LOP_EXCLUSIVE, LOCK_FILE, \
LOCK_LINE, NULL)
#define witness_check_shared(l) \
WITNESS_CHECKORDER(&(l)->lock_object, 0, LOCK_FILE, LOCK_LINE, NULL)
#endif /* _KERNEL */
#endif /* _MACHINE__KERNEL_LOCK_H_ */

View File

@ -48,12 +48,13 @@
#include <sys/proc.h>
#include <sys/conf.h>
static void assert_mtx(struct lock_object *lock, int what);
static void lock_mtx(struct lock_object *lock, int how);
static void assert_mtx(const struct lock_object *lock, int what);
static void lock_mtx(struct lock_object *lock, uintptr_t how);
#ifdef KDTRACE_HOOKS
static int owner_mtx(struct lock_object *lock, struct thread **owner);
static int owner_mtx(const struct lock_object *lock,
struct thread **owner);
#endif
static int unlock_mtx(struct lock_object *lock);
static uintptr_t unlock_mtx(struct lock_object *lock);
/*
* Lock classes for sleep and spin mutexes.
@ -89,26 +90,27 @@ struct lock_class lock_class_mtx_spin = {
struct mtx Giant;
void
assert_mtx(struct lock_object *lock, int what)
assert_mtx(const struct lock_object *lock, int what)
{
mtx_assert((struct mtx *)lock, what);
mtx_assert((const struct mtx *)lock, what);
}
void
lock_mtx(struct lock_object *lock, int how)
lock_mtx(struct lock_object *lock, uintptr_t how)
{
mtx_lock((struct mtx *)lock);
}
int
uintptr_t
unlock_mtx(struct lock_object *lock)
{
mtx_unlock((struct mtx *)lock);
mtx_unlock((struct mtx *)lock);
return (0);
}
#ifdef KDTRACE_HOOKS
int
owner_mtx(struct lock_object *lock, struct thread **owner)

View File

@ -58,12 +58,12 @@
#define _rw_assert(rw, what, file, line)
#endif
static void assert_rw(struct lock_object *lock, int what);
static void lock_rw(struct lock_object *lock, int how);
static void assert_rw(const struct lock_object *lock, int what);
static void lock_rw(struct lock_object *lock, uintptr_t how);
#ifdef KDTRACE_HOOKS
static int owner_rw(struct lock_object *lock, struct thread **owner);
static int owner_rw(const struct lock_object *lock, struct thread **owner);
#endif
static int unlock_rw(struct lock_object *lock);
static uintptr_t unlock_rw(struct lock_object *lock);
struct lock_class lock_class_rw = {
.lc_name = "rw",
@ -84,22 +84,24 @@ struct lock_class lock_class_rw = {
#define rw_recursed(rw) rtems_bsd_mutex_recursed(&(rw)->mutex)
void
assert_rw(struct lock_object *lock, int what)
assert_rw(const struct lock_object *lock, int what)
{
rw_assert((struct rwlock *)lock, what);
rw_assert((const struct rwlock *)lock, what);
}
void
lock_rw(struct lock_object *lock, int how)
lock_rw(struct lock_object *lock, uintptr_t how)
{
rw_wlock((struct rwlock *)lock);
}
int
uintptr_t
unlock_rw(struct lock_object *lock)
{
rw_unlock((struct rwlock *)lock);
rw_unlock((struct rwlock *)lock);
return (0);
}

View File

@ -47,12 +47,12 @@
#include <sys/lock.h>
#include <sys/sx.h>
static void assert_sx(struct lock_object *lock, int what);
static void lock_sx(struct lock_object *lock, int how);
static void assert_sx(const struct lock_object *lock, int what);
static void lock_sx(struct lock_object *lock, uintptr_t how);
#ifdef KDTRACE_HOOKS
static int owner_sx(struct lock_object *lock, struct thread **owner);
static int owner_sx(const struct lock_object *lock, struct thread **owner);
#endif
static int unlock_sx(struct lock_object *lock);
static uintptr_t unlock_sx(struct lock_object *lock);
struct lock_class lock_class_sx = {
.lc_name = "sx",
@ -73,22 +73,24 @@ struct lock_class lock_class_sx = {
#define sx_recursed(sx) rtems_bsd_mutex_recursed(&(sx)->mutex)
void
assert_sx(struct lock_object *lock, int what)
assert_sx(const struct lock_object *lock, int what)
{
sx_assert((struct sx *)lock, what);
sx_assert((const struct sx *)lock, what);
}
void
lock_sx(struct lock_object *lock, int how)
lock_sx(struct lock_object *lock, uintptr_t how)
{
sx_xlock((struct sx *)lock);
}
int
uintptr_t
unlock_sx(struct lock_object *lock)
{
sx_xunlock((struct sx *)lock);
sx_xunlock((struct sx *)lock);
return (0);
}