Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1329004 > unrolled thread

[PATCH 0/2] sched/deadline: fix cpusets bandwidth accounting

Started byJuri Lelli <juri.lelli@arm.com>
First post2016-02-08 13:50 +0100
Last post2016-02-08 13:50 +0100
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/2] sched/deadline: fix cpusets bandwidth accounting Juri Lelli <juri.lelli@arm.com> - 2016-02-08 13:50 +0100
    [PATCH 1/2] sched/deadline: add per rq tracking of admitted bandwidth Juri Lelli <juri.lelli@arm.com> - 2016-02-08 13:50 +0100
    [PATCH 2/2] sched/deadline: rq_{online,offline}_dl for root_domain changes Juri Lelli <juri.lelli@arm.com> - 2016-02-08 13:50 +0100

#1329004 — [PATCH 0/2] sched/deadline: fix cpusets bandwidth accounting

FromJuri Lelli <juri.lelli@arm.com>
Date2016-02-08 13:50 +0100
Subject[PATCH 0/2] sched/deadline: fix cpusets bandwidth accounting
Message-ID<qZTqq-5fX-11@gated-at.bofh.it>
Steven Rostedt provided a detailed bug report [1] highlighting the fact that we
lose bandwidth accounting information across scheduling domains changes.  This
happens when we make changes to cpusets or when hotplug comes into play (this
has been already pointed out in the past by Wanpeng Li). Problem is that these
operations are destructive w.r.t. root_domain data structure(s), that is where
we store information about the amount of bandwidth has been admitted.

This set proposes to fix that by relying on the rq_{online, offline} calls,
that IIUC were introduced exactly to cope with the problem that we have.

Patches description:

 o 01/02 introduces per-rq admitted bandwidth accounting (I stole this from
         Luca with his approval, but I changed it a bit; I kept attribution in
         the patch, but everything that I could have break is on me; also,
         Vincent posted something similar as part of the sched-freq story)
 o 02/02 uses information provided by 01/02 to save restore bandwidth
         information in root_domain(s)

Steven already provided instructions on how to reproduce that problem and test
the proposed fix in [1]. I updated my tests accordingly

 https://github.com/jlelli/tests

This set is based on tip/sched/core as of today. I pushed this set on a branch
together with Steve's sched_debug enhancements to print root_domain bandwidth
and some trace_printks that should help to track what these changes are doing.

 git://linux-arm.org/linux-jl.git upstream/fixes/dl_rootdomain_account-v1

Changelogs can be improved and patches requires more comments, but I wanted to
send this out early to understand if we are really fixing the problem and to
see if people think this approach could fly. Also, I expect that there are
still corner cases that we don't cover with the bandwidth tracking.

Testing and feedback is more than welcome.

Best,

- Juri

[1] https://lkml.org/lkml/2016/2/3/966

Juri Lelli (2):
  sched/deadline: add per rq tracking of admitted bandwidth
  sched/deadline: rq_{online,offline}_dl for root_domain changes

 kernel/sched/core.c     |  2 ++
 kernel/sched/deadline.c | 20 ++++++++++++++++++++
 kernel/sched/sched.h    | 22 ++++++++++++++++++++++
 3 files changed, 44 insertions(+)

-- 
2.7.0

[toc] | [next] | [standalone]


#1329010 — [PATCH 1/2] sched/deadline: add per rq tracking of admitted bandwidth

FromJuri Lelli <juri.lelli@arm.com>
Date2016-02-08 13:50 +0100
Subject[PATCH 1/2] sched/deadline: add per rq tracking of admitted bandwidth
Message-ID<qZTqr-5fX-27@gated-at.bofh.it>
In reply to#1329004
Currently SCHED_DEADLINE scheduling policy tracks bandwidth of tasks
that passed admission control at root_domain level only. This creates
problems when such data structure(s) are destroyed, when we reconfigure
scheduling domains for example.

This is part one of two changes required to fix the problem. In this
patch we add per-rq tracking of admitted bandwidth. Tasks bring with
them their bandwidth contribution when they enter the system and are
enqueued for the first time. Contributions are then moved around when
migrations happen and removed when tasks die.

