From: Oleg Nesterov <oleg@redhat.com>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org,
"Eric W . Biederman" <ebiederm@xmission.com>,
Frederic Weisbecker <frederic@kernel.org>,
Marco Elver <elver@google.com>
Subject: Re: [RFC PATCH v2] posix-timers: Support delivery of signals to the current thread
Date: Wed, 25 Jan 2023 17:31:37 +0100 [thread overview]
Message-ID: <20230125163137.GC13746@redhat.com> (raw)
In-Reply-To: <CACT4Y+YKy_4mBLYomr49+fTm31Y6Q_kXhJz8O-_RTjMe=B-6eg@mail.gmail.com>
On 01/25, Dmitry Vyukov wrote:
>
> > diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
> > index 5dead89308b7..e38b53a0f814 100644
> > --- a/kernel/time/posix-timers.c
> > +++ b/kernel/time/posix-timers.c
> > @@ -336,6 +336,7 @@ void posixtimer_rearm(struct kernel_siginfo *info)
> > int posix_timer_event(struct k_itimer *timr, int si_private)
> > {
> > enum pid_type type;
> > + struct pid *pid;
> > int ret;
> > /*
> > * FIXME: if ->sigq is queued we can race with
> > @@ -350,8 +351,9 @@ int posix_timer_event(struct k_itimer *timr, int si_private)
> > */
> > timr->sigq->info.si_sys_private = si_private;
> >
> > - type = !(timr->it_sigev_notify & SIGEV_THREAD_ID) ? PIDTYPE_TGID : PIDTYPE_PID;
> > - ret = send_sigqueue(timr->sigq, timr->it_pid, type);
> > + type = (timr->it_sigev_notify & SIGEV_THREAD_ID) ? PIDTYPE_PID : PIDTYPE_TGID;
> > + pid = (type == PIDTYPE_PID) ? timr->it_pid : task_pid(current);
> > + ret = send_sigqueue(timr->sigq, pid, type);
> > /* If we failed to send the signal the timer stops. */
> > return ret > 0;
> > }
>
> Hi Oleg,
>
> This is indeed much simpler!
>
> Do I understand correctly that:
> 1. I would need to use SIGEV_SIGNAL (without SIGEV_THREAD_ID)
Yes,
> 2. The signal is still queued into process shared_pending
Yes. But just in case, please note that if this signal is not realtime
(sigev_signo < SIGRTMIN) and it is already queued, it will be dropped.
And I do not know if this can work for you.
However this is what we already have with SIGEV_SIGNAL w/o SIGEV_THREAD_ID,
and the same is true for SIGEV_THREAD_ID if the signal is already pending in
target_task->pending.
> 3. If the current task has not blocked the signal (it shouldn't), then
> it won't kick any other task
Yes,
> 4. The current task will likely deliver the signal right on the timer
> interrupt return to userspace
> ?
Yes.
But! I just noticed send_sigqueue() does pid_task(pid, type), so the patch
above needs another change
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -1970,7 +1970,8 @@ int send_sigqueue(struct sigqueue *q, struct pid *pid, enum pid_type type)
ret = -1;
rcu_read_lock();
- t = pid_task(pid, type);
+ // comment to explain why don't we use "type"
+ t = pid_task(pid, PIDTYPE_PID);
if (!t || !likely(lock_task_sighand(t, &flags)))
goto ret;
> This changes the existing behavior (the "average bear" may be surprised :))
> https://elixir.bootlin.com/linux/v6.2-rc5/source/kernel/signal.c#L1007
this comment looks a bit misleading, s/main thread/target thread/
> But currnently it's also queued into shared_pending and any thread
> could get the signal anyway. So I think this should be fine.
Yes.
> On the positive side: it should improve performance. Delivering to the
> currently running task is better on all fronts (no kicking,
> rescheduling, IPIs, better locality), right?
Well, iiuc this was the goal of your patch ? ;)
Oleg.
next prev parent reply other threads:[~2023-01-25 16:32 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-16 17:18 [RFC PATCH] posix-timers: Support delivery of signals to the current thread Dmitry Vyukov
2023-01-11 15:49 ` Dmitry Vyukov
2023-01-11 21:28 ` Thomas Gleixner
2023-01-12 11:24 ` [RFC PATCH v2] " Dmitry Vyukov
2023-01-25 12:43 ` Oleg Nesterov
2023-01-25 15:17 ` Oleg Nesterov
2023-01-25 15:34 ` Dmitry Vyukov
2023-01-25 16:31 ` Oleg Nesterov [this message]
2023-01-25 16:45 ` Oleg Nesterov
2023-01-25 17:07 ` Oleg Nesterov
2023-01-26 10:58 ` Dmitry Vyukov
2023-01-26 10:56 ` Dmitry Vyukov
2023-01-26 10:51 ` [PATCH v3] posix-timers: Prefer " Dmitry Vyukov
2023-01-26 14:46 ` Oleg Nesterov
2023-01-26 15:41 ` [PATCH v4] " Dmitry Vyukov
2023-01-26 17:51 ` Marco Elver
2023-01-26 19:57 ` Thomas Gleixner
2023-01-27 6:58 ` Dmitry Vyukov
2023-01-28 19:56 ` Oleg Nesterov
2023-01-28 20:15 ` Oleg Nesterov
2023-01-30 9:00 ` Dmitry Vyukov
2023-01-30 16:49 ` Oleg Nesterov
2023-02-02 7:36 ` Dmitry Vyukov
2023-02-20 14:43 ` [PATCH v5] " Dmitry Vyukov
2023-02-22 15:19 ` Oleg Nesterov
2023-03-14 8:25 ` 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=20230125163137.GC13746@redhat.com \
--to=oleg@redhat.com \
--cc=dvyukov@google.com \
--cc=ebiederm@xmission.com \
--cc=elver@google.com \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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