Hyper-Threading Technology, Multi-core, and Mobile Intel® Pentium® Processor-M Toolbox

Submit New Article

Last Modified On :   March 9, 2009 10:55 PM PDT
Rate
 


Introduction

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.


Conclusion


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.

Additional References


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

About the Author


Khang Nguyen is Senior Applications Engineer working with Intel's Software and Solutions Group. He can be reached at khang.t.nguyen@intel.com.