> 256 is a common default
> (I know that's what FreeBSD uses for x86) as the APIC IDs are 8-bit,
> and I think this should be 256 rather than 255 too
I agree. It's a mistake.
> Though I do
> question what the point of mach_ncpus is if it isn't being used to
> determine NCPUS.
Currently, mach_ncpus is used to define NCPUS. I keep It, because It can be useful to enable/disable the SMP support, and this patch is low-invasive, avoiding to broke more things.
> AC_DEFINE_UNQUOTED([NCPUS], [$mach_ncpus], [number of CPUs])
This define can be removed, of course. I don't know because I keep It there.
>> + return apic_id;
This line doesn't get the Kernel ID, but the APIC ID.
The APIC ID can be obtained from the common Local APIC address, which points to the Local APIC of the current CPU (if you access this address from cpu1, you get the APIC ID of cpu1).
The ACPI tables also stores the APIC ID of each CPU, so I enumerate the processors in an array using this. The array is indexed by Kernel ID (the logical ID), and stores the APIC ID for each cpu.