powerpc: During context switch, check before setting mm_cpumask
authorAnton Blanchard <anton@samba.org>
Mon, 3 Oct 2016 06:40:29 +0000 (17:40 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 4 Oct 2016 05:12:16 +0000 (16:12 +1100)
During context switch, switch_mm() sets our current CPU in mm_cpumask.
We can avoid this atomic sequence in most cases by checking before
setting the bit.

Testing on a POWER8 using our context switch microbenchmark:

tools/testing/selftests/powerpc/benchmarks/context_switch \
--process --no-fp --no-altivec --no-vector

Performance improves 2%.

Signed-off-by: Anton Blanchard <anton@samba.org>
Acked-by: Balbir Singh <bsingharora@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/mmu_context.h

index 475d1be391916e8dffffb0fc7c93c4df1d29b690..5c451140660a91b3abc7130040685cea8e3db62d 100644 (file)
@@ -72,7 +72,8 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
                             struct task_struct *tsk)
 {
        /* Mark this context has been used on the new CPU */
-       cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
+       if (!cpumask_test_cpu(smp_processor_id(), mm_cpumask(next)))
+               cpumask_set_cpu(smp_processor_id(), mm_cpumask(next));
 
        /* 32-bit keeps track of the current PGDIR in the thread struct */
 #ifdef CONFIG_PPC32