Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f646e227 authored by Oleg Nesterov's avatar Oleg Nesterov
Browse files

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: 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 0edceb7b
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -2203,10 +2203,15 @@ relock:
 * group-wide signal. Another thread should be notified now to take
 * group-wide signal. Another thread should be notified now to take
 * the signal since we will not.
 * the signal since we will not.
 */
 */
static void retarget_shared_pending(struct task_struct *tsk)
static void retarget_shared_pending(struct task_struct *tsk, sigset_t *which)
{
{
	sigset_t retarget;
	struct task_struct *t;
	struct task_struct *t;


	sigandsets(&retarget, &tsk->signal->shared_pending.signal, which);
	if (sigisemptyset(&retarget))
		return;

	t = tsk;
	t = tsk;
	while_each_thread(tsk, t) {
	while_each_thread(tsk, t) {
		if (!signal_pending(t) && !(t->flags & PF_EXITING))
		if (!signal_pending(t) && !(t->flags & PF_EXITING))
@@ -2217,6 +2222,7 @@ static void retarget_shared_pending(struct task_struct *tsk)
void exit_signals(struct task_struct *tsk)
void exit_signals(struct task_struct *tsk)
{
{
	int group_stop = 0;
	int group_stop = 0;
	sigset_t unblocked;


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


	retarget_shared_pending(tsk);
	unblocked = tsk->blocked;
	signotset(&unblocked);
	retarget_shared_pending(tsk, &unblocked);


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