Merge branch 'semaphore' of git://git.kernel.org/pub/scm/linux/kernel/git/willy/misc
[sfrench/cifs-2.6.git] / kernel / kthread.c
index bbd51b81a3e86e239584925dfaf637dce187a831..92cf6930ab51a74e034ae9db30d72b21e9a84e9d 100644 (file)
@@ -13,7 +13,8 @@
 #include <linux/file.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
-#include <asm/semaphore.h>
+
+#define KTHREAD_NICE_LEVEL (-5)
 
 static DEFINE_SPINLOCK(kthread_create_lock);
 static LIST_HEAD(kthread_create_list);
@@ -94,10 +95,18 @@ static void create_kthread(struct kthread_create_info *create)
        if (pid < 0) {
                create->result = ERR_PTR(pid);
        } else {
+               struct sched_param param = { .sched_priority = 0 };
                wait_for_completion(&create->started);
                read_lock(&tasklist_lock);
                create->result = find_task_by_pid(pid);
                read_unlock(&tasklist_lock);
+               /*
+                * root may have changed our (kthreadd's) priority or CPU mask.
+                * The kernel thread should not inherit these properties.
+                */
+               sched_setscheduler(create->result, SCHED_NORMAL, &param);
+               set_user_nice(create->result, KTHREAD_NICE_LEVEL);
+               set_cpus_allowed(create->result, CPU_MASK_ALL);
        }
        complete(&create->done);
 }
@@ -170,6 +179,7 @@ void kthread_bind(struct task_struct *k, unsigned int cpu)
        wait_task_inactive(k);
        set_task_cpu(k, cpu);
        k->cpus_allowed = cpumask_of_cpu(cpu);
+       k->rt.nr_cpus_allowed = 1;
 }
 EXPORT_SYMBOL(kthread_bind);
 
@@ -214,23 +224,15 @@ int kthread_stop(struct task_struct *k)
 }
 EXPORT_SYMBOL(kthread_stop);
 
-
-static __init void kthreadd_setup(void)
+int kthreadd(void *unused)
 {
        struct task_struct *tsk = current;
 
+       /* Setup a clean context for our children to inherit. */
        set_task_comm(tsk, "kthreadd");
-
        ignore_signals(tsk);
-
-       set_user_nice(tsk, -5);
+       set_user_nice(tsk, KTHREAD_NICE_LEVEL);
        set_cpus_allowed(tsk, CPU_MASK_ALL);
-}
-
-int kthreadd(void *unused)
-{
-       /* Setup a clean context for our children to inherit. */
-       kthreadd_setup();
 
        current->flags |= PF_NOFREEZE;