background image

8-44 Vol. 3A

MULTIPLE-PROCESSOR MANAGEMENT

Example 8-22.  Compute the Number of Packages, Cores, and Processor Relationships in a MP System

a) Assemble lists of PACKAGE_ID, CORE_ID, and SMT_ID of each enabled logical processors

//The BIOS and/or OS may limit the number of logical processors available to applications 
// after system boot. The below algorithm will compute topology for the processors visible 
// to the thread that is computing it.

// Extract the 3-levels of IDs on every processor
// SystemAffinity is a bitmask of all the processors started by the OS. Use OS specific APIs to
// obtain it.
// ThreadAffinityMask is used to affinitize the topology enumeration thread to each processor
using OS specific APIs.
// Allocate per processor arrays to store the Package_ID, Core_ID and SMT_ID for every started
// processor.
 

ThreadAffinityMask = 1;

     ProcessorNum = 0;

while (ThreadAffinityMask ≠ 0 && ThreadAffinityMask <= SystemAffinity) {

// Check to make sure we can utilize this processor first.
if (ThreadAffinityMask & SystemAffinity){

Set thread to run on the processor specified in ThreadAffinityMask
Wait if necessary and ensure thread is running on specified processor

APIC_ID = GetAPIC_ID(); // 32 bit ID in Example 8-19 or 8-bit ID in Example 8-20
Extract the Package_ID, Core_ID and SMT_ID as explained in three level extraction 

algorithm of Example 8-21

PackageID[ProcessorNUM] = PACKAGE_ID;
CoreID[ProcessorNum] = CORE_ID;
SmtID[ProcessorNum] = SMT_ID;
ProcessorNum++;

}
ThreadAffinityMask <<= 1;

}
NumStartedLPs = ProcessorNum;

b) Using the list of PACKAGE_ID to count the number of physical packages in a MP system and construct, for each package, a multi-bit 

mask corresponding to those logical processors residing in the same package.

// Compute the number of packages by counting the number of processors 

// with unique PACKAGE_IDs in the PackageID array. 

// Compute the mask of processors in each package.

PackageIDBucket is an array of unique PACKAGE_ID values. Allocate an array of

NumStartedLPs count of entries in this array.
PackageProcessorMask is a corresponding array of the bit mask of processors belonging to

the same package, these are processors with the same PACKAGE_ID 
The algorithm below assumes there is symmetry across package boundary if more than 

one socket is populated in an MP system.
// Bucket Package IDs and compute processor mask for every package.

PackageNum = 1;
PackageIDBucket[0] = PackageID[0];
ProcessorMask = 1;
PackageProcessorMask[0] = ProcessorMask;