Skip to content

Commit 9145eff

Browse files
npigginmpe
authored andcommitted
powerpc/64: Drop explicit hwsync in context switch
The sync (aka. hwsync, aka. heavyweight sync) in the context switch code to prevent MMIO access being reordered from the point of view of a single process if it gets migrated to a different CPU is not required because there is an hwsync performed earlier in the context switch path. Comment this so it's clear enough if anything changes on the scheduler or the powerpc sides. Remove the hwsync from _switch. This improves context switch performance by 2-3% on POWER8. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 837e72f commit 9145eff

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

‎arch/powerpc/include/asm/barrier.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ do { \
7474
___p1; \
7575
})
7676

77+
/*
78+
* This must resolve to hwsync on SMP for the context switch path.
79+
* See _switch, and core scheduler context switch memory ordering
80+
* comments.
81+
*/
7782
#define smp_mb__before_spinlock() smp_mb()
7883

7984
#include <asm-generic/barrier.h>

‎arch/powerpc/kernel/entry_64.S‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,24 @@ _GLOBAL(_switch)
512512
std r23,_CCR(r1)
513513
std r1,KSP(r3) /* Set old stack pointer */
514514

515-
#ifdef CONFIG_SMP
516-
/* We need a sync somewhere here to make sure that if the
517-
* previous task gets rescheduled on another CPU, it sees all
518-
* stores it has performed on this one.
515+
/*
516+
* On SMP kernels, care must be taken because a task may be
517+
* scheduled off CPUx and on to CPUy. Memory ordering must be
518+
* considered.
519+
*
520+
* Cacheable stores on CPUx will be visible when the task is
521+
* scheduled on CPUy by virtue of the core scheduler barriers
522+
* (see "Notes on Program-Order guarantees on SMP systems." in
523+
* kernel/sched/core.c).
524+
*
525+
* Uncacheable stores in the case of involuntary preemption must
526+
* be taken care of. The smp_mb__before_spin_lock() in __schedule()
527+
* is implemented as hwsync on powerpc, which orders MMIO too. So
528+
* long as there is an hwsync in the context switch path, it will
529+
* be executed on the source CPU after the task has performed
530+
* all MMIO ops on that CPU, and on the destination CPU before the
531+
* task performs any MMIO ops there.
519532
*/
520-
sync
521-
#endif /* CONFIG_SMP */
522533

523534
/*
524535
* The kernel context switch path must contain a spin_lock,

0 commit comments

Comments
 (0)