4 ms·
> A few lines of memory-less stack-less assembly could get the CPU number and then change the stack... Except for that TSC_AUX (MSR that stores CPU id number)
by vardump 4y ago
> A few lines of memory-less stack-less assembly could get the CPU number and then change the stack...
Except for that TSC_AUX (MSR that stores CPU id number) is going to be 0 for all of the cores. Unless you know some other way to get CPU number?
- dfox 4y agoCore ID in TSC_AUX is essentially an concession to userspace. As an OS and firmware you are supposed to identify CPU cores by means of their LAPIC ID (as read from APIC configurations MSR or from CPUID). Small issue there is that APIC IDs are structured according to HT/NUMA topology and thus not necessarily consecutive. On the other hand, as an OS on PC-like platform you know how many cores there are supposed to be and what are their APIC IDs before-hand because they were already enumerated by firmware (which is the reason why you can do the one by one AP startup sequence in the first place).
- JoshTriplett 4y agoExactly: either read the APIC ID and use that to look up the CPU number in a table you already have, or arrange a location in memory to use xadd to assign a sequential CPU number, whichever your OS prefers.