From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Roland McGrath <roland@redhat.com>,
Veaceslav Falico <vfalico@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] exit: avoid sig->count in de_thread/__exit_signal synchronization
Date: Wed, 17 Mar 2010 20:28:57 +0100 [thread overview]
Message-ID: <20100317192857.GA2105@redhat.com> (raw)
de_thread() and __exit_signal() use signal_struct->count/notify_count
for synchronization. We can simplify the code and use ->notify_count
only. Instead of comparing these two counters, we can change de_thread()
to set ->notify_count = nr_of_sub_threads, then change __exit_signal()
to dec-and-test this counter and notify group_exit_task.
Note that __exit_signal() checks "notify_count > 0" just for symmetry
with exit_notify(), we could just check it is != 0.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
fs/exec.c | 11 +++++------
kernel/exit.c | 2 +-
2 files changed, 6 insertions(+), 7 deletions(-)
--- 34-rc1/fs/exec.c~3_DE_THREAD_AND_EXIT_SIGNAL 2010-03-17 19:10:27.000000000 +0100
+++ 34-rc1/fs/exec.c 2010-03-17 19:37:18.000000000 +0100
@@ -763,7 +763,6 @@ static int de_thread(struct task_struct
struct signal_struct *sig = tsk->signal;
struct sighand_struct *oldsighand = tsk->sighand;
spinlock_t *lock = &oldsighand->siglock;
- int count;
if (thread_group_empty(tsk))
goto no_thread_group;
@@ -780,13 +779,13 @@ static int de_thread(struct task_struct
spin_unlock_irq(lock);
return -EAGAIN;
}
+
sig->group_exit_task = tsk;
- zap_other_threads(tsk);
+ sig->notify_count = zap_other_threads(tsk);
+ if (!thread_group_leader(tsk))
+ sig->notify_count--;
- /* Account for the thread group leader hanging around: */
- count = thread_group_leader(tsk) ? 1 : 2;
- sig->notify_count = count;
- while (atomic_read(&sig->count) > count) {
+ while (sig->notify_count) {
__set_current_state(TASK_UNINTERRUPTIBLE);
spin_unlock_irq(lock);
schedule();
--- 34-rc1/kernel/exit.c~3_DE_THREAD_AND_EXIT_SIGNAL 2010-03-17 19:17:39.000000000 +0100
+++ 34-rc1/kernel/exit.c 2010-03-17 19:37:18.000000000 +0100
@@ -98,7 +98,7 @@ static void __exit_signal(struct task_st
* If there is any task waiting for the group exit
* then notify it:
*/
- if (sig->group_exit_task && atomic_read(&sig->count) == sig->notify_count)
+ if (sig->notify_count > 0 && !--sig->notify_count)
wake_up_process(sig->group_exit_task);
if (tsk == sig->curr_target)
reply other threads:[~2010-03-17 19:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100317192857.GA2105@redhat.com \
--to=oleg@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roland@redhat.com \
--cc=vfalico@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.