public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/futex: Order calls to futex_lock_pi
@ 2023-08-14  8:09 Nysal Jan K.A
  2023-08-16 16:52 ` Shuah Khan
  0 siblings, 1 reply; 2+ messages in thread
From: Nysal Jan K.A @ 2023-08-14  8:09 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar
  Cc: Peter Zijlstra, Darren Hart, Davidlohr Bueso, André Almeida,
	Shuah Khan, linux-kernel, linux-kselftest, Nysal Jan K . A

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: f4addd54b161 ("selftests: futex: Expand timeout test")
Signed-off-by: Nysal Jan K.A <nysal@linux.ibm.com>
---
 .../selftests/futex/functional/futex_wait_timeout.c        | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/futex/functional/futex_wait_timeout.c b/tools/testing/selftests/futex/functional/futex_wait_timeout.c
index 3651ce17beeb..d183f878360b 100644
--- a/tools/testing/selftests/futex/functional/futex_wait_timeout.c
+++ b/tools/testing/selftests/futex/functional/futex_wait_timeout.c
@@ -24,6 +24,7 @@
 
 static long timeout_ns = 100000;	/* 100us default timeout */
 static futex_t futex_pi;
+static pthread_barrier_t barrier;
 
 void usage(char *prog)
 {
@@ -48,6 +49,8 @@ void *get_pi_lock(void *arg)
 	if (ret != 0)
 		error("futex_lock_pi failed\n", ret);
 
+	pthread_barrier_wait(&barrier);
+
 	/* Blocks forever */
 	ret = futex_wait(&lock, 0, NULL, 0);
 	error("futex_wait failed\n", ret);
@@ -130,6 +133,7 @@ int main(int argc, char *argv[])
 	       basename(argv[0]));
 	ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns);
 
+	pthread_barrier_init(&barrier, NULL, 2);
 	pthread_create(&thread, NULL, get_pi_lock, NULL);
 
 	/* initialize relative timeout */
@@ -163,6 +167,9 @@ int main(int argc, char *argv[])
 	res = futex_wait_requeue_pi(&f1, f1, &futex_pi, &to, 0);
 	test_timeout(res, &ret, "futex_wait_requeue_pi monotonic", ETIMEDOUT);
 
+	/* Wait until the other thread calls futex_lock_pi() */
+	pthread_barrier_wait(&barrier);
+	pthread_barrier_destroy(&barrier);
 	/*
 	 * FUTEX_LOCK_PI with CLOCK_REALTIME
 	 * Due to historical reasons, FUTEX_LOCK_PI supports only realtime
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests/futex: Order calls to futex_lock_pi
  2023-08-14  8:09 [PATCH] selftests/futex: Order calls to futex_lock_pi Nysal Jan K.A
@ 2023-08-16 16:52 ` Shuah Khan
  0 siblings, 0 replies; 2+ messages in thread
From: Shuah Khan @ 2023-08-16 16:52 UTC (permalink / raw)
  To: Nysal Jan K.A, Thomas Gleixner, Ingo Molnar
  Cc: Peter Zijlstra, Darren Hart, Davidlohr Bueso, André Almeida,
	Shuah Khan, linux-kernel, linux-kselftest, Shuah Khan

On 8/14/23 02:09, Nysal Jan K.A wrote:
> 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: f4addd54b161 ("selftests: futex: Expand timeout test")
> Signed-off-by: Nysal Jan K.A <nysal@linux.ibm.com>
> ---

Thank you. Applied to linux-kselftest next for Linux 6.6-rc1.

thanks,
-- Shuah


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-16 16:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-14  8:09 [PATCH] selftests/futex: Order calls to futex_lock_pi Nysal Jan K.A
2023-08-16 16:52 ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox