Skip to content

Commit b75a225

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched/core: Better document the try_to_wake_up() barriers
Explain how the control dependency and smp_rmb() end up providing ACQUIRE semantics and pair with smp_store_release() in finish_lock_switch(). Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mike Galbraith <efault@gmx.de> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 2541117 commit b75a225

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

kernel/sched/core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,13 @@ try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
19531953
while (p->on_cpu)
19541954
cpu_relax();
19551955
/*
1956-
* Pairs with the smp_wmb() in finish_lock_switch().
1956+
* Combined with the control dependency above, we have an effective
1957+
* smp_load_acquire() without the need for full barriers.
1958+
*
1959+
* Pairs with the smp_store_release() in finish_lock_switch().
1960+
*
1961+
* This ensures that tasks getting woken will be fully ordered against
1962+
* their previous state and preserve Program Order.
19571963
*/
19581964
smp_rmb();
19591965

kernel/sched/sched.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,9 @@ static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
10731073
* We must ensure this doesn't happen until the switch is completely
10741074
* finished.
10751075
*
1076+
* In particular, the load of prev->state in finish_task_switch() must
1077+
* happen before this.
1078+
*
10761079
* Pairs with the control dependency and rmb in try_to_wake_up().
10771080
*/
10781081
smp_store_release(&prev->on_cpu, 0);

0 commit comments

Comments
 (0)