[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <162081530576.29796.15435912336745931501.tip-bot2@tip-bot2>
Date: Wed, 12 May 2021 10:28:25 -0000
From: "tip-bot2 for Peter Zijlstra" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: "Peter Zijlstra (Intel)" <peterz@...radead.org>,
Don Hiatt <dhiatt@...italocean.com>,
Hongyu Ning <hongyu.ning@...ux.intel.com>,
Vincent Guittot <vincent.guittot@...aro.org>, x86@...nel.org,
linux-kernel@...r.kernel.org
Subject: [tip: sched/core] sched: Allow sched_core_put() from atomic context
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 875feb41fd20f6bd6054c9e79a5bcd9da6d8d2b2
Gitweb: https://git.kernel.org/tip/875feb41fd20f6bd6054c9e79a5bcd9da6d8d2b2
Author: Peter Zijlstra <peterz@...radead.org>
AuthorDate: Mon, 29 Mar 2021 10:08:58 +02:00
Committer: Peter Zijlstra <peterz@...radead.org>
CommitterDate: Wed, 12 May 2021 11:43:27 +02:00
sched: Allow sched_core_put() from atomic context
Stuff the meat of sched_core_put() into a work such that we can use
sched_core_put() from atomic context.
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Tested-by: Don Hiatt <dhiatt@...italocean.com>
Tested-by: Hongyu Ning <hongyu.ning@...ux.intel.com>
Tested-by: Vincent Guittot <vincent.guittot@...aro.org>
Link: https://lkml.kernel.org/r/20210422123308.377455632@infradead.org
---
kernel/sched/core.c | 33 +++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 42c1c88..85147be 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -102,7 +102,7 @@ DEFINE_STATIC_KEY_FALSE(__sched_core_enabled);
*/
static DEFINE_MUTEX(sched_core_mutex);
-static int sched_core_count;
+static atomic_t sched_core_count;
static struct cpumask sched_core_mask;
static void __sched_core_flip(bool enabled)
@@ -170,18 +170,39 @@ static void __sched_core_disable(void)
void sched_core_get(void)
{
+ if (atomic_inc_not_zero(&sched_core_count))
+ return;
+
mutex_lock(&sched_core_mutex);
- if (!sched_core_count++)
+ if (!atomic_read(&sched_core_count))
__sched_core_enable();
+
+ smp_mb__before_atomic();
+ atomic_inc(&sched_core_count);
mutex_unlock(&sched_core_mutex);
}
-void sched_core_put(void)
+static void __sched_core_put(struct work_struct *work)
{
- mutex_lock(&sched_core_mutex);
- if (!--sched_core_count)
+ if (atomic_dec_and_mutex_lock(&sched_core_count, &sched_core_mutex)) {
__sched_core_disable();
- mutex_unlock(&sched_core_mutex);
+ mutex_unlock(&sched_core_mutex);
+ }
+}
+
+void sched_core_put(void)
+{
+ static DECLARE_WORK(_work, __sched_core_put);
+
+ /*
+ * "There can be only one"
+ *
+ * Either this is the last one, or we don't actually need to do any
+ * 'work'. If it is the last *again*, we rely on
+ * WORK_STRUCT_PENDING_BIT.
+ */
+ if (!atomic_add_unless(&sched_core_count, -1, 1))
+ schedule_work(&_work);
}
#endif /* CONFIG_SCHED_CORE */
Powered by blists - more mailing lists