Commit f646e227b88a164a841d6b6dd969d8a45272dd83

Authored by Oleg Nesterov
1 parent 0edceb7bcd

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>

Showing 1 changed file with 10 additions and 2 deletions Side-by-side Diff

... ... @@ -2203,10 +2203,15 @@
2203 2203 * group-wide signal. Another thread should be notified now to take
2204 2204 * the signal since we will not.
2205 2205 */
2206   -static void retarget_shared_pending(struct task_struct *tsk)
  2206 +static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which)
2207 2207 {
  2208 + sigset_t retarget;
2208 2209 struct task_struct *t;
2209 2210  
  2211 + sigandsets(&retarget, &tsk->signal->shared_pending.signal, which);
  2212 + if (sigisemptyset(&retarget))
  2213 + return;
  2214 +
2210 2215 t = tsk;
2211 2216 while_each_thread(tsk, t) {
2212 2217 if (!signal_pending(t) && !(t->flags & PF_EXITING))
... ... @@ -2217,6 +2222,7 @@
2217 2222 void exit_signals(struct task_struct *tsk)
2218 2223 {
2219 2224 int group_stop = 0;
  2225 + sigset_t unblocked;
2220 2226  
2221 2227 if (thread_group_empty(tsk) || signal_group_exit(tsk->signal)) {
2222 2228 tsk->flags |= PF_EXITING;
... ... @@ -2232,7 +2238,9 @@
2232 2238 if (!signal_pending(tsk))
2233 2239 goto out;
2234 2240  
2235   - retarget_shared_pending(tsk);
  2241 + unblocked = tsk->blocked;
  2242 + signotset(&unblocked);
  2243 + retarget_shared_pending(tsk, &unblocked);
2236 2244  
2237 2245 if (unlikely(tsk->group_stop & GROUP_STOP_PENDING) &&
2238 2246 task_participate_group_stop(tsk))