Intel architecture ia-32 User Manual

Page of 636
7-42 Vol. 3A
MULTIPLE-PROCESSOR MANAGEMENT
CORE_ID, assuming the number of physical packages in each node of a clustered
system is symmetric.
Assemble the three-level identifiers of SMT_ID, CORE_ID, PACKAGE_IDs into arrays
for each enabled logical processor. This is shown in Example 7-3a.
To detect the number of physical packages: use PACKAGE_ID to identify those logical
processors that reside in the same physical package. This is shown in Example 7-3b. This
example also depicts a technique to construct a mask to represent the logical processors
that reside in the same package.
To detect the number of processor cores: use CORE_ID to identify those logical processors
that reside in the same core. This is shown in Example 7-3. This example also depicts a
technique to construct a mask to represent the logical processors that reside in the same
core.
In Example 7-2, the numerical ID value can be obtained from the value extracted with the mask
by shifting it right by shift count. Algorithms below do not shift the value. The assumption is
that the SubID values can be compared for equivalence without the need to shift. 
Example 7-2
Pseudo Code Depicting Three-level Extraction Algorithm
For Each local_APIC_ID{
// Determine MaxLPPerCore available in hardware
// This algorithm assumes there is symmetry across core boundary, i.e. each core within a 
package has the same number of logical processors
MaxLPPerCore = MaxLPPerPackage()/MaxCoresPerPackage();
// Extract SMT_ID first, this is the innermost of the three levels
// bit mask width is determined from MaxLPPerCore topological info.
// shift size is 0, corresponding to the right-most bit-field
SMT_ID = GetSubID(local_APIC_ID, MaxLPPerCore, 0);
// Extract CORE_ID:
// bit width is determined from maximum number of cores per package possible in hardware
// shift count is determined by maximum logical processors per core in hardware
CORE_ID = GetSubID(InitAPIC_ID, MaxCoresPerPackage(), FindMaskWidth( 
MaxLPPerCore) );
// Extract PACKAGE_ID:
// Assume single cluster. 
// Shift out the mask width for maximum logical processors per package
PackageIDMask = ((uchar) (0xff << FindMaskWidth(MaxLPPerPackage()));
PACKAGE_ID = InitAPIC_ID &  PackageIDMask;
}