| Last Modified On : | July 16, 2007 1:07 PM PDT |
Rate |
|
Identify the number of Hyper-Threading Technology enabled logical processors supported by a physical processor. To maximize performance from Hyper-Threading Technology, applications may set processor affinity on a per-thread basis. With knowledge of application thread-resource requirements, you can effectively schedule threads on logical processors based on their association to the physical processors.
Use the cpuid instruction to retrieve bits 16-23 in register ebx with eax equal to 1. If the physical processor supports Hyper-Threading Technology, then bits 16-23 in register ebx, using the cpuid instruction with eax equal to 1, identifies the number of logical processors the physical processor supports.
The following sample code identifies the number of logical processors per physical processor:
#define NUM_LOGICAL_BITS 0x00FF0000 // |
Other issues related to the detection of support for Hyper-Threading Technology are covered in separate items:
The steps for determining whether Hyper-Threading Technology is supported and for retrieving the number of logical processors per physical processor can be combined, thus minimizing the number of calls to the cpuid instruction.
Note that, although a processor supports Hyper-Threading Technology and has more than one logical processor within the package, Hyper-Threading Technology may not be enabled by BIOS, and the operating system may not utilize the extra logical processors. If Hyper-Threading Technology is not supported, the default number of logical processors per physical processor is one.

Alex Kosenkov
Also it doesn't solve the problem of determining if SMT is enabled at the _moment_ - not just supported -> the solution for this one would be more useful