Using htmobile Library Functions to Discover Processor Information


Introduction

The htmobile library provides a convenient means to retrieve feature and identification data to improve application performance.

The variety of hardware platforms currently available requires applications to have access to increasingly large amounts of hardware information in order to run efficiently.

Systems that support Hyper-Threading Technology, for instance, expose two logical processors to the operating system for each physical processor. This characteristic produces a challenge, since the two logical processors share some resources and must be treated differently than two physical processors. Moreover, since the operating system will report two CPUs instead of one, Hyper-Threading Technology must be addressed in terms of software licensing when implementing per-processor pricing models.

Another problem to be considered is the case of multithreaded applications in a multiprocessor system. Ideally, the number of threads created should be equal to the number of available processors, in order to optimize performance.

In a Hyper-Threading Technology-enabled system, however, the operating system will return the number of logical processors instead of physical processors. Thus, the number of threads created could be greater than the number of physical processors. This situation would result in threads competing for resources, causing degraded performance.

It is also necessary to know the IDs of the current physical processor, logical processor, process, and thread for purposes of load balancing.

Finally, Intel® Centrino® mobile technology raises the need for a utility to detect the Pentium® M processor, since its architecture is different from that of the Pentium® 4 processor. Due to the differences in architecture, programs optimized for the Pentium 4 processor are not guaranteed to run well on systems based on Intel Centrino mobile technology.


The htmobile Library Retrieves Robust Platform Information

The htmobile library contains functions that provide information to address many of the issues associated with these challenges. Roles served by these functions range from detecting Hyper-Threading, physical processors, and processor IDs to identifying mobile system characteristics and status, detecting Streaming SIMD Extensions (SSE/SSE2) support, and support for Prescott New Instructions (PNI) Technology.

The library was created in an attempt to make a one-stop shop so that developers do not have to spend their time recreating utility functions or linking many libraries. They can therefore concentrate their energy on developing their own programs.

The library supports a wide variety of hardware platforms, including the AMD Athlon*, Pentium® processor, Pentium® Pro processor, Pentium® II processor, Pentium® III processor, Pentium® III Xeon™ processor, Pentium 4 processor, and Pentium M processor. Systems can have any number of physical processors. The library supports Windows* 98 SE, Windows ME, 32-bit Windows 2000, and 32-bit Windows XP. It supports the Intel® C++ compilers, as well as the Microsoft Visual C++ 6.0 compiler and later.

The htmobile library consists of two parts: the library itself, called htmobile.lib, and the include file, named htmobile.h. The functions in the library can logically be divided into three categories: functions related to Hyper-Threading Technology, functions related to processor features, and functions related to mobility. The following discussion of the functions divides them into those three categories.

Functions in the htmobile Library Related to Hyper-Threading Technology

The following htmobile functions gather information related to Hyper-Threading technology:

  • GetAPIC_Physical_IDreturns a byte value that contains both the physical and logical IDs of the current process.
    • Syntax: unsigned char GetAPIC_Physical_ID (void)
    • Return Value: 0xFF if the system does not support this feature.
  • LogicalProcPerPhysicalProcreturns a byte value that contains the number of logical processors per physical package.
    • Syntax: unsigned char LogicalProcPerPhysicalProc (void)
    • Return Value: Number of logical processors.
  • SupportHTchecks to see if the processor has Hyper-Threading technology built-in.
    • Syntax: unsigned int SupportHT (void)
    • Return Value: 0 If Hyper-Threading technology is not built-in.
  • HTStatusretrieves the status of Hyper-Threading Technology.
    • Syntax: BYTE HTStatus (void)
    • Return Values:
      HT_NOT_CAPABLE 1
      HT_ENABLED 2
      HT_PERMANENT_DISABLED 4
      HT_SUPPORTED_NOT_ENABLED 8
      HT_CANNOT_DETECT 16
  • NumberOfPhysicalCPUretrieves the number of physical processors, regardless of whether or not Hyper-Threading Technology is enabled.
    • Syntax: DWORD NumberOfPhysicalCPU (void)
    • Return Value: CANNOT_DETECT_PHY_CPU 0xFF if there is an error.
  • CurPhysicalProcIdretrieves the ID number of the current physical processor.
    • Syntax: DWORD CurPhysicalProcId (void)
    • Return Value: PHY_ID_NOT_SUPPORTED 0xFFFFFFFF if the processor is neither a Pentium 4 processor nor a Mobile Intel® Pentium® 4 Processor-M.
  • CurLogicalProcIdretrieves the ID number of the current physical processor.
    • Syntax: DWORD CurLogicalProcId (void)
    • Return Value: LOG_ID_NOT_SUPPORTED 0xFFFFFFFF if the processor is neither a Pentium 4 processor nor a Mobile Intel Pentium 4 Processor-M.
  • CurProcessIdretrieves the ID number of the current process.
    • Syntax: DWORD CurProcessId (void)
  • CurThreadIdretrieves the ID number of the current physical processor.
    • Syntax: DWORD CurThreadId (void)

 


