Intel x86_64 CPUs relate each logical processor to a unique APIC ID.
This answer mentions a Linux kernel table named x86_cpu_to_apicid, containing a mapping between the core id numbers used inside the OS (and lscpu, for example) and the corresponding APIC ID.
apropos x86_cpu_to_apicid gave no results. The only material I found is the kernel sourcecode files using it.
Is there a way, from userspace, to access and read this table? Or can it only be accessed in a kernel module? And how?
As far as I know,
x86_cpu_to_apicidis not a table but aper_cpuvariable, meaning that it gets replicated for each CPU but it isn't strictly aggregated into a table.Of course, you can consider each replicated section of per-cpu data as an "entry" in a table but that's a bit of a stretch.
x86_cpu_to_apicidis a kernel variable and you cannot access it from user space. It would be pretty trivial to make an LKM that return the APIC ID for the current processor:Then you could read the APIC ID of the current processor from
/proc/apicid, e.g. withparallel -v taskset -c {} dd status=none if=/proc/apicid bs=2 count=1 '|' xxd -p ::: {1..4}(for the first four CPUs).However, for Intel's CPU the APIC ID is also available through the
cpuidinstruction. Initially at leaf 0x1, then 0xb and finally at leaf 0x1f (if supported and the value returned is not zero).For example the output of the command
cpuid -l 0xbgives me the same APIC IDs retrieved through the LKM above.Note that the Intel's LAPIC can be in APIC, xAPIC and x2APIC mode and that the APIC ID in the xAPIC and APIC mode can be modified in some processor. The value returned by
cpuidis the initial value. Modern OSes uses APIC in x2APIC mode and don't/cannot modify the APIC ID AFAIK, socpuidis a valid way to get the APIC IDs from userspace.For completeness, there was once a
/proctree that exposed the APIC ID of each CPU but it's now gone.I don't know if it's still possible find the APIC ID somewhere under
/sysor/proc.