All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wanpeng Li <wanpeng.li@linux.intel.com>
To: Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>
Cc: Juri Lelli <juri.lelli@arm.com>,
	Kirill Tkhai <ktkhai@parallels.com>,
	linux-kernel@vger.kernel.org,
	Wanpeng Li <wanpeng.li@linux.intel.com>
Subject: [PATCH v6 7/7] sched/deadline: support dl task migration during cpu hotplug
Date: Wed, 26 Nov 2014 08:44:07 +0800	[thread overview]
Message-ID: <1416962647-76792-8-git-send-email-wanpeng.li@linux.intel.com> (raw)
In-Reply-To: <1416962647-76792-1-git-send-email-wanpeng.li@linux.intel.com>

I observe that dl task can't be migrated to other cpus during cpu hotplug,
in addition, task may/may not be running again if cpu is added back. The
root cause which I found is that dl task will be throtted and removed from
dl rq after comsuming all budget, which leads to stop task can't pick it up
from dl rq and migrate to other cpus during hotplug.

The method to reproduce:
schedtool -E -t 50000:100000 -e ./test
Actually test is just a simple for loop. Then observe which cpu the test
task is on.
echo 0 > /sys/devices/system/cpu/cpuN/online

This patch adds the dl task migration during cpu hotplug by finding a most
suitable later deadline rq after dl timer fire if current rq is offline,
if fail to find a suitable later deadline rq then fallback to any eligible
online cpu in order that the deadline task will come back to us, and the
push/pull mechanism should then move it around properly.

Cc: Juri Lelli <juri.lelli@arm.com>
Signed-off-by: Wanpeng Li <wanpeng.li@linux.intel.com>
---
v5 -> v6:
 * add double_lock_balance in the fallback path
v4 -> v5:
 * remove raw_spin_unlock(&rq->lock)
 * cleanup codes, spotted by Peterz
 * cleanup patch description
v3 -> v4:
 * use tsk_cpus_allowed wrapper
 * fix compile error
v2 -> v3:
 * don't get_task_struct
 * if cannot preempt any rq, fallback to pick any online cpus
 * use cpu_active_mask as original later_mask if cpu is offline
v1 -> v2:
 * push the task to another cpu in dl_task_timer() if rq is offline.

 kernel/sched/deadline.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 42 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index b102f35..b907fdf 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -487,6 +487,7 @@ static int start_dl_timer(struct sched_dl_entity *dl_se, bool boosted)
 	return hrtimer_active(&dl_se->dl_timer);
 }
 
+static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq);
 /*
  * This is the bandwidth enforcement timer callback. If here, we know
  * a task is not on its dl_rq, since the fact that the timer was running
@@ -538,6 +539,44 @@ again:
 	update_rq_clock(rq);
 	dl_se->dl_throttled = 0;
 	dl_se->dl_yielded = 0;
+
+	/*
+	 * So if we find that the rq the task was on is no longer
+	 * available, we need to select a new rq.
+	 */
+	if (unlikely(!rq->online)) {
+		struct rq *later_rq = NULL;
+
+		later_rq = find_lock_later_rq(p, rq);
+
+		if (!later_rq) {
+			int cpu;
+
+			/*
+			 * If cannot preempt any rq, fallback to pick any
+			 * online cpu.
+			 */
+			cpu = cpumask_any_and(cpu_active_mask,
+					tsk_cpus_allowed(p));
+			if (cpu >= nr_cpu_ids) {
+				pr_warn("fail to find any online cpu and task will never come back\n");
+				goto unlock;
+			}
+			later_rq = cpu_rq(cpu);
+			double_lock_balance(rq, later_rq);
+		}
+
+		deactivate_task(rq, p, 0);
+		set_task_cpu(p, later_rq->cpu);
+		activate_task(later_rq, p, 0);
+
+		resched_curr(later_rq);
+
+		double_unlock_balance(rq, later_rq);
+
+		goto unlock;
+	}
+
 	if (task_on_rq_queued(p)) {
 		enqueue_task_dl(rq, p, ENQUEUE_REPLENISH);
 		if (dl_task(rq->curr))
@@ -1196,8 +1235,9 @@ static int find_later_rq(struct task_struct *task)
 	 * We have to consider system topology and task affinity
 	 * first, then we can look for a suitable cpu.
 	 */
-	cpumask_copy(later_mask, task_rq(task)->rd->span);
-	cpumask_and(later_mask, later_mask, cpu_active_mask);
+	cpumask_copy(later_mask, cpu_active_mask);
+	if (likely(task_rq(task)->online))
+		cpumask_and(later_mask, later_mask, task_rq(task)->rd->span);
 	cpumask_and(later_mask, later_mask, &task->cpus_allowed);
 	best_cpu = cpudl_find(&task_rq(task)->rd->cpudl,
 			task, later_mask);
-- 
1.9.1


  parent reply	other threads:[~2014-11-26  0:45 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-26  0:44 [PATCH v6 0/7] sched: support dl task migration during cpu hotplug and other fixes Wanpeng Li
2014-11-26  0:44 ` [PATCH v6 1/7] sched/deadline: fix start high-res preemption tick for a non-leftmost task Wanpeng Li
2015-02-04 14:34   ` [tip:sched/core] sched/deadline: Fix hrtick " tip-bot for Wanpeng Li
2014-11-26  0:44 ` [PATCH v6 1/7] sched/deadline: fix start high-res preemption tick " Wanpeng Li
2014-11-26  0:34   ` Wanpeng Li
2014-11-26  0:44 ` [PATCH v6 3/7] sched/deadline: fix dl entity is still mark yield after replenishing Wanpeng Li
2015-02-04 14:35   ` [tip:sched/core] sched/deadline: Fix stale yield state tip-bot for Peter Zijlstra
2014-11-26  0:44 ` [PATCH v6 4/7] sched/deadline: reduce overhead if there are no scheduling parameters changed Wanpeng Li
2015-02-04 14:35   ` [tip:sched/core] sched/deadline: Avoid pointless __setscheduler() tip-bot for Wanpeng Li
2014-11-26  0:44 ` [PATCH v6 5/7] sched/fair: fix idle balance when remaining tasks are all non-CFS tasks Wanpeng Li
2015-01-19 12:45   ` Peter Zijlstra
2015-01-19 17:48     ` Tim Chen
2015-01-19 23:16       ` Wanpeng Li
2015-01-19 23:18     ` Wanpeng Li
2015-01-22  4:05       ` Wanpeng Li
2015-01-22 18:13         ` Tim Chen
2014-11-26  0:44 ` [PATCH v6 6/7] sched: fix start hrtick for short schedule slices on UP Wanpeng Li
2015-02-04 14:35   ` [tip:sched/core] sched: Fix hrtick_start() " tip-bot for Wanpeng Li
2014-11-26  0:44 ` Wanpeng Li [this message]
2014-12-18  1:28 ` [PATCH v6 0/7] sched: support dl task migration during cpu hotplug and other fixes Wanpeng Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1416962647-76792-8-git-send-email-wanpeng.li@linux.intel.com \
    --to=wanpeng.li@linux.intel.com \
    --cc=juri.lelli@arm.com \
    --cc=ktkhai@parallels.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.