Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c5b28038 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar
Browse files

sched: Make sched_class::set_cpus_allowed() unconditional



Give every class a set_cpus_allowed() method, this enables some small
optimization in the RT,DL implementation by avoiding a double
cpumask_weight() call.

Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: dedekind1@gmail.com
Cc: juri.lelli@arm.com
Cc: mgorman@suse.de
Cc: riel@redhat.com
Cc: rostedt@goodmis.org
Link: http://lkml.kernel.org/r/20150515154833.614517487@infradead.org


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 25834c73
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -1151,15 +1151,20 @@ static int migration_cpu_stop(void *data)
	return 0;
}

/*
 * sched_class::set_cpus_allowed must do the below, but is not required to
 * actually call this function.
 */
void set_cpus_allowed_common(struct task_struct *p, const struct cpumask *new_mask)
{
	cpumask_copy(&p->cpus_allowed, new_mask);
	p->nr_cpus_allowed = cpumask_weight(new_mask);
}

void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
{
	lockdep_assert_held(&p->pi_lock);

	if (p->sched_class->set_cpus_allowed)
	p->sched_class->set_cpus_allowed(p, new_mask);

	cpumask_copy(&p->cpus_allowed, new_mask);
	p->nr_cpus_allowed = cpumask_weight(new_mask);
}

/*
+12 −8
Original line number Diff line number Diff line
@@ -1696,13 +1696,6 @@ static void set_cpus_allowed_dl(struct task_struct *p,
		raw_spin_unlock(&src_dl_b->lock);
	}

	/*
	 * Update only if the task is actually running (i.e.,
	 * it is on the rq AND it is not throttled).
	 */
	if (!on_dl_rq(&p->dl))
		return;

	weight = cpumask_weight(new_mask);

	/*
@@ -1710,7 +1703,14 @@ static void set_cpus_allowed_dl(struct task_struct *p,
	 * can migrate or not.
	 */
	if ((p->nr_cpus_allowed > 1) == (weight > 1))
		return;
		goto done;

	/*
	 * Update only if the task is actually running (i.e.,
	 * it is on the rq AND it is not throttled).
	 */
	if (!on_dl_rq(&p->dl))
		goto done;

	/*
	 * The process used to be able to migrate OR it can now migrate
@@ -1727,6 +1727,10 @@ static void set_cpus_allowed_dl(struct task_struct *p,
	}

	update_dl_migration(&rq->dl);

done:
	cpumask_copy(&p->cpus_allowed, new_mask);
	p->nr_cpus_allowed = weight;
}

/* Assumes rq->lock is held */
+1 −0
Original line number Diff line number Diff line
@@ -8252,6 +8252,7 @@ const struct sched_class fair_sched_class = {

	.task_waking		= task_waking_fair,
	.task_dead		= task_dead_fair,
	.set_cpus_allowed	= set_cpus_allowed_common,
#endif

	.set_curr_task          = set_curr_task_fair,
+1 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ const struct sched_class idle_sched_class = {

#ifdef CONFIG_SMP
	.select_task_rq		= select_task_rq_idle,
	.set_cpus_allowed	= set_cpus_allowed_common,
#endif

	.set_curr_task          = set_curr_task_idle,
+8 −4
Original line number Diff line number Diff line
@@ -2084,9 +2084,6 @@ static void set_cpus_allowed_rt(struct task_struct *p,

	BUG_ON(!rt_task(p));

	if (!task_on_rq_queued(p))
		return;

	weight = cpumask_weight(new_mask);

	/*
@@ -2094,7 +2091,10 @@ static void set_cpus_allowed_rt(struct task_struct *p,
	 * can migrate or not.
	 */
	if ((p->nr_cpus_allowed > 1) == (weight > 1))
		return;
		goto done;

	if (!task_on_rq_queued(p))
		goto done;

	rq = task_rq(p);

@@ -2113,6 +2113,10 @@ static void set_cpus_allowed_rt(struct task_struct *p,
	}

	update_rt_migration(&rq->rt);

done:
	cpumask_copy(&p->cpus_allowed, new_mask);
	p->nr_cpus_allowed = weight;
}

/* Assumes rq->lock is held */
Loading