mirror of
https://github.com/torvalds/linux.git
synced 2026-10-07 05:31:08 -04: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) <[email protected]> Tested-by: Don Hiatt <[email protected]> Tested-by: Hongyu Ning <[email protected]> Tested-by: Vincent Guittot <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
This commit is contained in:
1 parent
9ef7e7e33b
commit
875feb41fd
1 file changed
+27
-6
+27
-6
@@ -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);
|
||||
}
|
||||
|
||||
static void __sched_core_put(struct work_struct *work)
|
||||
{
|
||||
if (atomic_dec_and_mutex_lock(&sched_core_count, &sched_core_mutex)) {
|
||||
__sched_core_disable();
|
||||
mutex_unlock(&sched_core_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
void sched_core_put(void)
|
||||
{
|
||||
mutex_lock(&sched_core_mutex);
|
||||
if (!--sched_core_count)
|
||||
__sched_core_disable();
|
||||
mutex_unlock(&sched_core_mutex);
|
||||
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 */
|
||||
|
||||
Reference in new issue
Block a user