beautypg.com

Example 7-3). figure 7-6 dep – Intel IA-32 User Manual

Page 311

background image

Vol. 3A 7-43

MULTIPLE-PROCESSOR MANAGEMENT

Example 7-3

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

InitAPIC_ID = GetInitAPIC_ID();
Extract the Package, Core and SMT ID as explained in three level extraction

algorithm

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 corresponging 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