On Tue, Mar 21, 2023 at 6:33 PM Almudena Garcia
<liberamenso10...@gmail.com> wrote:
> > But how does a core know its CPU number?
>
> Calling cpu_number() function, or getting its APIC ID from its Local APIC

Ah.

That's too hardware-y for me to understand; but I see that cpu_number
() in i386/i386/cpu_number.c also uses apic, and apic_get_current_cpu
() in i386/i386/apic.c looks fast enough, so, cool!

I know that Linux uses %gs; in particular their docs say:

-- >8 --
For example:

DEFINE_PER_CPU(int, x);
int z;

z = this_cpu_read(x);

results in a single instruction:

mov ax, gs:[x]
-- 8< --

https://docs.kernel.org/core-api/this_cpu_ops.html#inner-working-of-this-cpu-operations

Sergey

Reply via email to