[RFC PATCH V2 09/19] sched: get rq potential maximum utilization

From: Preeti U Murthy
Date: Mon Aug 11 2014 - 07:37:44 EST


From: Alex Shi <alex.shi@xxxxxxxxx>

Since the rt task priority is higher than fair tasks, cfs_rq utilization
is just the left of rt utilization.

When there are some cfs tasks in queue, the potential utilization may
be yielded, so mulitiplying cfs task number to get max potential
utilization of cfs. Then the rq utilization is sum of rt util and cfs
util.

Signed-off-by: Alex Shi <alex.shi@xxxxxxxxx>
[Added CONFIG_SCHED_POWER switch to enable this patch]
Signed-off-by: Preeti U Murthy <preeti@xxxxxxxxxxxxxxxxxx>
---

kernel/sched/fair.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 031d115..60abaf4 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3308,6 +3308,53 @@ static inline int throttled_hierarchy(struct cfs_rq *cfs_rq)
return cfs_bandwidth_used() && cfs_rq->throttle_count;
}

+#ifdef CONFIG_SCHED_POWER
+static unsigned long scale_rt_util(int cpu)
+{
+ struct rq *rq = cpu_rq(cpu);
+ u64 total, age_stamp, avg;
+ s64 delta;
+
+ /*
+ * Since we're reading these variables without serialization make sure
+ * we read them once before doing sanity checks on them.
+ */
+ age_stamp = ACCESS_ONCE(rq->age_stamp);
+ avg = ACCESS_ONCE(rq->rt_avg);
+
+ delta = rq_clock(rq) - age_stamp;
+ if (unlikely(delta < 0))
+ delta = 0;
+
+ total = sched_avg_period() + delta;
+
+ if (unlikely(total < avg)) {
+ /* Ensures that capacity won't go beyond full scaled value */
+ return SCHED_CAPACITY_SCALE;
+ }
+
+ if (unlikely((s64)total < SCHED_CAPACITY_SCALE))
+ total = SCHED_CAPACITY_SCALE;
+
+ total >>= SCHED_CAPACITY_SHIFT;
+
+ return div_u64(avg, total);
+}
+
+static unsigned int max_rq_util(int cpu)
+{
+ struct rq *rq = cpu_rq(cpu);
+ unsigned int rt_util = scale_rt_util(cpu);
+ unsigned int cfs_util;
+ unsigned int nr_running;
+
+ cfs_util = (FULL_UTIL - rt_util) > rq->util ? rq->util
+ : (FULL_UTIL - rt_util);
+ nr_running = rq->nr_running ? rq->nr_running : 1;
+
+ return rt_util + cfs_util * nr_running;
+}
+#endif
/*
* Ensure that neither of the group entities corresponding to src_cpu or
* dest_cpu are members of a throttled hierarchy when performing group

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/