Commit 893a7d32 authored by Jan Glauber's avatar Jan Glauber Committed by Linus Torvalds

lockref: Limit number of cmpxchg loop retries

The lockref cmpxchg loop is unbound as long as the spinlock is not
taken. Depending on the hardware implementation of compare-and-swap
a high number of loop retries might happen.

Add an upper bound to the loop to force the fallback to spinlocks
after some time. A retry value of 100 should not impact any hardware
that does not have this issue.

With the retry limit the performance of an open-close testcase
improved between 60-70% on ThunderX2.
Suggested-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarJan Glauber <jglauber@marvell.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d9344522
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* failure case. * failure case.
*/ */
#define CMPXCHG_LOOP(CODE, SUCCESS) do { \ #define CMPXCHG_LOOP(CODE, SUCCESS) do { \
int retry = 100; \
struct lockref old; \ struct lockref old; \
BUILD_BUG_ON(sizeof(old) != 8); \ BUILD_BUG_ON(sizeof(old) != 8); \
old.lock_count = READ_ONCE(lockref->lock_count); \ old.lock_count = READ_ONCE(lockref->lock_count); \
...@@ -21,6 +22,8 @@ ...@@ -21,6 +22,8 @@
if (likely(old.lock_count == prev.lock_count)) { \ if (likely(old.lock_count == prev.lock_count)) { \
SUCCESS; \ SUCCESS; \
} \ } \
if (!--retry) \
break; \
cpu_relax(); \ cpu_relax(); \
} \ } \
} while (0) } while (0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment