background image

Vol. 3A 8-39

MULTIPLE-PROCESSOR MANAGEMENT

Example 8-18.  Support Routines for Detecting Hardware Multi-Threading and Identifying the Relationships Between Package, 

Core and Logical Processors

1.

Detect support for Hardware Multi-Threading Support in a processor.

//  Returns a non-zero value if CPUID reports the presence of hardware multi-threading 

//  support in the physical package where the current logical processor is located. 
//  This does not guarantee BIOS or OS will enable all logical processors in the physical 
//  package and make them available to applications. 
//  Returns zero if hardware multi-threading is not present. 

#define HWMT_BIT 10000000H

unsigned int HWMTSupported(void)
{

 // ensure cpuid instruction is supported

execute cpuid with eax = 0 to get vendor string
execute cpuid with eax = 1 to get feature flag and signature

// Check to see if this a Genuine Intel Processor 

if (vendor string EQ GenuineIntel) {

return (feature_flag_edx & HWMT_BIT); // bit 28

}
return 0;

}

Example 8-19.  Support Routines for Identifying Package, Core and Logical Processors from 32-bit x2APIC ID

a.

Derive the extraction bitmask for logical processors in a processor core and associated mask offset for different
cores.

int DeriveSMT_Mask_Offsets (void)
{

if (!HWMTSupported()) return -1;
execute cpuid with eax = 11, ECX = 0;
If (returned level type encoding in ECX[15:8] does not match SMT) return -1;
Mask_SMT_shift = EAX[4:0]; // # bits shift right of APIC ID to distinguish different cores
SMT_MASK = ~( (-1) << Mask_SMT_shift); // shift left to derive extraction bitmask for SMT_ID
return 0;

}