Re: spinlock assertion macros

From: Arnd Bergmann (arnd@bergmann-dalldorf.de)
Date: Thu Jul 11 2002 - 05:51:38 EST


On Thursday 11 July 2002 01:36, Jesse Barnes wrote:

+#define spin_assert_unlocked(lock) if (spin_is_locked(lock)) { printk("lock assertion failure: lock at %s:%d should be unlocked!\n", __FILE__, __LINE__); }

I suppose what would at least be as helpful is to check if _any_
lock is held, e.g. when calling a potentially sleeping function.

Something along these lines:

#ifdef CONFIG_DEBUG_SPINLOCK
extern char *volatile last_spinlock[NR_CPUS];

#define spin_assert_unlocked_all() ({ \
        char *lock = last_spinlock[smp_processor_id()]; \
        if (lock) { \
                printk (KERN_CRIT "%s:%d: lock %s is held\n", \
                        __func__, __LINE__, lock); \
                BUG(); \
        } \
})

#define spin_lock(lock) ({ \
        last_spinlock[smp_processor_id()] = __stringify(lock) "@" \
                __FILE__ ":" __stringify(__LINE__); \
        __really_spin_lock(lock); \
})
#endif

probably, a per-cpu lock depth should be used to also catch
spin_lock(foo_lock);
spin_lock(bar_lock);
spin_unlock(bar_lock);
spin_assert_unlock_all();

        Arnd <><
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Jul 15 2002 - 22:00:19 EST