Re: [PATCH 1/1] V3: hotplug cpu: migrate a task within its cpuset

Oleg Nesterov
2007-08-27T16:23:50Z

On 08/27, Cliff Wickman wrote:
>
> --- linus.070821.orig/kernel/sched.c
> +++ linus.070821/kernel/sched.c
> @@ -61,6 +61,7 @@
> #include <linux/delayacct.h>
> #include <linux/reciprocal_div.h>
> #include <linux/unistd.h>
> +#include <linux/cpuset.h>
>
> #include <asm/tlb.h>
>
> @@ -5091,6 +5092,19 @@ restart:
> if (dest_cpu == NR_CPUS)
> dest_cpu = any_online_cpu(p->cpus_allowed);
>
> + /* try to stay on the same cpuset */
> + if (dest_cpu == NR_CPUS) {
> + rq = task_rq_lock(p, &flags);
> + /*
> + * The cpuset_cpus_allowed_locked() variant of
> + * cpuset_cpus_allowed() will not block
> + * It must be called within calls to cpuset_lock/cpuset_unlock.
> + */
> + p->cpus_allowed = cpuset_cpus_allowed_locked(p);
> + dest_cpu = any_online_cpu(p->cpus_allowed);
> + task_rq_unlock(rq, &flags);

No, no, we can't take task_lock() under rq->lock, nesting error. I think we
need a local "cpumask_t cpus_allowed = cpuset_cpus_allowed_locked()", like
sched_setaffinity() does.

task_lock() doesn't disable irqs, this means that it can't be used under any
lock which can be used from interrupt context.

Oleg.