| Last Modified On : | March 9, 2009 10:55 PM PDT |
Rate |
|
A Hyper-Threading Technology (HT Technology) enabled system appears to have more processors than it actually has. With this technology, one physical processor with a single-core is seen as two logical processors. The term logical is used here purposely as these two logical processors are not the same as a dual physical processor. Windows* will report to have two CPUs instead of one. This can be a big problem for licensing software especially when implementing per-processor models, since a two-logical processor system doesn’t perform equally to the real dual-physical processor system. Now, with the introduction of multi-core, the licensing problem is getting worse.
A core is different from a logical processor. The core has its own set of execution units. Also, a core can have more than one logical processor associated with it. In a multi-core HT Technology enabled system, one physical processor can have a minimum of two cores (dual-core) and four logical processors. This is good for multi-threading applications. Cores have their own set of execution units. Therefore, unlike running on logical processors, two threads, each running on a separate core of the same physical processor, do not compete for execution units. Additionally, in multi-core systems you can retrieve the number of threads that can be served by any cache level. This information is generally important for cache blocking applications. For load balancing, it is important that you know which logical processor is associated with which physical processor. Finally, there is a need for a utility to detect the Mobile Intel® Pentium® 4 Processor-M, since its architecture is different from that of the Intel® Pentium® 4 Processor. Due to the difference in architecture between the Pentium 4 processor and Mobile Intel Pentium 4 Processor-M, programs optimized for Pentium 4 processors are not guaranteed to run well on Mobile Intel Pentium 4 Processor-M systems. The library, HTMulticore, contains many functions ranging from detecting HT Technology, multi-core, physical processors, processor ID to identifying Mobile Intel Pentium 4 Processor-M, and Streaming SIMD Extension (SSE/SSE2/SSE3). The library was created in an attempt to make it a one-stop shop so that developers don’t have to spend time recreating those utility functions or link to many libraries. They can concentrate their energy in developing their own programs.
Overview of the HTMulticore Library
The HTMulticore library consists of two parts, the library itself called HTMulticore.lib and the include file, named HTMulticore.h.
This library can be divided into three categories namely: HT Technology, Features, and Mobile. The functions included in the HTMulticore library are listed under these three categories. The subsequent sections of this article describe each of these categories in detail.
HT Technology
The following functions are listed under the HT Technology category:
GetAPIC_Physical_ID
Syntax: unsigned char GetAPIC_Physical_ID (void)
Description: This function returns a byte value that contains both the physical and logical ids of the current process.
Return Value: 0xFF if the system does not support this feature.
LogicalProcPerPhysicalProc
Syntax: unsigned char LogicalProcPerPhysicalProc (void)
Description: This function returns a byte value that contains the maximum number of logical processors per physical package. This is the maximum value of a logical processor that a physical package can handle. In order to get the number of available logical processors that a program can use, use the function CPUCount to get the value of AvailLogicalNum.
Return Value: Number of logical processors.
CorePerPhysicalProc
Syntax: unsigned char CorePerPhysicalProc (void)
Description: This function returns a byte value that contains the maximum number of cores per physical package. This is the maximum value of cores that a physical package can handle. In order to get the number of available cores that a program can use, use the function CPUCount to get the value of AvailCoreNum.
Return Value: Number of maximum cores per physical package.
HTSupported
Syntax: unsigned int HTSupported (void)
Description: This function checks if the processor has Hyper-Threading technology built-in.
Return Value: 0 If Hyper-Threading is not built-in.
CPUCount
Syntax: unsigned char CPUCount
(unsigned char *AvailLogicalNum, unsigned char *AvailCoreNum, unsigned char *PhysicalNum,)
Description: This function retrieves the number of available logical processors per physical package, available cores per physical package, and the total number of physical processors. The term “available” implies that the number of logical or cores that an application can use. These numbers are different from those returned by the functions LogicalProcPerPhysicalProc and CorePerPhysicalProc. These two functions return the maximum values of logical and cores that a physical package can handle. These numbers are for reference only. They cannot be used to create threads. Otherwise, performance will be degraded.
If for some reason that the total number of physical cannot be determined, the variable “PhysicalNum” will be set to this value: CANNOT_DETECT_PHY_CPU 0xFF
Return Value: Returns the status of the system. Following are the possible status:
SINGLE_CORE_AND_HT_ENABLED 1 SINGLE_CORE_AND_HT_DISABLED 2 SINGLE_CORE_AND_HT_NOT_CAPABLE 4 MULTI_CORE_AND_HT_NOT_CAPABLE 5 MULTI_CORE_AND_HT_ENABLED 6 MULTI_CORE_AND_HT_DISABLED 7 CORE_AND_HT_CANNOT_DETECT 8 CORE_CANNOT_DETECT_AND_HT_NOT_CAPABLE 9
IsMultiCore
Syntax: unsigned int IsMultiCore (void)
Description: This function will check if the processor is multi-core or not.
Return Value: 0 if the processor is not multi-core.
CurProcessId
Syntax: DWORD CurProcessId (void)
Description: This function retrieves the id number of the current process.
Return Value: DWORD
CurThreadId
Syntax: DWORD CurThreadId (void)
Description: This function retrieves the id number of the current physical processor.
Return Value: DWORD
Features
The following functions are listed under the Features category:
SupportMMX
Syntax: bool SupportMMX (void)
Description: This function checks if the processor supports Intel® MMX™ Technology
Return Value: 0 if MMX Technology is not supported.
SupportSSE
Syntax: bool SupportSSE (void)
Description: This function checks if the processor supports SSE
Return Value: 0 if SSE is not supported.
SupportSSE2
Syntax: bool SupportSSE2 (void)
Description: This function checks if the processor supports SSE2
Return Value: 0 if SSE2 is not supported.
SupportSSE3
Syntax: bool SupportSSE3 (void)
Description: This function checks if the processor supports SSE3 (PNI)
Return Value: 0 If SSE3 (PNI) is not supported.
Mobile
The following functions are listed under the Mobile category:
ACLineON
Syntax: bool ACLineON (void)
Description: This function checks if the laptop is plugged into the AC outlet.
Return Value: 0 If not plug in.
GetBatteryChargingStatus
Syntax: BYTE GetBatteryChargingStatus (void)
Description: This function gets the status of the laptop battery.
Return Value: NO_BATTERY 128 BATTERY_STATUS_UNKNOWN 255 CHARGE_HIGH 1 CHARGE_LOW 2 CHARGE_CRITICAL 4 CHARGE_CHARGING 8 Note: This function can only be used for non-critical applications.
PercentBatteryRemain
Syntax: BYTE PercentBatteryRemain (void)
Description: This function gets the percentage remain of the laptop battery.
Return Value: PERCENT_BATTERY_UNKNOWN 255 if there is error.
Note: This function can only be used for non-critical applications.
BatteryTimeRemain
Syntax: DWORD BatteryTimeRemain (void)
Description: This function gets the time remain of the laptop battery.
Return Value: UNKNOWN 0xFFFFFFFF if there is error.
Note: This function can only be used for non-critical applications.
BatteryFullTime
Syntax: DWORD BatteryFullTime (void)
Description: This function gets the percentage remain of the laptop battery.
Return Value: UNKNOWN 0xFFFFFFFF if there is error.
Note: This function can only be used for non-critical applications.
Multi-core systems will definitely improve multi-threaded applications written for HT Technology enabled systems. Counting the number of physical processors correctly in a system is very important, even before the introduction of HT Technology since it is the building block of performance for multi-threaded applications in multi-processor machines. It becomes a must-have piece of information on HT Technology enabled systems since Windows has no way to obtain information about the number of physical processors. Also, note that a multi-core system is still not the same as a multi-processor system. Multi-core systems still shares certain cache levels. Therefore, keep in mind that multi-core is not a multi-processor when developing multi-threaded applications. Developers also need to distinguish between Pentium 4 processors and Mobile Intel Pentium 4 Processor-M, since different architectures need different methods to optimize the applications. As of mobile battery functions, they are useful to estimate the time remaining. Since the battery functions are used for estimation, do not use it for critical applications. They are used for rough estimation only.
Read about the Intel Application Note: AP485- “Intel Processor Identification and CPUID Instruction” that explains how to use the CPUID instruction in software applications, BIOS implementations, and various processor tools at:
http://www.intel.com/design/xeon/applnots/241618.htm
Khang Nguyen is Senior Applications Engineer working with Intel's Software and Solutions Group. He can be reached at khang.t.nguyen@intel.com.
| April 30, 2009 5:20 AM PDT
Pavol Marton |
Does not work on my Core i7 920... Reports 8 cores instead of 4: Pentium M processor: No MMX : Yes SSE : Yes SSE2: Yes SSE3: Yes Hyper-Threading Technology: Not Capable System: Multi-core Number of available logical processors per physical processor: 1 Number of available cores per physical processor: 8 Number of physical processors: 1 |
| August 16, 2009 10:57 AM PDT
Nick Black
|
Outstanding! I've been carrying around my own code to interpret <a href="http://dank.qemfd.net/dankwiki/index.php/Cpuid">CPUID</a> (requiring constant attention to processor updates, or at least Dave Jones's excellent <a href="http://www.codemonkey.org.uk/projects/x86info/">x86info</a>) and OS-level exports to determine <a href="http://dank.qemfd.net/dankwiki/index.php/SMP_on_x86">processor count</a>. I assume that, as this library grows, it'll detail core topology? Hopefully things like CPUSETS and Linux's Control Groups will make this less important to the parallel systems programmer than it is now. The inexorable march of manycore makes this kind of thing a major issue (we don't want two processes scheduled on widely-separated cores) -- good solutions at the OS level ought solve this, though. Extension of this library to report other CPUID elements (especially interior cache parameters) would be a similarly-welcomed development. I'm surely not the only guy carrying around his own code with comments like: // Uses all four primary general-purpose 32-bit registers (e[abcd]x), returning // these in gpregs[0123]. We must preserve EBX ourselves in when -fPIC is used. or, regarding signets (always happiest to see GenuntelineI! =D): // There's also: (Collect them all! Impress your friends!) // " UMC UMC UMC" "CyriteadxIns" "NexGivenenDr" // "RiseRiseRise" "GenuMx86ineT" "Geod NSCe by" or, in a moment of rage: // XXX What a cheap piece of garbage, yeargh! VIA doesn't supply cache // line info via CPUID. VIA C3 Antaur/Centaur both use 32b. The proof // is by method of esoteric reference: // http://www.digit-life.com/articles2/rmma/rmma-via-c3.html |
| September 3, 2009 12:44 AM PDT
softnjuhotmail.com
|
Use the CPUID instruction to detect the presence of hardware multi-threading support in a physical processor. Hardware multi-threading can support several varieties of multigrade and/or Intel Hyper-Threading Technology. CPUID instruction provides several sets of parameter information to aid software enumerating topology information. The relevant topology enumeration parameters provided by CPUID include: •Hardware Multi-Threading feature flag (CPUID.1:EDX[28] = 1) — Indicates when set that the physical package is capable of supporting Intel Hyper-Threading Technology and/or multiple cores. I want to detect whethere a system is support HT only, but it seems EDX[28] means HT/MULTICORE, how can I identify HT? |
| September 3, 2009 11:38 AM PDT
Khang Nguyen (Intel)
|
Hi Gaston, I am sorry that it took too long to reply to your post. I have had problem with my account for a long time. I am also busy with other projects. Anyway, I need to update this tool to handle next generation of Intel processors. This current version won't detect i7 correctly. I am looking for the correct link that shows how to correctly detect processors including i7. Stay tuned. Khang |
| September 3, 2009 11:41 AM PDT
Khang Nguyen (Intel)
|
Hi Pavol, I apologize for taking too long to reply to your post ( reasons in my previous post.) The current version of this tool does not support i7. Khang |
| September 3, 2009 11:44 AM PDT
Khang Nguyen (Intel)
|
Hi Nick, I have been busy with other higher priority projects. I will try to find some time updating this tool. Thanks, Khang |
| September 3, 2009 12:32 PM PDT
Gastón C. Hillar
|
Hi Khang, It's great to know there is going to be an updated release. I'm looking forward to working with the new version soon. Thanks, Gaston |
| September 3, 2009 7:28 PM PDT
softnjuhotmail.com
|
HI Khang, I am trying to find a way to detect whether a system is supporting HT, EDX[28] seems means both HT and Multi core, do you have a way to identify HT only? thanks a lot Here is the define of HT_BIT from you .h file. #define HT_BIT 0x10000000 // EDX[28] Bit 28 is set if HT is supported // Doesn't mean HT is enabled in BIOS |
| September 10, 2009 5:47 AM PDT
Malathi |
i am getting the number of cores per processor 8 instead of 4. I am using Intel Xeon E5540. And also i got, Number of available logical processors per physical processor: 1 Number of physical processor: 1 (as that of previous post given by Pavol). Please give me the suggestion? |
| September 11, 2009 3:52 AM PDT
Malathi | Sorry, I got number of cores per processor as 16 instead of 4 |
| September 11, 2009 3:55 AM PDT
Malathi | CPU-z utility is giving me the right information of number of cores per processor as 4. In my machine "HT is not enabled". May i know why this variation between intel products. |
| September 17, 2009 6:27 AM PDT
John |
I am using Intel Xeon E5540 Processor. Is there any way to get 1.)Number of cores per processor. 2.) Number of logical processors. Please let me know , since I am getting incorrect values. |
| September 18, 2009 2:44 PM PDT
Intel Software Network Support
|
Readers might also be interested in Shih Kuo's article, Intel® 64 Architecture Processor Topology Enumeration: http://software.intel.com/en-us/articles/intel-64-architectu.....umeration/ Also, we recommend posting requests for technical assistance to the Threading on Intel(R) Parallel Architectures forum at http://software.intel.com/en-us/forums/threading-on-intel-pa..... itectures/ rather than on this page, as technical support is not generally offered via page comments. |
| October 20, 2009 10:27 PM PDT
Geoffrey Grinton |
I have been using this code for some time - thanks! But I am also aware of, and have started using the code in Shih Kuo's article, referenced above. Now I am trying to reconcile the two sets of data, and need help please. Here is output on my Lenovo ThinkPad, using the distributed sample programs. HTMultiCore tells me: Hyper-Threading Technology: Not Capable System: Multi-core Number of available logical processors per physical processor: 1 Number of available cores per physical processor: 2 Number of physical processors: 1 cpu_topo tells me: Number of logical processors visible to the OS: 2 Number of logical processors visible to this process: 2 Number of processor cores visible to this process: 2 Number of physical packages visible to this process: 1 And, for reference, the systeminfo command tells me: System type: X86-based PC Processor(s): 2 Processor(s) Installed. [01]: x86 Family 6 Model 15 Stepping 10 GenuineIntel ~1995 Mhz [02]: x86 Family 6 Model 15 Stepping 10 GenuineIntel ~1994 Mhz It is unclear to me whether the terms "physical processor" (HTMultiCore) and "physical package" (cpu_topo) are synonymous or not. If they are meant to be, then it seems to me that I am getting different answers, since in once case I see 1 logical processor per physical processor, and in the other case, 2 logical processors "visible" - which I presume means per physical package, since there is only one of them. Can you help me understand how to interpret these results please? Thanks. Geoffrey |
| November 20, 2009 12:08 PM PST
Brian Ipsen |
I have problems using this library in Visual Studio 2008 - when linking, it complains that it cannot find LIBC.lib Is it possible to have a rebuild of the linker lib, so it can be used with Visual Studio 2008 ? Thanks Brian |

English | 中文 | Русский | Français
Khang Nguyen (Intel)
|
Gastón C. Hillar
3,156
Status Points:
3,156
The code is very useful. Nowadays that Core i7 comes with HT + multicore, I needed to go back to Hyper-Threading days, combined with multicore. I am calling these code from C# (wrapping it) and it works fine.
I guess it should be great to have a new release supporting SSE4 AND SSE4.2 detection.
Cheers,
Gastón