History

sched/deadline: Do not reclaim the whole CPU bandwidth

Original GRUB tends to reclaim 100% of the CPU time... And this allows a CPU hog to starve non-deadline tasks. To address this issue, allow the scheduler to reclaim only a specified fraction of CPU time, stored in the new "bw_ratio" field of the dl runqueue structure.

Luca Abeni committed 9 years ago

Commit 4da3abc1 parent c52f14d3 files · +30 −1Browse files

Unified · Split

3 files
  1. kernel/sched/core.c +11 −0
  2. kernel/sched/deadline.c +11 −1
  3. kernel/sched/sched.h +8 −0
kernel/sched/core.c+11−0
@@ -6759,6 +6759,16 @@ static int sched_dl_global_validate(void) · 6758 unmodified lines
67596759 return ret;
67606760 }
67616761
6762+void init_dl_rq_bw_ratio(struct dl_rq *dl_rq)
6763+{
6764+ if (global_rt_runtime() == RUNTIME_INF) {
6765+ dl_rq->bw_ratio = 1 << RATIO_SHIFT;
6766+ } else {
6767+ dl_rq->bw_ratio = to_ratio(global_rt_runtime(),
6768+ global_rt_period()) >> (BW_SHIFT - RATIO_SHIFT);
6769+ }
6770+}
6771+
67626772 static void sched_dl_do_global(void)
67636773 {
67646774 u64 new_bw = -1;
@@ -6784,6 +6794,7 @@ static void sched_dl_do_global(void) · 19 unmodified lines
67846794 raw_spin_unlock_irqrestore(&dl_b->lock, flags);
67856795
67866796 rcu_read_unlock_sched();
6797+ init_dl_rq_bw_ratio(&cpu_rq(cpu)->dl);
67876798 }
67886799 }
67896800
kernel/sched/deadline.c+11−1
@@ -268,6 +268,7 @@ void init_dl_rq(struct dl_rq *dl_rq) · 267 unmodified lines
268268 #endif
269269
270270 dl_rq->running_bw = 0;
271+ init_dl_rq_bw_ratio(dl_rq);
271272 }
272273
273274 #ifdef CONFIG_SMP
@@ -924,11 +925,20 @@ extern bool sched_rt_bandwidth_account(struct rt_rq *rt_rq); · 650 unmodified lines
924925 * Uact is the (per-runqueue) active utilization.
925926 * Since rq->dl.running_bw contains Uact * 2^BW_SHIFT, the result
926927 * has to be shifted right by BW_SHIFT.
928+ * To reclaim only a fraction Umax of the CPU time, the
929+ * runtime accounting rule is modified as
930+ * "dq = -Uact / Umax dt"; since rq->dl.bw_ratio contains
931+ * 2^RATIO_SHIFT / Umax, delta is multiplied by bw_ratio and shifted
932+ * right by RATIO_SHIFT.
933+ * Since delta is a 64 bit variable, to have an overflow its value
934+ * should be larger than 2^(64 - 20 - 8), which is more than 64 seconds.
935+ * So, overflow is not an issue here.
927936 */
928937 u64 grub_reclaim(u64 delta, struct rq *rq)
929938 {
930939 delta *= rq->dl.running_bw;
931− delta >>= BW_SHIFT;
940+ delta *= rq->dl.bw_ratio;
941+ delta >>= BW_SHIFT + RATIO_SHIFT;
932942
933943 return delta;
934944 }
kernel/sched/sched.h+8−0
@@ -565,6 +565,12 @@ struct dl_rq { · 564 unmodified lines
565565 * task blocks
566566 */
567567 u64 running_bw;
568+
569+ /*
570+ * Inverse of the fraction of CPU utilization that can be reclaimed
571+ * by the GRUB algorithm.
572+ */
573+ u64 bw_ratio;
568574 };
569575
570576 #ifdef CONFIG_SMP
@@ -1495,9 +1501,11 @@ extern struct dl_bandwidth def_dl_bandwidth; · 924 unmodified lines
14951501 extern void init_dl_bandwidth(struct dl_bandwidth *dl_b, u64 period, u64 runtime);
14961502 extern void init_dl_task_timer(struct sched_dl_entity *dl_se);
14971503 extern void init_dl_inactive_task_timer(struct sched_dl_entity *dl_se);
1504+extern void init_dl_rq_bw_ratio(struct dl_rq *dl_rq);
14981505
14991506 #define BW_SHIFT 20
15001507 #define BW_UNIT (1 << BW_SHIFT)
1508+#define RATIO_SHIFT 8
15011509 unsigned long to_ratio(u64 period, u64 runtime);
15021510
15031511 extern void init_entity_runnable_average(struct sched_entity *se);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t