提交 4ecdafc8 编写于 作者: O Oleg Nesterov 提交者: Linus Torvalds

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: NOleg 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: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 ec25e246
...@@ -52,8 +52,21 @@ enum KTHREAD_BITS { ...@@ -52,8 +52,21 @@ enum KTHREAD_BITS {
KTHREAD_IS_PARKED, KTHREAD_IS_PARKED,
}; };
#define to_kthread(tsk) \ #define __to_kthread(vfork) \
container_of((tsk)->vfork_done, struct kthread, exited) container_of(vfork, struct kthread, exited)
static inline struct kthread *to_kthread(struct task_struct *k)
{
return __to_kthread(k->vfork_done);
}
static struct kthread *to_live_kthread(struct task_struct *k)
{
struct completion *vfork = ACCESS_ONCE(k->vfork_done);
if (likely(vfork))
return __to_kthread(vfork);
return NULL;
}
/** /**
* kthread_should_stop - should this kthread return now? * kthread_should_stop - should this kthread return now?
...@@ -313,15 +326,8 @@ struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data), ...@@ -313,15 +326,8 @@ struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data),
static struct kthread *task_get_live_kthread(struct task_struct *k) static struct kthread *task_get_live_kthread(struct task_struct *k)
{ {
struct kthread *kthread;
get_task_struct(k); get_task_struct(k);
kthread = to_kthread(k); return to_live_kthread(k);
/* It might have exited */
barrier();
if (k->vfork_done != NULL)
return kthread;
return NULL;
} }
static void __kthread_unpark(struct task_struct *k, struct kthread *kthread) static void __kthread_unpark(struct task_struct *k, struct kthread *kthread)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册