From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Aaron Lu <aaron.lu@intel.com>
Subject: [RFC PATCH v9 1/2] sched: Fix: Handle target_cpu offlining in active_load_balance_cpu_stop
Date: Wed, 19 Apr 2023 11:50:11 -0400 [thread overview]
Message-ID: <20230419155012.63901-1-mathieu.desnoyers@efficios.com> (raw)
Handle scenario where the target cpu is going offline concurrently with
execution of active_load_balance_cpu_stop, which can cause
__sched_core_flip to flip rq->core_enabled without rq lock held, which
can trigger lockdep_assert_rq_held() warnings.
This scenario possibly has other unwanted effects such as migrating
tasks to offline cpus, which may prevent their execution for a long
time until the cpu is brought back online.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Aaron Lu <aaron.lu@intel.com>
---
kernel/sched/fair.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 5f6587d94c1d..1c837ba41704 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8744,6 +8744,27 @@ static void attach_one_task(struct rq *rq, struct task_struct *p)
rq_unlock(rq, &rf);
}
+/*
+ * try_attach_one_task() -- attaches the task returned from detach_one_task() to
+ * its new rq if the rq is online. Returns false if the rq is not online.
+ */
+static bool try_attach_one_task(struct rq *rq, struct task_struct *p)
+{
+ struct rq_flags rf;
+ bool result = true;
+
+ rq_lock(rq, &rf);
+ if (!rq->online) {
+ result = false;
+ goto unlock;
+ }
+ update_rq_clock(rq);
+ attach_task(rq, p);
+unlock:
+ rq_unlock(rq, &rf);
+ return result;
+}
+
/*
* attach_tasks() -- attaches all tasks detached by detach_tasks() to their
* new rq.
@@ -11048,8 +11069,17 @@ static int active_load_balance_cpu_stop(void *data)
busiest_rq->active_balance = 0;
rq_unlock(busiest_rq, &rf);
- if (p)
- attach_one_task(target_rq, p);
+ if (p) {
+ if (!try_attach_one_task(target_rq, p)) {
+ /*
+ * target_rq was offlined concurrently. There is no
+ * guarantee that the busiest cpu is still online at
+ * this point. Fallback on using the CPU on which the
+ * stopper thread is running as target.
+ */
+ attach_one_task(this_rq(), p);
+ }
+ }
local_irq_enable();
--
2.25.1
next reply other threads:[~2023-04-19 15:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-19 15:50 Mathieu Desnoyers [this message]
2023-04-19 15:50 ` [RFC PATCH v9 2/2] sched: Fix performance regression introduced by mm_cid Mathieu Desnoyers
2023-04-20 9:56 ` Aaron Lu
2023-04-20 12:41 ` Mathieu Desnoyers
2023-04-20 12:50 ` Aaron Lu
2023-04-20 13:10 ` Mathieu Desnoyers
2023-04-20 13:35 ` Aaron Lu
2023-04-20 13:54 ` Mathieu Desnoyers
2023-04-20 14:18 ` Aaron Lu
2023-04-20 14:39 ` Aaron Lu
2023-04-20 14:41 ` Mathieu Desnoyers
2023-04-20 14:35 ` Mathieu Desnoyers
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=20230419155012.63901-1-mathieu.desnoyers@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=aaron.lu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®