Skip to content

Commit fbf4dec

Browse files
Nysal Jan K.Ashuahkh
authored andcommitted
selftests/futex: Order calls to futex_lock_pi
Observed occassional failures in the futex_wait_timeout test: ok 1 futex_wait relative succeeds ok 2 futex_wait_bitset realtime succeeds ok 3 futex_wait_bitset monotonic succeeds ok 4 futex_wait_requeue_pi realtime succeeds ok 5 futex_wait_requeue_pi monotonic succeeds not ok 6 futex_lock_pi realtime returned 0 ...... The test expects the child thread to complete some steps before the parent thread gets to run. There is an implicit expectation of the order of invocation of futex_lock_pi between the child thread and the parent thread. Make this order explicit. If the order is not met, the futex_lock_pi call in the parent thread succeeds and will not timeout. Fixes: f4addd5 ("selftests: futex: Expand timeout test") Signed-off-by: Nysal Jan K.A <nysal@linux.ibm.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 888c72d commit fbf4dec

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tools/testing/selftests/futex/functional/futex_wait_timeout.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
static long timeout_ns = 100000; /* 100us default timeout */
2626
static futex_t futex_pi;
27+
static pthread_barrier_t barrier;
2728

2829
void usage(char *prog)
2930
{
@@ -48,6 +49,8 @@ void *get_pi_lock(void *arg)
4849
if (ret != 0)
4950
error("futex_lock_pi failed\n", ret);
5051

52+
pthread_barrier_wait(&barrier);
53+
5154
/* Blocks forever */
5255
ret = futex_wait(&lock, 0, NULL, 0);
5356
error("futex_wait failed\n", ret);
@@ -130,6 +133,7 @@ int main(int argc, char *argv[])
130133
basename(argv[0]));
131134
ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns);
132135

136+
pthread_barrier_init(&barrier, NULL, 2);
133137
pthread_create(&thread, NULL, get_pi_lock, NULL);
134138

135139
/* initialize relative timeout */
@@ -163,6 +167,9 @@ int main(int argc, char *argv[])
163167
res = futex_wait_requeue_pi(&f1, f1, &futex_pi, &to, 0);
164168
test_timeout(res, &ret, "futex_wait_requeue_pi monotonic", ETIMEDOUT);
165169

170+
/* Wait until the other thread calls futex_lock_pi() */
171+
pthread_barrier_wait(&barrier);
172+
pthread_barrier_destroy(&barrier);
166173
/*
167174
* FUTEX_LOCK_PI with CLOCK_REALTIME
168175
* Due to historical reasons, FUTEX_LOCK_PI supports only realtime

0 commit comments

Comments
 (0)