summaryrefslogtreecommitdiffstats
path: root/sys/sys/lock.h
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2006-01-06 18:07:32 +0000
committerjhb <jhb@FreeBSD.org>2006-01-06 18:07:32 +0000
commit8f18f21de1bd66b7ee393a6c26e6b404214128d5 (patch)
tree79baaa91275592f61e12702cac7c092b2d2d4074 /sys/sys/lock.h
parentb183f7d5ee2596f436239b4b518900baf2efa962 (diff)
downloadFreeBSD-src-8f18f21de1bd66b7ee393a6c26e6b404214128d5.zip
FreeBSD-src-8f18f21de1bd66b7ee393a6c26e6b404214128d5.tar.gz
Trim another pointer from struct lock_object (and thus from struct mtx and
struct sx). Instead of storing a direct pointer to a our lock_class struct in lock_object, reserve 4 bits in the lo_flags field to serve as an index into a global lock_classes array that contains pointers to the lock classes. Only debugging code such as WITNESS or INVARIANTS checks and KTR logging need to access the lock_class member, so this shouldn't add any overhead to production kernels. It might add some slight overhead to kernels using those debug options however. As with the previous set of changes to lock_object, this is going to completely obliterate the kernel ABI, so be sure to recompile all your modules.
Diffstat (limited to 'sys/sys/lock.h')
-rw-r--r--sys/sys/lock.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/sys/sys/lock.h b/sys/sys/lock.h
index 31b22690..a6f9080 100644
--- a/sys/sys/lock.h
+++ b/sys/sys/lock.h
@@ -68,6 +68,20 @@ struct lock_class {
#define LO_UPGRADABLE 0x00200000 /* Lock may be upgraded/downgraded. */
#define LO_DUPOK 0x00400000 /* Don't check for duplicate acquires */
#define LO_ENROLLPEND 0x00800000 /* On the pending enroll list. */
+#define LO_CLASSMASK 0x0f000000 /* Class index bitmask. */
+
+/*
+ * Lock classes are statically assigned an index into the gobal lock_classes
+ * array. Debugging code looks up the lock class for a given lock object
+ * by indexing the array.
+ */
+#define LO_CLASSSHIFT 24
+#define LO_CLASSINDEX(lock) ((((lock)->lo_flags) & LO_CLASSMASK) >> LO_CLASSSHIFT)
+#define LOCK_CLASS(lock) (lock_classes[LO_CLASSINDEX((lock))])
+#define LOCK_CLASS_SPIN_MUTEX 0
+#define LOCK_CLASS_SLEEP_MUTEX 1
+#define LOCK_CLASS_SX 2
+#define LOCK_CLASS_MAX LOCK_CLASS_SX
#define LI_RECURSEMASK 0x0000ffff /* Recursion depth of lock instance. */
#define LI_EXCLUSIVE 0x00010000 /* Exclusive lock instance. */
@@ -166,21 +180,21 @@ struct lock_list_entry {
#define LOCK_LOG_LOCK(opname, lo, flags, recurse, file, line) do { \
if (LOCK_LOG_TEST((lo), (flags))) \
CTR5(KTR_LOCK, opname " (%s) %s r = %d at %s:%d", \
- (lo)->lo_class->lc_name, (lo)->lo_name, \
+ LOCK_CLASS(lo)->lc_name, (lo)->lo_name, \
(u_int)(recurse), (file), (line)); \
} while (0)
#define LOCK_LOG_TRY(opname, lo, flags, result, file, line) do { \
if (LOCK_LOG_TEST((lo), (flags))) \
CTR5(KTR_LOCK, "TRY_" opname " (%s) %s result=%d at %s:%d",\
- (lo)->lo_class->lc_name, (lo)->lo_name, \
+ LOCK_CLASS(lo)->lc_name, (lo)->lo_name, \
(u_int)(result), (file), (line)); \
} while (0)
#define LOCK_LOG_INIT(lo, flags) do { \
if (LOCK_LOG_TEST((lo), (flags))) \
CTR4(KTR_LOCK, "%s: %p (%s) %s", __func__, (lo), \
- (lo)->lo_class->lc_name, (lo)->lo_name); \
+ LOCK_CLASS(lo)->lc_name, (lo)->lo_name); \
} while (0)
#define LOCK_LOG_DESTROY(lo, flags) LOCK_LOG_INIT(lo, flags)
@@ -199,6 +213,8 @@ extern struct lock_class lock_class_mtx_sleep;
extern struct lock_class lock_class_mtx_spin;
extern struct lock_class lock_class_sx;
+extern struct lock_class *lock_classes[];
+
void spinlock_enter(void);
void spinlock_exit(void);
void witness_init(struct lock_object *);
OpenPOWER on IntegriCloud