Skip to content

Commit 975707f

Browse files
author
Peter Zijlstra
committed
sched: Prepare to use balance_push in ttwu()
In preparation of using the balance_push state in ttwu() we need it to provide a reliable and consistent state. The immediate problem is that rq->balance_callback gets cleared every schedule() and then re-set in the balance_push_callback() itself. This is not a reliable signal, so add a variable that stays set during the entire time. Also move setting it before the synchronize_rcu() in sched_cpu_deactivate(), such that we get guaranteed visibility to ttwu(), which is a preempt-disable region. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Valentin Schneider <[email protected]> Tested-by: Valentin Schneider <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 640f17c commit 975707f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

kernel/sched/core.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7320,6 +7320,7 @@ static void balance_push_set(int cpu, bool on)
73207320
struct rq_flags rf;
73217321

73227322
rq_lock_irqsave(rq, &rf);
7323+
rq->balance_push = on;
73237324
if (on) {
73247325
WARN_ON_ONCE(rq->balance_callback);
73257326
rq->balance_callback = &balance_push_callback;
@@ -7489,17 +7490,17 @@ int sched_cpu_deactivate(unsigned int cpu)
74897490
int ret;
74907491

74917492
set_cpu_active(cpu, false);
7493+
balance_push_set(cpu, true);
7494+
74927495
/*
7493-
* We've cleared cpu_active_mask, wait for all preempt-disabled and RCU
7494-
* users of this state to go away such that all new such users will
7495-
* observe it.
7496+
* We've cleared cpu_active_mask / set balance_push, wait for all
7497+
* preempt-disabled and RCU users of this state to go away such that
7498+
* all new such users will observe it.
74967499
*
74977500
* Do sync before park smpboot threads to take care the rcu boost case.
74987501
*/
74997502
synchronize_rcu();
75007503

7501-
balance_push_set(cpu, true);
7502-
75037504
rq_lock_irqsave(rq, &rf);
75047505
if (rq->rd) {
75057506
update_rq_clock(rq);

kernel/sched/sched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ struct rq {
975975
unsigned long cpu_capacity_orig;
976976

977977
struct callback_head *balance_callback;
978+
unsigned char balance_push;
978979

979980
unsigned char nohz_idle_balance;
980981
unsigned char idle_balance;

0 commit comments

Comments
 (0)