CPUINFO Appnote Version 1.0
CPUINFO
TECHNICAL SPECIFICATIONSAPPNOTE
VERSION 1.2
INTEL CORPORATION
JANUARY 1997
TABLE OF CONTENTS
CPUINFO Appnote Version 1.0 i
1. INTRODUCTION 1
1.1 MOTIVATION 1
1.2 ABSTRACT 1
1.3 USAGE 1
2. SYSTEM REQUIREMENTS 1
2.1 CPUINF16.DLL 1
2.2 CPUINF32.DLL 2
3. THEORY 2
3.1 PROCESSOR AND FEATURE IDENTIFICATION 2
3.2 PROCESSOR CLOCK FREQUENCY 2
4. CPUINFO CODE OVERVIEW 5
4.1 CPUINF16.DLL 5
4.1.1 CPUID.C 6
4.1.2 TIMEPROC.ASM 6
4.1.3 SPEED. C 7
4.2 CPUINF32.DLL 8
4.2.1 CPUID.C 9
4.2.2 SPEED.C 9
4.3 SAMPLE PROGRAMS: TSTDLL16 & TSTDLL32 9
4.3.1 TSTDLL32.C 9
4.3.2 TSTDLL16.C 11
5. DISCLAIMER 11
CPUINFO Appnote Version 1.0 0
1. INTRODUCTION
1.1 MOTIVATION
Multimedia applications have a tendency to push the capabilities of any PC. Since you are able to
do more interesting things on high-performance machines, you need to develop ‘scaleable’
applications to enhance your users’ experiences. If you know that they have high-performance
systems, then your application can do more exciting things. For customers with slower systems,
some features will have to be scaled down or removed. CPUINFO allows your code to detect
CPU type and performance at runtime, so you can develop high-performance scalable
applicationsapplications which automatically adapt their features to each user’s system.
1.2 ABSTRACT
Background and OrganizationPart of the CPUINFO package is a collection ofThe CPUINFO
package includes two DLLs (Dynamic Link Libraries) for WindowsMicrosoft Windows*
Operating Systems (Windows 3.1, Win32s*, Windows for Workgroups*, Windows 95*, and
Windows NT*). These DLLs test for the presence of a Genuine Intel processor, the family,
model, feature set, and processor clock frequency. Also included is a Windows example program
for each of thefor DLLs to show sample implementation of the DLL calls.
The DLLs are CPUINF16.DLL and CPUINF32.DLL which provide, providing five functions
accessible by 16 and 32-bit Windows programs respectively. These functions are CPU
identification, CPU extended identification, CPU clock frequency, CPU features, and the CPU
Time Stamp Read.
1.3 USAGE
The information returned by cpuspeed() can be unreliable under some circumstances. On systems
which do not support the Time Stamp register, for example, the speed measurement is simply a
trivial benchmark. Therefore, although cpuspeed() usually returns accurate data, it is likely that
there are processors which will return incorrect or skewed values. In addition, the DOS version of
this code returns low values for Pentium® Processors with clock speeds in excess of 120 MHz
running Windows NT. Due to these possible errors on some systems, it is suggested not to return
information about the processor speed to the user. The suggested use of this program is to set
default values of which features (i.e. stereo sound, high graphic detail, or whatever it is that
consumes large amounts of processor cycles and may need to be disabled on slower processors)
to use in your software upon program start-up or installation.
While this program works on all current Intel processors, the code is designed to not analyze
processor speed if it has been verified that the host processor is an Intel imitator.
2. SYSTEM REQUIREMENTS
****Mark, what should I say here?****
CPUINFO Appnote Version 1.0 1
2.1 CPUINF16.DLL
Requires a system with at least an Intel386
TM
(TM) processor running Windows 3.1. This 16-bit
DLL also runs correctly under Win32s, Windows for Workgroups, Windows 95*, and Windows
NT*.
2.2 CPUINF32.DLL
Requires a system with at least an Intel386 (TM)processor system running Windows 3.1. This
32-bit DLL also runs correctly under Win32s, Windows for Workgroups with 32-bit extensions,
Windows 95*, and Windows NT*.
3. THEORY
3.1 PROCESSOR AND FEATURE IDENTIFICATION
Three of the CPUINFO DLL functions (wincpuid(), wincpuidext(), and wincpufeatures()) use
the Intel CPUID instruction (opcode 0FA2h) if supported. CPUID was created to let software
determine information like the CPU generation, manufacturer, or existence of an Overdrive
TM
processor. It also identifies features like floating point, page size, and others to be defined for
future processors. The CPUID instruction works on newer Intel486�TM), and all Pentium(R),
and all Pentium and later processors. On older processors, the type must be detected otherwise --
by reading bits in the FLAGS and EFLAGS register.
More details of the CPUID instruction can be found in Intel application note AP-485, available
on the Intel Architecture Labs CD-ROM, or on the Intel FTP site (ftp.intel.com), or as hardcopy
via Intel Literature, order #241618.
3.2 PROCESSOR CLOCK FREQUENCY
The CPUINFO DLL function for processor clock frequency determination, cpuspeed(), is
capable of calculating a raw clock frequency and normalizing that frequency to the nearest value.
The 16-bit and the 32-bit version each have two algorithms to determine clock speed. Which
algorithm gets used, depends upon whether the host processor supports Time Stamp register reads
(RDTSC, Read Time Stamp Counter, opcode 0F 31h).
Currently the Time Stamp read on a Pentium processor is a Ring 0 operation. In Windows,
applications usually run in Ring 3, however this operation can be emulated. On a Pentium Pro
processor, the read Time Stamp opcode is a valid Ring 3 operation. Thus the Time Stamp Counter
can be used on both the Pentium processor and the Pentium Pro processor from Windows. In
DOS, many memory managers cause applications to run in Ring 3 with no method for emulating
a Ring 0 opcode, thus the DOS version of this code can use the Time Stamp Counter only on
Pentium Pro processor or above.
The first algorithm, which is used on systems which do not support the Time Stamp Counter,
times a known test instruction sequence as it runs on the processor. In the 16-bit DLL and in the
DOS code, the timing is performed with an external hardware timer built into the PC chipset. On
the 32-bit code, timing is performed by calls to the Win32 API Call
QueryPerformanceCounter, which directly reads the high-resolution performance counter. The