aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/kthread.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2013-04-29 18:05:01 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 18:54:25 -0400
commit4ecdafc8084fe1d95bb59ed7753b345abcd586fb (patch)
treeb119ed319cfb2f526ac5666f04bef7e13caecd3c /kernel/kthread.c
parentec25e246b94a3233ab064994ef05a170bdba0e7c (diff)
kthread: introduce to_live_kthread()
"k->vfork_done != NULL" with a barrier() after to_kthread(k) in task_get_live_kthread(k) looks unclear, and sub-optimal because we load ->vfork_done twice. All we need is to ensure that we do not return to_kthread(NULL). Add a new trivial helper which loads/checks ->vfork_done once, this also looks more understandable. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Namhyung Kim <namhyung@kernel.org> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/kthread.c')
-rw-r--r--kernel/kthread.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/kernel/kthread.c b/kernel/kthread.c
index 9eb7fed0bbaa..a84dee265f94 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -52,8 +52,21 @@ enum KTHREAD_BITS {
52 KTHREAD_IS_PARKED, 52 KTHREAD_IS_PARKED,
53}; 53};
54 54
55#define to_kthread(tsk) \ 55#define __to_kthread(vfork) \
56 container_of((tsk)->vfork_done, struct kthread, exited) 56 container_of(vfork, struct kthread, exited)
57
58static inline struct kthread *to_kthread(struct task_struct *k)
59{
60 return __to_kthread(k->vfork_done);
61}
62
63static struct kthread *to_live_kthread(struct task_struct *k)
64{
65 struct completion *vfork = ACCESS_ONCE(k->vfork_done);
66 if (likely(vfork))
67 return __to_kthread(vfork);
68 return NULL;
69}
57 70
58/** 71/**
59 * kthread_should_stop - should this kthread return now? 72 * kthread_should_stop - should this kthread return now?
@@ -313,15 +326,8 @@ struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data),
313 326
314static struct kthread *task_get_live_kthread(struct task_struct *k) 327static struct kthread *task_get_live_kthread(struct task_struct *k)
315{ 328{
316 struct kthread *kthread;
317
318 get_task_struct(k); 329 get_task_struct(k);
319 kthread = to_kthread(k); 330 return to_live_kthread(k);
320 /* It might have exited */
321 barrier();
322 if (k->vfork_done != NULL)
323 return kthread;
324 return NULL;
325} 331}
326 332
327static void __kthread_unpark(struct task_struct *k, struct kthread *kthread) 333static void __kthread_unpark(struct task_struct *k, struct kthread *kthread)