Intel IA-32 User Manual
Page 307
Vol. 3A 7-39
MULTIPLE-PROCESSOR MANAGEMENT
unsigned int HWMTSupported(void)
{
try { // verify cpuid instruction is supported
execute cpuid with eax = 0 to get vendor string
execute cpuid with eax = 1 to get feature flag and signature
}
except (EXCEPTION_EXECUTE_HANDLER) {
return 0 ; // CPUID is not supported; So HW Multi-threading capability is not present
}
// Check to see if this a Genuine Intel Processor
if (vendor string EQ GenuineIntel) {
return (feature_flag_edx & HWMT_BIT); // bit 28
}
return 0;
}
2.
Find the Max number of logical processors per physical processor package.
#define NUM_LOGICAL_BITS 0x00FF0000
// EBX[23:16] indicates the max number of logical processors per package.
// Returns the max number of logical processors per physical processor package;
// the actual number of logical processors per package enabled by OS may be less.
// Software should not assume the value of (cpuid.1.ebx[23:16]) must be power of 2.
unsigned char MaxLPPerPackage(void)
{
if (!HWMTSupported()) return 1;
execute cpuid with eax = 1
store returned value of ebx
return (unsigned char) ((reg_ebx & NUM_LOGICAL_BITS) >> 16);
}
3.
Find the max number of processor cores per physical processor package.
// Returns the max number of processor cores per physical processor package;
// the actual number of processor cores per package that are enabled may be less.
// Software should not assume the value of (cpuid.4.eax[31:26] +1) must be power of 2.
unsigned MaxCoresPerPackage(void)
{
if (!HWMTSupported()) return (unsigned char) 1;
if cpuid supports leaf number 4
{ // we can retrieve multi-core topology info using leaf 4
execute cpuid with eax = 4, ecx = 0