mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Muhammad Usama Anjum <usama.anjum@collabora.com>
To: "Edward Liaw" <edliaw@google.com>,
	shuah@kernel.org, "Thomas Gleixner" <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"André Almeida" <andrealmeid@igalia.com>
Cc: Muhammad Usama Anjum <usama.anjum@collabora.com>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	kernel-team@android.com
Subject: Re: [PATCH] selftests/futex: Order calls in futex_requeue
Date: Fri, 21 Jun 2024 10:45:48 +0500	[thread overview]
Message-ID: <0f9ec70e-2faf-4bb9-ae79-6cea8f4c3a66@collabora.com> (raw)
In-Reply-To: <20240619002204.2492673-1-edliaw@google.com>

On 6/19/24 5:22 AM, Edward Liaw wrote:
> Like fbf4dec70277 ("selftests/futex: Order calls to futex_lock_pi"),
> which fixed a flake in futex_lock_pi due to racing between the parent
> and child threads.
> 
> The same issue can occur in the futex_requeue test, because it expects
> waiterfn to make progress to futex_wait before the parent starts to
> requeue. This is mitigated by the parent sleeping for WAKE_WAIT_US, but
> it still fails occasionally. This can be reproduced by adding a sleep in
> the waiterfn before futex_wait:
> 
> TAP version 13
> 1..2
> not ok 1 futex_requeue simple returned: 0
> not ok 2 futex_requeue simple returned: 0
> not ok 3 futex_requeue many returned: 0
> not ok 4 futex_requeue many returned: 0
> 
> Instead, replace the sleep with barriers to make the sequencing
> explicit.
> 
> Fixes: 7cb5dd8e2c8c ("selftests: futex: Add futex compare requeue test")
> Signed-off-by: Edward Liaw <edliaw@google.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>

> ---
>  .../selftests/futex/functional/futex_requeue.c       | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/testing/selftests/futex/functional/futex_requeue.c b/tools/testing/selftests/futex/functional/futex_requeue.c
> index 51485be6eb2f..8f7d3e8bf32a 100644
> --- a/tools/testing/selftests/futex/functional/futex_requeue.c
> +++ b/tools/testing/selftests/futex/functional/futex_requeue.c
> @@ -12,9 +12,9 @@
>  
>  #define TEST_NAME "futex-requeue"
>  #define timeout_ns  30000000
> -#define WAKE_WAIT_US 10000
>  
>  volatile futex_t *f1;
> +static pthread_barrier_t barrier;
>  
>  void usage(char *prog)
>  {
> @@ -32,6 +32,8 @@ void *waiterfn(void *arg)
>  	to.tv_sec = 0;
>  	to.tv_nsec = timeout_ns;
>  
> +	pthread_barrier_wait(&barrier);
> +
>  	if (futex_wait(f1, *f1, &to, 0))
>  		printf("waiter failed errno %d\n", errno);
>  
> @@ -70,13 +72,15 @@ int main(int argc, char *argv[])
>  	ksft_print_msg("%s: Test futex_requeue\n",
>  		       basename(argv[0]));
>  
> +	pthread_barrier_init(&barrier, NULL, 2);
>  	/*
>  	 * Requeue a waiter from f1 to f2, and wake f2.
>  	 */
>  	if (pthread_create(&waiter[0], NULL, waiterfn, NULL))
>  		error("pthread_create failed\n", errno);
>  
> -	usleep(WAKE_WAIT_US);
> +	pthread_barrier_wait(&barrier);
> +	pthread_barrier_destroy(&barrier);
>  
>  	info("Requeuing 1 futex from f1 to f2\n");
>  	res = futex_cmp_requeue(f1, 0, &f2, 0, 1, 0);
> @@ -99,6 +103,7 @@ int main(int argc, char *argv[])
>  		ksft_test_result_pass("futex_requeue simple succeeds\n");
>  	}
>  
> +	pthread_barrier_init(&barrier, NULL, 11);
>  
>  	/*
>  	 * Create 10 waiters at f1. At futex_requeue, wake 3 and requeue 7.
> @@ -109,7 +114,8 @@ int main(int argc, char *argv[])
>  			error("pthread_create failed\n", errno);
>  	}
>  
> -	usleep(WAKE_WAIT_US);
> +	pthread_barrier_wait(&barrier);
> +	pthread_barrier_destroy(&barrier);
>  
>  	info("Waking 3 futexes at f1 and requeuing 7 futexes from f1 to f2\n");
>  	res = futex_cmp_requeue(f1, 0, &f2, 3, 7, 0);

-- 
BR,
Muhammad Usama Anjum

      reply	other threads:[~2024-06-21  5:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19  0:22 Edward Liaw
2024-06-21  5:45 ` Muhammad Usama Anjum [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0f9ec70e-2faf-4bb9-ae79-6cea8f4c3a66@collabora.com \
    --to=usama.anjum@collabora.com \
    --cc=andrealmeid@igalia.com \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=edliaw@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®