From 36b7cd41b7c1b1b36103fd49ab3770a9d6464c5e Mon Sep 17 00:00:00 2001 From: Merlin Scholz Date: Tue, 25 Oct 2022 20:58:09 +0200 Subject: Hook into lockdebug.h --- sys/lockdoc/log.c | 36 ++++++++++++++++++++++++++++++++++++ sys/sys/lockdebug.h | 44 +++++++++++++++++++++++++++++++++++++++++--- sys/sys/lockdoc.h | 13 +++++++++++++ 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/sys/lockdoc/log.c b/sys/lockdoc/log.c index 52d5115da41..5bf1a9dbab4 100644 --- a/sys/lockdoc/log.c +++ b/sys/lockdoc/log.c @@ -1,10 +1,44 @@ #include +#include #include #ifdef LOCKDOC struct log_action la_buffer; +bool lockdoc_alloc(const char *func, size_t line, volatile void *lock, lockops_t *lo, uintptr_t initaddr){ + // TODO Actually log things + return lockdebug_alloc(func, line, lock, lo, initaddr); +} +void lockdoc_free(bool dodebug, const char *func, size_t line, volatile void *lock){ + // TODO Actually log things + if (dodebug) lockdebug_free(func, line, lock); +} +void lockdoc_wantlock(bool dodebug, const char *func, size_t line, const volatile void *lock, uintptr_t where, int shared){ + // TODO Actually log things + if (dodebug) lockdebug_wantlock(func, line, lock, where, shared); +} +void lockdoc_locked(bool dodebug, const char *func, size_t line, volatile void *lock, void *cvlock, uintptr_t where, int shared){ + // TODO Actually log things + if (dodebug) lockdebug_locked(func, line, lock, cvlock, where, shared); +} +void lockdoc_unlocked(bool dodebug, const char *func, size_t line, volatile void *lock, uintptr_t where, int shared){ + // TODO Actually log things + if (dodebug) lockdebug_unlocked(func, line, lock, where, shared); +} +void lockdoc_barrier(const char *func, size_t line, volatile void *spinlock, int slplocks){ + // TODO Actually log things + lockdebug_barrier(func, line, spinlock, slplocks); +} +void lockdoc_mem_check(const char *func, size_t line, void *base, size_t sz){ + // TODO Actually log things + lockdebug_mem_check(func, line, base, sz); +} +void lockdoc_wakeup(bool dodebug, const char *func, size_t line, volatile void *lock, uintptr_t where){ + // TODO Actually log things + if (dodebug) lockdebug_wakeup(func, line, lock, where); +} + void __x86_disable_intr(const char *file, int line, const char *func){ // TODO Actually log things lockdoc_x86_disable_intr(); @@ -15,4 +49,6 @@ void __x86_enable_intr(const char *file, int line, const char *func){ lockdoc_x86_enable_intr(); } + + #endif /* LOCKDOC */ \ No newline at end of file diff --git a/sys/sys/lockdebug.h b/sys/sys/lockdebug.h index 514bfd06911..3df332aedef 100644 --- a/sys/sys/lockdebug.h +++ b/sys/sys/lockdebug.h @@ -52,6 +52,8 @@ typedef struct lockops { void (*lo_dump)(const volatile void *, lockop_printer_t); } lockops_t; +#include // Has to be included *after* lockops_t definition + #define LOCKDEBUG_ABORT(f, ln, l, o, m) \ lockdebug_abort(f, ln, l, o, m) @@ -65,7 +67,39 @@ void lockdebug_show_all_locks(void (*)(const char *, ...) __printflike(1, 2), const char *); void lockdebug_show_lockstats(void (*)(const char *, ...) __printflike(1, 2)); -#ifdef LOCKDEBUG +#if defined(LOCKDEBUG) && defined(LOCKDOC) + +bool lockdebug_alloc(const char *, size_t, volatile void *, lockops_t *, + uintptr_t); +void lockdebug_free(const char *, size_t, volatile void *); +void lockdebug_wantlock(const char *, size_t, const volatile void *, + uintptr_t, int); +void lockdebug_locked(const char *, size_t, volatile void *, void *, + uintptr_t, int); +void lockdebug_unlocked(const char *, size_t, volatile void *, + uintptr_t, int); +void lockdebug_barrier(const char *, size_t, volatile void *, int); +void lockdebug_mem_check(const char *, size_t, void *, size_t); +void lockdebug_wakeup(const char *, size_t, volatile void *, uintptr_t); + +#define LOCKDEBUG_ALLOC(lock, ops, addr) \ + lockdoc_alloc(__func__, __LINE__, lock, ops, addr) +#define LOCKDEBUG_FREE(dodebug, lock) \ + lockdoc_free(dodebug, __func__, __LINE__, lock) +#define LOCKDEBUG_WANTLOCK(dodebug, lock, where, s) \ + lockdoc_wantlock(dodebug, __func__, __LINE__, lock, where, s) +#define LOCKDEBUG_LOCKED(dodebug, lock, al, where, s) \ + lockdoc_locked(dodebug, __func__, __LINE__, lock, al, where, s) +#define LOCKDEBUG_UNLOCKED(dodebug, lock, where, s) \ + lockdoc_unlocked(dodebug, __func__, __LINE__, lock, where, s) +#define LOCKDEBUG_BARRIER(lock, slp) \ + lockdoc_barrier(__func__, __LINE__, lock, slp) +#define LOCKDEBUG_MEM_CHECK(base, sz) \ + lockdoc_mem_check(__func__, __LINE__, base, sz) +#define LOCKDEBUG_WAKEUP(dodebug, lock, where) \ + lockdoc_wakeup(dodebug, __func__, __LINE__, lock, where) + +#elif defined(LOCKDEBUG) && !defined(LOCKDOC) bool lockdebug_alloc(const char *, size_t, volatile void *, lockops_t *, uintptr_t); @@ -97,7 +131,11 @@ void lockdebug_wakeup(const char *, size_t, volatile void *, uintptr_t); #define LOCKDEBUG_WAKEUP(dodebug, lock, where) \ if (dodebug) lockdebug_wakeup(__func__, __LINE__, lock, where) -#else /* LOCKDEBUG */ +#elif !defined(LOCKDEBUG) && defined(LOCKDOC) + +#error "Enabling the LOCKDOC compile flag requires the LOCKDEBUG option to be set too" + +#else /* !LOCKDEBUG && !LOCKDOC */ #define LOCKDEBUG_ALLOC(lock, ops, addr) false #define LOCKDEBUG_FREE(dodebug, lock) /* nothing */ @@ -108,6 +146,6 @@ void lockdebug_wakeup(const char *, size_t, volatile void *, uintptr_t); #define LOCKDEBUG_MEM_CHECK(base, sz) /* nothing */ #define LOCKDEBUG_WAKEUP(dodebug, lock, where) /* nothing */ -#endif /* LOCKDEBUG */ +#endif /* LOCKDEBUG && LOCKDOC */ #endif /* __SYS_LOCKDEBUG_H__ */ diff --git a/sys/sys/lockdoc.h b/sys/sys/lockdoc.h index 7c265707ed4..d350f721f93 100644 --- a/sys/sys/lockdoc.h +++ b/sys/sys/lockdoc.h @@ -3,6 +3,7 @@ #include #include +#include #include #define DELIMITER "#" @@ -15,6 +16,18 @@ extern struct log_action la_buffer; + +// For DEFINEs in lockdebug.h +// Implemented in lockdoc/log.c +bool lockdoc_alloc(const char *, size_t, volatile void *, lockops_t *, uintptr_t); +void lockdoc_free(bool, const char *, size_t, volatile void *); +void lockdoc_wantlock(bool, const char *, size_t, const volatile void *, uintptr_t, int); +void lockdoc_locked(bool, const char *, size_t, volatile void *, void *, uintptr_t, int); +void lockdoc_unlocked(bool, const char *, size_t, volatile void *, uintptr_t, int); +void lockdoc_barrier(const char *, size_t, volatile void *, int); +void lockdoc_mem_check(const char *, size_t, void *, size_t); +void lockdoc_wakeup(bool, const char *, size_t, volatile void *, uintptr_t); + /* Basic port I/O */ static inline void outb_(u_int8_t v, u_int16_t port) { -- cgit