sched: Make the idle task quack like a per-CPU kthread
[sfrench/cifs-2.6.git] / kernel / kthread.c
index fe3f2a40d61e8620f01fe057ec1e3dda92709b0e..3d326833092be16c3a3ad44a80af25cc5f7b92b7 100644 (file)
@@ -68,16 +68,6 @@ enum KTHREAD_BITS {
        KTHREAD_SHOULD_PARK,
 };
 
-static inline void set_kthread_struct(void *kthread)
-{
-       /*
-        * We abuse ->set_child_tid to avoid the new member and because it
-        * can't be wrongly copied by copy_process(). We also rely on fact
-        * that the caller can't exec, so PF_KTHREAD can't be cleared.
-        */
-       current->set_child_tid = (__force void __user *)kthread;
-}
-
 static inline struct kthread *to_kthread(struct task_struct *k)
 {
        WARN_ON(!(k->flags & PF_KTHREAD));
@@ -103,6 +93,22 @@ static inline struct kthread *__to_kthread(struct task_struct *p)
        return kthread;
 }
 
+void set_kthread_struct(struct task_struct *p)
+{
+       struct kthread *kthread;
+
+       if (__to_kthread(p))
+               return;
+
+       kthread = kzalloc(sizeof(*kthread), GFP_KERNEL);
+       /*
+        * We abuse ->set_child_tid to avoid the new member and because it
+        * can't be wrongly copied by copy_process(). We also rely on fact
+        * that the caller can't exec, so PF_KTHREAD can't be cleared.
+        */
+       p->set_child_tid = (__force void __user *)kthread;
+}
+
 void free_kthread_struct(struct task_struct *k)
 {
        struct kthread *kthread;
@@ -272,8 +278,8 @@ static int kthread(void *_create)
        struct kthread *self;
        int ret;
 
-       self = kzalloc(sizeof(*self), GFP_KERNEL);
-       set_kthread_struct(self);
+       set_kthread_struct(current);
+       self = to_kthread(current);
 
        /* If user was SIGKILLed, I release the structure. */
        done = xchg(&create->done, NULL);