From nobody Sun Feb 8 23:35:13 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB0F7C7EE24 for ; Tue, 6 Jun 2023 14:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237988AbjFFOhg (ORCPT ); Tue, 6 Jun 2023 10:37:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236520AbjFFOh0 (ORCPT ); Tue, 6 Jun 2023 10:37:26 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDB7010C3 for ; Tue, 6 Jun 2023 07:37:21 -0700 (PDT) Message-ID: <20230606142031.071059989@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686062240; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=iBZbrM8aXg0lrMpkqk/B9ueGbYMxSh3wWbEDiu0Wh1o=; b=zAvCHooVXCehbvvBRL4bEjYh9UjlT1Dg5/wlaOn2FjT9/Q6BaQ0j7jdRCyE+KtygLsHVZx olQCqmJVAu4L20tAv2dh63LCsSboF8YM+3vOsTbdbS+KvI7ZXf83UVCgJuum6THOr4jdjm NHbW8bWPt8dzatd4cDAUNw0RYnKZeNEXal/Zmoz0h1fuVzFFiHeaBO6XD/QCIKBI5VrrQl 0DipQL9zXTv/BCAKUZnQVWrWXJFtGfOWBMqWeR8zSgnF6jQfjTDuyHY+1cGAcJE62SUrj0 JHE6gdfaFFsLE5cjvBxFkPT7lK1xbaE9MxUp8l5Xqtyp3GzHC3xKpO64kBb10g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686062240; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=iBZbrM8aXg0lrMpkqk/B9ueGbYMxSh3wWbEDiu0Wh1o=; b=9VqH++YV0s3KDheDw0FwKjW9k1vXOoHmjwK4BwJVHg7Foj9ibE8CzUrGhhrJerU4EL5OZ3 NqBkukSrCqmHTQBw== From: Thomas Gleixner To: LKML Cc: Frederic Weisbecker , Anna-Maria Behnsen , John Stultz , Peter Zijlstra , Ingo Molnar , Stephen Boyd , Eric Biederman , Oleg Nesterov Subject: [patch 01/45] selftests/timers/posix_timers: Make signal distribution test less fragile References: <20230606132949.068951363@linutronix.de> MIME-Version: 1.0 Date: Tue, 6 Jun 2023 16:37:19 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The signal distribution test has a tendency to hang for a long time as the signal delivery is not really evenly distributed. Increasing the timer interval to 10ms makes this less likely. Add a timeout to catch the case where it hangs and terminate the test gracefully. While at it get rid of the pointless atomic operation on a the thread local variable in the signal handler. Signed-off-by: Thomas Gleixner --- tools/testing/selftests/timers/posix_timers.c | 42 ++++++++++++++++-----= ----- 1 file changed, 27 insertions(+), 15 deletions(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -188,18 +188,19 @@ static int check_timer_create(int which) return 0; } =20 -int remain; -__thread int got_signal; +static int remain; +static __thread int got_signal; =20 static void *distribution_thread(void *arg) { - while (__atomic_load_n(&remain, __ATOMIC_RELAXED)); + while (__atomic_load_n(&remain, __ATOMIC_RELAXED) && !done); + return NULL; } =20 static void distribution_handler(int nr) { - if (!__atomic_exchange_n(&got_signal, 1, __ATOMIC_RELAXED)) + if (++got_signal =3D=3D 1) __atomic_fetch_sub(&remain, 1, __ATOMIC_RELAXED); } =20 @@ -209,20 +210,22 @@ static void distribution_handler(int nr) */ static int check_timer_distribution(void) { - int err, i; - timer_t id; const int nthreads =3D 10; pthread_t threads[nthreads]; struct itimerspec val =3D { .it_value.tv_sec =3D 0, - .it_value.tv_nsec =3D 1000 * 1000, + .it_value.tv_nsec =3D 20 * 1000 * 1000, .it_interval.tv_sec =3D 0, - .it_interval.tv_nsec =3D 1000 * 1000, + .it_interval.tv_nsec =3D 20 * 1000 * 1000, }; + time_t start, now; + int err, i; + timer_t id; =20 printf("Check timer_create() per process signal distribution... "); fflush(stdout); =20 + done =3D 0; remain =3D nthreads + 1; /* worker threads + this thread */ signal(SIGALRM, distribution_handler); err =3D timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id); @@ -244,7 +247,18 @@ static int check_timer_distribution(void } =20 /* Wait for all threads to receive the signal. */ - while (__atomic_load_n(&remain, __ATOMIC_RELAXED)); + now =3D start =3D time(NULL); + while (__atomic_load_n(&remain, __ATOMIC_RELAXED)) { + now =3D time(NULL); + if (now - start > 5) + break; + } + done =3D 1; + + if (timer_delete(id)) { + perror("Can't delete timer\n"); + return -1; + } =20 for (i =3D 0; i < nthreads; i++) { if (pthread_join(threads[i], NULL)) { @@ -253,12 +267,10 @@ static int check_timer_distribution(void } } =20 - if (timer_delete(id)) { - perror("Can't delete timer\n"); - return -1; - } - - printf("[OK]\n"); + if (now - start <=3D 5) + printf("[OK]\n"); + else + printf("%d [FAIL]\n", got_signal); return 0; }