Re: [PATCH v2 1/2] sched/rt: Check to push task away when its affinity is changed

From: Peter Zijlstra
Date: Tue May 05 2015 - 08:10:19 EST


On Tue, May 05, 2015 at 07:56:07PM +0800, Xunlei Pang wrote:
> +++ b/kernel/sched/core.c
> @@ -4773,6 +4773,9 @@ void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
>
> cpumask_copy(&p->cpus_allowed, new_mask);
> p->nr_cpus_allowed = cpumask_weight(new_mask);
> +
> + if (p->sched_class->post_set_cpus_allowed)
> + p->sched_class->post_set_cpus_allowed(p);
> }
>
> /*
> diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
> index 8885b65..4176f33 100644
> --- a/kernel/sched/rt.c
> +++ b/kernel/sched/rt.c
> @@ -2280,6 +2280,20 @@ static void set_cpus_allowed_rt(struct task_struct *p,
> update_rt_migration(&rq->rt);
> }
>
> +static void post_set_cpus_allowed_rt(struct task_struct *p)
> +{
> + struct rq *rq;
> +
> + if (!task_on_rq_queued(p))
> + return;
> +
> + rq = task_rq(p);
> + if (!task_running(rq, p) &&
> + p->nr_cpus_allowed > 1 &&
> + !test_tsk_need_resched(rq->curr))
> + push_rt_tasks(rq);
> +}

Guys, this is disgusting. Please don't do these minimal effort hacks.

Either fix up all the classes with a trivial set_cpus_allowed() function
and make do_set_cpus_allowed() := p->sched_class->set_cpus_allowed().

Or just do the p->{nr_,}cpus_allowed assignments in
set_cpus_allowed_rt() and keep it all in the one callback.
--
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/