Functions in the htmobile Library Related to Features

The following htmobile functions gather information related to processor features:

  • SupportMMXchecks to see if the processor supports MMX.
    • Syntax: bool SupportMMX (void)
    • Return Value: 0 If MMX is not supported.
  • SupportSSEchecks to see if the processor supports SSE.
    • Syntax: bool SupportSSE (void)
    • Return Value: 0 If SSE is not supported.
  • SupportSSE2checks to see if the processor supports SSE2.
    • Syntax: bool SupportSSE2 (void)
    • Return Value: 0 If SSE2 is not supported.
  • SupportPNIchecks to see if the processor supports PNI.
    • Syntax: bool SupportPNI (void)
    • Return Value: 0 If PNI is not supported.

 


Functions in the htmobile Library Related to Mobility

The following htmobile functions gather information related to mobile system functionality:

  • ACLineONchecks to see if the laptop is plugged into the AC outlet.
    • - Syntax: bool ACLineON (void)
    • - Return Value: 0 If the system is not plugged in.
  • GetBatteryChargingStatus gets the status of the laptop battery. (Note:This function can only be used for non-critical applications.)
    • - Syntax: BYTE GetBatteryChargingStatus (void)
    • - Return Values:
      NO_BATTERY 128
      BATTERY_STATUS_UNKNOWN 255
      CHARGE_HIGH 1
      CHARGE_LOW 2
      CHARGE_CRITICAL 4
      CHARGE_CHARGING 8
  • PercentBatteryRemain gets the percentage of charge remaining in the laptop battery. (Note:This function can only be used for non-critical applications.)
    • - Syntax: BYTE PercentBatteryRemain (void)
    • - Return Value: PERCENT_BATTERY_UNKNOWN 255 if there is error.
  • BatteryTimeRemain gets the operating time remaining from the laptop battery. (Note:This function can only be used for non-critical applications.)
    • - Syntax: DWORD BatteryTimeRemain (void)
    • - Return Value: UNKNOWN 0xFFFFFFFF if there is error.
  • BatteryFullTime gets the percentage remaining of the laptop battery. (Note:This function can only be used for non-critical applications.)
    • - Syntax: DWORD BatteryFullTime (void)
    • - Return Value: UNKNOWN 0xFFFFFFFF if there is error.

 


Conclusion

Counting correctly the number of physical processors in a system is very important, since that information is the building block of performance for multi-threaded applications in multi-processor machines. It is even more vital in systems that support Hyper-Threading Technology, since Windows has no way on its own to obtain information about the number of physical processors.

Developers must distinguish between systems based on Pentium 4 processors and Pentium M processors, since these two different architectures require different optimizations by applications. Coupled with additional information that is provided by the functions in the htmobile library, including processor features and mobile power data, this information can efficiently provide the basis for applications to detect key information about the operating hardware platform. That information is vital to providing responsive applications that make the best use of the hardware.


Additional Resources

Information related to the material covered in this article is available from the Intel® 64 and IA-32 Architectures Developer's Manual: Vol. 2A.

Intel, the world's largest chipmaker, also provides an array of value-added products and information to software developers:

  • Intel Software Development Products include Compilers, Performance Analyzers, Performance Libraries and Threading Tools.
  • IT@Intel through a series of white papers, case studies, and other materials, describes the lessons it has learned in identifying, evaluating, and deploying new technologies.

Download Source Code

 

Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.