public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Oleg Nesterov <oleg@redhat.com>, Dmitry Vyukov <dvyukov@google.com>
Cc: John Stultz <jstultz@google.com>, Marco Elver <elver@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	kasan-dev@googlegroups.com, Edward Liaw <edliaw@google.com>,
	Carlos Llamas <cmllamas@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v6 1/2] posix-timers: Prefer delivery of signals to the current thread
Date: Thu, 04 Apr 2024 17:10:18 +0200	[thread overview]
Message-ID: <87v84x9nad.ffs@tglx> (raw)
In-Reply-To: <20240404134357.GA7153@redhat.com>

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


  reply	other threads:[~2024-04-04 15:10 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16 12:30 [PATCH v6 1/2] posix-timers: Prefer delivery of signals to the current thread Marco Elver
2023-03-16 12:30 ` [PATCH v6 2/2] selftests/timers/posix_timers: Test delivery of signals across threads Marco Elver
2023-04-16  7:04   ` [tip: timers/core] " tip-bot2 for Dmitry Vyukov
2024-04-06 20:53   ` [PATCH v6 2/2] " Muhammad Usama Anjum
2024-04-06 21:13     ` Oleg Nesterov
2024-04-06 21:32       ` Muhammad Usama Anjum
2023-03-30 10:19 ` [PATCH v6 1/2] posix-timers: Prefer delivery of signals to the current thread Marco Elver
2023-04-06 14:12 ` Marco Elver
2023-04-06 15:13   ` Frederic Weisbecker
2023-04-06 20:22 ` Peter Zijlstra
2023-04-16  7:04 ` [tip: timers/core] " tip-bot2 for Dmitry Vyukov
2024-04-01 20:17 ` [PATCH v6 1/2] " John Stultz
2024-04-02  9:07   ` Dmitry Vyukov
2024-04-02 14:57   ` Thomas Gleixner
2024-04-02 17:23     ` John Stultz
2024-04-03 12:41       ` Thomas Gleixner
2024-04-03 15:03         ` Oleg Nesterov
2024-04-03 15:43           ` Thomas Gleixner
2024-04-03 16:32             ` Thomas Gleixner
2024-04-03 18:16               ` John Stultz
2024-04-03 19:09                 ` Thomas Gleixner
2024-04-03 19:35                   ` John Stultz
2024-04-03 22:24                     ` Thomas Gleixner
2024-04-04 14:54                       ` Oleg Nesterov
2024-04-04 18:08                         ` Thomas Gleixner
2024-04-06 15:09                           ` [PATCH] selftests/timers/posix_timers: reimplement check_timer_distribution() Oleg Nesterov
2024-04-06 15:10                             ` Oleg Nesterov
2024-04-06 22:00                               ` Thomas Gleixner
2024-04-08  8:30                               ` Dmitry Vyukov
2024-04-08 10:01                                 ` Thomas Gleixner
2024-04-08 10:26                                 ` Oleg Nesterov
2024-04-08 18:49                                   ` Oleg Nesterov
2024-04-08 22:17                                     ` Thomas Gleixner
2024-04-09 11:10                                       ` Oleg Nesterov
2024-04-09 11:45                                         ` Dmitry Vyukov
2024-04-09 12:02                                         ` Thomas Gleixner
2024-04-09 13:38                                           ` [PATCH v2] " Oleg Nesterov
2024-04-09 15:57                                             ` [tip: timers/urgent] selftests/timers/posix_timers: Reimplement check_timer_distribution() tip-bot2 for Oleg Nesterov
2024-04-10 22:21                                             ` [PATCH v2] selftests/timers/posix_timers: reimplement check_timer_distribution() John Stultz
2024-04-10 22:31                                               ` Thomas Gleixner
2024-04-10 22:33                                                 ` John Stultz
2024-04-11 12:41                             ` [PATCH] " Mark Brown
2024-04-11 15:33                               ` John Stultz
2024-04-11 12:44                             ` Mark Brown
2024-04-11 14:17                               ` Thomas Gleixner
2024-04-11 15:50                                 ` Oleg Nesterov
2024-04-11 16:03                                   ` Mark Brown
2024-04-12 12:35                               ` [PATCH] selftests: fix build failure with NOLIBC Oleg Nesterov
2024-04-12 14:58                                 ` [tip: timers/urgent] selftests: kselftest: Fix " tip-bot2 for Oleg Nesterov
2024-04-14  7:42                                 ` [PATCH] selftests: fix " Mark Brown
2024-04-04  8:55             ` [PATCH v6 1/2] posix-timers: Prefer delivery of signals to the current thread Dmitry Vyukov
2024-04-04 13:43               ` Oleg Nesterov
2024-04-04 15:10                 ` Thomas Gleixner [this message]
2024-04-04 15:23                   ` Oleg Nesterov
2024-04-05  4:28                 ` Dmitry Vyukov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v84x9nad.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=cmllamas@google.com \
    --cc=dvyukov@google.com \
    --cc=ebiederm@xmission.com \
    --cc=edliaw@google.com \
    --cc=elver@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jstultz@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox