From 165a7dab558c8118622a387683521bea1ebf2e6c Mon Sep 17 00:00:00 2001 From: Moyang Wang Date: Mon, 2 Apr 2018 16:23:13 -0400 Subject: kern,sim: implement FUTEX_WAKE_OP This patch implements FUTEX_WAKE_OP operation in the futex syscall. Below is its description: int futex(int *uaddr, int futex_op, int val, const struct timespec *timeout, int *uaddr2, int val3); This operation was added to support some user-space use cases where more than one futex must be handled at the same time. The most notable example is the implementation of pthread_cond_signal(3), which requires operations on two futexes, the one used to implement the mutex and the one used in the implementation of the wait queue associated with the condition variable. FUTEX_WAKE_OP allows such cases to be implemented without leading to high rates of contention and context switching. Reference: http://man7.org/linux/man-pages/man2/futex.2.html Change-Id: I215f3c2a7bdc6374e5dfe06ee721c76933a10f2d Reviewed-on: https://gem5-review.googlesource.com/c/9630 Reviewed-by: Jason Lowe-Power Reviewed-by: Brandon Potter Maintainer: Jason Lowe-Power --- src/kern/linux/linux.hh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/kern/linux') diff --git a/src/kern/linux/linux.hh b/src/kern/linux/linux.hh index 4ed39028b..93253012a 100644 --- a/src/kern/linux/linux.hh +++ b/src/kern/linux/linux.hh @@ -243,12 +243,28 @@ class Linux : public OperatingSystem static const unsigned TGT_FUTEX_WAKE = 1; static const unsigned TGT_FUTEX_REQUEUE = 3; static const unsigned TGT_FUTEX_CMP_REQUEUE = 4; + static const unsigned TGT_FUTEX_WAKE_OP = 5; static const unsigned TGT_FUTEX_WAIT_BITSET = 9; static const unsigned TGT_FUTEX_WAKE_BITSET = 10; static const unsigned TGT_EAGAIN = 11; static const unsigned TGT_EWOULDBLOCK = TGT_EAGAIN; static const unsigned TGT_FUTEX_PRIVATE_FLAG = 128; static const unsigned TGT_FUTEX_CLOCK_REALTIME_FLAG = 256; + // op field of futex_wake_op operation + static const unsigned TGT_FUTEX_OP_SET = 0; // uaddr2 = oparg; + static const unsigned TGT_FUTEX_OP_ADD = 1; // uaddr2 += oparg; + static const unsigned TGT_FUTEX_OP_OR = 2; // uaddr2 |= oparg; + static const unsigned TGT_FUTEX_OP_ANDN = 3; // uaddr2 &= ~oparg; + static const unsigned TGT_FUTEX_OP_XOR = 4; // uaddr2 ^= oparg; + // Use (1 << oparg) as operand + static const unsigned TGT_FUTEX_OP_ARG_SHIFT = 8; + // cmp field of futex_wake_op operation + static const unsigned TGT_FUTEX_OP_CMP_EQ = 0; + static const unsigned TGT_FUTEX_OP_CMP_NE = 1; + static const unsigned TGT_FUTEX_OP_CMP_LT = 2; + static const unsigned TGT_FUTEX_OP_CMP_LE = 3; + static const unsigned TGT_FUTEX_OP_CMP_GT = 4; + static const unsigned TGT_FUTEX_OP_CMP_GE = 5; // for *at syscalls static const int TGT_AT_FDCWD = -100; -- cgit v1.2.3