[PATCH 21/29] locking, tsx: Protect assert_spin_locked() with _xtest()

Andi Kleen
2013-03-23T01:27:08Z

lock_is_locked aborts with lock elision. Some code does a lot of lock asserts,
which causes a lot of aborts. Add a _xtest() here so that the checking is only
done when the lock is not elided. This always happens occasionally due to
fallbacks, so there is still enough assert coverage.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
include/linux/spinlock_api_smp.h | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/include/linux/spinlock_api_smp.h b/include/linux/spinlock_api_smp.h
index cf9bf3b..cd9269b 100644
--- a/include/linux/spinlock_api_smp.h
+++ b/include/linux/spinlock_api_smp.h
@@ -5,6 +5,8 @@
# error "please don't include this file directly"
#endif

+#include <linux/rtm.h>
+
/*
* include/linux/spinlock_api_smp.h
*
@@ -17,7 +19,10 @@

int in_lock_functions(unsigned long addr);

-#define assert_raw_spin_locked(x) BUG_ON(!raw_spin_is_locked(x))
+#define assert_raw_spin_locked(x) do { \
+ if (!_xtest()) \
+ BUG_ON(!raw_spin_is_locked(x)); \
+ } while (0)

void __lockfunc _raw_spin_lock(raw_spinlock_t *lock) __acquires(lock);
void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass)
--
1.7.7.6