Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp105360lqp; Thu, 4 Apr 2024 08:10:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUfVpFTDiu/c7NRcoJ7A9eUcWeouyxPdwLK9kAdQiCNZX3CCpWtUeybFnd704bcxKjrwGKbaKL5weOhSiOXhtdipI31EH0hyrYFrOtKcw== X-Google-Smtp-Source: AGHT+IEb/PUK6AhajLqh0cN59rJE4MtP1w1gM/VDJU1nl09JMj3jzehjhC7E8IZe8iIyNYlmCzgq X-Received: by 2002:a05:6358:3128:b0:17c:1b9b:bf46 with SMTP id c40-20020a056358312800b0017c1b9bbf46mr2759882rwe.13.1712243457246; Thu, 04 Apr 2024 08:10:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712243457; cv=pass; d=google.com; s=arc-20160816; b=izAerQzoMLNQ1KipmL6+77lIjdDy+IeCIxbRNSdjx0f6CdKtWcyoQO/x2xpq/bmTOU /iRw17N3tWaIcGlTZ9kl+X4vn27P5xFhXkTgane21OpbSwSC8VMNHV9clVs5xqovA+B/ sbe+o0eF1gs0GQyr5tP2gcEH656cKZBHIEGIMISZiw7neV3CW6bCH+61OctVv31zxeM9 iz5DnzCHgsuw27t03yZIGdeXBwEgbU3ql2/amHkypCKNyqx/rt4fMYW8EEy+njm+YnVk N5Iq4cisonaPgRzD9s+uhV7gJVIOeFS9mXDZd1K4K8NlwO2opLaKNsxx1b3nUkL0m+ag Y4gA== 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:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=Z5plkxd242OMtGKpte6blfseLcSdvpYvQ4c9jL8q5L8=; fh=4Nv/nEfyFs8DOpffvrTsm+4TdL3Ck8nKKOoUBFJ9uL8=; b=zPQ3kUCaVsWoV64eBwe0myBG/IdaNuypVt/N8pJIXdm3uUIAk55cLAo3oIssguJx3l SZYVAFA1jE/JY7v87QLISC5cengUFEFLn30z95fwLbfG8x2QR3YEm+VbHJUn7eGAUq3W y/C3te8pxsI1I0zkNl/XG2737KcfuhPcI0ZXGWOdxw++epSQXaqTmIuoQtB38knJyff0 piYKXCg/FpeaQPXIInYi5Rup8qSv+i8RKnfR9DQO7fsHnsUyRgOmdX+I9j2eFEsoSTh0 kMgfPavJfZfyvPLyuvlcKA6FQjUf/YB/qIPKf8M3pD0Y2HYyBne82xOb1zqRCwPy/NG9 eOyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="yyw/gEou"; 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-131679-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131679-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. [139.178.88.99]) by mx.google.com with ESMTPS id o28-20020a635d5c000000b005f0a540fe9esi1096154pgm.781.2024.04.04.08.10.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 08:10:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131679-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="yyw/gEou"; 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-131679-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131679-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 7CAA628236C for ; Thu, 4 Apr 2024 15:10:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A51A97580B; Thu, 4 Apr 2024 15:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yyw/gEou"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8WI+dxa9" 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 470EC1D551; Thu, 4 Apr 2024 15:10:20 +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=1712243421; cv=none; b=bBsKWlEUwmIK53UP3iRVdcqgs0mN+DhJbKvXLgK620Be8EBFGiAE1Gi65buQYEGCir9IABiWslagwhEWZjjoSv7KBQ0+gVILsm2uZj0uP1r40TU4nqVxluUxbCBLbU2YOwjj25CIzLFX6NQXWRs98yh6hiOR0z1yYduxbCfvZMk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712243421; c=relaxed/simple; bh=h1CjU1JG+GY3d4PN/CqDUdYCCccyfwlv8y9jCvqQC4U=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=iWrn91AkYKZecNZNIFZ76QZQmuOOOlefqWDOkHYwRMZ9S6iWsaZE73oQSmXkLakGUC0KcYymnIq7QW5dYfCI8f37K/LRBtMAse9S3rdGr4KRzsi5nc8hKBCBf/nHMHKwhKZmN9Jrtd+D7ig5w5QPyC5Ca8QJmUIyKUmh1Ocy/yY= 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=yyw/gEou; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8WI+dxa9; 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=1712243418; 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:references:references; bh=Z5plkxd242OMtGKpte6blfseLcSdvpYvQ4c9jL8q5L8=; b=yyw/gEouiS/IirwoaGCvhqLow9UcQMFHq2e2pVbOE1DGGUy1t1tm/etM2iXo2XmnZb1Dml pJubPntaxb88vo1I8T9Whvgsv+mmfQ1NvDhqf2W7wJIpmCFWfiLegNHyU2IXJREivBdGdA nXSLCzBxYxR/ikOOS5Q8DQS5/cf1ux4RnhR2/Is0DDa+JJOTqmpBl6UG6JQqXVJOnrHpce CVH8QhCE9ANEJflWjzyEM/uZNMFmf/r77j9auRcS9jHbrTohpaYhxg5RzLM28euKgRYdm8 2GjfgSsR1ilUa74dy/ug+pvus4mvBJ8fIWiK38/hj3muIILFdAIKPdb5CA+t4w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712243418; 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:references:references; bh=Z5plkxd242OMtGKpte6blfseLcSdvpYvQ4c9jL8q5L8=; b=8WI+dxa9jLUQ9K5BxoE/j18iAq0nizDN1BJ1lU0wqbv13V88erwi+Q8LGUQdIdkQmOJxYB jXZJKD5+9zDDPdDw== To: Oleg Nesterov , Dmitry Vyukov Cc: John Stultz , Marco Elver , Peter Zijlstra , Ingo Molnar , "Eric W. Biederman" , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, 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: <20240404134357.GA7153@redhat.com> References: <20230316123028.2890338-1-elver@google.com> <87frw3dd7d.ffs@tglx> <874jcid3f6.ffs@tglx> <20240403150343.GC31764@redhat.com> <87sf02bgez.ffs@tglx> <20240404134357.GA7153@redhat.com> Date: Thu, 04 Apr 2024 17:10:18 +0200 Message-ID: <87v84x9nad.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 Thu, Apr 04 2024 at 15:43, Oleg Nesterov wrote: > On 04/04, Dmitry Vyukov wrote: >> they all should get a signal eventually. > > Well, yes and no. > > No, in a sense that the motivation was not to ensure that all threads > get a signal, the motivation was to ensure that cpu_timer_fire() paths > will use the current task as the default target for signal_wake_up/etc. > This is just optimization. > > But yes, all should get a signal eventually. And this will happen with > or without the commit bcb7ee79029dca ("posix-timers: Prefer delivery of > signals to the current thread"). Any thread can dequeue a shared signal, > say, on return from interrupt. > > Just without that commit this "eventually" means A_LOT_OF_TIME > statistically. bcb7ee79029dca only directs the wakeup to current, but the signal is still queued in the process wide shared pending list. So the thread which sees sigpending() first will grab and deliver it to itself. > But yes, I agree, if thread exits once it get a signal, then A_LOT_OF_TIME > will be significantly decreased. But again, this is just statistical issue, > I do not see how can we test the commit bcb7ee79029dca reliably. We can't. What we can actually test is the avoidance of waking up the main thread by doing the following in the main thread: start_threads(); barrier_wait(); nanosleep(2 seconds); done = 1; stop_threads(); and in the first thread which is started: first_thread() barrier_wait(); start_timer(); loop() On a pre 6.3 kernel nanosleep() will return early because the main thread is woken up and will eventually win the race to deliver the signal. On a 6.3 and later kernel nanosleep() will not return early because the main thread is not woken up as the wake up is directed at current, i.e. a worker thread, which is running anyway and will consume the signal. > OTOH. If the threads do not exit after they get signal, then _in theory_ > nothing can guarantee that this test-case will ever complete even with > that commit. It is possible that one of the threads will "never" have a > chance to run cpu_timer_fire(). Even with the exit I managed to make one out of 100 runs run into the timeout because the main thread always won the race. > In short, I leave this to you and Thomas. I have no idea how to write a > "good" test for that commit. > > Well... perhaps the main thread should just sleep in pause(), and > distribution_handler() should check that gettid() != getpid() ? > Something like this maybe... We need to ensure that the main thread > enters pause before timer_settime(). I'm testing a modification which implements something like the above and the success condition is that the main thread does not return early from nanosleep() and has no signal accounted. It survived 2000 iterations by now. Let me polish it up. Thanks, tglx