]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - kernel/sched.c
sched: fix update_load_add()/sub()
[karo-tx-linux.git] / kernel / sched.c
index dcd553cc4ee89b52ec511f70361c4f7fd586d976..3a4ba3dc0f498fe71d04d7b33b8cfe086695d4a5 100644 (file)
@@ -1108,11 +1108,13 @@ calc_delta_fair(unsigned long delta_exec, struct load_weight *lw)
 static inline void update_load_add(struct load_weight *lw, unsigned long inc)
 {
        lw->weight += inc;
+       lw->inv_weight = 0;
 }
 
 static inline void update_load_sub(struct load_weight *lw, unsigned long dec)
 {
        lw->weight -= dec;
+       lw->inv_weight = 0;
 }
 
 /*
@@ -4268,11 +4270,10 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
        oldprio = p->prio;
        on_rq = p->se.on_rq;
        running = task_current(rq, p);
-       if (on_rq) {
+       if (on_rq)
                dequeue_task(rq, p, 0);
-               if (running)
-                       p->sched_class->put_prev_task(rq, p);
-       }
+       if (running)
+               p->sched_class->put_prev_task(rq, p);
 
        if (rt_prio(prio))
                p->sched_class = &rt_sched_class;
@@ -4281,10 +4282,9 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
 
        p->prio = prio;
 
+       if (running)
+               p->sched_class->set_curr_task(rq);
        if (on_rq) {
-               if (running)
-                       p->sched_class->set_curr_task(rq);
-
                enqueue_task(rq, p, 0);
 
                check_class_changed(rq, p, prev_class, oldprio, running);
@@ -4422,7 +4422,7 @@ int task_nice(const struct task_struct *p)
 {
        return TASK_NICE(p);
 }
-EXPORT_SYMBOL_GPL(task_nice);
+EXPORT_SYMBOL(task_nice);
 
 /**
  * idle_cpu - is a given cpu idle currently?
@@ -4581,19 +4581,17 @@ recheck:
        update_rq_clock(rq);
        on_rq = p->se.on_rq;
        running = task_current(rq, p);
-       if (on_rq) {
+       if (on_rq)
                deactivate_task(rq, p, 0);
-               if (running)
-                       p->sched_class->put_prev_task(rq, p);
-       }
+       if (running)
+               p->sched_class->put_prev_task(rq, p);
 
        oldprio = p->prio;
        __setscheduler(rq, p, policy, param->sched_priority);
 
+       if (running)
+               p->sched_class->set_curr_task(rq);
        if (on_rq) {
-               if (running)
-                       p->sched_class->set_curr_task(rq);
-
                activate_task(rq, p, 0);
 
                check_class_changed(rq, p, prev_class, oldprio, running);
@@ -5100,7 +5098,7 @@ long sys_sched_rr_get_interval(pid_t pid, struct timespec __user *interval)
        time_slice = 0;
        if (p->policy == SCHED_RR) {
                time_slice = DEF_TIMESLICE;
-       } else {
+       } else if (p->policy != SCHED_FIFO) {
                struct sched_entity *se = &p->se;
                unsigned long flags;
                struct rq *rq;
@@ -5881,7 +5879,8 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
                spin_unlock_irq(&rq->lock);
                break;
 
-       case CPU_DOWN_PREPARE:
+       case CPU_DYING:
+       case CPU_DYING_FROZEN:
                /* Update our root-domain */
                rq = cpu_rq(cpu);
                spin_lock_irqsave(&rq->lock, flags);
@@ -7617,19 +7616,22 @@ void sched_move_task(struct task_struct *tsk)
        running = task_current(rq, tsk);
        on_rq = tsk->se.on_rq;
 
-       if (on_rq) {
+       if (on_rq)
                dequeue_task(rq, tsk, 0);
-               if (unlikely(running))
-                       tsk->sched_class->put_prev_task(rq, tsk);
-       }
+       if (unlikely(running))
+               tsk->sched_class->put_prev_task(rq, tsk);
 
        set_task_rq(tsk, task_cpu(tsk));
 
-       if (on_rq) {
-               if (unlikely(running))
-                       tsk->sched_class->set_curr_task(rq);
+#ifdef CONFIG_FAIR_GROUP_SCHED
+       if (tsk->sched_class->moved_group)
+               tsk->sched_class->moved_group(tsk);
+#endif
+
+       if (unlikely(running))
+               tsk->sched_class->set_curr_task(rq);
+       if (on_rq)
                enqueue_task(rq, tsk, 0);
-       }
 
        task_rq_unlock(rq, &flags);
 }
@@ -7721,9 +7723,7 @@ static unsigned long to_ratio(u64 period, u64 runtime)
        if (runtime == RUNTIME_INF)
                return 1ULL << 16;
 
-       runtime *= (1ULL << 16);
-       div64_64(runtime, period);
-       return runtime;
+       return div64_64(runtime << 16, period);
 }
 
 static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime)
@@ -7747,25 +7747,40 @@ static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime)
        return total + to_ratio(period, runtime) < global_ratio;
 }
 
+/* Must be called with tasklist_lock held */
+static inline int tg_has_rt_tasks(struct task_group *tg)
+{
+       struct task_struct *g, *p;
+       do_each_thread(g, p) {
+               if (rt_task(p) && rt_rq_of_se(&p->rt)->tg == tg)
+                       return 1;
+       } while_each_thread(g, p);
+       return 0;
+}
+
 int sched_group_set_rt_runtime(struct task_group *tg, long rt_runtime_us)
 {
        u64 rt_runtime, rt_period;
        int err = 0;
 
-       rt_period = sysctl_sched_rt_period * NSEC_PER_USEC;
+       rt_period = (u64)sysctl_sched_rt_period * NSEC_PER_USEC;
        rt_runtime = (u64)rt_runtime_us * NSEC_PER_USEC;
        if (rt_runtime_us == -1)
-               rt_runtime = rt_period;
+               rt_runtime = RUNTIME_INF;
 
        mutex_lock(&rt_constraints_mutex);
+       read_lock(&tasklist_lock);
+       if (rt_runtime_us == 0 && tg_has_rt_tasks(tg)) {
+               err = -EBUSY;
+               goto unlock;
+       }
        if (!__rt_schedulable(tg, rt_period, rt_runtime)) {
                err = -EINVAL;
                goto unlock;
        }
-       if (rt_runtime_us == -1)
-               rt_runtime = RUNTIME_INF;
        tg->rt_runtime = rt_runtime;
  unlock:
+       read_unlock(&tasklist_lock);
        mutex_unlock(&rt_constraints_mutex);
 
        return err;