Per-rq admitted bandwidth information will be leveraged in the next
commit to save/restore per-rq bandwidth contribution towards the root
domain (using the rq_{online,offline} mechanism).

Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Reported-by: Wanpeng Li <wanpeng.li@hotmail.com>
Reported-by: Steven Rostedt <rostedt@goodmis.org>
[ original patch by ]
Signed-off-by: Luca Abeni <luca.abeni@unitn.it>
Signed-off-by: Juri Lelli <juri.lelli@arm.com>
---
 kernel/sched/core.c     |  2 ++
 kernel/sched/deadline.c | 18 ++++++++++++++++++
 kernel/sched/sched.h    | 22 ++++++++++++++++++++++
 3 files changed, 42 insertions(+)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 24fcdbf..706ca23 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2449,7 +2449,9 @@ static int dl_overflow(struct task_struct *p, int policy,
 	} else if (dl_policy(policy) && task_has_dl_policy(p) &&
 		   !__dl_overflow(dl_b, cpus, p->dl.dl_bw, new_bw)) {
 		__dl_clear(dl_b, p->dl.dl_bw);
+		__dl_sub_ac(task_rq(p), p->dl.dl_bw);
 		__dl_add(dl_b, new_bw);
+		__dl_add_ac(task_rq(p), new_bw);
 		err = 0;
 	} else if (!dl_policy(policy) && task_has_dl_policy(p)) {
 		__dl_clear(dl_b, p->dl.dl_bw);
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index cd64c97..2480cab 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -83,6 +83,7 @@ void init_dl_rq(struct dl_rq *dl_rq)
 #else
 	init_dl_bw(&dl_rq->dl_bw);
 #endif
+	dl_rq->ac_bw = 0;
 }
 
 #ifdef CONFIG_SMP
@@ -278,8 +279,10 @@ static struct rq *dl_task_offline_migration(struct rq *rq, struct task_struct *p
 	 * By now the task is replenished and enqueued; migrate it.
 	 */
 	deactivate_task(rq, p, 0);
+	__dl_sub_ac(rq, p->dl.dl_bw);
 	set_task_cpu(p, later_rq->cpu);
 	activate_task(later_rq, p, 0);
+	__dl_add_ac(later_rq, p->dl.dl_bw);
 
 	if (!fallback)
 		resched_curr(later_rq);
@@ -506,6 +509,7 @@ static void update_dl_entity(struct sched_dl_entity *dl_se,
 	 */
 	if (dl_se->dl_new) {
 		setup_new_dl_entity(dl_se, pi_se);
+		__dl_add_ac(rq, dl_se->dl_bw);
 		return;
 	}
 
@@ -955,6 +959,9 @@ static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 		return;
 	}
 
+	if (p->on_rq == TASK_ON_RQ_MIGRATING)
+		__dl_add_ac(rq, p->dl.dl_bw);
+
 	/*
 	 * If p is throttled, we do nothing. In fact, if it exhausted
 	 * its budget it needs a replenishment and, since it now is on
@@ -980,6 +987,8 @@ static void dequeue_task_dl(struct rq *rq, struct task_struct *p, int flags)
 {
 	update_curr_dl(rq);
 	__dequeue_task_dl(rq, p, flags);
+	if (p->on_rq == TASK_ON_RQ_MIGRATING)
+		__dl_sub_ac(rq, p->dl.dl_bw);
 }
 
 /*
@@ -1219,6 +1228,8 @@ static void task_dead_dl(struct task_struct *p)
 {
 	struct dl_bw *dl_b = dl_bw_of(task_cpu(p));
 
+	__dl_sub_ac(task_rq(p), p->dl.dl_bw);
+
 	/*
 	 * Since we are TASK_DEAD we won't slip out of the domain!
 	 */
@@ -1511,8 +1522,10 @@ retry:
 	}
 
 	deactivate_task(rq, next_task, 0);
+	__dl_sub_ac(rq, next_task->dl.dl_bw);
 	set_task_cpu(next_task, later_rq->cpu);
 	activate_task(later_rq, next_task, 0);
+	__dl_add_ac(later_rq, next_task->dl.dl_bw);
 	ret = 1;
 
 	resched_curr(later_rq);
