background image

8-40 Vol. 3A

MULTIPLE-PROCESSOR MANAGEMENT

b.

Derive the extraction bitmask for processor cores in a physical processor package and associated mask offset for
different packages.

int DeriveCore_Mask_Offsets (void)
{

if (!HWMTSupported()) return -1;

execute cpuid with eax = 11, ECX = 0;

while( ECX[15:8] ) { // level type encoding is valid

If (returned level type encoding in ECX[15:8] matches CORE) {

Mask_Core_shift = EAX[4:0]; // needed to distinguish different physical packages
COREPlusSMT_MASK = ~( (-1) << Mask_Core_shift);
CORE_MASK = COREPlusSMT_MASK ^ SMT_MASK;
PACKAGE_MASK = (-1) << Mask_Core_shift;
return 0

}
ECX ++;
execute cpuid with eax = 11;

}
return -1;

}

c.

Query the x2APIC ID of a logical processor.

APIC_IDs for each logical processor.

unsigned char Getx2APIC_ID (void)
{

unsigned reg_edx = 0;
execute cpuid with eax = 11, ECX = 0
store returned value of edx
return (unsigned) (reg_edx) ;

}

Example 8-20.  Support Routines for Identifying Package, Core and Logical Processors from 8-bit Initial APIC ID

a.

Find the size of address space for logical processors in a physical processor package.

#define NUM_LOGICAL_BITS 00FF0000H 
// Use the mask above and CPUID.1.EBX[23:16] to obtain the max number of addressable IDs
// for logical processors in a physical package, 

//Returns the size of address space of logical processors in a physical processor package;
// Software should not assume the value to be a power of 2.

unsigned char MaxLPIDsPerPackage(void)
{

if (!HWMTSupported()) return 1;

execute cpuid with eax = 1

store returned value of ebx
return (unsigned char) ((reg_ebx & NUM_LOGICAL_BITS) >> 16);

}