Skip to content

Commit 0be32b8

Browse files
andrea-parriopsiff
authored andcommitted
membarrier: Create Documentation/scheduler/membarrier.rst
mainline inclusion from mainline-v6.9-rc1 link:deepin-community#398 To gather the architecture requirements of the "private/global expedited" membarrier commands. The file will be expanded to integrate further information about the membarrier syscall (as needed/desired in the future). While at it, amend some related inline comments in the membarrier codebase. Suggested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Andrea Parri <parri.andrea@gmail.com> Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Link: https://lore.kernel.org/r/20240131144936.29190-3-parri.andrea@gmail.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com> (cherry picked from commit a14d11a) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 4641560 commit 0be32b8

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

Documentation/scheduler/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Scheduler
77

88

99
completion
10+
membarrier
1011
sched-arch
1112
sched-bwc
1213
sched-deadline
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
========================
4+
membarrier() System Call
5+
========================
6+
7+
MEMBARRIER_CMD_{PRIVATE,GLOBAL}_EXPEDITED - Architecture requirements
8+
=====================================================================
9+
10+
Memory barriers before updating rq->curr
11+
----------------------------------------
12+
13+
The commands MEMBARRIER_CMD_PRIVATE_EXPEDITED and MEMBARRIER_CMD_GLOBAL_EXPEDITED
14+
require each architecture to have a full memory barrier after coming from
15+
user-space, before updating rq->curr. This barrier is implied by the sequence
16+
rq_lock(); smp_mb__after_spinlock() in __schedule(). The barrier matches a full
17+
barrier in the proximity of the membarrier system call exit, cf.
18+
membarrier_{private,global}_expedited().
19+
20+
Memory barriers after updating rq->curr
21+
---------------------------------------
22+
23+
The commands MEMBARRIER_CMD_PRIVATE_EXPEDITED and MEMBARRIER_CMD_GLOBAL_EXPEDITED
24+
require each architecture to have a full memory barrier after updating rq->curr,
25+
before returning to user-space. The schemes providing this barrier on the various
26+
architectures are as follows.
27+
28+
- alpha, arc, arm, hexagon, mips rely on the full barrier implied by
29+
spin_unlock() in finish_lock_switch().
30+
31+
- arm64 relies on the full barrier implied by switch_to().
32+
33+
- powerpc, riscv, s390, sparc, x86 rely on the full barrier implied by
34+
switch_mm(), if mm is not NULL; they rely on the full barrier implied
35+
by mmdrop(), otherwise. On powerpc and riscv, switch_mm() relies on
36+
membarrier_arch_switch_mm().
37+
38+
The barrier matches a full barrier in the proximity of the membarrier system call
39+
entry, cf. membarrier_{private,global}_expedited().

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13733,6 +13733,7 @@ M: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
1373313733
M: "Paul E. McKenney" <paulmck@kernel.org>
1373413734
L: linux-kernel@vger.kernel.org
1373513735
S: Supported
13736+
F: Documentation/scheduler/membarrier.rst
1373613737
F: arch/*/include/asm/membarrier.h
1373713738
F: include/uapi/linux/membarrier.h
1373813739
F: kernel/sched/membarrier.c

kernel/sched/core.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6609,7 +6609,9 @@ static void __sched notrace __schedule(unsigned int sched_mode)
66096609
* if (signal_pending_state()) if (p->state & @state)
66106610
*
66116611
* Also, the membarrier system call requires a full memory barrier
6612-
* after coming from user-space, before storing to rq->curr.
6612+
* after coming from user-space, before storing to rq->curr; this
6613+
* barrier matches a full barrier in the proximity of the membarrier
6614+
* system call exit.
66136615
*/
66146616
rq_lock(rq, &rf);
66156617
smp_mb__after_spinlock();
@@ -6687,6 +6689,9 @@ static void __sched notrace __schedule(unsigned int sched_mode)
66876689
* architectures where spin_unlock is a full barrier,
66886690
* - switch_to() for arm64 (weakly-ordered, spin_unlock
66896691
* is a RELEASE barrier),
6692+
*
6693+
* The barrier matches a full barrier in the proximity of
6694+
* the membarrier system call entry.
66906695
*/
66916696
++*switch_count;
66926697

kernel/sched/membarrier.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static int membarrier_global_expedited(void)
254254
return 0;
255255

256256
/*
257-
* Matches memory barriers around rq->curr modification in
257+
* Matches memory barriers after rq->curr modification in
258258
* scheduler.
259259
*/
260260
smp_mb(); /* system call entry is not a mb. */
@@ -304,7 +304,7 @@ static int membarrier_global_expedited(void)
304304

305305
/*
306306
* Memory barrier on the caller thread _after_ we finished
307-
* waiting for the last IPI. Matches memory barriers around
307+
* waiting for the last IPI. Matches memory barriers before
308308
* rq->curr modification in scheduler.
309309
*/
310310
smp_mb(); /* exit from system call is not a mb */
@@ -343,7 +343,7 @@ static int membarrier_private_expedited(int flags, int cpu_id)
343343
return 0;
344344

345345
/*
346-
* Matches memory barriers around rq->curr modification in
346+
* Matches memory barriers after rq->curr modification in
347347
* scheduler.
348348
*/
349349
smp_mb(); /* system call entry is not a mb. */
@@ -420,7 +420,7 @@ static int membarrier_private_expedited(int flags, int cpu_id)
420420

421421
/*
422422
* Memory barrier on the caller thread _after_ we finished
423-
* waiting for the last IPI. Matches memory barriers around
423+
* waiting for the last IPI. Matches memory barriers before
424424
* rq->curr modification in scheduler.
425425
*/
426426
smp_mb(); /* exit from system call is not a mb */

0 commit comments

Comments
 (0)