Commit fec9993db093acfc3999a364e31f8adae41fcb28

Authored by Oleg Nesterov
1 parent f646e227b8

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>

Showing 1 changed file with 15 additions and 4 deletions Side-by-side Diff

... ... @@ -2200,8 +2200,8 @@
2200 2200  
2201 2201 /*
2202 2202 * 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.
2205 2205 */
2206 2206 static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which)
2207 2207 {
... ... @@ -2214,8 +2214,19 @@
2214 2214  
2215 2215 t = tsk;
2216 2216 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;
2219 2230 }
2220 2231 }
2221 2232