background image

8-42 Vol. 3A

MULTIPLE-PROCESSOR MANAGEMENT

d.

Find the width of an extraction bitmask from the maximum count of the bit-field (address size).

// Returns the mask bit width of a bit field from the maximum count that bit field can represent.
// This algorithm does not assume ‘address size’ to have a value equal to power of 2.
// Address size for SMT_ID can be calculated from MaxLPIDsPerPackage()/MaxCoreIDsPerPackage()
// Then use the routine below to derive the corresponding width of SMT extraction bitmask
// Address size for CORE_ID is MaxCoreIDsPerPackage(), 
// Derive the bitwidth for CORE extraction mask similarly

unsigned FindMaskWidth(Unsigned Max_Count)
{unsigned int mask_width, cnt = Max_Count;

__asm {

mov eax, cnt
mov ecx, 0
mov mask_width, ecx
dec eax
bsr cx, ax
jz next
inc cx
mov  mask_width, ecx
next:  
mov eax, mask_width

}

return mask_width;

}

e.

Extract a sub ID from an 8-bit full ID, using address size of the sub ID and shift count.

// The routine below can extract SMT_ID, CORE_ID, and PACKAGE_ID respectively from the init APIC_ID
// To extract SMT_ID, MaxSubIDvalue is set to the address size of SMT_ID, Shift_Count = 0
// To extract CORE_ID, MaxSubIDvalue is the address size of CORE_ID, Shift_Count is width of SMT extraction bitmask.
// Returns the value of the sub ID, this is not a zero-based value 

Unsigned char GetSubID(unsigned char Full_ID, unsigned char MaxSubIDvalue, unsigned char Shift_Count)
{

MaskWidth = FindMaskWidth(MaxSubIDValue);
MaskBits = ((uchar) (FFH << Shift_Count)) ^ ((uchar) (FFH << Shift_Count + MaskWidth)) ;
SubID = Full_ID & MaskBits;
Return SubID;

}

Software must not assume local APIC_ID values in an MP system are consecutive. Non-consecutive local APIC_IDs 
may be the result of hardware configurations or debug features implemented in the BIOS or OS.
An identifier for each hierarchical level can be extracted from an 8-bit APIC_ID using the support routines illus-
trated in Example 8-20. The appropriate bit mask and shift value to construct the appropriate bit mask for each 
level must be determined dynamically at runtime. 

8.9.5 

Identifying Topological Relationships in a MP System

To detect the number of physical packages, processor cores, or other topological relationships in a MP system, the 
following procedures are recommended:

Extract the three-level identifiers from the APIC ID of each logical processor enabled by system software. The 
sequence is as follows (See the pseudo code shown in Example 8-21 and support routines shown in Example 
8-18
):