int rt_load_balance_idx;
        struct list_head *rt_load_balance_head, *rt_load_balance_curr;
        unsigned long rt_nr_running;
+       unsigned long rt_nr_migratory;
        /* highest queued rt task prio */
        int highest_prio;
 };
                goto out;
        }
 
-       p->cpus_allowed = new_mask;
+       if (p->sched_class->set_cpus_allowed)
+               p->sched_class->set_cpus_allowed(p, &new_mask);
+       else {
+               p->cpus_allowed    = new_mask;
+               p->nr_cpus_allowed = cpus_weight(new_mask);
+       }
+
        /* Can the task run on the task's current CPU? If so, we're done */
        if (cpu_isset(task_cpu(p), new_mask))
                goto out;
 
        atomic_dec(&rto_count);
        cpu_clear(rq->cpu, rt_overload_mask);
 }
+
+static void update_rt_migration(struct rq *rq)
+{
+       if (rq->rt.rt_nr_migratory && (rq->rt.rt_nr_running > 1))
+               rt_set_overload(rq);
+       else
+               rt_clear_overload(rq);
+}
 #endif /* CONFIG_SMP */
 
 /*
 #ifdef CONFIG_SMP
        if (p->prio < rq->rt.highest_prio)
                rq->rt.highest_prio = p->prio;
-       if (rq->rt.rt_nr_running > 1)
-               rt_set_overload(rq);
+       if (p->nr_cpus_allowed > 1)
+               rq->rt.rt_nr_migratory++;
+
+       update_rt_migration(rq);
 #endif /* CONFIG_SMP */
 }
 
                } /* otherwise leave rq->highest prio alone */
        } else
                rq->rt.highest_prio = MAX_RT_PRIO;
-       if (rq->rt.rt_nr_running < 2)
-               rt_clear_overload(rq);
+       if (p->nr_cpus_allowed > 1)
+               rq->rt.rt_nr_migratory--;
+
+       update_rt_migration(rq);
 #endif /* CONFIG_SMP */
 }
 
 static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu)
 {
        if (!task_running(rq, p) &&
-           (cpu < 0 || cpu_isset(cpu, p->cpus_allowed)))
+           (cpu < 0 || cpu_isset(cpu, p->cpus_allowed)) &&
+           (p->nr_cpus_allowed > 1))
                return 1;
        return 0;
 }
        /* don't touch RT tasks */
        return 0;
 }
+static void set_cpus_allowed_rt(struct task_struct *p, cpumask_t *new_mask)
+{
+       int weight = cpus_weight(*new_mask);
+
+       BUG_ON(!rt_task(p));
+
+       /*
+        * Update the migration status of the RQ if we have an RT task
+        * which is running AND changing its weight value.
+        */
+       if (p->se.on_rq && (weight != p->nr_cpus_allowed)) {
+               struct rq *rq = task_rq(p);
+
+               if ((p->nr_cpus_allowed <= 1) && (weight > 1))
+                       rq->rt.rt_nr_migratory++;
+               else if((p->nr_cpus_allowed > 1) && (weight <= 1)) {
+                       BUG_ON(!rq->rt.rt_nr_migratory);
+                       rq->rt.rt_nr_migratory--;
+               }
+
+               update_rt_migration(rq);
+       }
+
+       p->cpus_allowed    = *new_mask;
+       p->nr_cpus_allowed = weight;
+}
 #else /* CONFIG_SMP */
 # define schedule_tail_balance_rt(rq)  do { } while (0)
 # define schedule_balance_rt(rq, prev) do { } while (0)
 #ifdef CONFIG_SMP
        .load_balance           = load_balance_rt,
        .move_one_task          = move_one_task_rt,
+       .set_cpus_allowed       = set_cpus_allowed_rt,
 #endif
 
        .set_curr_task          = set_curr_task_rt,