@@ -1599,8 +1612,10 @@ static void pull_dl_task(struct rq *this_rq)
 			resched = true;
 
 			deactivate_task(src_rq, p, 0);
+			__dl_sub_ac(src_rq, p->dl.dl_bw);
 			set_task_cpu(p, this_cpu);
 			activate_task(this_rq, p, 0);
+			__dl_add_ac(this_rq, p->dl.dl_bw);
 			dmin = p->dl.deadline;
 
 			/* Is there any other task even earlier? */
@@ -1705,6 +1720,9 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)
 	if (!start_dl_timer(p))
 		__dl_clear_params(p);
 
+	if (dl_prio(p->normal_prio))
+		__dl_sub_ac(rq, p->dl.dl_bw);
+
 	/*
 	 * Since this might be the only -deadline task on the rq,
 	 * this is the right place to try to pull some other one
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 10f1637..e754680 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -519,6 +519,14 @@ struct dl_rq {
 #else
 	struct dl_bw dl_bw;
 #endif
+
+	/*
+	 * ac_bw keeps track of per rq admitted bandwidth. It only changes
+	 * when a new task is admitted, it dies, it changes scheduling policy
+	 * or is migrated to another rq. It is used to correctly save/resore
+	 * total_bw on root_domain changes.
+	 */
+	u64 ac_bw;
 };
 
 #ifdef CONFIG_SMP
@@ -720,6 +728,20 @@ DECLARE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
 #define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
 #define raw_rq()		raw_cpu_ptr(&runqueues)
 
+static inline
+void __dl_sub_ac(struct rq *rq, u64 tsk_bw)
+{
+	WARN_ON(rq->dl.ac_bw == 0);
+
+	rq->dl.ac_bw -= tsk_bw;
+}
+
+static inline
+void __dl_add_ac(struct rq *rq, u64 tsk_bw)
+{
+	rq->dl.ac_bw += tsk_bw;
+}
+
 static inline u64 __rq_clock_broken(struct rq *rq)
 {
 	return READ_ONCE(rq->clock);
-- 
2.7.0

[toc] | [prev] | [next] | [standalone]


#1329012 — [PATCH 2/2] sched/deadline: rq_{online,offline}_dl for root_domain changes

FromJuri Lelli <juri.lelli@arm.com>
Date2016-02-08 13:50 +0100
Subject[PATCH 2/2] sched/deadline: rq_{online,offline}_dl for root_domain changes
Message-ID<qZTqr-5fX-37@gated-at.bofh.it>
In reply to#1329004
Steven Rostedt reported that we lose information about the amount of
bandwidth that has been admitted to the system across operations that
reconfigure scheduling domains (and are thus destructive w.r.t. root
domains). Wanpeng Li also previously reported a similar problem related
to hotplug, but, since hotplug operations entail scheduling domains
reconfiguration, we can fix both problems at once.

This patch leverages per-rq admitted bandwidth information introduced by
previous commit and couple that with rq_{online,offline}_dl calls to
save and restore root_domain state across scheduling domains
reconfiguration.

Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Reported-by: Wanpeng Li <wanpeng.li@hotmail.com>
Reported-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Juri Lelli <juri.lelli@arm.com>
---
 kernel/sched/deadline.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 2480cab..925814e 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1683,6 +1683,7 @@ static void rq_online_dl(struct rq *rq)
 	if (rq->dl.overloaded)
 		dl_set_overload(rq);
 
+	__dl_add(&rq->rd->dl_bw, rq->dl.ac_bw);
 	cpudl_set_freecpu(&rq->rd->cpudl, rq->cpu);
 	if (rq->dl.dl_nr_running > 0)
 		cpudl_set(&rq->rd->cpudl, rq->cpu, rq->dl.earliest_dl.curr, 1);
@@ -1696,6 +1697,7 @@ static void rq_offline_dl(struct rq *rq)
 
 	cpudl_set(&rq->rd->cpudl, rq->cpu, 0, 0);
 	cpudl_clear_freecpu(&rq->rd->cpudl, rq->cpu);
+	__dl_clear(&rq->rd->dl_bw, rq->dl.ac_bw);
 }
 
 void __init init_sched_dl_class(void)
-- 
2.7.0

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web