Skip to content
Snippets Groups Projects
Commit ac112d02 authored by André Almeida's avatar André Almeida
Browse files

nptl: Use futex2

parent 9826b03b
No related branches found
Tags glibc-2.28
No related merge requests found
......@@ -125,7 +125,7 @@ while (<SOVERSIONS>) {
next if ($build_mathvec == 0 && $name eq "mvec");
if ($name ne "nss_ldap" && $name ne "db1"
&& $name ne "thread_db"
&& $name ne "nss_test1" && $name ne "libgcc_s") {
&& $name ne "nss_test1" && $name ne "nss_test2" && $name ne "nss_nis" && $name ne "nss_nisplus" && $name ne "libgcc_s") {
$link_libs .= " -l$name";
$versions{$name} = $version;
}
......
......@@ -30,6 +30,7 @@ __futex_abstimed_wait_common32 (unsigned int* futex_word,
int private, bool cancel)
{
struct timespec ts32, *pts32 = NULL;
int flags = FUTEX_32;
if (abstime != NULL)
{
if (! in_time_t_range (abstime->tv_sec))
......@@ -39,14 +40,12 @@ __futex_abstimed_wait_common32 (unsigned int* futex_word,
pts32 = &ts32;
}
flags |= private ? 0 : FUTEX_SHARED_FLAG;
if (cancel)
return INTERNAL_SYSCALL_CANCEL (futex, futex_word, op, expected,
pts32, NULL /* Unused. */,
FUTEX_BITSET_MATCH_ANY);
return INTERNAL_SYSCALL_CANCEL (futex_wait, futex_word, expected, flags, abstime);
else
return INTERNAL_SYSCALL_CALL (futex, futex_word, op, expected,
pts32, NULL /* Unused. */,
FUTEX_BITSET_MATCH_ANY);
return INTERNAL_SYSCALL_CALL (futex_wait, futex_word, expected, flags, abstime);
}
#endif /* ! __ASSUME_TIME64_SYSCALLS */
......@@ -58,6 +57,7 @@ __futex_abstimed_wait_common64 (unsigned int* futex_word,
{
unsigned int clockbit;
int err;
int flags = FUTEX_32;
/* Work around the fact that the kernel rejects negative timeout values
despite them being valid. */
......@@ -67,17 +67,17 @@ __futex_abstimed_wait_common64 (unsigned int* futex_word,
if (! lll_futex_supported_clockid (clockid))
return EINVAL;
clockbit = (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0;
int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private);
flags |= (clockid == CLOCK_REALTIME) ? FUTEX_CLOCK_REALTIME : 0;
if (private)
flags |= FUTEX_SHARED_FLAG;
//int op = __lll_private_flag (FUTEX_WAIT_BITSET | clockbit, private);
if (cancel)
err = INTERNAL_SYSCALL_CANCEL (futex_time64, futex_word, op, expected,
abstime, NULL /* Unused. */,
FUTEX_BITSET_MATCH_ANY);
err = INTERNAL_SYSCALL_CANCEL (futex_wait, futex_word,
expected, flags, abstime);
else
err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op, expected,
abstime, NULL /* Ununsed. */,
FUTEX_BITSET_MATCH_ANY);
err = INTERNAL_SYSCALL_CALL (futex_wait, futex_word,
expected, flags, abstime);
#ifndef __ASSUME_TIME64_SYSCALLS
if (err == -ENOSYS)
err = __futex_abstimed_wait_common32 (futex_word, expected, op, abstime,
......
......@@ -23,7 +23,7 @@
#include <sys/time.h>
#include <stdio.h>
#include <stdbool.h>
#include <lowlevellock-futex.h>
#include <lowlevellock-futex2.h>
#include <libc-diag.h>
/* This file defines futex operations used internally in glibc. A futex
......
......@@ -25,8 +25,8 @@
# include <kernel-features.h>
#endif
#define FUTEX_WAIT 0
#define FUTEX_WAKE 1
//#define FUTEX_WAIT 0
//#define FUTEX_WAKE 1
#define FUTEX_REQUEUE 3
#define FUTEX_CMP_REQUEUE 4
#define FUTEX_WAKE_OP 5
......@@ -34,14 +34,16 @@
#define FUTEX_LOCK_PI 6
#define FUTEX_UNLOCK_PI 7
#define FUTEX_TRYLOCK_PI 8
#define FUTEX_WAIT_BITSET 9
#define FUTEX_WAKE_BITSET 10
//#define FUTEX_WAIT_BITSET 9
//#define FUTEX_WAKE_BITSET 10
#define FUTEX_WAIT_REQUEUE_PI 11
#define FUTEX_CMP_REQUEUE_PI 12
#define FUTEX_PRIVATE_FLAG 128
#define FUTEX_CLOCK_REALTIME 256
#define FUTEX_BITSET_MATCH_ANY 0xffffffff
#define FUTEX_32 2
#define FUTEX_SHARED_FLAG 8
/* Values for 'private' parameter of locking macros. Yes, the
definition seems to be backwards. But it is not. The bit will be
......@@ -73,6 +75,18 @@
? -INTERNAL_SYSCALL_ERRNO (__ret) : 0); \
})
# if IS_IN (libc) || IS_IN (rtld)
static inline unsigned int __lll_private_flag2(unsigned int flag)
{
return FUTEX_32;
}
# else
static inline unsigned int __lll_private_flag2(unsigned int flag)
{
return ((flag & LLL_SHARED) ? FUTEX_SHARED_FLAG : 0) | FUTEX_32;
}
# endif
/* For most of these macros, the return value is never really used.
Nevertheless, the protocol is that each one returns a negated errno
code for failure or zero for success. (Note that the corresponding
......@@ -84,10 +98,16 @@
# define lll_futex_wait(futexp, val, private) \
lll_futex_timed_wait (futexp, val, NULL, private)
# define lll_futex_timed_wait(futexp, val, timeout, private) \
lll_futex_syscall (4, futexp, \
__lll_private_flag (FUTEX_WAIT, private), \
val, timeout)
# define lll_futex_timed_wait(futexp, val, timeout, flags) \
({ \
long int __ret = INTERNAL_SYSCALL (futex_wait, 4, futexp, \
val, \
__lll_private_flag2(flags) | FUTEX_32, \
timeout); \
(__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret)) \
? -INTERNAL_SYSCALL_ERRNO (__ret) : 0); \
})
/* Verify whether the supplied clockid is supported by
lll_futex_clock_wait_bitset. */
......@@ -96,8 +116,13 @@
/* Wake up up to NR waiters on FUTEXP. */
# define lll_futex_wake(futexp, nr, private) \
lll_futex_syscall (4, futexp, \
__lll_private_flag (FUTEX_WAKE, private), nr, 0)
({ \
long int __ret = INTERNAL_SYSCALL (futex_wake, 3, futexp, \
nr, \
__lll_private_flag2(private) | FUTEX_32); \
(__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (__ret)) \
? -INTERNAL_SYSCALL_ERRNO (__ret) : 0); \
})
/* Wake up up to NR_WAKE waiters on FUTEXP. Move up to NR_MOVE of the
rest from waiting on FUTEXP to waiting on MUTEX (a different futex).
......
......@@ -20,7 +20,8 @@
#define _LOWLEVELLOCK_H 1
#include <atomic.h>
#include <lowlevellock-futex.h>
#include <elision-conf.h>
#include <lowlevellock-futex2.h>
#include <time.h>
/* Low-level locks use a combination of atomic operations (to acquire and
......
......@@ -351,3 +351,6 @@
#define __NR_waitid 247
#define __NR_write 1
#define __NR_writev 20
#define __NR_futex_wait 447
#define __NR_futex_wake 448
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment