From nobody Wed Feb 11 22:55:03 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E6F61C20 for ; Wed, 19 Jun 2024 00:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718756531; cv=none; b=RwVp9vnnSWxDMrsqxiBbZR/e5UW9xpaZjwD8u3NkF9xL8mvtaTOl1N28c4cB+tR84gi46rtz0R3CXREd5tIneM/ZFFzcmz1D6WxQ9t0IjBxmbw5yg4nPE59Nlp9qhiKDzuh50NyAubaLA049ZYillwzh+6TsmYyww/cGkayAq+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718756531; c=relaxed/simple; bh=qM+LxVb3gd4Cbbp6AwSC8O9zXKOmQtVsfa3JiOHGIIg=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=XfsJgc6a3UTmWH21ggKyiGcCmG+WpMCTbLk0aKGNBI7XJzhqi/FpIhOvISlm9S3IOfE3RW3VDFcyBKuHAB5BMabre/cMGsL6Eu+CszCRfH1uncuoaBemdkAZzXWMwkmbhuTMihMcuGi0IZsNOGWO7lcRd/USUmupm+rgltM39NY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=I1r9twxW; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--edliaw.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="I1r9twxW" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-6658175f9d4so6027048a12.0 for ; Tue, 18 Jun 2024 17:22:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718756530; x=1719361330; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=ahBmUPS4Gd/AZ2DWokpFsWoFXzbZMIx0lYvExMMEgDs=; b=I1r9twxWQRxXYWRGLBkRuBkU8DXC53/eyeemo0zH+L7zK2N62hO4IRfjVcMzaHYXmU 7S3OEb9goyKGpw2i1gYjo/kFeKYERSUQlJLHCf2zVACVwqS8+51pLfSbSigmcm16+jXG qB964P56z0fJ8M16rDSow0rRwfvMQBD7nhrWCNT7A7pW0kSAC3o0hbA/hNnwxIkE0OlT KOB/ZQZpFmQpWavEvzd0s5Hr6HEdwJmyO69L1kRRQd7+8vFXwJn8YqAzQExicCa5/QbO UD3sYYkErNXOl/B3L7uGC0nBVJKwoI6q07cbCX/bjvaUMHqypuqpfmhTMPKkPmBl3VBJ 3zfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718756530; x=1719361330; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ahBmUPS4Gd/AZ2DWokpFsWoFXzbZMIx0lYvExMMEgDs=; b=pkyidyC9diUeXuRX7CCHDHVGnmHq9M+HBfyQIe/lmgx+NYi9azPAPCu9y4KplrbMPw RnkCL0N/xrqkswAe1tRWmMvbOlPMAEnU+72/1MKoW8ntMT7x77hLjGtQ3uXe70gfhN3z IRVJ7S4jB8fR7R02Ev+CBsJlz8rH+PzNf/ITukNw7cPnJ/BwXV3n+/iCx+ZSMFK3s1vH U3jJ+DwB6p10xjcee+V0jI+Ldeh5aKzZLZ/vnV1ZH4IX67Mk7pKlnqYniNhTEBIMcWLW UaT5Ykmppsrg0CJBEGcKT12poUYLuUGlCjREbYa99unXzsA5/AiHHZ61mrC2di7FvnPz vAjA== X-Gm-Message-State: AOJu0YzoKO2/cCz9tsvm+vySWSFLCZ6RfrmRaf1Lbg9FkXvPigF8obOD HAx8lIDu0ilH9T0mIvUbZxbXoy/nGkmRgZcmwIER8HFaV96VB0IVuR7v7ktyuWPTbRaiA+QX0HW H5Q== X-Google-Smtp-Source: AGHT+IGuzqkcfFNHspKhd9S3iQjNf5nMtU8q6h/0CLbWzogJs2rTSXjiomF+jr/wK3M2dHQupyre3nYJvrc= X-Received: from edliaw.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:305d]) (user=edliaw job=sendgmr) by 2002:a17:902:e744:b0:1f6:fbea:7959 with SMTP id d9443c01a7336-1f9aa25aaa7mr302005ad.0.1718756529581; Tue, 18 Jun 2024 17:22:09 -0700 (PDT) Date: Wed, 19 Jun 2024 00:22:03 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240619002204.2492673-1-edliaw@google.com> Subject: [PATCH] selftests/futex: Order calls in futex_requeue From: Edward Liaw To: shuah@kernel.org, Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , "=?UTF-8?q?Andr=C3=A9=20Almeida?=" Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-team@android.com, Edward Liaw Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Muhammad Usama Anjum --- .../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/too= ls/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 @@ =20 #define TEST_NAME "futex-requeue" #define timeout_ns 30000000 -#define WAKE_WAIT_US 10000 =20 volatile futex_t *f1; +static pthread_barrier_t barrier; =20 void usage(char *prog) { @@ -32,6 +32,8 @@ void *waiterfn(void *arg) to.tv_sec =3D 0; to.tv_nsec =3D timeout_ns; =20 + pthread_barrier_wait(&barrier); + if (futex_wait(f1, *f1, &to, 0)) printf("waiter failed errno %d\n", errno); =20 @@ -70,13 +72,15 @@ int main(int argc, char *argv[]) ksft_print_msg("%s: Test futex_requeue\n", basename(argv[0])); =20 + 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); =20 - usleep(WAKE_WAIT_US); + pthread_barrier_wait(&barrier); + pthread_barrier_destroy(&barrier); =20 info("Requeuing 1 futex from f1 to f2\n"); res =3D 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"); } =20 + pthread_barrier_init(&barrier, NULL, 11); =20 /* * 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); } =20 - usleep(WAKE_WAIT_US); + pthread_barrier_wait(&barrier); + pthread_barrier_destroy(&barrier); =20 info("Waking 3 futexes at f1 and requeuing 7 futexes from f1 to f2\n"); res =3D futex_cmp_requeue(f1, 0, &f2, 3, 7, 0); --=20 2.45.2.627.g7a2c4fd464-goog