Page MenuHomeFreeBSD

Remove the secondary_stacks array in arm64 and riscv kernels.
ClosedPublic

Authored by markj on Mar 22 2020, 9:06 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Oct 24, 6:22 AM
Unknown Object (File)
Oct 3 2024, 5:08 PM
Unknown Object (File)
Oct 3 2024, 12:41 PM
Unknown Object (File)
Oct 2 2024, 10:22 PM
Unknown Object (File)
Oct 1 2024, 2:55 PM
Unknown Object (File)
Oct 1 2024, 12:23 PM
Unknown Object (File)
Sep 28 2024, 12:32 AM
Unknown Object (File)
Sep 27 2024, 12:13 AM

Details

Summary

Instead, dynamically allocate a page for the boot stack of each AP when
starting them up, like we do on x86. This shrinks the bss by
MAXCPU*KSTACK_PAGES pages, which corresponds to 4MB on arm64 and 256KB
on riscv. mpentry is slightly simplified as well.

Duplicate the logic used on x86 to free the bootstacks, by using a
sysinit to wait for APs to switch to a thread.

While here, mark some static MD variables as such.

Test Plan

Tested boot-up in QEMU for arm64 and riscv.

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 30051
Build 27862: arc lint + arc unit

Event Timeline

markj edited the test plan for this revision. (Show Details)
kib added inline comments.
sys/arm64/arm64/mp_machdep.c
279

Don't you need to check for bootstacks[cpu] == NULL before waiting for curpcb change ?

479–480

I would add 'err' value to the printf.

This revision is now accepted and ready to land.Mar 22 2020, 10:24 PM

Address feedback:

  • Print the error from PSCI if we fail to start a CPU.
  • Check for a NULL bootstack pointer before freeing, on both riscv and arm64.
This revision now requires review to proceed.Mar 22 2020, 11:26 PM
This revision is now accepted and ready to land.Mar 22 2020, 11:31 PM
sys/arm64/arm64/mp_machdep.c
485

Is there a reason to not use wfe here?

sys/arm64/arm64/mp_machdep.c
485

I don't think so, I just assumed cpu_spinwait() would be fine since we should spend relatively little time here.

sys/arm64/arm64/mp_machdep.c
485

... presumably there is some threshold where a short wfe interval is not any better from a power consumption perspective than a spinwait loop?

mmel added inline comments.
head/sys/arm64/arm64/mp_machdep.c
281 ↗(On Diff #69835)

Hi Mark,
Unfortunately, this creates a race condition. In cpu_throw(), pc_curpcb[1] is set before switching to kernel stack[2] and moreover the stack is used between these two points (because pmap_switch() is implemented in C). This means that the bootstrap stack can be freed while the AP is still using it.
I've encountered this problem on my own RK3399 boards, where the primary CPU cluster (i.e. bootstrap CPU) starts at a fast clock speed, but the secondary CPU cluster starts at a very low frequency (tens of MHz)...
[1] https://cgit.freebsd.org/src/tree/sys/arm64/arm64/swtch.S#n84
[2] https://cgit.freebsd.org/src/tree/sys/arm64/arm64/swtch.S#n93

head/sys/arm64/arm64/mp_machdep.c
281 ↗(On Diff #69835)

I see. Can you confirm whether this approach works on your hardware? https://reviews.freebsd.org/D35435