Correct the logical_cpus calculation in mptable_hyperthread_fixup()
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Wed, 17 Jun 2009 11:54:22 +0000 (19:54 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 22 Jun 2009 11:39:49 +0000 (19:39 +0800)
commit7ea07fd226314dc116e1089cb39196610300b406
tree5e914bb816116ce251e4a9e5e7c13d8e902414a3
parent1224db28eb878893947ccf6f99e69a9acdc5144f
Correct the logical_cpus calculation in mptable_hyperthread_fixup()

The original code extracts logical_cpus directly from the output of
cpuid(eax=1), however,
According to Intel's #253668, section 7.7
"(CPUID.1:EBX[23:16]) -- Indicates the maximum number of addressable
 ID for logical processors in a physical package."
According to AMD's #25481 CPUID Fn0000_0001_EBX
"LogicalProcessorCount is the number of threads per CPU core times the
 number of CPU cores per processor."

So what we originally saved in logical_cpus is actually the upper limit
of the logical CPUs per phyical CPU package.  It may work correctly if
there is only one logical CPU per physical CPU package detected in MP
table.  But if more than one logical CPUs per phyical CPU package are
detected in the MP table, then the missing logical CPUs will not be
detected later, since the code assumed that logical_cpus is the number
of logical CPUs missed between two detected logical CPUs.

We try to fix the problem by calculating the distances between two nearest
APIC IDs.  If all such distances for all detect logical CPUs are same,
then the logical_cpus is set the calculated distance.  The value extracted
from cpuid(eax=1) just serves as the upper limit of the logical_cpus now.

Reported-and-Tested-by: Robert Luciani <rluciani@gmail.com>
sys/platform/pc32/i386/mp_machdep.c