Counting Physical and Logical 32-bit processors

One of the consequences of the introduction of the Hyper-Threading technology into the Intel® Xeon® processor, is that systems with Hyper-Threading technology enabled appear to the Windows* operating system to have more physical processors than are actually installed. That is because with this technology, one physical processor will be seen as two logical processors. The term logical is used here to distinguish, for example, between the two logical processors in a system with one CPU and the two CPUs in a dual physical processor. When MS Windows* boots on a single processor system with Hyper-Threading enabled, it will report the presence of two CPUs instead of one. This can be a problem for licensing software when implementing per-processor models. Since a two-logical processor system doesn't perform equally to the real dual-physical processor system, users would expect to license for a single physical processor.

Another problem worth considering is the effect on multithreaded applications in a multi processor system. Ideally, to optimize performance, the number of threads created should be equal to the number of available processors. However, in a Hyper-Threading enabled system, a Windows operating system will return the number of logical processors instead of physical processors. Therefore, the number of threads created will be more than the available physical processors. This results in threads competing with each other for resources and can cause degradation in performance. Finally, if the system has Hyper-Threading enabled in the BIOS, there is no guarantee that it will get turned off and on appropriately. To allow developers to account for these issues, the program CPUCount was created to always correctly count the total number of physical CPUs and logical processors per physical CPU, regardless whether or not the system has Hyper-Threading technology and whether Hyper-Threading gets toggled off and on. (For information on CPUCount, and to download a copy of the sample code, go to CPU Counting Utility.)

If CPU Count is used as a stand-alone application, it will return the number of logical processors per physical CPU and the number of physical processors. It will also detect whether Hyper-Threading is enabled or if the processor is capable of supporting Hyper-Threading. You can integrate this program into your own application by eliminating the function "main()" and call the function "CPUCount" from your program to detect Hyper-Threading and count physical processors. CPUCount will return a status flag indicating Hyper-Threading status and number of processors. The number of logical processors per physical one and the total physical processors will be returned in the first and second parameters of the function CPUCount, respectively.

The function "CPUCount" calls three functions:

  • Function "HTSupported"-detects whether Hyper-Threading technology is supported. This function will check to see if the CPU is a genuine Intel CPU and if bit 28 of the register EDX is set to 1. Note that the above conditions only indicate that Hyper-threading is supported, not enabled.
  • Function "LogicalProcPerPhysicalProc"-returns the number of logical processors associating with one physica l processor. If Hyper-Threading is not supported the return value will be 1.
  • Function "GetAPIC_ID" to return the ID of the logical processor. To identify whether Hyper-Threading technology is enabled or not is to check if there exist more than one logical processor ID per physical processor ID.

Messages Displayed by CPUCount

Following are explanations of the messages for cases when the program is to be used as a stand-alone application:

Hyper-threading technology not capable
Hyper-threading technology doesn't exist in this system
Hyper-threading technology disabled
Hyper-threading technology is disabled in the hardware
Hyper-threading technology enabled
Hyper-threading technology is enabled in this system
Hyper-threading capable but not enabled
Hyper-threading technology is supported but disabled in the BIOS
Hyper-threading technology cannot be detected

When the program cannot run on all processors due to some restrictions. The main function of the program is IsHyperT. The other three programs, HTSupported, LogicalProcPerPhysicalProc and GetAPIC_ID are for detecting Hyper-Threading. The function IsHyperT will return a number corresponding to the above messages:

Hyper-threading technology not capable
Hyper-threading technology enabled
Hyper-threading technology disabled
Hyper-threading capable but not enabled
Hyper-threading technology cannot be detected

Related Resources:

For IA-32 Architecture:

For Intel® 64 Architecture (formerly known as Intel® EM64T):


For more complete information about compiler optimizations, see our Optimization Notice.


todd-bezenek's picture

This goes back to a comment I made about utilization of real and Hyperthreaded cores.


anonymous's picture

The "Detecting Multi-Core Processor Topology in an IA-32 Platform" article is missing. Could you please provide an update valid link ? I am very interested in it.

Thank you !

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.