Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[firefly-linux-kernel-4.4.55.git] / kernel / kthread.c
index fdea0bee7b5a4d5e2fcf43ee3b92e1a37dea6c71..490924cc9e7c8252c447e802f142d0a3a150865d 100644 (file)
@@ -327,16 +327,30 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
 }
 EXPORT_SYMBOL(kthread_create_on_node);
 
-static void __kthread_bind(struct task_struct *p, unsigned int cpu, long state)
+static void __kthread_bind_mask(struct task_struct *p, const struct cpumask *mask, long state)
 {
-       /* Must have done schedule() in kthread() before we set_task_cpu */
+       unsigned long flags;
+
        if (!wait_task_inactive(p, state)) {
                WARN_ON(1);
                return;
        }
+
        /* It's safe because the task is inactive. */
-       do_set_cpus_allowed(p, cpumask_of(cpu));
+       raw_spin_lock_irqsave(&p->pi_lock, flags);
+       do_set_cpus_allowed(p, mask);
        p->flags |= PF_NO_SETAFFINITY;
+       raw_spin_unlock_irqrestore(&p->pi_lock, flags);
+}
+
+static void __kthread_bind(struct task_struct *p, unsigned int cpu, long state)
+{
+       __kthread_bind_mask(p, cpumask_of(cpu), state);
+}
+
+void kthread_bind_mask(struct task_struct *p, const struct cpumask *mask)
+{
+       __kthread_bind_mask(p, mask, TASK_UNINTERRUPTIBLE);
 }
 
 /**