]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
sched: Make sched_class::set_cpus_allowed() unconditional
authorPeter Zijlstra <peterz@infradead.org>
Fri, 15 May 2015 15:43:35 +0000 (17:43 +0200)
committerIngo Molnar <mingo@kernel.org>
Wed, 12 Aug 2015 10:06:09 +0000 (12:06 +0200)
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: Peter 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: Ingo Molnar <mingo@kernel.org>
kernel/sched/core.c
kernel/sched/deadline.c
kernel/sched/fair.c
kernel/sched/idle_task.c
kernel/sched/rt.c
kernel/sched/sched.h
kernel/sched/stop_task.c

index 2e3b983da836a70bc642489e6779b7e8fbf2433b..740f90bdc67b28de1eb926a1fe8ea5c50c04fff3 100644 (file)
@@ -1151,17 +1151,22 @@ static int migration_cpu_stop(void *data)
        return 0;
 }
 
-void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
+/*
+ * 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)
 {
-       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);
 }
 
+void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
+{
+       lockdep_assert_held(&p->pi_lock);
+       p->sched_class->set_cpus_allowed(p, new_mask);
+}
+
 /*
  * Change a given task's CPU affinity. Migrate the thread to a
  * proper CPU and schedule it away if the CPU it's executing on
index 20772eea67f2bcdb54c22e33f9cde20fde141e35..dc357fa572b02eaf8eb0c4332fd33910f33f8c03 100644 (file)
@@ -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 */
index f0950fde1f5ba3b1004fd25b2ba7bba59eba86ff..6e2e3483b1ecff588e76103e0b7b7d673f16d2a5 100644 (file)
@@ -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,
index c65dac8c97cdd5dd72f636455dcecc2742d9706d..c4ae0f1fdf9bfc13eae3f85afdeeb8c8d60f1079 100644 (file)
@@ -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,
index 00816eeaa3083272e39648c215b862c2b19a8ed0..63692efeca82591d8e5f7e001811bd939212d3ef 100644 (file)
@@ -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 */
index 22ccc5556c42302e34bc500edbee8e5ec316fb35..68cda117574c3aed0e1849a6c07eb28e1f3369c9 100644 (file)
@@ -1255,6 +1255,8 @@ extern void trigger_load_balance(struct rq *rq);
 extern void idle_enter_fair(struct rq *this_rq);
 extern void idle_exit_fair(struct rq *this_rq);
 
+extern void set_cpus_allowed_common(struct task_struct *p, const struct cpumask *new_mask);
+
 #else
 
 static inline void idle_enter_fair(struct rq *rq) { }
index 79ffec45a6acd9415d31d90906b529a6bc0d752b..cbc67da109544c4f0841b609e44d7337650aa81c 100644 (file)
@@ -123,6 +123,7 @@ const struct sched_class stop_sched_class = {
 
 #ifdef CONFIG_SMP
        .select_task_rq         = select_task_rq_stop,
+       .set_cpus_allowed       = set_cpus_allowed_common,
 #endif
 
        .set_curr_task          = set_curr_task_stop,