2019-05-14 Adhemerval Zanella <adhemerval.zanella@linaro.org>
+ * nptl/lowlevellock.c (__lll_lock_wait, __lll_lock_wait_private):
+ Optimize futex call and add systemtap probe.
+
* nptl/pthreadP.h (CANCEL_ASYNC, CANCEL_RESET, LIBC_CANCEL_ASYNC,
LIBC_CANCEL_RESET, __libc_enable_asynccancel,
__libc_disable_asynccancel, __librt_enable_asynccancel,
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-#include <errno.h>
#include <sysdep.h>
#include <lowlevellock.h>
-#include <sys/time.h>
#include <atomic.h>
+#include <stap-probe.h>
void
__lll_lock_wait_private (int *futex)
{
- if (*futex == 2)
- lll_futex_wait (futex, 2, LLL_PRIVATE); /* Wait if *futex == 2. */
-
- while (atomic_exchange_acq (futex, 2) != 0)
- lll_futex_wait (futex, 2, LLL_PRIVATE); /* Wait if *futex == 2. */
+ if (atomic_load_relaxed (futex) == 2)
+ goto futex;
+
+ while (atomic_exchange_acquire (futex, 2) != 0)
+ {
+ futex:
+ LIBC_PROBE (lll_lock_wait_private, 1, futex);
+ lll_futex_wait (futex, 2, LLL_PRIVATE); /* Wait if *futex == 2. */
+ }
}
void
__lll_lock_wait (int *futex, int private)
{
- if (*futex == 2)
- lll_futex_wait (futex, 2, private); /* Wait if *futex == 2. */
-
- while (atomic_exchange_acq (futex, 2) != 0)
- lll_futex_wait (futex, 2, private); /* Wait if *futex == 2. */
+ if (atomic_load_relaxed (futex) == 2)
+ goto futex;
+
+ while (atomic_exchange_acquire (futex, 2) != 0)
+ {
+ futex:
+ LIBC_PROBE (lll_lock_wait, 1, futex);
+ lll_futex_wait (futex, 2, private); /* Wait if *futex == 2. */
+ }
}
#endif