Re: [patch] sched: fix set_task_cpu() and provide an unlockedrunqueue variant

From: Peter Zijlstra
Date: Wed Nov 25 2009 - 13:28:01 EST


On Sun, 2009-11-22 at 13:09 +0100, Mike Galbraith wrote:
> sched: fix set_task_cpu() and provide an unlocked runqueue variant.
>
> set_task_cpu() falsifies migration stats by unconditionally generating migration
> stats whether a task's cpu actually changed or not. As used in copy_process(),
> the runqueue is unlocked, so we need to provide an unlocked variant which does
> the locking to provide a write barrier.
>
> Signed-off-by: Mike Galbraith <efault@xxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxx>
> Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
> LKML-Reference: <new-submission>
>
> ---

> +void set_task_cpu_unlocked(struct task_struct *p, unsigned int new_cpu)
> +{
> + unsigned long flags;
> + struct rq *rq, *new_rq = cpu_rq(new_cpu);
> +
> + smp_wmb();
> + rq = task_rq_lock(p, &flags);
> + update_rq_clock(rq);
> + if (rq != new_rq)
> + update_rq_clock(new_rq);
> + set_task_cpu(p, new_cpu);
> + task_rq_unlock(rq, &flags);
> +}

I've got to ask, what's that barrier for?



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/