Skip to content

Commit f646e22

Browse files
committed
signal: retarget_shared_pending: consider shared/unblocked signals only
exit_signals() checks signal_pending() before retarget_shared_pending() but this is suboptimal. We can avoid the while_each_thread() loop in case when there are no shared signals visible to us. Add the "shared_pending.signal & ~blocked" check. We don't use tsk->blocked directly but pass ~blocked as an argument, this is needed for the next patch. Note: we can optimize this more. while_each_thread(t) can check t->blocked into account and stop after every pending signal has the new target, see the next patch. 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 0edceb7 commit f646e22

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

kernel/signal.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,10 +2203,15 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
22032203
* group-wide signal. Another thread should be notified now to take
22042204
* the signal since we will not.
22052205
*/
2206-
static void retarget_shared_pending(struct task_struct *tsk)
2206+
static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which)
22072207
{
2208+
sigset_t retarget;
22082209
struct task_struct *t;
22092210

2211+
sigandsets(&retarget, &tsk->signal->shared_pending.signal, which);
2212+
if (sigisemptyset(&retarget))
2213+
return;
2214+
22102215
t = tsk;
22112216
while_each_thread(tsk, t) {
22122217
if (!signal_pending(t) && !(t->flags & PF_EXITING))
@@ -2217,6 +2222,7 @@ static void retarget_shared_pending(struct task_struct *tsk)
22172222
void exit_signals(struct task_struct *tsk)
22182223
{
22192224
int group_stop = 0;
2225+
sigset_t unblocked;
22202226

22212227
if (thread_group_empty(tsk) || signal_group_exit(tsk->signal)) {
22222228
tsk->flags |= PF_EXITING;
@@ -2232,7 +2238,9 @@ void exit_signals(struct task_struct *tsk)
22322238
if (!signal_pending(tsk))
22332239
goto out;
22342240

2235-
retarget_shared_pending(tsk);
2241+
unblocked = tsk->blocked;
2242+
signotset(&unblocked);
2243+
retarget_shared_pending(tsk, &unblocked);
22362244

22372245
if (unlikely(tsk->group_stop & GROUP_STOP_PENDING) &&
22382246
task_participate_group_stop(tsk))

0 commit comments

Comments
 (0)