background image

Vol. 3A 8-41

MULTIPLE-PROCESSOR MANAGEMENT

b.

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

// Returns the max number of addressable IDs for processor cores in a physical processor package;
// Software should not assume cpuid reports this value to be a power of 2.

unsigned MaxCoreIDsPerPackage(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
store returned value of eax
return (unsigned) ((reg_eax >> 26) +1);

}
else // must be a single-core processor
return 1;

}

c.

Query the initial APIC ID of a logical processor.

#define INITIAL_APIC_ID_BITS FF000000H // CPUID.1.EBX[31:24] initial APIC ID

// Returns the 8-bit unique initial APIC ID for the processor running the code. 
// Software can use OS services to affinitize the current thread to each logical processor 
// available under the OS to gather the initial APIC_IDs for each logical processor.

unsigned GetInitAPIC_ID (void)
{

unsigned int reg_ebx = 0;
execute cpuid with eax = 1
store returned value of ebx
return (unsigned) ((reg_ebx & INITIAL_APIC_ID_BITS) >> 24;

}