Commit fec9993d authored by Oleg Nesterov's avatar Oleg Nesterov

signal: retarget_shared_pending: optimize while_each_thread() loop

retarget_shared_pending() blindly does recalc_sigpending_and_wake() for
every sub-thread, this is suboptimal. We can check t->blocked and stop
looping once every bit in shared_pending has the new target.

Note: we do not take task_is_stopped_or_traced(t) into account, we are
not trying to speed up the signal delivery or to avoid the unnecessary
(but harmless) signal_wake_up(0) in this unlikely case.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Reviewed-by: default avatarMatt Fleming <matt.fleming@linux.intel.com>
Acked-by: default avatarTejun Heo <tj@kernel.org>
parent f646e227
...@@ -2200,8 +2200,8 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, ...@@ -2200,8 +2200,8 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
/* /*
* It could be that complete_signal() picked us to notify about the * It could be that complete_signal() picked us to notify about the
* group-wide signal. Another thread should be notified now to take * group-wide signal. Other threads should be notified now to take
* the signal since we will not. * the shared signals in @which since we will not.
*/ */
static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which) static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which)
{ {
...@@ -2214,8 +2214,19 @@ static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which) ...@@ -2214,8 +2214,19 @@ static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which)
t = tsk; t = tsk;
while_each_thread(tsk, t) { while_each_thread(tsk, t) {
if (!signal_pending(t) && !(t->flags & PF_EXITING)) if (t->flags & PF_EXITING)
recalc_sigpending_and_wake(t); continue;
if (!has_pending_signals(&retarget, &t->blocked))
continue;
/* Remove the signals this thread can handle. */
sigandsets(&retarget, &retarget, &t->blocked);
if (!signal_pending(t))
signal_wake_up(t, 0);
if (sigisemptyset(&retarget))
break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment