diff options
author | behlendo <behlendo@7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c> | 2008-04-21 17:29:47 +0000 |
---|---|---|
committer | behlendo <behlendo@7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c> | 2008-04-21 17:29:47 +0000 |
commit | 937879f11db15a4842306f9da4b4a3e60cf073b7 (patch) | |
tree | 3a72837d2323df2f844951229ecbbdb22925ac6a /include/sys | |
parent | 2fae1b3d0af1caa2aaa77552a0c96f121016381d (diff) |
Update SPL to use new debug infrastructure. This means:
- Replacing all BUG_ON()'s with proper ASSERT()'s
- Using ENTRY,EXIT,GOTO, and RETURN macro to instument call paths
git-svn-id: https://outreach.scidac.gov/svn/spl/trunk@78 7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c
Diffstat (limited to 'include/sys')
-rw-r--r-- | include/sys/callb.h | 2 | ||||
-rw-r--r-- | include/sys/condvar.h | 40 | ||||
-rw-r--r-- | include/sys/debug.h | 72 | ||||
-rw-r--r-- | include/sys/kmem.h | 11 | ||||
-rw-r--r-- | include/sys/mutex.h | 37 | ||||
-rw-r--r-- | include/sys/random.h | 4 | ||||
-rw-r--r-- | include/sys/rwlock.h | 50 | ||||
-rw-r--r-- | include/sys/signal.h | 2 | ||||
-rw-r--r-- | include/sys/sysmacros.h | 4 | ||||
-rw-r--r-- | include/sys/time.h | 2 |
10 files changed, 130 insertions, 94 deletions
diff --git a/include/sys/callb.h b/include/sys/callb.h index 053ddf500..39cdf9622 100644 --- a/include/sys/callb.h +++ b/include/sys/callb.h @@ -11,7 +11,7 @@ extern "C" { #define DEBUG_CALLB #ifndef DEBUG_CALLB -#define CALLB_CPR_ASSERT(cp) BUG_ON(!(MUTEX_HELD((cp)->cc_lockp))); +#define CALLB_CPR_ASSERT(cp) ASSERT(MUTEX_HELD((cp)->cc_lockp)); #else #define CALLB_CPR_ASSERT(cp) #endif diff --git a/include/sys/condvar.h b/include/sys/condvar.h index 3318ec595..fd845d9c1 100644 --- a/include/sys/condvar.h +++ b/include/sys/condvar.h @@ -28,9 +28,9 @@ typedef enum { CV_DEFAULT=0, CV_DRIVER } kcv_type_t; static __inline__ void cv_init(kcondvar_t *cvp, char *name, kcv_type_t type, void *arg) { - BUG_ON(cvp == NULL); - BUG_ON(type != CV_DEFAULT); - BUG_ON(arg != NULL); + ASSERT(cvp); + ASSERT(type == CV_DEFAULT); + ASSERT(arg == NULL); cvp->cv_magic = CV_MAGIC; init_waitqueue_head(&cvp->cv_event); @@ -49,11 +49,11 @@ cv_init(kcondvar_t *cvp, char *name, kcv_type_t type, void *arg) static __inline__ void cv_destroy(kcondvar_t *cvp) { - BUG_ON(cvp == NULL); + ASSERT(cvp); + ASSERT(cvp->cv_magic == CV_MAGIC); spin_lock(&cvp->cv_lock); - BUG_ON(cvp->cv_magic != CV_MAGIC); - BUG_ON(atomic_read(&cvp->cv_waiters) != 0); - BUG_ON(waitqueue_active(&cvp->cv_event)); + ASSERT(atomic_read(&cvp->cv_waiters) == 0); + ASSERT(!waitqueue_active(&cvp->cv_event)); if (cvp->cv_name) kfree(cvp->cv_name); @@ -67,16 +67,17 @@ cv_wait(kcondvar_t *cvp, kmutex_t *mtx) { DEFINE_WAIT(wait); - BUG_ON(cvp == NULL || mtx == NULL); + ASSERT(cvp); + ASSERT(mtx); + ASSERT(cvp->cv_magic == CV_MAGIC); spin_lock(&cvp->cv_lock); - BUG_ON(cvp->cv_magic != CV_MAGIC); - BUG_ON(!mutex_owned(mtx)); + ASSERT(mutex_owned(mtx)); if (cvp->cv_mutex == NULL) cvp->cv_mutex = mtx; /* Ensure the same mutex is used by all callers */ - BUG_ON(cvp->cv_mutex != mtx); + ASSERT(cvp->cv_mutex == mtx); spin_unlock(&cvp->cv_lock); prepare_to_wait_exclusive(&cvp->cv_event, &wait, @@ -103,16 +104,17 @@ cv_timedwait(kcondvar_t *cvp, kmutex_t *mtx, clock_t expire_time) DEFINE_WAIT(wait); clock_t time_left; - BUG_ON(cvp == NULL || mtx == NULL); + ASSERT(cvp); + ASSERT(mtx); + ASSERT(cvp->cv_magic == CV_MAGIC); spin_lock(&cvp->cv_lock); - BUG_ON(cvp->cv_magic != CV_MAGIC); - BUG_ON(!mutex_owned(mtx)); + ASSERT(mutex_owned(mtx)); if (cvp->cv_mutex == NULL) cvp->cv_mutex = mtx; /* Ensure the same mutex is used by all callers */ - BUG_ON(cvp->cv_mutex != mtx); + ASSERT(cvp->cv_mutex == mtx); spin_unlock(&cvp->cv_lock); /* XXX - Does not handle jiffie wrap properly */ @@ -140,8 +142,8 @@ cv_timedwait(kcondvar_t *cvp, kmutex_t *mtx, clock_t expire_time) static __inline__ void cv_signal(kcondvar_t *cvp) { - BUG_ON(cvp == NULL); - BUG_ON(cvp->cv_magic != CV_MAGIC); + ASSERT(cvp); + ASSERT(cvp->cv_magic == CV_MAGIC); /* All waiters are added with WQ_FLAG_EXCLUSIVE so only one * waiter will be set runable with each call to wake_up(). @@ -154,8 +156,8 @@ cv_signal(kcondvar_t *cvp) static __inline__ void cv_broadcast(kcondvar_t *cvp) { - BUG_ON(cvp == NULL); - BUG_ON(cvp->cv_magic != CV_MAGIC); + ASSERT(cvp); + ASSERT(cvp->cv_magic == CV_MAGIC); /* Wake_up_all() will wake up all waiters even those which * have the WQ_FLAG_EXCLUSIVE flag set. */ diff --git a/include/sys/debug.h b/include/sys/debug.h index 13c030c9e..12585e00f 100644 --- a/include/sys/debug.h +++ b/include/sys/debug.h @@ -22,6 +22,7 @@ extern unsigned long spl_debug_subsys; #define S_DEBUG 0x00001000 #define S_GENERIC 0x00002000 #define S_PROC 0x00004000 +#define S_MODULE 0x00008000 #define D_TRACE 0x00000001 #define D_INFO 0x00000002 @@ -148,9 +149,47 @@ struct page_collection { #define SBUG() spl_debug_bug(__FILE__, __FUNCTION__, __LINE__); +#ifdef __ia64__ +#define CDEBUG_STACK() (THREAD_SIZE - \ + ((unsigned long)__builtin_dwarf_cfa() & \ + (THREAD_SIZE - 1))) +#else +#define CDEBUG_STACK() (THREAD_SIZE - \ + ((unsigned long)__builtin_frame_address(0) & \ + (THREAD_SIZE - 1))) +# endif /* __ia64__ */ + +#define __CHECK_STACK(file, func, line) \ +do { \ + unsigned long _stack = CDEBUG_STACK(); \ + unsigned long _soft_limit = (9 * THREAD_SIZE) / 10; \ + \ + if (unlikely(_stack > _soft_limit && _stack > spl_debug_stack)){\ + spl_debug_stack = _stack; \ + if (_stack <= THREAD_SIZE) { \ + spl_debug_msg(NULL, D_TRACE, D_WARNING, \ + file, func, line, "Warning " \ + "exceeded 90%% of maximum safe " \ + "stack size (%lu/%lu)\n", \ + _stack, THREAD_SIZE); \ + } else { \ + spl_debug_msg(NULL, D_TRACE, D_WARNING, \ + file, func, line, "Error " \ + "exceeded maximum safe stack " \ + "size (%lu/%lu)\n", \ + _stack, THREAD_SIZE); \ + SBUG(); \ + } \ + } \ +} while (0) + +#define CHECK_STACK()__CHECK_STACK(__FILE__, __func__, __LINE__) + /* ASSERTION that is safe to use within the debug system */ #define __ASSERT(cond) \ do { \ + CHECK_STACK(); \ + \ if (unlikely(!(cond))) { \ printk(KERN_ERR "ASSERTION("#cond") failed"); \ SBUG(); \ @@ -168,6 +207,8 @@ do { \ /* ASSERTION that will debug log used outside the debug sysytem */ #define ASSERT(cond) \ do { \ + CHECK_STACK(); \ + \ if (unlikely(!(cond))) { \ spl_debug_msg(NULL, DEBUG_SUBSYSTEM, D_EMERG, \ __FILE__, __FUNCTION__, __LINE__, \ @@ -178,6 +219,8 @@ do { \ #define ASSERTF(cond, fmt, a...) \ do { \ + CHECK_STACK(); \ + \ if (unlikely(!(cond))) { \ spl_debug_msg(NULL, DEBUG_SUBSYSTEM, D_EMERG, \ __FILE__, __FUNCTION__, __LINE__, \ @@ -191,6 +234,9 @@ do { \ do { \ const TYPE __left = (TYPE)(LEFT); \ const TYPE __right = (TYPE)(RIGHT); \ + \ + CHECK_STACK(); \ + \ if (!(__left OP __right)) { \ spl_debug_msg(NULL, DEBUG_SUBSYSTEM, D_EMERG, \ __FILE__, __FUNCTION__, __LINE__, \ @@ -214,32 +260,6 @@ do { \ spl_debug_vmsg(cdls, subsys, mask, file, fn, \ line, NULL, NULL, format, ##a) -#ifdef __ia64__ -#define CDEBUG_STACK() (THREAD_SIZE - \ - ((unsigned long)__builtin_dwarf_cfa() & \ - (THREAD_SIZE - 1))) -#else -#define CDEBUG_STACK() (THREAD_SIZE - \ - ((unsigned long)__builtin_frame_address(0) & \ - (THREAD_SIZE - 1))) -# endif /* __ia64__ */ - -#define __CHECK_STACK(file, func, line) \ -do { \ - unsigned long _stack = CDEBUG_STACK(); \ - \ - if (_stack > (3*THREAD_SIZE/4) && _stack > spl_debug_stack) { \ - spl_debug_stack = _stack; \ - spl_debug_msg(NULL, D_TRACE, D_WARNING, \ - file, func, line, \ - "Exceeded maximum safe stack " \ - "%lu/%lu\n", _stack, THREAD_SIZE); \ - __ASSERT(0); \ - } \ -} while (0) - -#define CHECK_STACK()__CHECK_STACK(__FILE__, __func__, __LINE__) - #define __CDEBUG(cdls, subsys, mask, format, a...) \ do { \ CHECK_STACK(); \ diff --git a/include/sys/kmem.h b/include/sys/kmem.h index a33643f15..7af10f9a4 100644 --- a/include/sys/kmem.h +++ b/include/sys/kmem.h @@ -13,6 +13,7 @@ extern "C" { #include <linux/vmalloc.h> #include <linux/mm.h> #include <linux/spinlock.h> +#include <sys/debug.h> /* * Memory allocation interfaces */ @@ -60,7 +61,7 @@ extern int kmem_warning_flag; #define kmem_free(ptr, size) \ ({ \ - BUG_ON(!(ptr) || (size) < 0); \ + ASSERT((ptr) || (size > 0)); \ atomic64_sub((size), &kmem_alloc_used); \ memset(ptr, 0x5a, (size)); /* Poison */ \ kfree(ptr); \ @@ -69,7 +70,7 @@ extern int kmem_warning_flag; #define __vmem_alloc(size, flags) \ ({ void *_ptr_; \ \ - BUG_ON(!(flags & KM_SLEEP)); \ + ASSERT(flags & KM_SLEEP); \ \ _ptr_ = (void *)__vmalloc((size), ((flags) | \ __GFP_HIGHMEM), PAGE_KERNEL); \ @@ -93,7 +94,7 @@ extern int kmem_warning_flag; #define vmem_free(ptr, size) \ ({ \ - BUG_ON(!(ptr) || (size) < 0); \ + ASSERT((ptr) || (size > 0)); \ atomic64_sub((size), &vmem_alloc_used); \ memset(ptr, 0x5a, (size)); /* Poison */ \ vfree(ptr); \ @@ -105,7 +106,7 @@ extern int kmem_warning_flag; #define kmem_zalloc(size, flags) kzalloc((size), (flags)) #define kmem_free(ptr, size) \ ({ \ - BUG_ON(!(ptr) || (size) < 0); \ + ASSERT((ptr) || (size > 0)); \ kfree(ptr); \ }) @@ -116,7 +117,7 @@ extern int kmem_warning_flag; PAGE_KERNEL) #define vmem_free(ptr, size) \ ({ \ - BUG_ON(!(ptr) || (size) < 0); \ + ASSERT((ptr) || (size > 0)); \ vfree(ptr); \ }) diff --git a/include/sys/mutex.h b/include/sys/mutex.h index ae8b81a7f..1f99c4d0d 100644 --- a/include/sys/mutex.h +++ b/include/sys/mutex.h @@ -36,9 +36,9 @@ typedef struct { static __inline__ void mutex_init(kmutex_t *mp, char *name, int type, void *ibc) { - BUG_ON(mp == NULL); - BUG_ON(ibc != NULL); /* XXX - Spin mutexes not needed? */ - BUG_ON(type != MUTEX_DEFAULT); /* XXX - Only default type supported? */ + ASSERT(mp); + ASSERT(ibc == NULL); /* XXX - Spin mutexes not needed */ + ASSERT(type == MUTEX_DEFAULT); /* XXX - Only default type supported */ mp->km_magic = KM_MAGIC; spin_lock_init(&mp->km_lock); @@ -57,9 +57,9 @@ mutex_init(kmutex_t *mp, char *name, int type, void *ibc) static __inline__ void mutex_destroy(kmutex_t *mp) { - BUG_ON(mp == NULL); + ASSERT(mp); + ASSERT(mp->km_magic == KM_MAGIC); spin_lock(&mp->km_lock); - BUG_ON(mp->km_magic != KM_MAGIC); if (mp->km_name) kfree(mp->km_name); @@ -71,9 +71,9 @@ mutex_destroy(kmutex_t *mp) static __inline__ void mutex_enter(kmutex_t *mp) { - BUG_ON(mp == NULL); + ASSERT(mp); + ASSERT(mp->km_magic == KM_MAGIC); spin_lock(&mp->km_lock); - BUG_ON(mp->km_magic != KM_MAGIC); if (unlikely(in_atomic() && !current->exit_state)) { printk("May schedule while atomic: %s/0x%08x/%d\n", @@ -87,7 +87,7 @@ mutex_enter(kmutex_t *mp) down(&mp->km_sem); spin_lock(&mp->km_lock); - BUG_ON(mp->km_owner != NULL); + ASSERT(mp->km_owner == NULL); mp->km_owner = current; spin_unlock(&mp->km_lock); } @@ -98,9 +98,9 @@ mutex_tryenter(kmutex_t *mp) { int rc; - BUG_ON(mp == NULL); + ASSERT(mp); + ASSERT(mp->km_magic == KM_MAGIC); spin_lock(&mp->km_lock); - BUG_ON(mp->km_magic != KM_MAGIC); if (unlikely(in_atomic() && !current->exit_state)) { printk("May schedule while atomic: %s/0x%08x/%d\n", @@ -113,7 +113,7 @@ mutex_tryenter(kmutex_t *mp) rc = down_trylock(&mp->km_sem); /* returns 0 if acquired */ if (rc == 0) { spin_lock(&mp->km_lock); - BUG_ON(mp->km_owner != NULL); + ASSERT(mp->km_owner == NULL); mp->km_owner = current; spin_unlock(&mp->km_lock); return 1; @@ -124,10 +124,11 @@ mutex_tryenter(kmutex_t *mp) static __inline__ void mutex_exit(kmutex_t *mp) { - BUG_ON(mp == NULL); + ASSERT(mp); + ASSERT(mp->km_magic == KM_MAGIC); spin_lock(&mp->km_lock); - BUG_ON(mp->km_magic != KM_MAGIC); - BUG_ON(mp->km_owner != current); + + ASSERT(mp->km_owner == current); mp->km_owner = NULL; spin_unlock(&mp->km_lock); up(&mp->km_sem); @@ -139,9 +140,9 @@ mutex_owned(kmutex_t *mp) { int rc; - BUG_ON(mp == NULL); + ASSERT(mp); + ASSERT(mp->km_magic == KM_MAGIC); spin_lock(&mp->km_lock); - BUG_ON(mp->km_magic != KM_MAGIC); rc = (mp->km_owner == current); spin_unlock(&mp->km_lock); @@ -154,9 +155,9 @@ mutex_owner(kmutex_t *mp) { kthread_t *thr; - BUG_ON(mp == NULL); + ASSERT(mp); + ASSERT(mp->km_magic == KM_MAGIC); spin_lock(&mp->km_lock); - BUG_ON(mp->km_magic != KM_MAGIC); thr = mp->km_owner; spin_unlock(&mp->km_lock); diff --git a/include/sys/random.h b/include/sys/random.h index b7f83ce1a..400aaa91f 100644 --- a/include/sys/random.h +++ b/include/sys/random.h @@ -17,7 +17,7 @@ extern "C" { static __inline__ int random_get_bytes(uint8_t *ptr, size_t len) { - BUG_ON(len < 0); + ASSERT(len >= 0); get_random_bytes((void *)ptr,(int)len); return 0; } @@ -26,7 +26,7 @@ random_get_bytes(uint8_t *ptr, size_t len) static __inline__ int random_get_pseudo_bytes(uint8_t *ptr, size_t len) { - BUG_ON(len < 0); + ASSERT(len >= 0); get_random_bytes((void *)ptr,(int)len); return 0; } diff --git a/include/sys/rwlock.h b/include/sys/rwlock.h index 83106846c..8fd34e9c6 100644 --- a/include/sys/rwlock.h +++ b/include/sys/rwlock.h @@ -102,8 +102,9 @@ extern int __rw_lock_held(krwlock_t *rwlp); static __inline__ void rw_init(krwlock_t *rwlp, char *name, krw_type_t type, void *arg) { - BUG_ON(type != RW_DEFAULT); /* XXX no irq handler use */ - BUG_ON(arg != NULL); /* XXX no irq handler use */ + ASSERT(type == RW_DEFAULT); /* XXX no irq handler use */ + ASSERT(arg == NULL); /* XXX no irq handler use */ + rwlp->rw_magic = RW_MAGIC; rwlp->rw_owner = NULL; /* no one holds the write lock yet */ init_rwsem(&rwlp->rw_sem); @@ -119,11 +120,11 @@ rw_init(krwlock_t *rwlp, char *name, krw_type_t type, void *arg) static __inline__ void rw_destroy(krwlock_t *rwlp) { - BUG_ON(rwlp == NULL); - BUG_ON(rwlp->rw_magic != RW_MAGIC); - BUG_ON(rwlp->rw_owner != NULL); + ASSERT(rwlp); + ASSERT(rwlp->rw_magic == RW_MAGIC); + ASSERT(rwlp->rw_owner == NULL); spin_lock(&rwlp->rw_sem.wait_lock); - BUG_ON(!list_empty(&rwlp->rw_sem.wait_list)); + ASSERT(list_empty(&rwlp->rw_sem.wait_list)); spin_unlock(&rwlp->rw_sem.wait_lock); if (rwlp->rw_name) @@ -139,7 +140,9 @@ rw_tryenter(krwlock_t *rwlp, krw_t rw) { int result; - BUG_ON(rwlp->rw_magic != RW_MAGIC); + ASSERT(rwlp); + ASSERT(rwlp->rw_magic == RW_MAGIC); + switch (rw) { /* these functions return 1 if success, 0 if contention */ case RW_READER: @@ -159,12 +162,12 @@ rw_tryenter(krwlock_t *rwlp, krw_t rw) if (result) { /* there better not be anyone else * holding the write lock here */ - BUG_ON(rwlp->rw_owner != NULL); + ASSERT(rwlp->rw_owner == NULL); rwlp->rw_owner = current; } break; default: - BUG_ON(1); + SBUG(); } return result; @@ -173,7 +176,9 @@ rw_tryenter(krwlock_t *rwlp, krw_t rw) static __inline__ void rw_enter(krwlock_t *rwlp, krw_t rw) { - BUG_ON(rwlp->rw_magic != RW_MAGIC); + ASSERT(rwlp); + ASSERT(rwlp->rw_magic == RW_MAGIC); + switch (rw) { case RW_READER: /* Here the Solaris code would block @@ -192,18 +197,19 @@ rw_enter(krwlock_t *rwlp, krw_t rw) /* there better not be anyone else * holding the write lock here */ - BUG_ON(rwlp->rw_owner != NULL); + ASSERT(rwlp->rw_owner == NULL); rwlp->rw_owner = current; break; default: - BUG_ON(1); + SBUG(); } } static __inline__ void rw_exit(krwlock_t *rwlp) { - BUG_ON(rwlp->rw_magic != RW_MAGIC); + ASSERT(rwlp); + ASSERT(rwlp->rw_magic == RW_MAGIC); /* rw_owner is held by current * thread iff it is a writer */ @@ -218,8 +224,10 @@ rw_exit(krwlock_t *rwlp) static __inline__ void rw_downgrade(krwlock_t *rwlp) { - BUG_ON(rwlp->rw_magic != RW_MAGIC); - BUG_ON(rwlp->rw_owner != current); + ASSERT(rwlp); + ASSERT(rwlp->rw_magic == RW_MAGIC); + ASSERT(rwlp->rw_owner == current); + rwlp->rw_owner = NULL; downgrade_write(&rwlp->rw_sem); } @@ -232,7 +240,9 @@ static __inline__ int rw_tryupgrade(krwlock_t *rwlp) { int result = 0; - BUG_ON(rwlp->rw_magic != RW_MAGIC); + + ASSERT(rwlp); + ASSERT(rwlp->rw_magic == RW_MAGIC); spin_lock(&rwlp->rw_sem.wait_lock); @@ -280,8 +290,8 @@ rw_tryupgrade(krwlock_t *rwlp) /* Check if upgrade failed. Should not ever happen * if we got to this point */ - BUG_ON(!result); - BUG_ON(rwlp->rw_owner != NULL); + ASSERT(result); + ASSERT(rwlp->rw_owner == NULL); rwlp->rw_owner = current; spin_unlock(&rwlp->rw_sem.wait_lock); return 1; @@ -290,7 +300,9 @@ rw_tryupgrade(krwlock_t *rwlp) static __inline__ kthread_t * rw_owner(krwlock_t *rwlp) { - BUG_ON(rwlp->rw_magic != RW_MAGIC); + ASSERT(rwlp); + ASSERT(rwlp->rw_magic == RW_MAGIC); + return rwlp->rw_owner; } diff --git a/include/sys/signal.h b/include/sys/signal.h index 120329686..e40b483e2 100644 --- a/include/sys/signal.h +++ b/include/sys/signal.h @@ -16,7 +16,7 @@ static __inline__ int issig(int why) { - BUG_ON(!(why == FORREAL || why == JUSTLOOKING)); + ASSERT(why == FORREAL || why == JUSTLOOKING); return signal_pending(current); } diff --git a/include/sys/sysmacros.h b/include/sys/sysmacros.h index 62a51aa38..0cafd7122 100644 --- a/include/sys/sysmacros.h +++ b/include/sys/sysmacros.h @@ -98,8 +98,8 @@ extern "C" { #define DTRACE_PROBE4(a, b, c, d, e, f, g, h, i) ((void)0) /* Missing globals */ -extern unsigned long spl_hostid; -extern char spl_hw_serial[11]; +extern long spl_hostid; +extern char hw_serial[11]; extern int p0; /* Missing misc functions */ diff --git a/include/sys/time.h b/include/sys/time.h index 2f03203e6..44a0ec3c9 100644 --- a/include/sys/time.h +++ b/include/sys/time.h @@ -41,7 +41,7 @@ typedef enum clock_type { #define hz \ ({ \ - BUG_ON(HZ < 100 || HZ > MICROSEC); \ + ASSERT(HZ >= 100 && HZ <= MICROSEC); \ HZ; \ }) |