News for hackers. Stuff that matters.
Re:Booting Modern Intel CPUs by toast0 on Monday April 17, 2023 @03:25AM (#35597712)
> All of the APs start up in the same state -- executing from the same CS:IP, and also the same stack pointer. Good luck having hundreds of CPUs stomping over each other's stacks.

I'm away from my hobby OS to double check, but isn't it the cae that the Start IPI includes a page number which drives CS? If you send those out one by one, you can give each AP its own code page and set the stack page based on that (either using the CS value to index into something, or as an immediate value in the code, that you modify as you copy to the page). Of course, if you do a broadcast SIPI, then all of those are going to have the same CS. Depending on how much early boot code you fancy writing in assembler, you could maybe jump into protected/long mode, find the current cpu id, and lookup the proper stack pointer without using the stack at all, and only then jump into C code? Of course, one probably has nice C functions for some of those things, so it doesn't seem nice to also have it in assembly.

Re:Booting Modern Intel CPUs by mananaysiempre on Monday April 17, 2023 @06:51AM (#35599028)
If you know how many CPUs you are bringing up, then you can allocate a bunch of stacks contiguously and have the CPUs race to pick up the next one, say

  mov rsp, STACKSIZE
  lock xadd [currstack], rsp
Of course, the contention on that xadd is going to cost you (if not 10ms per CPU... probably?), and this presumes you aren’t using the kernel stack pointer for anything (like a stable CPU number). To fix that, you probably will need to traverse a CPU -> startup data map in assembly. But it’s a start (no pun intended), and is not as horrendous a hack as having multiple CPUs push the same return address onto the same stack.
Re:Booting Modern Intel CPUs by klempner on Monday April 17, 2023 @07:21AM (#35599198)
As an order of magnitude point, my experience has been that a bunch of CPUs trying to xadd has a throughput bottleneck on the scale of once per 50 to 100 nanoseconds.

But even if you allow an entire extra order of magnitude, at one per microsecond, that's still 10000 over the course of 10 milliseconds which is plenty for this usecase, at least for now.

Re:Booting Modern Intel CPUs by toast0 on Monday April 17, 2023 @01:51PM (#35604118)
> I'm away from my hobby OS to double check, but isn't it the cae that the Start IPI includes a page number which drives CS?

I double checked, and as I understand it, with traditional APIC start IPI, you get to pick the CS address to be (0-255) * 0x1000; although how much of the first 1MB of physical address space is available within that depends on the system memory map. I just start one AP at a time, and use the top of the code page as stack space until it switches to the intended kernel stack, and then that AP starts the next one. That's not time efficient though; you could pretty easily start as many APs as you've got low pages available; although the option where everybody starts from the same place and they figure it out among themselves is probably simpler; because there's never a need to wait for an AP to finish starting before starting more APs; just saying, you've got options, they don't all have to start at the same CS:IP.