History

futex: Implement sys_futex_waitv()

Add support to wait on multiple futexes. This is the interface implemented by this syscall: futex_waitv(struct futex_waitv *waiters, unsigned int nr_futexes, unsigned int flags, struct timespec *timeout, clockid_t clockid) struct futex_waitv { __u64 val; __u64 uaddr; __u32 flags; __u32 __reserved; }; Given an array of struct futex_waitv, wait on each uaddr. The thread wakes if a futex_wake() is performed at any uaddr. The syscall returns immediately if any waiter has *uaddr != val. *timeout is an optional absolute timeout value for the operation. This syscall supports only 64bit sized timeout structs. The flags argument of the syscall should be empty, but it can be used for future extensions. Flags for shared futexes, sizes, etc. should be used on the individual flags of each waiter. __reserved is used for explicit padding and should be 0, but it might be used for future extensions. If the userspace uses 32-bit pointers, it should make sure to explicitly cast it when assigning to waitv::uaddr. Returns the array index of one of the woken futexes. There’s no given information of how many were woken, or any particular attribute of it (if it’s the first woken, if it is of the smaller index...).

André Almeida committed 5 years ago

Commit bf69bad1 parent bff7c578 files · +371 −1Browse files

Showing the changes to include/uapi (2 of 8 files). Show all

Unified · Split

2 files
  1. include/uapi/asm-generic/unistd.h +4 −1
  2. include/uapi/linux/futex.h +25 −0
include/uapi/asm-generic/unistd.h+4−1
@@ -880,8 +880,11 @@ __SYSCALL(__NR_memfd_secret, sys_memfd_secret) · 879 unmodified lines
880#define __NR_process_mrelease 448880#define __NR_process_mrelease 448
881__SYSCALL(__NR_process_mrelease, sys_process_mrelease)881__SYSCALL(__NR_process_mrelease, sys_process_mrelease)
882 882
883#define __NR_futex_waitv 449
884__SYSCALL(__NR_futex_waitv, sys_futex_waitv)
885
883#undef __NR_syscalls886#undef __NR_syscalls
884#define __NR_syscalls 449887#define __NR_syscalls 450
885 888
886/*889/*
887 * 32 bit systems traditionally used different890 * 32 bit systems traditionally used different
include/uapi/linux/futex.h+25−0
@@ -43,6 +43,31 @@ · 42 unmodified lines
43#define FUTEX_CMP_REQUEUE_PI_PRIVATE (FUTEX_CMP_REQUEUE_PI | \43#define FUTEX_CMP_REQUEUE_PI_PRIVATE (FUTEX_CMP_REQUEUE_PI | \
44 FUTEX_PRIVATE_FLAG)44 FUTEX_PRIVATE_FLAG)
45 45
46/*
47 * Flags to specify the bit length of the futex word for futex2 syscalls.
48 * Currently, only 32 is supported.
49 */
50#define FUTEX_32 2
51
52/*
53 * Max numbers of elements in a futex_waitv array
54 */
55#define FUTEX_WAITV_MAX 128
56
57/**
58 * struct futex_waitv - A waiter for vectorized wait
59 * @val: Expected value at uaddr
60 * @uaddr: User address to wait on
61 * @flags: Flags for this waiter
62 * @__reserved: Reserved member to preserve data alignment. Should be 0.
63 */
64struct futex_waitv {
65 __u64 val;
66 __u64 uaddr;
67 __u32 flags;
68 __u32 __reserved;
69};
70
46/*71/*
47 * Support for robust futexes: the kernel cleans up held futexes at72 * Support for robust futexes: the kernel cleans up held futexes at
48 * thread exit time.73 * thread exit time.