diff options
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/arch/i386/i386/lock_stubs.S | 27 | ||||
| -rw-r--r-- | sys/dev/apm/apm.c | 13 | ||||
| -rw-r--r-- | sys/kern/kern_rwlock.c | 6 | ||||
| -rw-r--r-- | sys/lockdoc/log.c | 45 | ||||
| -rw-r--r-- | sys/sys/lockdoc.h | 42 | ||||
| -rw-r--r-- | sys/sys/rwlock.h | 13 |
6 files changed, 110 insertions, 36 deletions
diff --git a/sys/arch/i386/i386/lock_stubs.S b/sys/arch/i386/i386/lock_stubs.S index 6ecc2cd28fd..bd62cd9d6e1 100644 --- a/sys/arch/i386/i386/lock_stubs.S +++ b/sys/arch/i386/i386/lock_stubs.S @@ -118,7 +118,11 @@ END(mutex_exit) * * Acquire one hold on a RW lock. */ +#ifdef LOCKDOC +ENTRY(_rw_enter) +#else ENTRY(rw_enter) +#endif movl 4(%esp), %edx cmpl $RW_READER, 8(%esp) jne 2f @@ -150,14 +154,21 @@ ENTRY(rw_enter) RET(3) 3: jmp _C_LABEL(rw_vector_enter) +#ifdef LOCKDOC +END(_rw_enter) +#else END(rw_enter) - +#endif /* * void rw_exit(krwlock_t *rwl); * * Release one hold on a RW lock. */ +#ifdef LOCKDOC +ENTRY(_rw_exit) +#else ENTRY(rw_exit) +#endif movl 4(%esp), %edx movl (%edx), %eax testb $RW_WRITE_LOCKED, %al @@ -193,14 +204,21 @@ ENTRY(rw_exit) * Slow path. */ 3: jmp _C_LABEL(rw_vector_exit) +#ifdef LOCKDOC +END(_rw_exit) +#else END(rw_exit) - +#endif /* * int rw_tryenter(krwlock_t *rwl, krw_t op); * * Try to acquire one hold on a RW lock. */ +#ifdef LOCKDOC +ENTRY(_rw_tryenter) +#else ENTRY(rw_tryenter) +#endif movl 4(%esp), %edx cmpl $RW_READER, 8(%esp) jne 2f @@ -237,8 +255,11 @@ ENTRY(rw_tryenter) 4: xorl %eax, %eax jmp 3b +#ifdef LOCKDOC +END(_rw_tryenter) +#else END(rw_tryenter) - +#endif /* * void mutex_spin_enter(kmutex_t *mtx); diff --git a/sys/dev/apm/apm.c b/sys/dev/apm/apm.c index 3eb84435a42..40861829d23 100644 --- a/sys/dev/apm/apm.c +++ b/sys/dev/apm/apm.c @@ -87,22 +87,11 @@ int apmdebug = 0; * assert an exclusive lock any time thread context enters the * APM module. This is both the APM thread itself, as well as * user context. - * - * LOCKDOC Update: I don't know why this is implemented as a - * macro with (void) cast here, but it breaks when LOCKDOC replaces - * mutex_enter with a macro. So we circumvent that. */ -#ifdef LOCKDOC -#define APM_LOCK(apmsc) \ - mutex_enter(&(apmsc)->sc_lock) -#define APM_UNLOCK(apmsc) \ - mutex_exit(&(apmsc)->sc_lock) -#else #define APM_LOCK(apmsc) \ (void) mutex_enter(&(apmsc)->sc_lock) #define APM_UNLOCK(apmsc) \ (void) mutex_exit(&(apmsc)->sc_lock) -#endif static void apm_event_handle(struct apm_softc *, u_int, u_int); static void apm_periodic_check(struct apm_softc *); @@ -922,4 +911,4 @@ apmkqfilter(dev_t dev, struct knote *kn) APM_UNLOCK(sc); return (0); -} +}
\ No newline at end of file diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 4546a154b97..a43f0d058dd 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -105,10 +105,16 @@ do { \ #endif #ifndef __HAVE_RW_STUBS +#ifdef LOCKDOC +__strong_alias(_rw_enter,rw_vector_enter); +__strong_alias(_rw_exit,rw_vector_exit); +__strong_alias(_rw_tryenter,rw_vector_tryenter); +#else __strong_alias(rw_enter,rw_vector_enter); __strong_alias(rw_exit,rw_vector_exit); __strong_alias(rw_tryenter,rw_vector_tryenter); #endif +#endif static void rw_abort(const char *, size_t, krwlock_t *, const char *); static void rw_dump(const volatile void *, lockop_printer_t); diff --git a/sys/lockdoc/log.c b/sys/lockdoc/log.c index 56815b93d75..9269baf2e65 100644 --- a/sys/lockdoc/log.c +++ b/sys/lockdoc/log.c @@ -7,6 +7,51 @@ struct log_action la_buffer; +inline void __mutex_enter(kmutex_t * lock, const char* file, int line) { + lockdoc_log_lock(P_WRITE, lock, file, line, LOCK_NONE); + _mutex_enter(lock); +} + +inline void __mutex_exit(kmutex_t * lock, const char* file, int line) { + lockdoc_log_lock(V_WRITE, lock, file, line, LOCK_NONE); + _mutex_exit(lock); +} + +inline void __mutex_spin_enter(kmutex_t * lock, const char* file, int line) { + lockdoc_log_lock(P_WRITE, lock, file, line, LOCK_NONE); + _mutex_spin_enter(lock); +} + +inline void __mutex_spin_exit(kmutex_t * lock, const char* file, int line) { + lockdoc_log_lock(V_WRITE, lock, file, line, LOCK_NONE); + _mutex_spin_exit(lock); +} + +inline void __rw_enter(krwlock_t * lock, const krw_t type, const char* file, int line) { + if(type == RW_READER) + lockdoc_log_lock(P_READ, lock, file, line, LOCK_NONE); + else + lockdoc_log_lock(P_WRITE, lock, file, line, LOCK_NONE); + _rw_enter(lock, type); +} + +inline int __rw_tryenter(krwlock_t * lock, const krw_t type, const char* file, int line) { + // TODO Check against other implementations + return _rw_tryenter(lock, type); +} + +inline void __rw_exit(krwlock_t * lock, const char* file, int line) { + if((lock->rw_owner & 0x02UL) > 0) + lockdoc_log_lock(V_WRITE, lock, file, line, LOCK_NONE); + else + lockdoc_log_lock(V_READ, lock, file, line, LOCK_NONE); + _rw_exit(lock); +} + +/* + * Yet to be implemented: Check https://man.netbsd.org/locking.9 + */ + int32_t lockdoc_get_ctx(void) { if (curlwp == NULL) { return 0; diff --git a/sys/sys/lockdoc.h b/sys/sys/lockdoc.h index 84fc5895680..81c987c2ce5 100644 --- a/sys/sys/lockdoc.h +++ b/sys/sys/lockdoc.h @@ -6,8 +6,9 @@ #include <sys/types.h> #include <sys/systm.h> -#include <sys/lockdebug.h> #include <sys/lockdoc_event.h> +#include <sys/mutex.h> +#include <sys/rwlock.h> #define DELIMITER "#" #define DELIMITER_CHAR '#' @@ -24,6 +25,17 @@ void _mutex_enter(kmutex_t *); void _mutex_exit(kmutex_t *); void _mutex_spin_enter(kmutex_t *); void _mutex_spin_exit(kmutex_t *); +void _rw_enter(krwlock_t *, const krw_t); +int _rw_tryenter(krwlock_t *, const krw_t); +void _rw_exit(krwlock_t *); + +void __mutex_enter(kmutex_t *, const char*, int); +void __mutex_exit(kmutex_t *, const char*, int); +void __mutex_spin_enter(kmutex_t *, const char*, int); +void __mutex_spin_exit(kmutex_t *, const char*, int); +void __rw_enter(krwlock_t *, const krw_t, const char*, int); +int __rw_tryenter(krwlock_t *, const krw_t, const char*, int); +void __rw_exit(krwlock_t *, const char*, int); void trace_irqs_on(struct trapframe *frame); void trace_irqs_off(struct trapframe *frame); @@ -33,25 +45,13 @@ extern struct log_action la_buffer; /* * Redefine lock function as macros instead of normal functions, so that __FILE__ etc. will work properly */ -#define mutex_enter(lock) do { \ - lockdoc_log_lock(P_WRITE, lock, __FILE__, __LINE__, LOCK_NONE); \ - _mutex_enter((lock)); \ -} while(/* CONSTCOND */ 0) - -#define mutex_exit(lock) do { \ - lockdoc_log_lock(V_WRITE, lock, __FILE__, __LINE__, LOCK_NONE); \ - _mutex_exit((lock)); \ -} while(/* CONSTCOND */ 0) - -#define mutex_spin_enter(lock) do { \ - lockdoc_log_lock(P_WRITE, lock, __FILE__, __LINE__, LOCK_NONE); \ - _mutex_spin_enter((lock)); \ -} while(/* CONSTCOND */ 0) - -#define mutex_spin_exit(lock) do { \ - lockdoc_log_lock(V_WRITE, lock, __FILE__, __LINE__, LOCK_NONE); \ - _mutex_spin_exit((lock)); \ -} while(/* CONSTCOND */ 0) +#define mutex_enter(lock) __mutex_enter(lock, __FILE__, __LINE__) +#define mutex_exit(lock) __mutex_exit(lock, __FILE__, __LINE__) +#define mutex_spin_enter(lock) __mutex_spin_enter(lock, __FILE__, __LINE__) +#define mutex_spin_exit(lock) __mutex_spin_exit(lock, __FILE__, __LINE__) +#define rw_enter(lock, type) __rw_enter(lock, type, __FILE__, __LINE__) +#define rw_tryenter(lock, type) __rw_tryenter(lock, type, __FILE__, __LINE__) +#define rw_exit(lock) __rw_exit(lock, __FILE__, __LINE__) /* Basic port I/O */ static inline void outb_(u_int8_t v, u_int16_t port) @@ -61,7 +61,7 @@ static inline void outb_(u_int8_t v, u_int16_t port) static inline void lockdoc_log_memory(int alloc, const char *datatype, const void *ptr, size_t size) { u_long flags; - + flags = lockdoc_x86_disable_intr(); memset(&la_buffer,0,sizeof(la_buffer)); diff --git a/sys/sys/rwlock.h b/sys/sys/rwlock.h index aa2eff7fb29..a6928a3dd96 100644 --- a/sys/sys/rwlock.h +++ b/sys/sys/rwlock.h @@ -90,13 +90,24 @@ struct krwlock { volatile uintptr_t rw_owner; }; +/* + * This import is needed so that the mutex_ are being defined + * without having to add the lockdoc.h import to every single+ + * file where mutex_functions are being called. + */ +#ifdef LOCKDOC +#include <sys/lockdoc.h> +#endif + #ifdef _KERNEL void _rw_init(krwlock_t *, uintptr_t); void rw_init(krwlock_t *); void rw_destroy(krwlock_t *); +#ifndef LOCKDOC int rw_tryenter(krwlock_t *, const krw_t); +#endif int rw_tryupgrade(krwlock_t *); void rw_downgrade(krwlock_t *); @@ -105,8 +116,10 @@ int rw_write_held(krwlock_t *); int rw_lock_held(krwlock_t *); krw_t rw_lock_op(krwlock_t *); +#ifndef LOCKDOC void rw_enter(krwlock_t *, const krw_t); void rw_exit(krwlock_t *); +#endif void rw_obj_init(void); krwlock_t *rw_obj_alloc(void); |
