| Last Modified On : | April 10, 2008 1:21 PM PDT |
Rate |
|
Determine the Advanced Programmable Interface Controller (APIC) ID for a processor. Each logical processor has a unique APIC ID,which is initially assigned by the hardware at system reset and can be later reprogrammed by the BIOS or the operating system. On a processor that supports Hyper-Threading Technology, the CPUID instruction also provides the initial APIC ID for a logical processor prior to any changes by the BIOS or operating system.
The initial APIC ID is composed of the physical processor's ID and the logical processor's ID within the physical processor. The least significant bits of the APIC ID are used to identify the logical processors within a single physical processor. The number of logical processors per physical processor package determines the number of least-significant bits needed. For example, one least-significant bit is needed to represent the logical IDs for two logical processors, but two least-significant bits are needed to represent the logical IDs for both three and four logical processors. The remaining most-significant bits identify the physical processor ID. As a result, initial APIC IDs are not necessarily consecutive values starting from zero. In general, the APIC ID is given by the following formula:
((Physical Package ID << (1 + ((int)(log(2)(max(Logical_Per_Package-1, |
Use the cpuid instruction with eax equal to 1. The following sample retrieves the processor APIC ID:
#define INITIAL_APIC_ID_BITS 0xFF000000 // EBX[31:24] unique APIC ID |
In order to retrieve the APIC ID for each of the logical processors recognized by the operating system, this code must be run on the specific processors. As shown in the item Associate Logical Processors to Physical Processors, this can be accomplished by setting the processor affinity for the executing code using operating specific system calls.
Other issues related to the detection of support for Hyper-Threading Technology are covered in separate items:

Subham Dutta