selftests/futex: add futex_swap selftest
RFC PATCH v2 3/3 selftests/futex: add futex_swap selftest
From 7b091e46de4f9227b5a943e6d78283564e8c1c72 Mon Sep 17 00:00:00 2001
From: Peter Oskolkov <[email protected]>
Date: Tue, 2 Jun 2020 13:01:17 -0700
Subject: [RFC PATCH 3/3 v2] selftests/futex: add futex_swap selftest
This is the final RFC patch in FUTEX_SWAP patchset. It adds a test/benchmark to validate behavior and compare performance of a new FUTEX_SWAP futex operation.
Detailed API design and behavior considerations are provided in the commit messages of the previous two patches.
Signed-off-by Peter Oskolkov <[email protected]>
--- .../selftests/futex/functional/.gitignore | 1 + .../selftests/futex/functional/Makefile | 1 + .../selftests/futex/functional/futex_swap.c | 209 ++++++++++++++++++ .../selftests/futex/include/futextest.h | 19 ++ 4 files changed, 230 insertions(+) create mode 100644 tools/testing/selftests/futex/functional/futex_swap.c
tools/testing/selftests/futex/functional/.gitignore +1 -0
@@ -2,6 +2,7 @@ futex_requeue_pi futex_requeue_pi_mismatched_ops futex_requeue_pi_signal_restart +futex_swap futex_wait_private_mapped_file futex_wait_timeout futex_wait_uninitialized_heap
tools/testing/selftests/futex/functional/Makefile +1 -0
@@ -13,6 +13,7 @@ TEST_GEN_FILES := \ futex_requeue_pi \ futex_requeue_pi_signal_restart \ futex_requeue_pi_mismatched_ops \ + futex_swap \ futex_wait_uninitialized_heap \ futex_wait_private_mapped_file
tools/testing/selftests/futex/functional/futex_swap.c new file +209 -0
209 lines not on this page · raw message
tools/testing/selftests/futex/include/futextest.h +19 -0
@@ -38,6 +38,9 @@ typedef volatile u_int32_t futex_t;#ifndef FUTEX_CMP_REQUEUE_PI #define FUTEX_CMP_REQUEUE_PI 12#endif +#ifndef FUTEX_SWAP +#define FUTEX_SWAP 13 +#endif #ifndef FUTEX_WAIT_REQUEUE_PI_PRIVATE #define FUTEX_WAIT_REQUEUE_PI_PRIVATE (FUTEX_WAIT_REQUEUE_PI | \ FUTEX_PRIVATE_FLAG)
@@ -46,6 +49,9 @@ typedef volatile u_int32_t futex_t;#define FUTEX_CMP_REQUEUE_PI_PRIVATE (FUTEX_CMP_REQUEUE_PI | \ FUTEX_PRIVATE_FLAG)#endif +#ifndef FUTEX_SWAP_PRIVATE +#define FUTEX_SWAP_PRIVATE (FUTEX_WAIT_WAKE | FUTEX_PRIVATE_FLAG) +#endif /** * futex() - SYS_futex syscall wrapper
@@ -204,6 +210,19 @@ futex_cmp_requeue_pi(futex_t *uaddr, futex_t val, futex_t *uaddr2, int nr_wake, val, opflags); } +/** +* futex_swap() - block on uaddr and wake one task blocked on uaddr2. +* @uaddr: futex to block the current task on +* @timeout: relative timeout for the current task block +* @uaddr2: futex to wake tasks at (can be the same as uaddr) +*/ +static inline int +futex_swap (futex_t *uaddr,futex_t val,struct timespec *timeout, +futex_t *uaddr2,int opflags) +{ +return futex (uaddr,FUTEX_SWAP , val, timeout, uaddr2,0 , opflags); +} +/** * futex_cmpxchg() - atomic compare and exchange * @uaddr: The address of the futex to be modified
--
2.25.1