···18031803static void set_cpus_allowed_rt(struct task_struct *p,18041804 const struct cpumask *new_mask)18051805{18061806- int weight = cpumask_weight(new_mask);18061806+ struct rq *rq;18071807+ int weight;1807180818081809 BUG_ON(!rt_task(p));1809181018111811+ if (!p->on_rq)18121812+ return;18131813+18141814+ weight = cpumask_weight(new_mask);18151815+18101816 /*18111811- * Update the migration status of the RQ if we have an RT task18121812- * which is running AND changing its weight value.18171817+ * Only update if the process changes its state from whether it18181818+ * can migrate or not.18131819 */18141814- if (p->on_rq && (weight != p->rt.nr_cpus_allowed)) {18151815- struct rq *rq = task_rq(p);18201820+ if ((p->rt.nr_cpus_allowed > 1) == (weight > 1))18211821+ return;1816182218171817- if (!task_current(rq, p)) {18181818- /*18191819- * Make sure we dequeue this task from the pushable list18201820- * before going further. It will either remain off of18211821- * the list because we are no longer pushable, or it18221822- * will be requeued.18231823- */18241824- if (p->rt.nr_cpus_allowed > 1)18251825- dequeue_pushable_task(rq, p);18231823+ rq = task_rq(p);1826182418271827- /*18281828- * Requeue if our weight is changing and still > 118291829- */18301830- if (weight > 1)18311831- enqueue_pushable_task(rq, p);18321832-18331833- }18341834-18351835- if ((p->rt.nr_cpus_allowed <= 1) && (weight > 1)) {18361836- rq->rt.rt_nr_migratory++;18371837- } else if ((p->rt.nr_cpus_allowed > 1) && (weight <= 1)) {18381838- BUG_ON(!rq->rt.rt_nr_migratory);18391839- rq->rt.rt_nr_migratory--;18401840- }18411841-18421842- update_rt_migration(&rq->rt);18251825+ /*18261826+ * The process used to be able to migrate OR it can now migrate18271827+ */18281828+ if (weight <= 1) {18291829+ if (!task_current(rq, p))18301830+ dequeue_pushable_task(rq, p);18311831+ BUG_ON(!rq->rt.rt_nr_migratory);18321832+ rq->rt.rt_nr_migratory--;18331833+ } else {18341834+ if (!task_current(rq, p))18351835+ enqueue_pushable_task(rq, p);18361836+ rq->rt.rt_nr_migratory++;18431837 }18381838+18391839+ update_rt_migration(&rq->rt);18441840}1845184118461842/* Assumes rq->lock is held */