x86/tlb: replace INVALIDATE_TLB_VECTOR by CALL_FUNCTION_VECTOR
PATCH 1/1 x86/tlb: replace INVALIDATE_TLB_VECTOR by CALL_FUNCTION_VECTOR
There are only 32 INVALIDATE_TLB_VECTOR now in kernel. but modern x86 sever has more cpu number. That causes lock contention in TLB flushing.
Now, useing generic smp call function to replace it.
In the NHM EX machine 4P * 8cores * HT = 64 CPUs, hackbench pthread has 3% performance increase.
And no clear performance changes on NHM EP(16CPUs), WSM EP(23CPU) and SNB EP(32CPU) machines.
This patch is base on my tlb flush range support patchset.
--- arch/x86/include/asm/entry_arch.h | 9 -- arch/x86/include/asm/irq_vectors.h | 11 -- arch/x86/kernel/entry_64.S | 18 --- arch/x86/kernel/irqinit.c | 73 ----------- arch/x86/mm/tlb.c | 234 +++++------------------------------- 5 files changed, 32 insertions(+), 313 deletions(-)
arch/x86/include/asm/entry_arch.h +0 -9
@@ -15,15 +15,6 @@ BUILD_INTERRUPT(call_function_interrupt,CALL_FUNCTION_VECTOR) BUILD_INTERRUPT(call_function_single_interrupt,CALL_FUNCTION_SINGLE_VECTOR) BUILD_INTERRUPT(irq_move_cleanup_interrupt,IRQ_MOVE_CLEANUP_VECTOR) BUILD_INTERRUPT(reboot_interrupt,REBOOT_VECTOR) - -.irp idx,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, \ -16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29 ,30 ,31 -.if NUM_INVALIDATE_TLB_VECTORS > \idx -BUILD_INTERRUPT3(invalidate_interrupt\idx, - (INVALIDATE_TLB_VECTOR_START)+\idx, - smp_invalidate_interrupt) -.endif -.endr#endif BUILD_INTERRUPT (x86_platform_ipi,X86_PLATFORM_IPI_VECTOR )
arch/x86/include/asm/irq_vectors.h +0 -11
@@ -119,17 +119,6 @@*/ #define LOCAL_TIMER_VECTOR 0xef -/* up to 32 vectors used for spreading out TLB flushes: */ -#if NR_CPUS <=32 -# define NUM_INVALIDATE_TLB_VECTORS (NR_CPUS) -#else -# define NUM_INVALIDATE_TLB_VECTORS (32) -#endif - -#define INVALIDATE_TLB_VECTOR_END (0xee) -#define INVALIDATE_TLB_VECTOR_START \ - (INVALIDATE_TLB_VECTOR_END-NUM_INVALIDATE_TLB_VECTORS+1) -#define NR_VECTORS 256#define FPU_IRQ 13
arch/x86/kernel/entry_64.S +0 -18
@@ -1015,24 +1015,6 @@ apicinterrupt LOCAL_TIMER_VECTOR \ apicinterrupt X86_PLATFORM_IPI_VECTOR \ x86_platform_ipi smp_x86_platform_ipi -#ifdef CONFIG_SMP - ALIGN - INTR_FRAME -.irp idx,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, \ - 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 -.if NUM_INVALIDATE_TLB_VECTORS > \idx -ENTRY(invalidate_interrupt\idx) - pushq_cfi $~(INVALIDATE_TLB_VECTOR_START+\idx) - jmp .Lcommon_invalidate_interrupt0 - CFI_ADJUST_CFA_OFFSET -8 -END(invalidate_interrupt\idx) -.endif -.endr - CFI_ENDPROC -apicinterrupt INVALIDATE_TLB_VECTOR_START, \ - invalidate_interrupt0, smp_invalidate_interrupt -#endif - apicinterrupt THRESHOLD_APIC_VECTOR \ threshold_interrupt smp_threshold_interrupt apicinterrupt THERMAL_APIC_VECTOR \
arch/x86/kernel/irqinit.c +0 -73
79 lines not on this page · raw message
arch/x86/mm/tlb.c +34 -204
276 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Quoted 10 lines · Alex Shi
There are only 32
INVALIDATE_TLB_VECTORnow in kernel. but modern x86 sever has more cpu number. That causes lock contention in TLB flushing.Now, useing generic smp call function to replace it.
In the NHM EX machine 4P * 8cores * HT = 64 CPUs, hackbench pthread has 3% performance increase.
And no clear performance changes on NHM EP(16CPUs), WSM EP(23CPU) and SNB EP(32CPU) machines.
Quoted 3 lines
This patch is base on my tlb flush range support patchset.
Signed-off-by Alex Shi <[email protected]>
refresh this patch will more clean up, and cc to PeterZ.
Actually, I tried to keep flush_tlb_info into dedicated cache line, but did find clear help.
Comments are appreciated!
---
Quoted 1 line
From
5be7aa1b69143bf5e8f3feeac862fa9559c2cf02Mon Sep 17 00:00:00 2001
From: Alex Shi <[email protected]>
Date: Sat, 19 May 2012 04:35:15 +0800
Subject: [PATCH 8/8] x86/tlb: replace INVALIDATE_TLB_VECTOR by
CALL_FUNCTION_VECTOR
There are only 32 INVALIDATE_TLB_VECTOR now in kernel. but modern x86 sever has more cpu number. That causes lock contention in TLB flushing.
Now, useing generic smp call function to replace it.
In the NHM EX machine 4P * 8cores * HT = 64 CPUs, hackbench pthread has 3% performance increase.
And no clear performance changes on NHM EP(16CPUs), WSM EP(23CPU) and SNB EP(32CPU) machines.
This patch is base on my tlb flush range support patchset.
--- arch/x86/include/asm/entry_arch.h | 9 -- arch/x86/include/asm/hw_irq.h | 39 ------ arch/x86/include/asm/irq_vectors.h | 14 +-- arch/x86/kernel/entry_64.S | 18 --- arch/x86/kernel/irqinit.c | 73 ----------- arch/x86/mm/tlb.c | 244 +++++------------------------------- 6 files changed, 33 insertions(+), 364 deletions(-)
arch/x86/include/asm/entry_arch.h +0 -9
@@ -15,15 +15,6 @@ BUILD_INTERRUPT(call_function_interrupt,CALL_FUNCTION_VECTOR) BUILD_INTERRUPT(call_function_single_interrupt,CALL_FUNCTION_SINGLE_VECTOR) BUILD_INTERRUPT(irq_move_cleanup_interrupt,IRQ_MOVE_CLEANUP_VECTOR) BUILD_INTERRUPT(reboot_interrupt,REBOOT_VECTOR) - -.irp idx,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, \ -16 ,17 ,18 ,19 ,20 ,21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29 ,30 ,31 -.if NUM_INVALIDATE_TLB_VECTORS > \idx -BUILD_INTERRUPT3(invalidate_interrupt\idx, - (INVALIDATE_TLB_VECTOR_START)+\idx, - smp_invalidate_interrupt) -.endif -.endr#endif BUILD_INTERRUPT (x86_platform_ipi,X86_PLATFORM_IPI_VECTOR )
arch/x86/include/asm/hw_irq.h +0 -39
@@ -35,40 +35,6 @@ extern void spurious_interrupt(void);extern void thermal_interrupt (void );extern void reschedule_interrupt (void ); -extern void invalidate_interrupt (void ); -extern void invalidate_interrupt0 (void ); -extern void invalidate_interrupt1 (void ); -extern void invalidate_interrupt2 (void ); -extern void invalidate_interrupt3 (void ); -extern void invalidate_interrupt4 (void ); -extern void invalidate_interrupt5 (void ); -extern void invalidate_interrupt6 (void ); -extern void invalidate_interrupt7 (void ); -extern void invalidate_interrupt8 (void ); -extern void invalidate_interrupt9 (void ); -extern void invalidate_interrupt10 (void ); -extern void invalidate_interrupt11 (void ); -extern void invalidate_interrupt12 (void ); -extern void invalidate_interrupt13 (void ); -extern void invalidate_interrupt14 (void ); -extern void invalidate_interrupt15 (void ); -extern void invalidate_interrupt16 (void ); -extern void invalidate_interrupt17 (void ); -extern void invalidate_interrupt18 (void ); -extern void invalidate_interrupt19 (void ); -extern void invalidate_interrupt20 (void ); -extern void invalidate_interrupt21 (void ); -extern void invalidate_interrupt22 (void ); -extern void invalidate_interrupt23 (void ); -extern void invalidate_interrupt24 (void ); -extern void invalidate_interrupt25 (void ); -extern void invalidate_interrupt26 (void ); -extern void invalidate_interrupt27 (void ); -extern void invalidate_interrupt28 (void ); -extern void invalidate_interrupt29 (void ); -extern void invalidate_interrupt30 (void ); -extern void invalidate_interrupt31 (void ); -extern void irq_move_cleanup_interrupt (void );extern void reboot_interrupt (void );extern void threshold_interrupt (void );
@@ -154,11 +120,6 @@ extern asmlinkage void smp_irq_move_cleanup_interrupt(void);extern void smp_reschedule_interrupt (struct pt_regs *);extern void smp_call_function_interrupt (struct pt_regs *);extern void smp_call_function_single_interrupt (struct pt_regs *); -#ifdef CONFIG_X86_32 -extern void smp_invalidate_interrupt (struct pt_regs *); -#else -extern asmlinkage void smp_invalidate_interrupt(struct pt_regs *); -#endif #endif extern void (*__initconst interrupt[NR_VECTORS -FIRST_EXTERNAL_VECTOR ])(void );
arch/x86/include/asm/irq_vectors.h +1 -13
@@ -17,8 +17,7 @@* Vectors 0 ... 31 : system traps and exceptions - hardcoded events * Vectors 32 ... 127 : device interrupts * Vector 128 : legacy int80 syscall interface -* Vectors 129 ... INVALIDATE_TLB_VECTOR_START-1 except 204 : device interrupts -* Vectors INVALIDATE_TLB_VECTOR_START ... 255 : special interrupts +* Vectors 129 ... 206 except 204 : device interrupts * * 64-bit x86 has per CPU IDT tables, 32-bit has one shared IDT table. *
@@ -119,17 +118,6 @@*/ #define LOCAL_TIMER_VECTOR 0xef -/* up to 32 vectors used for spreading out TLB flushes: */ -#if NR_CPUS <=32 -# define NUM_INVALIDATE_TLB_VECTORS (NR_CPUS) -#else -# define NUM_INVALIDATE_TLB_VECTORS (32) -#endif - -#define INVALIDATE_TLB_VECTOR_END (0xee) -#define INVALIDATE_TLB_VECTOR_START \ - (INVALIDATE_TLB_VECTOR_END-NUM_INVALIDATE_TLB_VECTORS+1) -#define NR_VECTORS 256#define FPU_IRQ 13
arch/x86/kernel/entry_64.S +0 -18
@@ -1015,24 +1015,6 @@ apicinterrupt LOCAL_TIMER_VECTOR \ apicinterrupt X86_PLATFORM_IPI_VECTOR \ x86_platform_ipi smp_x86_platform_ipi -#ifdef CONFIG_SMP - ALIGN - INTR_FRAME -.irp idx,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, \ - 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 -.if NUM_INVALIDATE_TLB_VECTORS > \idx -ENTRY(invalidate_interrupt\idx) - pushq_cfi $~(INVALIDATE_TLB_VECTOR_START+\idx) - jmp .Lcommon_invalidate_interrupt0 - CFI_ADJUST_CFA_OFFSET -8 -END(invalidate_interrupt\idx) -.endif -.endr - CFI_ENDPROC -apicinterrupt INVALIDATE_TLB_VECTOR_START, \ - invalidate_interrupt0, smp_invalidate_interrupt -#endif - apicinterrupt THRESHOLD_APIC_VECTOR \ threshold_interrupt smp_threshold_interrupt apicinterrupt THERMAL_APIC_VECTOR \
arch/x86/kernel/irqinit.c +0 -73
79 lines not on this page · raw message
arch/x86/mm/tlb.c +34 -214
286 lines not on this page · raw message
Signature · 1 line
1.7.5.4
Quoted 12 lines · Alex Shi
Quoted 10 lines · Alex Shi
There are only 32
INVALIDATE_TLB_VECTORnow in kernel. but modern x86 sever has more cpu number. That causes lock contention in TLB flushing.Now, useing generic smp call function to replace it.
In the NHM EX machine 4P * 8cores * HT = 64 CPUs, hackbench pthread has 3% performance increase.
And no clear performance changes on NHM EP(16CPUs), WSM EP(23CPU) and SNB EP(32CPU) machines.
Quoted 8 lines
Quoted 3 lines
This patch is base on my tlb flush range support patchset.
Signed-off-by Alex Shi <[email protected]>refresh this patch will more clean up, and cc to PeterZ.
Actually, I tried to keepflush_tlb_infointo dedicated cache line, but did find clear help.
Correct: I did _not_ find clear help for dedicated cache line for flush_tlb_info.
Quoted 3 lines
Comments are appreciated!
Any comments for this patch?
Peter Zijlstra
maintainerQuoted 31 lines · Alex Shi
/*
- *
- * The flush IPI assumes that a thread switch happens in this order:
- * [cpu0: the cpu that switches]
- * 1)switch_mm()either 1a) or 1b)
- * 1a) thread switch to a different mm
- * 1a1)cpu_clear(cpu, old_mm->cpu_vm_mask);- * Stop ipi delivery for the old mm. This is not synchronized with - * the other cpus, but smp_invalidate_interrupt ignore flush ipis - * for the wrong mm, and in the worst case we perform a superfluous - * tlb flush.- * 1a2) set cpu
mmu_statetoTLBSTATE_OK
- * Now thesmp_invalidate_interruptwon't callleave_mmif cpu0
- * was in lazy tlb mode.
- * 1a3) update cpuactive_mm
- * Now cpu0 accepts tlb flushes for the new mm.
- * 1a4)cpu_set(cpu, new_mm->cpu_vm_mask);
- * Now the other cpus will send tlb flush ipis.
- * 1a4) change cr3.
- * 1b) thread switch without mm change
- * cpuactive_mmis correct, cpu0 already handles
- * flush ipis.
- * 1b1) set cpummu_statetoTLBSTATE_OK
- * 1b2)test_and_setthe cpu bit incpu_vm_mask.
- * Atomically set the bit [other cpus will start sending flush ipis],
- * and test the bit.
- * 1b3) if the bit was 0:leave_mmwas called, flush the tlb.
- * 2) switch %%esp, ie current
- *
- * The interrupt must handle 2 special cases:
Quoted 8 lines
- * - cr3 is changed before %%esp, ie. it cannot use current->{active_,}mm.
- * - the cpu performs speculative tlb reads, i.e. even if the cpu only
- * runs in kernel space, the cpu could load tlb entries for user space
- * pages.
- *
- * The good news is that cpummu_stateis local to each cpu, no
- * write/read ordering problems.
- */
It would be nice to update that comment instead of removing it.
Quoted 41 lines · Peter Zijlstra
Quoted 31 lines · Alex Shi
/*
- *
- * The flush IPI assumes that a thread switch happens in this order:
- * [cpu0: the cpu that switches]
- * 1)switch_mm()either 1a) or 1b)
- * 1a) thread switch to a different mm
- * 1a1)cpu_clear(cpu, old_mm->cpu_vm_mask);- * Stop ipi delivery for the old mm. This is not synchronized with - * the other cpus, but smp_invalidate_interrupt ignore flush ipis - * for the wrong mm, and in the worst case we perform a superfluous - * tlb flush.- * 1a2) set cpu
mmu_statetoTLBSTATE_OK
- * Now thesmp_invalidate_interruptwon't callleave_mmif cpu0
- * was in lazy tlb mode.
- * 1a3) update cpuactive_mm
- * Now cpu0 accepts tlb flushes for the new mm.
- * 1a4)cpu_set(cpu, new_mm->cpu_vm_mask);
- * Now the other cpus will send tlb flush ipis.
- * 1a4) change cr3.
- * 1b) thread switch without mm change
- * cpuactive_mmis correct, cpu0 already handles
- * flush ipis.
- * 1b1) set cpummu_statetoTLBSTATE_OK
- * 1b2)test_and_setthe cpu bit incpu_vm_mask.
- * Atomically set the bit [other cpus will start sending flush ipis],
- * and test the bit.
- * 1b3) if the bit was 0:leave_mmwas called, flush the tlb.
- * 2) switch %%esp, ie current
- *
- * The interrupt must handle 2 special cases:Quoted 8 lines
- * - cr3 is changed before %%esp, ie. it cannot use current->{active_,}mm.
- * - the cpu performs speculative tlb reads, i.e. even if the cpu only
- * runs in kernel space, the cpu could load tlb entries for user space
- * pages.
- *
- * The good news is that cpummu_stateis local to each cpu, no
- * write/read ordering problems.
- */
Quoted 2 lines
It would be nice to update that comment instead of removing it.
How about the following new comments? I changed them to match latest switch_mm and tlbflush code.
but as to the 'The interrupt must handle 2 special cases' section, I am wondering if it should be kept, since current tlb flush IPI handler don't need %%esp at all.
Comments welcome!
-------
/*
* The flush IPI assumes that a thread switch happens in this order:
* [cpu0: the cpu that switches]
* 1) switch_mm() either 1a) or 1b)
* 1a) thread switch to a different mm
* 1a1) set cpu_tlbstate to TLBSTATE_OK
* Now the tlb flush IPI handler flush_tlb_func won't call leave_mm
* if cpu0 was in lazy tlb mode.
* 1a2) update cpu active_mm
* Now cpu0 accepts tlb flushes for the new mm.
* 1a3) cpu_set(cpu, new_mm->cpu_vm_mask);
* Now the other cpus will send tlb flush ipis.
* 1a4) change cr3.
* 1a5) cpu_clear(cpu, old_mm->cpu_vm_mask);
* Stop ipi delivery for the old mm. This is not synchronized with
* the other cpus, but flush_tlb_func ignore flush ipis for the wrong
* mm, and in the worst case we perform a superfluous tlb flush.
* 1b) thread switch without mm change
* cpu active_mm is correct, cpu0 already handles
* flush ipis.
* 1b1) set cpu_tlbstate to TLBSTATE_OK
* 1b2) test_and_set the cpu bit in cpu_vm_mask.
* Atomically set the bit [other cpus will start sending flush ipis],
* and test the bit.
* 1b3) if the bit was 0: leave_mm was called, flush the tlb.
* 2) switch %%esp, ie current
*
* The interrupt must handle 2 special cases:
* - cr3 is changed before %%esp, ie. it cannot use current->{active_,}mm.
* - the cpu performs speculative tlb reads, i.e. even if the cpu only
* runs in kernel space, the cpu could load tlb entries for user space
* pages.
*
* The good news is that cpu_tlbstate is local to each cpu, no
* write/read ordering problems.
*/
Quoted 10 lines
How about the following new comments? I changed them to match latest
switch_mmand tlbflush code.
but as to the 'The interrupt must handle 2 special cases' section, I am wondering if it should be kept, since current tlb flush IPI handler don't need %%esp at all.Comments welcome!
If no further comments here, I am going to use the following comments. Actually, all of them are useful for full view of code.
I will refresh whole patcheset on 3.5-rc1 kernel. Thanks!
Quoted 41 lines
-------
/*
* The flush IPI assumes that a thread switch happens in this order:
* [cpu0: the cpu that switches]
* 1)switch_mm()either 1a) or 1b)
* 1a) thread switch to a different mm
* 1a1) setcpu_tlbstatetoTLBSTATE_OK
* Now the tlb flush IPI handlerflush_tlb_funcwon't callleave_mm
* if cpu0 was in lazy tlb mode.
* 1a2) update cpuactive_mm
* Now cpu0 accepts tlb flushes for the new mm.
* 1a3)cpu_set(cpu, new_mm->cpu_vm_mask);
* Now the other cpus will send tlb flush ipis.
* 1a4) change cr3.
* 1a5)cpu_clear(cpu, old_mm->cpu_vm_mask);
* Stop ipi delivery for the old mm. This is not synchronized with
* the other cpus, butflush_tlb_funcignore flush ipis for the wrong
* mm, and in the worst case we perform a superfluous tlb flush.
* 1b) thread switch without mm change
* cpuactive_mmis correct, cpu0 already handles
* flush ipis.
* 1b1) setcpu_tlbstatetoTLBSTATE_OK
* 1b2)test_and_setthe cpu bit incpu_vm_mask.
* Atomically set the bit [other cpus will start sending flush ipis],
* and test the bit.
* 1b3) if the bit was 0:leave_mmwas called, flush the tlb.
* 2) switch %%esp, ie current
*
* The interrupt must handle 2 special cases:
* - cr3 is changed before %%esp, ie. it cannot use current->{active_,}mm.
* - the cpu performs speculative tlb reads, i.e. even if the cpu only
* runs in kernel space, the cpu could load tlb entries for user space
* pages.
*
* The good news is thatcpu_tlbstateis local to each cpu, no
* write/read ordering problems.
*/