Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2824201lqz; Wed, 3 Apr 2024 09:32:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOLG1aidO3t5W/ZwqTQOyOidDAuShIAS69Ryy/BzIVEbrnph5ULffep2UJE9CYSHKqgUfBGOIDPScYI1zDGdYLbKxx30Vop6MQw5kjCQ== X-Google-Smtp-Source: AGHT+IHiadeUgYsssEtnI+XHzVyYxegEvPMznqkZiuqYNDR5Ie6dKuycyGrsFvOqoowG6iaMBJTd X-Received: by 2002:a05:6358:788:b0:17a:bd36:5156 with SMTP id n8-20020a056358078800b0017abd365156mr20110763rwj.26.1712161932771; Wed, 03 Apr 2024 09:32:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712161932; cv=pass; d=google.com; s=arc-20160816; b=ejNVzH8wzIusmD1Y5DYiFEzJoIdv6S1TB3tfoyvoQXk0ebuHYiw6K6oHGkpUG+UN2M WKFX9zgZZ2kVCULHndPDZ9APvC8aV23rVOe2vRgNTILeN6VoxzjuCViGczeOaIQqDMI9 JF9sYHSOndY87URqffhY9FivK0TooczGVqqSWVsMDAoCqIyruWGzrX7VnUAdEvawlBbA WiR/SjOc2oUecEonKN4R4gGqNiFKSrD3fSAVkFEMlLZIcF/bc4bJFjs3vV/m/0QUpVcF yCdHPm+bW/5qU2+J0zBWPrIOmTG4PEDE2nX4TMb/AW/+U0NnjJWcp6nhiFKeoV8tk2yx 5amg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=QL5+NDE0RM/D6PNrdYdHtXWw+c3iYIalpqMyMeR1Y8E=; fh=OuAojZ9XtyzR6STIF2qTI9iuNn5xasdqzotJ7hmY3kQ=; b=VPELZOXAqMIW1J17H+agyXxM2cN7lX4Z/924L4+BXWl7eZgFIvQEh2CK67m7boLuJP IO/JUrFjTOnj2FUZE+8yJ+X1vlRlHy3q8bx6QzIcVOuyP6HDHjNyPV/3Fqng+jzaXbyp GRFJW1caAsE6+6+t+c+FEvb+gCyH+6A00+j0HEAK79SpUyQ10JrtOh8c2el+GJHVd1VQ Vr5zARmfh4BijcOiAqBzBOn7SUOzq3+kEaPJ18JvhjnRbpVNiiBPSumaeF3OZjN8bYTp K9alKinarDBmU3qx4mzuBHZ2adafcLGqTh8+kHNQbopgiDrBc/UecpHkxsIOA7Nvceps G+sg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ouf7GHaC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-130199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130199-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l14-20020a63570e000000b005ee3f1a19c2si13399588pgb.244.2024.04.03.09.32.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 09:32:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Ouf7GHaC; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-130199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130199-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 28B7B28C3CB for ; Wed, 3 Apr 2024 16:32:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E702136E1B; Wed, 3 Apr 2024 16:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ouf7GHaC"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="z9SOqAvv" 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 E9ABF17C98; Wed, 3 Apr 2024 16:32:04 +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=1712161926; cv=none; b=Pf07x9Z3SGS9WxbSg82yfYKhaTiEST//Zzm2+R4eKO2HEFAdcVspXM2viyzV9yQSUQUiYGrt4pu8Jzobh6Y3JFTrAeg9MEqyDbTwLvw6IsZgOFVrE3PN9PZhKVMPDyLbZZVeuf+cR+1LutP9WRdrVH/vm8JblEcIeD6pBAQeDJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712161926; c=relaxed/simple; bh=9vgw20i3aY7puKKhpdSKUq8VMauUIYN/C6m+FYzatuo=; h=From:To:Cc:Subject:In-Reply-To:Date:Message-ID:MIME-Version: Content-Type; b=eq+86g0eO7fhN5MxW5HZkQ9p7QRd68JEZvyBzz3iIZ50vzES27Lob/da9FBNSnPuIFS5opsKZAkCbqnafArfDfNgJ4LKLkxM3eHfRli3DctBA8rwOpomeosZ972bXq9HXAxnDPg8hp9kmRavDii4CwoMHJGzPZRzJARqjn9pQ6c= 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=Ouf7GHaC; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=z9SOqAvv; 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 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712161923; 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: in-reply-to:in-reply-to; bh=QL5+NDE0RM/D6PNrdYdHtXWw+c3iYIalpqMyMeR1Y8E=; b=Ouf7GHaCwmroDlOY5y+oNG1tK3hx2BlX9bPsk0F2TVkDtdpLUqCNGm3t8e84B0TlSO16jm BPQn9K8kisSVvWkk8QAbI2A1ZClo61prHZoE86Oks5qBZJRlPrM5ZeCopbsTFwL771xm/h spR37v+PnY5/H/mJOCEq7JYCCwPe5VAbSogXdGK99HaqTOSqmU4HmSKDFTS0kTwUM+vjgu PvuguutEBq1BcqB278Su2fiIArFKHdDzAJ6g/LjvxwXbe/nd5e8kG+0l54f/Agftqz0DbV c/1YfGszueCR4Y3n87etCYhu3xQgHL3TdC7kQmXucsmbxSec7j8jTvtHz+zfkg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712161923; 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: in-reply-to:in-reply-to; bh=QL5+NDE0RM/D6PNrdYdHtXWw+c3iYIalpqMyMeR1Y8E=; b=z9SOqAvvuemk2Ka9WcmpR5blHQJSW3c4lCUIs5SdylkA6G74nLnC7oTtfXL+Zn53MysRv1 voT5MGNgrTg/EmBg== To: Oleg Nesterov Cc: John Stultz , Marco Elver , Peter Zijlstra , Ingo Molnar , "Eric W. Biederman" , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Dmitry Vyukov , kasan-dev@googlegroups.com, Edward Liaw , Carlos Llamas , Greg Kroah-Hartman Subject: Re: [PATCH v6 1/2] posix-timers: Prefer delivery of signals to the current thread In-Reply-To: <87sf02bgez.ffs@tglx> Date: Wed, 03 Apr 2024 18:32:02 +0200 Message-ID: <87r0fmbe65.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Wed, Apr 03 2024 at 17:43, Thomas Gleixner wrote: > On Wed, Apr 03 2024 at 17:03, Oleg Nesterov wrote: >> >> Why distribution_thread() can't simply exit if got_signal != 0 ? >> >> See https://lore.kernel.org/all/20230128195641.GA14906@redhat.com/ > > Indeed. It's too obvious :) Revised simpler version below. Thanks, tglx --- Subject: selftests/timers/posix_timers: Make signal distribution test less fragile From: Thomas Gleixner The signal distribution test has a tendency to hang for a long time as the signal delivery is not really evenly distributed. In fact it might never be distributed across all threads ever in the way it is written. Address this by: 1) Adding a timeout which aborts the test 2) Letting the test threads exit once they got a signal instead of running continuously. That ensures that the other threads will have a chance to expire the timer and get the signal. 3) Adding a detection whether all signals arrvied at the main thread, which allows to run the test on older kernels and emit 'SKIP'. 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 | 41 ++++++++++++++++---------- 1 file changed, 26 insertions(+), 15 deletions(-) --- a/tools/testing/selftests/timers/posix_timers.c +++ b/tools/testing/selftests/timers/posix_timers.c @@ -184,18 +184,19 @@ static int check_timer_create(int which) return 0; } -int remain; -__thread int got_signal; +static int remain; +static __thread int got_signal; static void *distribution_thread(void *arg) { - while (__atomic_load_n(&remain, __ATOMIC_RELAXED)); + while (!done && !got_signal); + return NULL; } static void distribution_handler(int nr) { - if (!__atomic_exchange_n(&got_signal, 1, __ATOMIC_RELAXED)) + if (++got_signal == 1) __atomic_fetch_sub(&remain, 1, __ATOMIC_RELAXED); } @@ -205,8 +206,6 @@ static void distribution_handler(int nr) */ static int check_timer_distribution(void) { - int err, i; - timer_t id; const int nthreads = 10; pthread_t threads[nthreads]; struct itimerspec val = { @@ -215,7 +214,11 @@ static int check_timer_distribution(void .it_interval.tv_sec = 0, .it_interval.tv_nsec = 1000 * 1000, }; + time_t start, now; + timer_t id; + int err, i; + done = 0; remain = nthreads + 1; /* worker threads + this thread */ signal(SIGALRM, distribution_handler); err = timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id); @@ -230,8 +233,7 @@ static int check_timer_distribution(void } for (i = 0; i < nthreads; i++) { - err = pthread_create(&threads[i], NULL, distribution_thread, - NULL); + err = pthread_create(&threads[i], NULL, distribution_thread, NULL); if (err) { ksft_print_msg("Can't create thread: %s (%d)\n", strerror(errno), errno); @@ -240,7 +242,18 @@ static int check_timer_distribution(void } /* Wait for all threads to receive the signal. */ - while (__atomic_load_n(&remain, __ATOMIC_RELAXED)); + now = start = time(NULL); + while (__atomic_load_n(&remain, __ATOMIC_RELAXED)) { + now = time(NULL); + if (now - start > 2) + break; + } + done = 1; + + if (timer_delete(id)) { + ksft_perror("Can't delete timer\n"); + return -1; + } for (i = 0; i < nthreads; i++) { err = pthread_join(threads[i], NULL); @@ -251,12 +264,10 @@ static int check_timer_distribution(void } } - if (timer_delete(id)) { - ksft_perror("Can't delete timer"); - return -1; - } - - ksft_test_result_pass("check_timer_distribution\n"); + if (__atomic_load_n(&remain, __ATOMIC_RELAXED) == nthreads) + ksft_test_result_skip("No signal distribution. Assuming old kernel\n"); + else + ksft_test_result(now - start <= 2, "check signal distribution\n"); return 0; }