use x86 cpu park to speedup smp_init in kexec situation
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 11 lines · Thomas Gleixner
Quoted 7 lines · Thomas Gleixner
On Thu, Feb 11 2021 at 22:58, David Woodhouse wrote:
I have no problem with making that jump based. It does not matter at all. But you can't use the idle task stack before the CR3 switch insecondary_startup_64- unless I'm missing something.And there's more than 'call
verify_cpu' on the way which uses stack. Let me stare more tomorrow with brain awake.The below boots on top of mainline. It probably breaks i386 and XEN and whatever :)
Nice. As discussed on IRC, you'll need more than 0xFFFF for APIC IDs but I think you can probably get away with 0xFFFFF for physical APIC ID since nothing more than that can fit in 32 bits of *logical* X2APIC ID.
Quoted 2 lines
I didn't come around to play with your patches yet and won't be able to do so before next week.
I threw it into my tree at
https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/parallel
It seems to work fairly nicely. The parallel SIPI seems to win be about a third of the bringup time on my 28-thread Haswell box. This is at the penultimate commit of the above branch:
[ 0.307590] smp: Bringing up secondary CPUs ... [ 0.307826] x86: Booting SMP configuration: [ 0.307830] .... node #0, CPUs: #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 [ 0.376677] MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details. [ 0.377177] #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 [ 0.402323] Brought CPUs online in 246691584 cycles [ 0.402323] smp: Brought up 1 node, 28 CPUs
... and this is the tip of the branch:
[ 0.308332] smp: Bringing up secondary CPUs ...<dwmw2_gone> [ 0.308569] x86: Booting SMP configuration: [ 0.308572] .... node #0, CPUs: #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 [ 0.321120] Brought 28 CPUs to x86/cpu:kick in 34828752 cycles [ 0.366663] MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details. [ 0.368749] Brought CPUs online in 124913032 cycles [ 0.368749] smp: Brought up 1 node, 28 CPUs [ 0.368749] smpboot: Max logical packages: 1 [ 0.368749] smpboot: Total of 28 processors activated (145259.85 BogoMIPS)
There's more to be gained here if we can fix up the next stage. Right now if I set every CPU's bit in cpu_initialized_mask to allow them to proceed from wait_for_master_cpu() through to the end of cpu_init() and onwards through start_secondary(), they all end up hitting check_tsc_sync_target() in parallel and it goes horridly wrong.
A simple answer might be to have another synchronisation point right before the TSC sync, to force them to do it one at a time but *without* having to wait for the rest of the AP bringup in series.
Other answers include inventing a magical parallel TSC sync algorithm that isn't 1-to-1 between the BSP and each AP. Or observing that we're running in KVM or after kexec, and we *know* they're in sync anyway and bypassing the whole bloody nonsense.
Recall, my initial debug patch timing the four stages of the bringup, which I've left in my branch above for visibility, was showing this kind of output with the original serial bringup...
Quoted 6 lines
[ 0.285312] CPU#10 up in 192950, 952898, 60014786, 28 ( 61160662) [ 0.288311] CPU#11 up in 181092, 962704, 60010432, 30 ( 61154258) [ 0.291312] CPU#12 up in 386080, 970416, 60013956, 28 ( 61370480) [ 0.294311] CPU#13 up in 372782, 964506, 60010564, 28 ( 61347880) [ 0.297312] CPU#14 up in 389602, 976280, 60013046, 28 ( 61378956) [ 0.300312] CPU#15 up in 213132, 968148, 60012138, 28 ( 61193446)
So that's almost a million cycles per CPU of do_wait_cpu_callin() before we get to the TSC sync (which is insanely expensive on KVM). It's something like three times the time taken by the SIPI+wait in the first phase, which is what we've parallelised so far (at a gain of about 33%).
Quoted 265 lines
--- arch/x86/include/asm/realmode.h | 3 + arch/x86/include/asm/smp.h | 9 +++- arch/x86/kernel/acpi/sleep.c | 1 arch/x86/kernel/apic/apic.c | 2 arch/x86/kernel/head_64.S | 71 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/smpboot.c | 19 ++++++++- arch/x86/realmode/init.c | 3 + arch/x86/realmode/rm/trampoline_64.S | 14 ++++++ kernel/smpboot.c | 2 9 files changed, 119 insertions(+), 5 deletions(-)arch/x86/include/asm/realmode.h +3
-0@@ -51,6 +51,7 @@ struct trampoline_header {u64 efer;u32 cr4;u32 flags; +u32 lock;#endif };@@ -64,6 +65,8 @@ extern unsigned long initial_stack;extern unsigned long initial_vc_handler;#endif +extern u32 *trampoline_lock; +extern unsigned char real_mode_blob[];extern unsigned char real_mode_relocs[];arch/x86/include/asm/smp.h +8
-1@@ -187,5 +187,12 @@ extern void nmi_selftest(void);#define nmi_selftest () do { } while (0)#endif -#endif /* __ASSEMBLY__ */ +extern unsigned int smpboot_control; + +#endif /* !__ASSEMBLY__ */ + +/* Control bits for startup_64 */ +#define STARTUP_USE_APICID 0x10000 +#define STARTUP_USE_CPUID_0B 0x20000 +#endif /* _ASM_X86_SMP_H */ arch/x86/kernel/acpi/sleep.c +1
-0@@ -114,6 +114,7 @@ int x86_acpi_suspend_lowlevel(void) early_gdt_descr.address = (unsigned long )get_cpu_gdt_rw (smp_processor_id ()); initial_gs =per_cpu_offset (smp_processor_id ()); + smpboot_control =0 ;#endif initial_code = (unsigned long )wakeup_long64; saved_magic =0x123456789abcdef0L ;arch/x86/kernel/apic/apic.c +1
-1@@ -2333,7 +2333,7 @@ static int nr_logical_cpuids = 1;/* * Used to store mapping between logical CPU IDs and APIC IDs. */ -static int cpuid_to_apicid[] = { +int cpuid_to_apicid[] = { [0 ...NR_CPUS -1 ] =-1 , };arch/x86/kernel/head_64.S +71
-0@@ -25,6 +25,7 @@ #include <asm/export.h> #include <asm/nospec-branch.h> #include <asm/fixmap.h> +#include <asm/smp.h> /* * We are not able to switch in one step to the final KERNEL ADDRESS SPACE@@ -177,6 +178,64 @@ SYM_INNER_LABEL(secondary_startup_64_no_ UNWIND_HINT_EMPTY /* + * Is this the boot CPU coming up? If so everything is available + * in initial_gs, initial_stack and early_gdt_descr. + */ + movl smpboot_control(%rip), %eax + testl %eax, %eax + jz .Lsetup_cpu + + /* + * Secondary CPUs find out the offsets via the APIC ID. For parallel + * boot the APIC ID is retrieved from CPUID, otherwise it's encoded + * in smpboot_control: + * Bit 0-15 APICID if STARTUP_USE_CPUID_0B is not set + * Bit 16 Secondary boot flag + * Bit 17 Parallel boot flag + */ + testl $STARTUP_USE_CPUID_0B, %eax + jz .Lsetup_AP + + mov $0x0B, %eax + xorl %ecx, %ecx + cpuid + mov %edx, %eax + +.Lsetup_AP: + /* EAX contains the APICID of the current CPU */ + andl $0xFFFF, %eax + xorl %ecx, %ecx + leaq cpuid_to_apicid(%rip), %rbx + +.Lfind_cpunr: + cmpl (%rbx), %eax + jz .Linit_cpu_data + addq $4, %rbx + addq $8, %rcx + jmp .Lfind_cpunr + +.Linit_cpu_data: + /* Get the per cpu offset */ + leaq __per_cpu_offset(%rip), %rbx + addq %rcx, %rbx + movq (%rbx), %rbx + /* Save it for GS BASE setup */ + movq %rbx, initial_gs(%rip) + + /* Calculate the GDT address */ + movq $gdt_page, %rcx + addq %rbx, %rcx + movq %rcx, early_gdt_descr_base(%rip) + + /* Find the idle task stack */ + movq $idle_threads, %rcx + addq %rbx, %rcx + movq (%rcx), %rcx + movq TASK_threadsp(%rcx), %rcx + movq %rcx, initial_stack(%rip) + +.Lsetup_cpu: + /* * We must switch to a new descriptor in kernel space for the GDT * because soon the kernel won't have access anymore to the userspace * addresses where we're currently running on. We have to do that here@@ -216,6 +275,14 @@ SYM_INNER_LABEL(secondary_startup_64_no_ */ movq initial_stack(%rip), %rsp + /* Drop the realmode protection. For the boot CPU the pointer is NULL! */ + movq trampoline_lock(%rip), %rax + testq %rax, %rax + jz .Lsetup_idt + lock + btrl $0, (%rax) + +.Lsetup_idt: /* Setup and Load IDT */ pushq %rsi call early_setup_idt@@ -347,6 +414,7 @@ SYM_DATA(initial_vc_handler, .quad handl * reliably detect the end of the stack. */ SYM_DATA(initial_stack, .quad init_thread_union + THREAD_SIZE - SIZEOF_PTREGS) +SYM_DATA(trampoline_lock, .quad 0); __FINITDATA __INIT@@ -573,6 +641,9 @@ SYM_DATA(early_gdt_descr, .word GDT_ENT SYM_DATA_LOCAL(early_gdt_descr_base, .quad INIT_PER_CPU_VAR(gdt_page)) .align 16 +SYM_DATA(smpboot_control, .long 0) + + .align 16 /* This must match the first entry in level2_kernel_pgt */ SYM_DATA(phys_base, .quad 0x0) EXPORT_SYMBOL(phys_base)arch/x86/kernel/smpboot.c +17
-2@@ -1021,6 +1021,16 @@ int common_cpu_up(unsigned int cpu, strureturn 0 ; } +static void setup_smpboot_control (unsigned int apicid) +{ +#ifdef CONFIG_X86_64 +if (boot_cpu_data.cpuid_level <0x0B ) + smpboot_control = apicid |STARTUP_USE_APICID ; +else + smpboot_control =STARTUP_USE_CPUID_0B ; +#endif +} +/* * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad * (ie clustered apic addressing mode), this is a LOGICAL apic ID. @@ -1037,9 +1047,14 @@ static int do_boot_cpu(int apicid, int cunsigned long timeout; idle->thread.sp = (unsigned long )task_pt_regs (idle); - early_gdt_descr.address = (unsigned long )get_cpu_gdt_rw (cpu); initial_code = (unsigned long )start_secondary; - initial_stack = idle->thread.sp; + +if (IS_ENABLED (CONFIG_X86_32 )) { + early_gdt_descr.address = (unsigned long )get_cpu_gdt_rw (cpu); + initial_stack = idle->thread.sp; + } + +setup_smpboot_control (apicid);/* Enable the espfix hack for this CPU */ init_espfix_ap (cpu);arch/x86/realmode/init.c +3
-0@@ -125,6 +125,9 @@ static void __init setup_real_mode(void) trampoline_header->flags =0 ; + trampoline_lock = &trampoline_header->lock; + *trampoline_lock =0 ; + trampoline_pgd = (u64 *)__va (real_mode_header->trampoline_pgd); trampoline_pgd[0 ] = trampoline_pgd_entry.pgd; trampoline_pgd[511 ] = init_top_pgt[511 ].pgd;arch/x86/realmode/rm/trampoline_64.S +14
-0@@ -49,6 +49,19 @@ SYM_CODE_START(trampoline_start) mov %ax, %es mov %ax, %ss + /* + * Make sure only one CPU fiddles with the realmode stack + */ +.Llock_rm: + btw $0, tr_lock + jnc 2f + pause + jmp .Llock_rm +2: + lock + btsw $0, tr_lock + jc .Llock_rm + # Setup stack movl $rm_stack_end, %esp@@ -192,6 +205,7 @@ SYM_DATA_START(trampoline_header) SYM_DATA(tr_efer, .space 8) SYM_DATA(tr_cr4, .space 4) SYM_DATA(tr_flags, .space 4) + SYM_DATA(tr_lock, .space 4) SYM_DATA_END(trampoline_header) #include "trampoline_common.S"kernel/smpboot.c +1
-1@@ -25,7 +25,7 @@* For the hotplug case we keep the task structs around and reuse * them. */ -static DEFINE_PER_CPU(struct task_struct *, idle_threads); +DEFINE_PER_CPU(struct task_struct *, idle_threads);struct task_struct *idle_thread_get (unsigned int cpu) {
Quoted 27 lines · David Woodhouse
I threw it into my tree at
https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/parallelIt seems to work fairly nicely. The parallel SIPI seems to win be about a third of the bringup time on my 28-thread Haswell box. This is at the penultimate commit of the above branch:
[ 0.307590] smp: Bringing up secondary CPUs ... [ 0.307826] x86: Booting SMP configuration: [ 0.307830] .... node #0, CPUs: #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 [ 0.376677] MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details. [ 0.377177] #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 [ 0.402323] Brought CPUs online in 246691584 cycles [ 0.402323] smp: Brought up 1 node, 28 CPUs... and this is the tip of the branch:
[ 0.308332] smp: Bringing up secondary CPUs ...<dwmw2_gone> [ 0.308569] x86: Booting SMP configuration: [ 0.308572] .... node #0, CPUs: #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 [ 0.321120] Brought 28 CPUs to x86/cpu:kick in 34828752 cycles [ 0.366663] MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details. [ 0.368749] Brought CPUs online in 124913032 cycles [ 0.368749] smp: Brought up 1 node, 28 CPUs [ 0.368749] smpboot: Max logical packages: 1 [ 0.368749] smpboot: Total of 28 processors activated (145259.85 BogoMIPS)
Quoted 5 lines
There's more to be gained here if we can fix up the next stage. Right now if I set every CPU's bit in
cpu_initialized_maskto allow them to proceed fromwait_for_master_cpu()through to the end ofcpu_init()and onwards throughstart_secondary(), they all end up hittingcheck_tsc_sync_target()in parallel and it goes horridly wrong.
Actually it breaks before that, in rcu_cpu_starting(). A spinlock around that, an atomic_t to let the APs do their TSC sync one at a time (both in the above tree now), and I have a 75% saving on CPU bringup time for my 28-thread Haswell:
[ 0.307341] smp: Bringing up secondary CPUs ... [ 0.307576] x86: Booting SMP configuration: [ 0.307579] .... node #0, CPUs: #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 [ 0.320100] Brought 28 CPUs to x86/cpu:kick in 34645984 cycles [ 0.325032] Brought 28 CPUs to x86/cpu:wait-init in 12865752 cycles [ 0.326902] MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details. [ 0.328739] Brought CPUs online in 11702224 cycles [ 0.328739] smp: Brought up 1 node, 28 CPUs [ 0.328739] smpboot: Max logical packages: 1 [ 0.328739] smpboot: Total of 28 processors activated (145261.81 BogoMIPS)
Quoted 4 lines · David Woodhouse
Actually it breaks before that, in
rcu_cpu_starting(). A spinlock around that, anatomic_tto let the APs do their TSC sync one at a time (both in the above tree now), and I have a 75% saving on CPU bringup time for my 28-thread Haswell:
Here's a dual-socket Skylake box (EC2 c5.metal)... before:
[ 1.449015] smp: Bringing up secondary CPUs ... [ 1.449358] x86: Booting SMP configuration: [ 1.449578] .... node #0, CPUs: #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16 #17 #18 #19 #20 #21 #22 #23 [ 1.514986] .... node #1, CPUs: #24 #25 #26 #27 #28 #29 #30 #31 #32 #33 #34 #35 #36 #37 #38 #39 #40 #41 #42 #43 #44 #45 #46 #47 [ 1.644978] .... node #0, CPUs: #48 #49 #50 #51 #52 #53 #54 #55 #56 #57 #58 #59 #60 #61 #62 #63 #64 #65 #66 #67 #68 #69 #70 #71 [ 1.711970] .... node #1, CPUs: #72 #73 #74 #75 #76 #77 #78 #79 #80 #81 #82 #83 #84 #85 #86 #87 #88 #89 #90 #91 #92 #93 #94 #95 [ 1.781438] Brought CPUs online in 1063391744 cycles [ 1.782289] smp: Brought up 2 nodes, 96 CPUs [ 1.782515] smpboot: Max logical packages: 2 [ 1.782738] smpboot: Total of 96 processors activated (576364.89 BogoMIPS)
... and after:
[ 1.445661] smp: Bringing up secondary CPUs ... [ 1.446004] x86: Booting SMP configuration: [ 1.446047] .... node #0, CPUs: #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16 #17 #18 #19 #20 #21 #22 #23 [ 1.451048] .... node #1, CPUs: #24 #25 #26 #27 #28 #29 #30 #31 #32 #33 #34 #35 #36 #37 #38 #39 #40 #41 #42 #43 #44 #45 #46 #47 [ 1.455046] .... node #0, CPUs: #48 #49 #50 #51 #52 #53 #54 #55 #56 #57 #58 #59 #60 #61 #62 #63 #64 #65 #66 #67 #68 #69 #70 #71 [ 1.462050] .... node #1, CPUs: #72 #73 #74 #75 #76 #77 #78 #79 #80 #81 #82 #83 #84 #85 #86 #87 #88 #89 #90 #91 #92 #93 #94 #95 [ 1.465983] Brought 96 CPUs to x86/cpu:kick in 68802688 cycles [ 0.094170] smpboot: CPU 26 Converting physical 1 to logical package 2 [ 1.468078] Brought 96 CPUs to x86/cpu:wait-init in 5178300 cycles [ 1.476112] Brought CPUs online in 23479546 cycles [ 1.476298] smp: Brought up 2 nodes, 96 CPUs [ 1.476520] smpboot: Max logical packages: 2 [ 1.476743] smpboot: Total of 96 processors activated (576000.00 BogoMIPS)
So the CPU bringup went from 334ms to 31ms on that one.
I might try that without spewing over 1KiB to the serial port at 115200 baud during the proceedings, and see if it makes a bigger difference :)
+Paul for the RCU question.
Quoted 34 lines · David Woodhouse
Quoted 27 lines · David Woodhouse
I threw it into my tree at
https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/parallelIt seems to work fairly nicely. The parallel SIPI seems to win be about a third of the bringup time on my 28-thread Haswell box. This is at the penultimate commit of the above branch:
[ 0.307590] smp: Bringing up secondary CPUs ... [ 0.307826] x86: Booting SMP configuration: [ 0.307830] .... node #0, CPUs: #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 [ 0.376677] MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details. [ 0.377177] #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 [ 0.402323] Brought CPUs online in 246691584 cycles [ 0.402323] smp: Brought up 1 node, 28 CPUs... and this is the tip of the branch:
[ 0.308332] smp: Bringing up secondary CPUs ...<dwmw2_gone> [ 0.308569] x86: Booting SMP configuration: [ 0.308572] .... node #0, CPUs: #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 [ 0.321120] Brought 28 CPUs to x86/cpu:kick in 34828752 cycles [ 0.366663] MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details. [ 0.368749] Brought CPUs online in 124913032 cycles [ 0.368749] smp: Brought up 1 node, 28 CPUs [ 0.368749] smpboot: Max logical packages: 1 [ 0.368749] smpboot: Total of 28 processors activated (145259.85 BogoMIPS)Quoted 5 lines
There's more to be gained here if we can fix up the next stage. Right now if I set every CPU's bit in
cpu_initialized_maskto allow them to proceed fromwait_for_master_cpu()through to the end ofcpu_init()and onwards throughstart_secondary(), they all end up hittingcheck_tsc_sync_target()in parallel and it goes horridly wrong.
Quoted 4 lines
Actually it breaks before that, in
rcu_cpu_starting(). A spinlock around that, anatomic_tto let the APs do their TSC sync one at a time (both in the above tree now), and I have a 75% saving on CPU bringup time for my 28-thread Haswell:
Coming back to this, I've updated it and thrown up a new branch at
https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/parallel-5.16
For those last two fixes I had started with a trivial naïve approach of just enforcing serialization.
I'm sure we can come up with a cleverer 1:N way of synchronizing the TSCs, instead of just serializing the existing 1:1 sync.
For rcu_cpu_starting() I see there's *already* a lock in the rcu_node... could we use that same lock to protect the manipulation of rnp->ofl_seq and allow rcu_cpu_starting() to be invoked by multiple APs in parallel? Paul?
On a related note, are you currently guaranteed that rcu_report_dead() cannot be called more than once in parallel? Might you want the same locking there?
Paul E. McKenney
maintainerQuoted 51 lines · David Woodhouse
+Paul for the RCU question.
Quoted 34 lines · David Woodhouse
Quoted 27 lines · David Woodhouse
I threw it into my tree at
https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/parallelIt seems to work fairly nicely. The parallel SIPI seems to win be about a third of the bringup time on my 28-thread Haswell box. This is at the penultimate commit of the above branch:
[ 0.307590] smp: Bringing up secondary CPUs ... [ 0.307826] x86: Booting SMP configuration: [ 0.307830] .... node #0, CPUs: #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 [ 0.376677] MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details. [ 0.377177] #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 [ 0.402323] Brought CPUs online in 246691584 cycles [ 0.402323] smp: Brought up 1 node, 28 CPUs... and this is the tip of the branch:
[ 0.308332] smp: Bringing up secondary CPUs ...<dwmw2_gone> [ 0.308569] x86: Booting SMP configuration: [ 0.308572] .... node #0, CPUs: #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 [ 0.321120] Brought 28 CPUs to x86/cpu:kick in 34828752 cycles [ 0.366663] MDS CPU bug present and SMT on, data leak possible. See https://www.kernel.org/doc/html/latest/admin-guide/hw-vuln/mds.html for more details. [ 0.368749] Brought CPUs online in 124913032 cycles [ 0.368749] smp: Brought up 1 node, 28 CPUs [ 0.368749] smpboot: Max logical packages: 1 [ 0.368749] smpboot: Total of 28 processors activated (145259.85 BogoMIPS)Quoted 5 lines
There's more to be gained here if we can fix up the next stage. Right now if I set every CPU's bit in
cpu_initialized_maskto allow them to proceed fromwait_for_master_cpu()through to the end ofcpu_init()and onwards throughstart_secondary(), they all end up hittingcheck_tsc_sync_target()in parallel and it goes horridly wrong.Quoted 4 lines
Actually it breaks before that, in
rcu_cpu_starting(). A spinlock around that, anatomic_tto let the APs do their TSC sync one at a time (both in the above tree now), and I have a 75% saving on CPU bringup time for my 28-thread Haswell:Coming back to this, I've updated it and thrown up a new branch at
https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/parallel-5.16For those last two fixes I had started with a trivial naïve approach of just enforcing serialization.
I'm sure we can come up with a cleverer 1:N way of synchronizing the TSCs, instead of just serializing the existing 1:1 sync.
Quoted 8 lines
For
rcu_cpu_starting()I see there's *already* a lock in thercu_node... could we use that same lock to protect the manipulation ofrnp->ofl_seqand allowrcu_cpu_starting()to be invoked by multiple APs in parallel? Paul?On a related note, are you currently guaranteed that
rcu_report_dead()cannot be called more than once in parallel? Might you want the same locking there?
Just to make sure I understand, the goal here is to bring multiple CPUs online concurrently, correct? If so, this will take some digging to check up on the current implicit assumptions about CPU-hotplug operations being serialized. Some of which might even be documented. ;-)
But first... Is it just bringing CPUs online that is to happen concurrently? Or is it also necessary to take CPUs offline concurrently?
Thanx, Paul
Quoted 21 lines · Paul E. McKenney
Quoted 20 lines · David Woodhouse
Quoted 4 lines
Actually it breaks before that, in
rcu_cpu_starting(). A spinlock around that, anatomic_tto let the APs do their TSC sync one at a time (both in the above tree now), and I have a 75% saving on CPU bringup time for my 28-thread Haswell:Coming back to this, I've updated it and thrown up a new branch at
https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/parallel-5.16For those last two fixes I had started with a trivial naïve approach of just enforcing serialization.
I'm sure we can come up with a cleverer 1:N way of synchronizing the TSCs, instead of just serializing the existing 1:1 sync.
For
rcu_cpu_starting()I see there's *already* a lock in thercu_node... could we use that same lock to protect the manipulation ofrnp->ofl_seqand allowrcu_cpu_starting()to be invoked by multiple APs in parallel? Paul?
Quoted 8 lines
Quoted 3 lines
On a related note, are you currently guaranteed that
rcu_report_dead()cannot be called more than once in parallel? Might you want the same locking there?Just to make sure I understand, the goal here is to bring multiple CPUs online concurrently, correct? If so, this will take some digging to check up on the current implicit assumptions about CPU-hotplug operations being serialized. Some of which might even be documented. ;-)
Indeed. All the APs end up calling rcu_cpu_starting() at the same time, and bad things happen. So I took the naïve "stick a lock around it" approach and the problem went away:
commit 60984965ac1945446eb23ff5a87a4c7acc821409
Author: David Woodhouse <[email protected]> Date: Tue Feb 16 15:04:34 2021 +0000
rcu: Add locking around rcu_cpu_starting()
To allow architectures to bring APs online in parallel, we need locking around rcu_cpu_starting(). Perhaps we could use the existing node spinlock... Paul?
kernel/rcu/tree.c +7 -1
@@ -4231,6 +4231,8 @@ int rcutree_offline_cpu(unsigned int cpu)* from the incoming CPU rather than from the cpuhp_step mechanism. * This is because this function must be invoked at a precise location. */ +static DEFINE_RAW_SPINLOCK (rcu_startup_lock); +void rcu_cpu_starting (unsigned int cpu) {unsigned long flags;
@@ -4239,9 +4241,11 @@ void rcu_cpu_starting(unsigned int cpu)struct rcu_node *rnp;bool newcpu; +raw_spin_lock (&rcu_startup_lock); + rdp =per_cpu_ptr (&rcu_data, cpu);if (rdp->cpu_started) -return ; + goto out; rdp->cpu_started = true; rnp = rdp->mynode;
@@ -4273,6 +4277,8 @@ void rcu_cpu_starting(unsigned int cpu)WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 );WARN_ON_ONCE (rnp->ofl_seq &0x1 );smp_mb ();/* Ensure RCU read-side usage follows above initialization. */ + out: +raw_spin_unlock (&rcu_startup_lock); }/*
On coming back to this and trying to work out the *correct* fix, I see that there's already a per-node spinlock covering most of this function, and I strongly suspect that the better fix is as simple as expanding the coverage of the existing lock? But I have questions...
kernel/rcu/tree.c +3 -3
@@ -4246,11 +4246,11 @@ void rcu_cpu_starting(unsigned int cpu) rnp = rdp->mynode; mask = rdp->grpmask; +raw_spin_lock_irqsave_rcu_node (rnp, flags);WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 );WARN_ON_ONCE (!(rnp->ofl_seq &0x1 ));rcu_dynticks_eqs_online ();smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). -raw_spin_lock_irqsave_rcu_node (rnp, flags);WRITE_ONCE (rnp->qsmaskinitnext, rnp->qsmaskinitnext | mask); newcpu = !(rnp->expmaskinitnext & mask); rnp->expmaskinitnext |= mask;
@@ -4266,13 +4266,13 @@ void rcu_cpu_starting(unsigned int cpu)rcu_disable_urgency_upon_qs (rdp);/* Report QS -after- changing ->qsmaskinitnext! */ rcu_report_qs_rnp (mask, rnp, rnp->gp_seq, flags); - }else { -raw_spin_unlock_irqrestore_rcu_node (rnp, flags); +/* Er, why didn't we drop the lock here? */ }smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 );WARN_ON_ONCE (rnp->ofl_seq &0x1 );smp_mb ();/* Ensure RCU read-side usage follows above initialization. */ +raw_spin_unlock_irqrestore_rcu_node (rnp, flags); }/*
Quoted 2 lines
But first... Is it just bringing CPUs online that is to happen concurrently? Or is it also necessary to take CPUs offline concurrently?
Yes. That is: *First*, it is just bringing CPUs online that is to happen concurrently. :)
As for offlining.... well, if the cpuhp code didn't intentionally guarantee that your existing rcu_report_dead() function can only be called once at a time, and you are only relying on the fact that *empirically* that seems to be the case, then you are naughty and should give it the same kind of locking we speak of above.
And although I don't currently have designs on parallel offlining, ask me again after I've audited the kexec code and seen how long it takes to do that in series (if it's properly offlining them at all).
Review void rcu_cpu_starting(unsigned int cpu) · line 4271
Quoted 9 lines · David Woodhouse
(quoted diff) +1
-2@@ -4266,13 +4266,13 @@ void rcu_cpu_starting(unsigned int cpu) rcu_disable_urgency_upon_qs(rdp); /* Report QS -after- changing ->qsmaskinitnext! */ rcu_report_qs_rnp(mask, rnp, rnp->gp_seq, flags); + /* Er, why didn't we drop the lock here? */ - } else { - raw_spin_unlock_irqrestore_rcu_node(rnp, flags); }
Oh, I see... how about this straw man then...
From 083c8fb2656e9fc60a17c9bfd538fcee4c5ebacc Mon Sep 17 00:00:00 2001
From: David Woodhouse <[email protected]>
Date: Tue, 16 Feb 2021 15:04:34 +0000
Subject: [PATCH 1/4] rcu: Expand locking around rcu_cpu_starting() to cover
rnp->ofl_seq bump
To allow architectures to bring APs online in parallel, we need only one of them to be going through rcu_cpu_starting() at a time. Expand the coverage of the existing per-node lock to cover the manipulation of rnp->ofl_seq too.
--- kernel/rcu/tree.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
kernel/rcu/tree.c +6 -5
@@ -4246,11 +4246,11 @@ void rcu_cpu_starting(unsigned int cpu) rnp = rdp->mynode; mask = rdp->grpmask; +raw_spin_lock_irqsave_rcu_node (rnp, flags);WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 );WARN_ON_ONCE (!(rnp->ofl_seq &0x1 ));rcu_dynticks_eqs_online ();smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). -raw_spin_lock_irqsave_rcu_node (rnp, flags);WRITE_ONCE (rnp->qsmaskinitnext, rnp->qsmaskinitnext | mask); newcpu = !(rnp->expmaskinitnext & mask); rnp->expmaskinitnext |= mask;
@@ -4261,6 +4261,11 @@ void rcu_cpu_starting(unsigned int cpu) rdp->rcu_onl_gp_seq =READ_ONCE (rcu_state.gp_seq); rdp->rcu_onl_gp_flags =READ_ONCE (rcu_state.gp_flags); +smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). +WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); +WARN_ON_ONCE (rnp->ofl_seq &0x1 ); +smp_mb ();/* Ensure RCU read-side usage follows above initialization. */ +/* An incoming CPU should never be blocking a grace period. */ if (WARN_ON_ONCE (rnp->qsmask & mask)) {/* RCU waiting on incoming CPU? */ rcu_disable_urgency_upon_qs (rdp);
@@ -4269,10 +4274,6 @@ void rcu_cpu_starting(unsigned int cpu) }else {raw_spin_unlock_irqrestore_rcu_node (rnp, flags); } -smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). -WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); -WARN_ON_ONCE (rnp->ofl_seq &0x1 ); -smp_mb ();/* Ensure RCU read-side usage follows above initialization. */ }/*
Signature · 1 line
2.31.1
Paul E. McKenney
maintainerQuoted 12 lines · David Woodhouse
Review void rcu_cpu_starting(unsigned int cpu) · line 4271
Quoted 9 lines · David Woodhouse
(quoted diff) +1
-2@@ -4266,13 +4266,13 @@ void rcu_cpu_starting(unsigned int cpu) rcu_disable_urgency_upon_qs(rdp); /* Report QS -after- changing ->qsmaskinitnext! */ rcu_report_qs_rnp(mask, rnp, rnp->gp_seq, flags); + /* Er, why didn't we drop the lock here? */ - } else { - raw_spin_unlock_irqrestore_rcu_node(rnp, flags); }Oh, I see... how about this straw man then...
Yes, rcu_report_qs_rnp() does drop the lock. (Apologies for not having replied earlier, but I had not yet consumed enough chocolate to correctly parse your comment.)
Quoted 21 lines
From
083c8fb2656e9fc60a17c9bfd538fcee4c5ebaccMon Sep 17 00:00:00 2001
From: David Woodhouse <[email protected]>
Date: Tue, 16 Feb 2021 15:04:34 +0000
Subject: [PATCH 1/4] rcu: Expand locking aroundrcu_cpu_starting()to cover
rnp->ofl_seqbumpTo allow architectures to bring APs online in parallel, we need only one of them to be going through
rcu_cpu_starting()at a time. Expand the coverage of the existing per-node lock to cover the manipulation ofrnp->ofl_seqtoo.Signed-off-by David Woodhouse <[email protected]>--- kernel/rcu/tree.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)kernel/rcu/tree.c +0
-0
kernel/rcu/tree.c void rcu_cpu_starting(unsigned int cpu) · line 4249
Quoted 4 lines
kernel/rcu/tree.c +1
-0@@ -4246,11 +4246,11 @@ void rcu_cpu_starting(unsigned int cpu) rnp = rdp->mynode; mask = rdp->grpmask; +raw_spin_lock_irqsave_rcu_node (rnp, flags);
If I am not too confused this morning, this can result in confusing lockdep splats because lockdep needs RCU to be watching the CPU acquiring the lock. See the rcu_lockdep_current_cpu_online() function and is callers, with emphasis on lockdep_rcu_suspicious() and rcu_read_lock_held_common().
Quoted 21 lines
kernel/rcu/tree.c +5
-1WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 );WARN_ON_ONCE (!(rnp->ofl_seq &0x1 ));rcu_dynticks_eqs_online ();smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). -raw_spin_lock_irqsave_rcu_node (rnp, flags);WRITE_ONCE (rnp->qsmaskinitnext, rnp->qsmaskinitnext | mask); newcpu = !(rnp->expmaskinitnext & mask); rnp->expmaskinitnext |= mask;@@ -4261,6 +4261,11 @@ void rcu_cpu_starting(unsigned int cpu) rdp->rcu_onl_gp_seq =READ_ONCE (rcu_state.gp_seq); rdp->rcu_onl_gp_flags =READ_ONCE (rcu_state.gp_flags); +smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). +WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); +WARN_ON_ONCE (rnp->ofl_seq &0x1 ); +smp_mb ();/* Ensure RCU read-side usage follows above initialization. */ +/* An incoming CPU should never be blocking a grace period. */ if (WARN_ON_ONCE (rnp->qsmask & mask)) {/* RCU waiting on incoming CPU? */ rcu_disable_urgency_upon_qs (rdp);
kernel/rcu/tree.c void rcu_cpu_starting(unsigned int cpu) · line 4275
Quoted 2 lines
kernel/rcu/tree.c +0
-0@@ -4269,10 +4274,6 @@ void rcu_cpu_starting(unsigned int cpu) }else {raw_spin_unlock_irqrestore_rcu_node (rnp, flags);
And ditto here upon release.
As a short-term hack, I suggest moving the ->ofl_seq field from the rcu_node structure to the rcu_data structure. This will require the loop in rcu_gp_init() to wait on each of the current rcu_node structure's CPUs. Which is not good from the viewpoint of the RCU grace-period kthread's CPU consumption, but it should allow you to make progress on your testing.
Though I are having some difficulty remembering why that wait loop in rcu_gp_init() needs to be there. I am going to try removing it and seeing if rcutorture will be kind enough to remind me. ;-)
And it will of course be necessary to upgrade rcutorture to test concurrent CPU-online operations. Will there be some sort of start-CPU-online function, or should I instead expect to need to provide multiple kthreads for onlining and an additional kthread for offliing?
Huh. I take it that concurrent online and offline is future work? Or does that need to work initially?
More to the point, what are you using to stress-test this capability?
Thanx, Paul
Quoted 11 lines
kernel/rcu/tree.c +0
-4} -smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). -WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); -WARN_ON_ONCE (rnp->ofl_seq &0x1 ); -smp_mb ();/* Ensure RCU read-side usage follows above initialization. */ }/* Signature · 1 line
2.31.1
Quoted 7 lines · Paul E. McKenney
Quoted 6 lines · David Woodhouse
kernel/rcu/tree.c +0
-0@@ -4246,11 +4246,11 @@ void rcu_cpu_starting(unsigned int cpu)
Quoted 9 lines
kernel/rcu/tree.c void rcu_cpu_starting(unsigned int cpu) · line 4249
Quoted 3 lines
kernel/rcu/tree.c +1
-0rnp = rdp->mynode; mask = rdp->grpmask; +raw_spin_lock_irqsave_rcu_node (rnp, flags);If I am not too confused this morning, this can result in confusing lockdep splats because lockdep needs RCU to be watching the CPU acquiring the lock. See the
rcu_lockdep_current_cpu_online()function and is callers, with emphasis onlockdep_rcu_suspicious()andrcu_read_lock_held_common().
Hm, OK. And it is the very act of setting rnp->ofl_seq & 1 which triggers that, yes?
Quoted 29 lines
Quoted 24 lines
kernel/rcu/tree.c +0
-1WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 );WARN_ON_ONCE (!(rnp->ofl_seq &0x1 ));rcu_dynticks_eqs_online ();smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). -raw_spin_lock_irqsave_rcu_node (rnp, flags);kernel/rcu/tree.c +5
-0WRITE_ONCE (rnp->qsmaskinitnext, rnp->qsmaskinitnext | mask); newcpu = !(rnp->expmaskinitnext & mask); rnp->expmaskinitnext |= mask;@@ -4261,6 +4261,11 @@ void rcu_cpu_starting(unsigned int cpu) rdp->rcu_onl_gp_seq =READ_ONCE (rcu_state.gp_seq); rdp->rcu_onl_gp_flags =READ_ONCE (rcu_state.gp_flags); +smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). +WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); +WARN_ON_ONCE (rnp->ofl_seq &0x1 ); +smp_mb ();/* Ensure RCU read-side usage follows above initialization. */ +/* An incoming CPU should never be blocking a grace period. */ if (WARN_ON_ONCE (rnp->qsmask & mask)) {/* RCU waiting on incoming CPU? */ rcu_disable_urgency_upon_qs (rdp);kernel/rcu/tree.c void rcu_cpu_starting(unsigned int cpu) · line 4275
Quoted 2 lines
kernel/rcu/tree.c +0
-0@@ -4269,10 +4274,6 @@ void rcu_cpu_starting(unsigned int cpu) }else {raw_spin_unlock_irqrestore_rcu_node (rnp, flags);And ditto here upon release.
Quoted 5 lines
As a short-term hack, I suggest moving the ->ofl_seq field from the
rcu_nodestructure to thercu_datastructure. This will require the loop inrcu_gp_init()to wait on each of the currentrcu_nodestructure's CPUs. Which is not good from the viewpoint of the RCU grace-period kthread's CPU consumption, but it should allow you to make progress on your testing.
Ok, thanks. My initial hack of sticking my own spinlock around the whole thing was also working for testing, but now I'm trying to clean it up so I can post something for merging.
Quoted 9 lines
Though I are having some difficulty remembering why that wait loop in
rcu_gp_init()needs to be there. I am going to try removing it and seeing if rcutorture will be kind enough to remind me. ;-)And it will of course be necessary to upgrade rcutorture to test concurrent CPU-online operations. Will there be some sort of start-CPU-online function, or should I instead expect to need to provide multiple kthreads for onlining and an additional kthread for offliing?
This is just at *boot* time, not runtime hotplug/unplug. We observed that we spend quite a lot of time on a 96-way 2-socket Skylake system just sending INIT to each CPU in turn, then waiting for it to be fully online, then moving on to the next one. Hence doing them all in parallel, which reduces the AP bringup time from about 300ms to 30ms.
https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/parallel-5.16
Quoted 3 lines
Huh. I take it that concurrent online and offline is future work? Or does that need to work initially?
Concurrent *online* (at boot) is the whole point. Those last two commits currently in the branch linked above are the "oh crap, *that* part doesn't work if you really let it happen concurrently, so let's serialize them" hacks. In particular, the RCU one is
https://git.infradead.org/users/dwmw2/linux.git/commitdiff/5f4b77c9459c
And now I'm trying to come up with something a little less hackish :)
Quoted 1 line
More to the point, what are you using to stress-test this capability?
Just boot. With lots of CPUs (and vCPUs in qemu, but even with a nice fast parallel CPU bringup, Linux then spends the next 16 seconds printing silly pr_info messages about KVM features so it isn't the most exciting overall result right now)
I confess I haven't actually tested runtime hotplug/unplug again recently. I should do that ;)
Paul E. McKenney
maintainerQuoted 18 lines · David Woodhouse
Quoted 7 lines · Paul E. McKenney
Quoted 6 lines · David Woodhouse
kernel/rcu/tree.c +0
-0@@ -4246,11 +4246,11 @@ void rcu_cpu_starting(unsigned int cpu)Quoted 9 lines
kernel/rcu/tree.c void rcu_cpu_starting(unsigned int cpu) · line 4249
Quoted 3 lines
kernel/rcu/tree.c +1
-0rnp = rdp->mynode; mask = rdp->grpmask; +raw_spin_lock_irqsave_rcu_node (rnp, flags);If I am not too confused this morning, this can result in confusing lockdep splats because lockdep needs RCU to be watching the CPU acquiring the lock. See the
rcu_lockdep_current_cpu_online()function and is callers, with emphasis onlockdep_rcu_suspicious()andrcu_read_lock_held_common().
Quoted 2 lines
Hm, OK. And it is the very act of setting
rnp->ofl_seq& 1 which triggers that, yes?
Prevents that from triggering, but if I recall correctly, yes.
Quoted 35 lines
Quoted 29 lines
Quoted 24 lines
kernel/rcu/tree.c +0
-1WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 );WARN_ON_ONCE (!(rnp->ofl_seq &0x1 ));rcu_dynticks_eqs_online ();smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). -raw_spin_lock_irqsave_rcu_node (rnp, flags);kernel/rcu/tree.c +5
-0WRITE_ONCE (rnp->qsmaskinitnext, rnp->qsmaskinitnext | mask); newcpu = !(rnp->expmaskinitnext & mask); rnp->expmaskinitnext |= mask;@@ -4261,6 +4261,11 @@ void rcu_cpu_starting(unsigned int cpu) rdp->rcu_onl_gp_seq =READ_ONCE (rcu_state.gp_seq); rdp->rcu_onl_gp_flags =READ_ONCE (rcu_state.gp_flags); +smp_mb ();// Pair with rcu_gp_cleanup()'s ->ofl_seq barrier(). +WRITE_ONCE (rnp->ofl_seq, rnp->ofl_seq +1 ); +WARN_ON_ONCE (rnp->ofl_seq &0x1 ); +smp_mb ();/* Ensure RCU read-side usage follows above initialization. */ +/* An incoming CPU should never be blocking a grace period. */ if (WARN_ON_ONCE (rnp->qsmask & mask)) {/* RCU waiting on incoming CPU? */ rcu_disable_urgency_upon_qs (rdp);kernel/rcu/tree.c void rcu_cpu_starting(unsigned int cpu) · line 4275
Quoted 2 lines
kernel/rcu/tree.c +0
-0@@ -4269,10 +4274,6 @@ void rcu_cpu_starting(unsigned int cpu) }else {raw_spin_unlock_irqrestore_rcu_node (rnp, flags);And ditto here upon release.
Quoted 5 lines
As a short-term hack, I suggest moving the ->ofl_seq field from the
rcu_nodestructure to thercu_datastructure. This will require the loop inrcu_gp_init()to wait on each of the currentrcu_nodestructure's CPUs. Which is not good from the viewpoint of the RCU grace-period kthread's CPU consumption, but it should allow you to make progress on your testing.
Quoted 3 lines
Ok, thanks. My initial hack of sticking my own spinlock around the whole thing was also working for testing, but now I'm trying to clean it up so I can post something for merging.
Sounds good!
You know, maybe it would be way easier to just create a new spinlock and use arch_spin_lock() to acquire it and arch_spin_unlock() to release it, bypassing lockdep for that one lock. Then proceed as in your initial patch.
Quoted 10 lines
Quoted 9 lines
Though I are having some difficulty remembering why that wait loop in
rcu_gp_init()needs to be there. I am going to try removing it and seeing if rcutorture will be kind enough to remind me. ;-)And it will of course be necessary to upgrade rcutorture to test concurrent CPU-online operations. Will there be some sort of start-CPU-online function, or should I instead expect to need to provide multiple kthreads for onlining and an additional kthread for offliing?
Quoted 7 lines
This is just at *boot* time, not runtime hotplug/unplug. We observed that we spend quite a lot of time on a 96-way 2-socket Skylake system just sending INIT to each CPU in turn, then waiting for it to be fully online, then moving on to the next one. Hence doing them all in parallel, which reduces the AP bringup time from about 300ms to 30ms.
https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/parallel-5.16
Nice win!!!
And I do understand that you are only worried about boot speed, but adequate stress-testing of this will require run-time exercising of this. Yes, 30ms is fast, but you have other overheads when repeatedly rebooting, and so doing runtime tests will find bugs faster.
Quoted 10 lines
Quoted 2 lines
Huh. I take it that concurrent online and offline is future work? Or does that need to work initially?
Concurrent *online* (at boot) is the whole point. Those last two commits currently in the branch linked above are the "oh crap, *that* part doesn't work if you really let it happen concurrently, so let's serialize them" hacks. In particular, the RCU one is
https://git.infradead.org/users/dwmw2/linux.git/commitdiff/5f4b77c9459cAnd now I'm trying to come up with something a little less hackish :)
Understood! I am just trying to work out a decent validation plan for this. Let's just say that changes in this area have not traditionally been boring. ;-)
Quoted 9 lines
Quoted 1 line
More to the point, what are you using to stress-test this capability?
Just boot. With lots of CPUs (and vCPUs in qemu, but even with a nice fast parallel CPU bringup, Linux then spends the next 16 seconds printing silly
pr_infomessages about KVM features so it isn't the most exciting overall result right now)I confess I haven't actually tested runtime hotplug/unplug again recently. I should do that ;)
The rcutorture TREE03 scenario is rather aggressive about this. From the root of a recent Linux-kernel source tree:
tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 1h configs "TREE03" --trust-make
Or, if you have a 64-CPU system:
tools/testing/selftests/rcutorture/bin/kvm.sh --allcpus --duration 1h configs "4*TREE03" --trust-make
The latter would be a semi-credible smoke test for this sort of change.
Thanx, Paul
Quoted 19 lines · Paul E. McKenney
Quoted 18 lines · David Woodhouse
Quoted 16 lines · Paul E. McKenney
kernel/rcu/tree.c void rcu_cpu_starting(unsigned int cpu) · line 4249
Quoted 9 lines · David Woodhouse
kernel/rcu/tree.c +1
-0@@ -4246,11 +4246,11 @@ void rcu_cpu_starting(unsigned int cpu) rnp = rdp->mynode; mask = rdp->grpmask; +raw_spin_lock_irqsave_rcu_node (rnp, flags);If I am not too confused this morning, this can result in confusing lockdep splats because lockdep needs RCU to be watching the CPU acquiring the lock. See the
rcu_lockdep_current_cpu_online()function and is callers, with emphasis onlockdep_rcu_suspicious()andrcu_read_lock_held_common().
Quoted 4 lines
Quoted 2 lines
Hm, OK. And it is the very act of setting
rnp->ofl_seq& 1 which triggers that, yes?Prevents that from triggering, but if I recall correctly, yes.
OK, thanks.
Quoted 10 lines
Quoted 3 lines
Ok, thanks. My initial hack of sticking my own spinlock around the whole thing was also working for testing, but now I'm trying to clean it up so I can post something for merging.
Sounds good!
You know, maybe it would be way easier to just create a new spinlock and use
arch_spin_lock()to acquire it andarch_spin_unlock()to release it, bypassing lockdep for that one lock. Then proceed as in your initial patch.
Hm. So... (summarising a little from IRC for the peanut gallery and our own subsequent recollection) I had a play with doing an atomic 'acquire' for rnp->ofl_seq which is basically "spin until you can use cmpxchg() to atomically increment it to an odd number".
http://david.woodhou.se/acquire-ofl-seq.patch
But *every* call to that 'acquire_ofl_seq() is paired with locking rcu_state.ofl_lock, and *every* release is paired with unlocking rcu_state.ofl_lock.
So I don't think I want a *new* lock; I think I want to use arch_spin_lock on rcu_state.ofl_lock and expand it slightly (as in my previous attempt to cover the modifications of rnp->ofl_seq.
Will throw that together and see what breaks...
Quoted 19 lines
Quoted 10 lines
Quoted 9 lines
Though I are having some difficulty remembering why that wait loop in
rcu_gp_init()needs to be there. I am going to try removing it and seeing if rcutorture will be kind enough to remind me. ;-)And it will of course be necessary to upgrade rcutorture to test concurrent CPU-online operations. Will there be some sort of start-CPU-online function, or should I instead expect to need to provide multiple kthreads for onlining and an additional kthread for offliing?
Quoted 8 lines
This is just at *boot* time, not runtime hotplug/unplug. We observed that we spend quite a lot of time on a 96-way 2-socket Skylake system just sending INIT to each CPU in turn, then waiting for it to be fully online, then moving on to the next one. Hence doing them all in parallel, which reduces the AP bringup time from about 300ms to 30ms.
https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/parallel-5.16
Quoted 6 lines
Nice win!!!
And I do understand that you are only worried about boot speed, but adequate stress-testing of this will require run-time exercising of this. Yes, 30ms is fast, but you have other overheads when repeatedly rebooting, and so doing runtime tests will find bugs faster.
Absolutely!
Quoted 29 lines
Quoted 11 lines
Quoted 2 lines
Huh. I take it that concurrent online and offline is future work? Or does that need to work initially?
Concurrent *online* (at boot) is the whole point. Those last two commits currently in the branch linked above are the "oh crap, *that* part doesn't work if you really let it happen concurrently, so let's serialize them" hacks. In particular, the RCU one is
https://git.infradead.org/users/dwmw2/linux.git/commitdiff/5f4b77c9459cAnd now I'm trying to come up with something a little less hackish :)
Understood! I am just trying to work out a decent validation plan for this. Let's just say that changes in this area have not traditionally been boring. ;-)
Quoted 9 lines
Quoted 1 line
More to the point, what are you using to stress-test this capability?
Just boot. With lots of CPUs (and vCPUs in qemu, but even with a nice fast parallel CPU bringup, Linux then spends the next 16 seconds printing silly
pr_infomessages about KVM features so it isn't the most exciting overall result right now)I confess I haven't actually tested runtime hotplug/unplug again recently. I should do that ;)
The rcutorture TREE03 scenario is rather aggressive about this. From the root of a recent Linux-kernel source tree:
Quoted 7 lines
tools/testing/selftests/rcutorture/bin/kvm.sh--allcpus --duration 1h configs "TREE03" --trust-makeOr, if you have a 64-CPU system:
tools/testing/selftests/rcutorture/bin/kvm.sh--allcpus --duration 1h configs "4*TREE03" --trust-makeThe latter would be a semi-credible smoke test for this sort of change.
Thanks.
Paul E. McKenney
maintainerQuoted 49 lines · David Woodhouse
Quoted 19 lines · Paul E. McKenney
Quoted 18 lines · David Woodhouse
Quoted 16 lines · Paul E. McKenney
kernel/rcu/tree.c void rcu_cpu_starting(unsigned int cpu) · line 4249
Quoted 9 lines · David Woodhouse
kernel/rcu/tree.c +1
-0@@ -4246,11 +4246,11 @@ void rcu_cpu_starting(unsigned int cpu) rnp = rdp->mynode; mask = rdp->grpmask; +raw_spin_lock_irqsave_rcu_node (rnp, flags);If I am not too confused this morning, this can result in confusing lockdep splats because lockdep needs RCU to be watching the CPU acquiring the lock. See the
rcu_lockdep_current_cpu_online()function and is callers, with emphasis onlockdep_rcu_suspicious()andrcu_read_lock_held_common().Quoted 4 lines
Quoted 2 lines
Hm, OK. And it is the very act of setting
rnp->ofl_seq& 1 which triggers that, yes?Prevents that from triggering, but if I recall correctly, yes.
OK, thanks.
Quoted 10 lines
Quoted 3 lines
Ok, thanks. My initial hack of sticking my own spinlock around the whole thing was also working for testing, but now I'm trying to clean it up so I can post something for merging.
Sounds good!
You know, maybe it would be way easier to just create a new spinlock and use
arch_spin_lock()to acquire it andarch_spin_unlock()to release it, bypassing lockdep for that one lock. Then proceed as in your initial patch.Hm. So... (summarising a little from IRC for the peanut gallery and our own subsequent recollection) I had a play with doing an atomic 'acquire' for
rnp->ofl_seqwhich is basically "spin until you can usecmpxchg()to atomically increment it to an odd number".http://david.woodhou.se/acquire-ofl-seq.patch
But *every* call to that '
acquire_ofl_seq()is paired with locking rcu_state.ofl_lock, and *every* release is paired with unlocking rcu_state.ofl_lock.
Quoted 5 lines
So I don't think I want a *new* lock; I think I want to use
arch_spin_lockon rcu_state.ofl_lock and expand it slightly (as in my previous attempt to cover the modifications ofrnp->ofl_seq.Will throw that together and see what breaks...
This approach makes sense to me!
Quoted 59 lines
Quoted 19 lines
Quoted 10 lines
Quoted 9 lines
Though I are having some difficulty remembering why that wait loop in
rcu_gp_init()needs to be there. I am going to try removing it and seeing if rcutorture will be kind enough to remind me. ;-)And it will of course be necessary to upgrade rcutorture to test concurrent CPU-online operations. Will there be some sort of start-CPU-online function, or should I instead expect to need to provide multiple kthreads for onlining and an additional kthread for offliing?
Quoted 8 lines
This is just at *boot* time, not runtime hotplug/unplug. We observed that we spend quite a lot of time on a 96-way 2-socket Skylake system just sending INIT to each CPU in turn, then waiting for it to be fully online, then moving on to the next one. Hence doing them all in parallel, which reduces the AP bringup time from about 300ms to 30ms.
https://git.infradead.org/users/dwmw2/linux.git/shortlog/refs/heads/parallel-5.16
Quoted 6 lines
Nice win!!!
And I do understand that you are only worried about boot speed, but adequate stress-testing of this will require run-time exercising of this. Yes, 30ms is fast, but you have other overheads when repeatedly rebooting, and so doing runtime tests will find bugs faster.
Absolutely!
Quoted 31 lines
Quoted 11 lines
Quoted 2 lines
Huh. I take it that concurrent online and offline is future work? Or does that need to work initially?
Concurrent *online* (at boot) is the whole point. Those last two commits currently in the branch linked above are the "oh crap, *that* part doesn't work if you really let it happen concurrently, so let's serialize them" hacks. In particular, the RCU one is
https://git.infradead.org/users/dwmw2/linux.git/commitdiff/5f4b77c9459cAnd now I'm trying to come up with something a little less hackish :)
Understood! I am just trying to work out a decent validation plan for this. Let's just say that changes in this area have not traditionally been boring. ;-)
Quoted 9 lines
Quoted 1 line
More to the point, what are you using to stress-test this capability?
Just boot. With lots of CPUs (and vCPUs in qemu, but even with a nice fast parallel CPU bringup, Linux then spends the next 16 seconds printing silly
pr_infomessages about KVM features so it isn't the most exciting overall result right now)I confess I haven't actually tested runtime hotplug/unplug again recently. I should do that ;)
The rcutorture TREE03 scenario is rather aggressive about this. From the root of a recent Linux-kernel source tree:
tools/testing/selftests/rcutorture/bin/kvm.sh--allcpus --duration 1h configs "TREE03" --trust-make
Quoted 7 lines
Quoted 5 lines
Or, if you have a 64-CPU system:
tools/testing/selftests/rcutorture/bin/kvm.sh--allcpus --duration 1h configs "4*TREE03" --trust-makeThe latter would be a semi-credible smoke test for this sort of change.
Thanks.
This should address the bug that RCU complained bitterly about. The search for bugs that RCU suffers in silence might take a bit longer. ;-)
Thanx, Paul