From nobody Sat Jul 25 02:12:59 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 249782E2665; Mon, 20 Jul 2026 19:00:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784574010; cv=none; b=rESxYa57frNXSpe+pYAHTqhY6Dz1gVE2iFrsrYUfax9HhWz+MlzXd1+9usx8TyuUCMMhqNC+E47sBgXL+wgCnRnlBT0iQVE0x/AaPPh5EZfp42n2d+IR5S8Cb1+A9P5E0pXQ2gDsv7X7HNTfJ4Pk+ixrSrt6lyYhw9dxFcoOumk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784574010; c=relaxed/simple; bh=ltWMciS2lVHLVenxkMNpi0chZsr4oIu/0tNoSndS7oI=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=CQik9f5rxLc11FdzZCp1TpJSbGpsZ6+QCKFkvXcx4fVd9IBGPjk+GamWT2YPFbgQ4N2xZKlntc/XaFQrtNUcojOV2slZQOjG/XoGsM+qNyHQ4e4kBrk3IzMsY4wuLaYW4Kwgq6K8p/Xirbtc/zqUOGCy2L7H0xxHF7ahxFErG40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Skkv3DhZ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=T/VERKsa; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Skkv3DhZ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="T/VERKsa" Date: Mon, 20 Jul 2026 19:00:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1784574007; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1WMPhQlfYf3s4t75Hb9B40TR26abNxGZAoJgRul5go8=; b=Skkv3DhZtV6JD4lCb32rRRKHWL+zFTXsUfDRP3pVUj+hQggSEaLtRQ+ku7rlR52B7s6V/K ViV4Uu4s3ArdB22EchVFqXGQMb2XAMzPpPuodw7LjMeLxeM3hZ7DcTOlK2p359Ld1FMoyl BWNFe8oyB29pnhyjiinnHHzmLe1OMm2OU8r59H+XJq32IickTsNsNnk9sKaNDyizOfG318 Z+9yoglBhvcokfzl46GZ4J/DYKevk+R1PhZFgbnWKSm+tLpgU6vJXsCfkGUt9FKTbwUZWp bC1DehUZzao/4jojgj+F6nPh33TsjxVfqiFZP0ZQGNAPI3N9adHWiuFZxVXziA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1784574007; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1WMPhQlfYf3s4t75Hb9B40TR26abNxGZAoJgRul5go8=; b=T/VERKsaWNIxaDxXIOQkwYyPZDHJRw2C6VnriQKwz2T2oRa8z6BQEeCHTbuOyiIhhxQEmP BQ2AUlKJ7efKIKDQ== From: "tip-bot2 for Yuwen Chen" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/futex] selftests/futex: Use thread synchronization helpers instead of usleep() Cc: Yuwen Chen , Edward Liaw , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178457400506.2943223.17834358781318195990.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the locking/futex branch of tip: Commit-ID: 23dd3f884926d945c1f6a7510f5b95164f2906e2 Gitweb: https://git.kernel.org/tip/23dd3f884926d945c1f6a7510f5b95164= f2906e2 Author: Yuwen Chen AuthorDate: Mon, 18 May 2026 10:16:54 +08:00 Committer: Thomas Gleixner CommitterDate: Mon, 20 Jul 2026 20:58:51 +02:00 selftests/futex: Use thread synchronization helpers instead of usleep() This test uses usleep() to delay the main thread after creating the test thread[s] under the assumption that they already are blocked on the futex when the main thread continues. That "works" on otherwise idle systems, but fails under load resulting in failed selftests because the requeue operation starts before the waiters reached the kernel. Replace the usleep() waits by the new thread synchronization helpers to cur= e that. [ tglx: Adapted to test harness changes, fixed coding style, sanitized the timeout handling and rewrote change log. Co-developed-by: Edward Liaw Signed-off-by: Yuwen Chen Signed-off-by: Edward Liaw Signed-off-by: Thomas Gleixner Link: https://patch.msgid.link/tencent_76B9DE9C9FE5C57F6D74B5149970DF8CCF0A= @qq.com --- tools/testing/selftests/futex/functional/futex_requeue.c | 47 ++++--- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/futex/functional/futex_requeue.c b/too= ls/testing/selftests/futex/functional/futex_requeue.c index f4b8dc1..cc31f05 100644 --- a/tools/testing/selftests/futex/functional/futex_requeue.c +++ b/tools/testing/selftests/futex/functional/futex_requeue.c @@ -10,21 +10,25 @@ #include =20 #include "futextest.h" +#include "futex_thread.h" #include "kselftest_harness.h" =20 -#define timeout_ns 30000000 -#define WAKE_WAIT_US 10000 +struct waiter_args { + struct __test_metadata *_metadata; + unsigned int n_threads; +}; =20 volatile futex_t *f1; =20 -void *waiterfn(void *arg) +static int waiterfn(void *arg) { - struct __test_metadata *_metadata =3D (struct __test_metadata *)arg; - struct timespec to; + struct __test_metadata *_metadata; + struct waiter_args *wargs =3D arg; + struct timespec to =3D { }; int res; =20 - to.tv_sec =3D 0; - to.tv_nsec =3D timeout_ns; + _metadata =3D wargs->_metadata; + to.tv_sec =3D (wargs->n_threads + 1) * WAIT_FOR_THREAD_SECS; =20 res =3D futex_wait(f1, *f1, &to, 0); if (res) { @@ -32,37 +36,39 @@ void *waiterfn(void *arg) TH_LOG("waiter failed errno %d: %s", errno, strerror(errno)); } =20 - return NULL; + return 0; } =20 TEST(requeue_single) { + struct waiter_args wargs =3D { ._metadata =3D _metadata, .n_threads =3D 1= }; + struct futex_thread waiter; volatile futex_t _f1 =3D 0; volatile futex_t f2 =3D 0; - pthread_t waiter[10]; =20 f1 =3D &_f1; =20 /* * Requeue a waiter from f1 to f2, and wake f2. */ - ASSERT_EQ(pthread_create(&waiter[0], NULL, waiterfn, _metadata), 0) + ASSERT_EQ(futex_thread_create(&waiter, waiterfn, &wargs), 0) TH_LOG("pthread_create failed"); =20 - usleep(WAKE_WAIT_US); + ASSERT_EQ(futex_wait_for_thread(&waiter, _metadata), 0) + TH_LOG("Wait for thread failed"); =20 EXPECT_EQ(futex_cmp_requeue(f1, 0, &f2, 0, 1, 0), 1); EXPECT_EQ(futex_wake(&f2, 1, 0), 1); =20 - pthread_join(waiter[0], NULL); + EXPECT_EQ(futex_thread_destroy(&waiter), 0); } =20 TEST(requeue_multiple) { + struct waiter_args wargs =3D { ._metadata =3D _metadata, .n_threads =3D 1= 0 }; + struct futex_thread waiter[10]; volatile futex_t _f1 =3D 0; volatile futex_t f2 =3D 0; - pthread_t waiter[10]; - int i; =20 f1 =3D &_f1; =20 @@ -70,18 +76,21 @@ TEST(requeue_multiple) * Create 10 waiters at f1. At futex_requeue, wake 3 and requeue 7. * At futex_wake, wake INT_MAX (should be exactly 7). */ - for (i =3D 0; i < 10; i++) { - ASSERT_EQ(pthread_create(&waiter[i], NULL, waiterfn, _metadata), 0) + for (int i =3D 0; i < 10; i++) { + ASSERT_EQ(futex_thread_create(&waiter[i], waiterfn, &wargs), 0) TH_LOG("pthread_create failed for waiter %d", i); } =20 - usleep(WAKE_WAIT_US); + for (int i =3D 0; i < 10; i++) { + ASSERT_EQ(futex_wait_for_thread(&waiter[i], _metadata), 0) + TH_LOG("Wait for waiter thread %d failed", i); + } =20 EXPECT_EQ(futex_cmp_requeue(f1, 0, &f2, 3, 7, 0), 10); EXPECT_EQ(futex_wake(&f2, INT_MAX, 0), 7); =20 - for (i =3D 0; i < 10; i++) - pthread_join(waiter[i], NULL); + for (int i =3D 0; i < 10; i++) + EXPECT_EQ(futex_thread_destroy(&waiter[i]), 0); } =20 TEST_HARNESS_MAIN