[RFC 8/8] Do not reclaim the whole CPU bandwidth

From: Luca Abeni
Date: Thu Jan 14 2016 - 10:31:49 EST


Original GRUB tends to reclaim 100% of the CPU time... And this allows a
"CPU hog" (i.e., a busy loop) to starve non-deadline tasks.
To address this issue, allow the scheduler to reclaim only a specified
fraction of CPU time.
NOTE: the fraction of CPU time that cannot be reclaimed is currently
hardcoded as (1 << 20) / 10 -> 90%, but it must be made configurable!
---
kernel/sched/deadline.c | 3 ++-
kernel/sched/sched.h | 4 ++++
2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 712cc6d..57b693b 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -185,6 +185,7 @@ void init_dl_rq(struct dl_rq *dl_rq)
#else
init_dl_bw(&dl_rq->dl_bw);
#endif
+ dl_rq->unusable_bw = (1 << 20) / 10; // FIXME: allow to set this!
}

#ifdef CONFIG_SMP
@@ -825,7 +826,7 @@ extern bool sched_rt_bandwidth_account(struct rt_rq *rt_rq);

u64 grub_reclaim(u64 delta, struct rq *rq, u64 u)
{
- return (delta * rq->dl.running_bw) >> 20;
+ return (delta * (rq->dl.unusable_bw + rq->dl.running_bw)) >> 20;
}

/*
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index d06005b..76df0ff 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -524,6 +524,10 @@ struct dl_rq {
* and decreased when a task blocks
*/
s64 running_bw;
+ /* This is the amount of utilization that GRUB can not
+ * reclaim (per runqueue)
+ */
+ s64 unusable_bw;

s64 this_bw;
};
--
1.9.1