|
|
190885 |
From bae6e60ec32acdbc5e61d94d6e222e456b796054 Mon Sep 17 00:00:00 2001
|
|
|
190885 |
From: Jangwoong Kim <6812skiii@gmail.com>
|
|
|
190885 |
Date: Tue, 14 Dec 2021 21:30:51 +0900
|
|
|
190885 |
Subject: [PATCH] nptl: Effectively skip CAS in spinlock loop
|
|
|
190885 |
|
|
|
190885 |
The commit:
|
|
|
190885 |
"Add LLL_MUTEX_READ_LOCK [BZ #28537]"
|
|
|
190885 |
SHA1: d672a98a1af106bd68deb15576710cd61363f7a6
|
|
|
190885 |
|
|
|
190885 |
introduced LLL_MUTEX_READ_LOCK, to skip CAS in spinlock loop
|
|
|
190885 |
if atomic load fails. But, "continue" inside of do-while loop
|
|
|
190885 |
does not skip the evaluation of escape expression, thus CAS
|
|
|
190885 |
is not skipped.
|
|
|
190885 |
|
|
|
190885 |
Replace do-while with while and skip LLL_MUTEX_TRYLOCK if
|
|
|
190885 |
LLL_MUTEX_READ_LOCK fails.
|
|
|
190885 |
|
|
|
190885 |
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
|
|
|
190885 |
(cherry picked from commit 6b8dbbd03ac88f169b65b5c7d7278576a11d2e44)
|
|
|
190885 |
---
|
|
|
190885 |
nptl/pthread_mutex_lock.c | 5 ++---
|
|
|
190885 |
1 file changed, 2 insertions(+), 3 deletions(-)
|
|
|
190885 |
|
|
|
190885 |
diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c
|
|
|
190885 |
index a633d95e..d96a9933 100644
|
|
|
190885 |
--- a/nptl/pthread_mutex_lock.c
|
|
|
190885 |
+++ b/nptl/pthread_mutex_lock.c
|
|
|
190885 |
@@ -141,10 +141,9 @@ __pthread_mutex_lock (pthread_mutex_t *mutex)
|
|
|
190885 |
break;
|
|
|
190885 |
}
|
|
|
190885 |
atomic_spin_nop ();
|
|
|
190885 |
- if (LLL_MUTEX_READ_LOCK (mutex) != 0)
|
|
|
190885 |
- continue;
|
|
|
190885 |
}
|
|
|
190885 |
- while (LLL_MUTEX_TRYLOCK (mutex) != 0);
|
|
|
190885 |
+ while (LLL_MUTEX_READ_LOCK (mutex) != 0
|
|
|
190885 |
+ || LLL_MUTEX_TRYLOCK (mutex) != 0);
|
|
|
190885 |
|
|
|
190885 |
mutex->__data.__spins += (cnt - mutex->__data.__spins) / 8;
|
|
|
190885 |
}
|
|
|
190885 |
--
|
|
|
190885 |
GitLab
|
|
|
190885 |
|