sched: debug: fix cfs_rq->wait_runtime accounting
[pandora-kernel.git] / kernel / sched_fair.c
index 9f06094..bac2aff 100644 (file)
@@ -194,6 +194,8 @@ __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
        update_load_add(&cfs_rq->load, se->load.weight);
        cfs_rq->nr_running++;
        se->on_rq = 1;
+
+       schedstat_add(cfs_rq, wait_runtime, se->wait_runtime);
 }
 
 static inline void
@@ -205,6 +207,8 @@ __dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
        update_load_sub(&cfs_rq->load, se->load.weight);
        cfs_rq->nr_running--;
        se->on_rq = 0;
+
+       schedstat_add(cfs_rq, wait_runtime, -se->wait_runtime);
 }
 
 static inline struct rb_node *first_fair(struct cfs_rq *cfs_rq)
@@ -291,7 +295,7 @@ niced_granularity(struct sched_entity *curr, unsigned long granularity)
        /*
         * It will always fit into 'long':
         */
-       return (long) (tmp >> WMULT_SHIFT);
+       return (long) (tmp >> (WMULT_SHIFT-NICE_0_SHIFT));
 }
 
 static inline void
@@ -489,6 +493,9 @@ update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
        unsigned long delta_fair;
 
+       if (unlikely(!se->wait_start_fair))
+               return;
+
        delta_fair = (unsigned long)min((u64)(2*sysctl_sched_runtime_limit),
                        (u64)(cfs_rq->fair_clock - se->wait_start_fair));
 
@@ -571,7 +578,6 @@ static void __enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se)
 
        prev_runtime = se->wait_runtime;
        __add_wait_runtime(cfs_rq, se, delta_fair);
-       schedstat_add(cfs_rq, wait_runtime, se->wait_runtime);
        delta_fair = se->wait_runtime - prev_runtime;
 
        /*
@@ -659,7 +665,6 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int sleep)
                        if (tsk->state & TASK_UNINTERRUPTIBLE)
                                se->block_start = rq_of(cfs_rq)->clock;
                }
-               cfs_rq->wait_runtime -= se->wait_runtime;
 #endif
        }
        __dequeue_entity(cfs_rq, se);
@@ -1105,21 +1110,21 @@ static void task_new_fair(struct rq *rq, struct task_struct *p)
         * until it reschedules once. We set up the key so that
         * it will preempt the parent:
         */
-       p->se.fair_key = current->se.fair_key -
+       se->fair_key = curr->fair_key -
                niced_granularity(curr, sched_granularity(cfs_rq)) - 1;
        /*
         * The first wait is dominated by the child-runs-first logic,
         * so do not credit it with that waiting time yet:
         */
        if (sysctl_sched_features & SCHED_FEAT_SKIP_INITIAL)
-               p->se.wait_start_fair = 0;
+               se->wait_start_fair = 0;
 
        /*
         * The statistical average of wait_runtime is about
         * -granularity/2, so initialize the task with that:
         */
        if (sysctl_sched_features & SCHED_FEAT_START_DEBIT)
-               p->se.wait_runtime = -(sched_granularity(cfs_rq) / 2);
+               se->wait_runtime = -(sched_granularity(cfs_rq) / 2);
 
        __enqueue_entity(cfs_rq, se);
 }