On 30 Jul 2020, at 22:06, Richard Braun <rbr...@sceen.net> wrote:
> On Thu, Jul 30, 2020 at 10:44:40PM +0200, Samuel Thibault wrote:
>>>> I'm wondering: is it really *that* simple to get the current cpu number,
>>>> just read a memory location?  I'm surprised that this would provide
>>>> different results on different cpus.
>>> 
>>> The APIC ID is stored in the Local APIC of each cpu. This address is common 
>>> for
>>> all Local APIC: accessing this from each cpu, it shows the Local APIC of 
>>> this
>>> cpu.
>>> By example, if you access this address from cpu1, you can see the Local 
>>> APIC of
>>> cpu1.
>> 
>> So it's a special address whose accesses are trapped within the chip and
>> don't actually get out on the memory bus?
> 
> It's physically memory mapped to the local APIC address space, but
> because of that, it's also not optimal. All systems I know use a scheme
> similar to TLS, i.e. using the fs or gs segment register, to fetch
> a per-CPU structure and from it, per-CPU data. This avoids relying on
> hardware running at a lower frequency than the CPU.

You need to do that anyway if you want any guarantees over _what_ the
IDs are (normally you want 0 for the BSP, 1 to N-1 for the APs).

Jess


Reply via email to