Skip to content

Commit fec9993

Browse files
committed
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: Oleg Nesterov <oleg@redhat.com> Reviewed-by: Matt Fleming <matt.fleming@linux.intel.com> Acked-by: Tejun Heo <tj@kernel.org>
1 parent f646e22 commit fec9993

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

kernel/signal.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,8 +2200,8 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
22002200

22012201
/*
22022202
* It could be that complete_signal() picked us to notify about the
2203-
* group-wide signal. Another thread should be notified now to take
2204-
* the signal since we will not.
2203+
* group-wide signal. Other threads should be notified now to take
2204+
* the shared signals in @which since we will not.
22052205
*/
22062206
static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which)
22072207
{
@@ -2214,8 +2214,19 @@ static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which)
22142214

22152215
t = tsk;
22162216
while_each_thread(tsk, t) {
2217-
if (!signal_pending(t) && !(t->flags & PF_EXITING))
2218-
recalc_sigpending_and_wake(t);
2217+
if (t->flags & PF_EXITING)
2218+
continue;
2219+
2220+
if (!has_pending_signals(&retarget, &t->blocked))
2221+
continue;
2222+
/* Remove the signals this thread can handle. */
2223+
sigandsets(&retarget, &retarget, &t->blocked);
2224+
2225+
if (!signal_pending(t))
2226+
signal_wake_up(t, 0);
2227+
2228+
if (sigisemptyset(&retarget))
2229+
break;
22192230
}
22202231
}
22212232

0 commit comments

Comments
 (0)