background image

Vol. 3B 17-41

DEBUG, BRANCH PROFILE, TSC, AND RESOURCE MONITORING FEATURES

NOTE

To determine average processor clock frequency, Intel recommends the use of performance 
monitoring logic to count processor core clocks over the period of time for which the average is 
required. See Section 18.17, “Counting Clocks,” and Chapter 19, “Performance-Monitoring Events,” 
for more information.

The RDTSC instruction reads the time-stamp counter and is guaranteed to return a monotonically increasing 
unique value whenever executed, except for a 64-bit counter wraparound. Intel guarantees that the time-stamp 
counter will not wraparound within 10 years after being reset. The period for counter wrap is longer for Pentium 4, 
Intel Xeon, P6 family, and Pentium processors.
Normally, the RDTSC instruction can be executed by programs and procedures running at any privilege level and in 
virtual-8086 mode. The TSD flag allows use of this instruction to be restricted to programs and procedures running 
at privilege level 0. A secure operating system would set the TSD flag during system initialization to disable user 
access to the time-stamp counter. An operating system that disables user access to the time-stamp counter should 
emulate the instruction through a user-accessible programming interface.
The RDTSC instruction is not serializing or ordered with other instructions. It does not necessarily wait until all 
previous instructions have been executed before reading the counter. Similarly, subsequent instructions may begin 
execution before the RDTSC instruction operation is performed.
The RDMSR and WRMSR instructions read and write the time-stamp counter, treating the time-stamp counter as 
an ordinary MSR (address 10H). In the Pentium 4, Intel Xeon, and P6 family processors, all 64-bits of the time-
stamp counter are read using RDMSR (just as with RDTSC). When WRMSR is used to write the time-stamp counter 
on processors before family [0FH], models [03H, 04H]: only the low-order 32-bits of the time-stamp counter can 
be written (the high-order 32 bits are cleared to 0). For family [0FH], models [03H, 04H, 06H]; for family [06H]], 
model [0EH, 0FH]; for family [06H]], DisplayModel [17H, 1AH, 1CH, 1DH]: all 64 bits are writable.

17.15.1 Invariant 

TSC

The time stamp counter in newer processors may support an enhancement, referred to as invariant TSC. 
Processor’s support for invariant TSC is indicated by CPUID.80000007H:EDX[8]. 
The invariant TSC will run at a constant rate in all ACPI P-, C-. and T-states. This is the architectural behavior 
moving forward. On processors with invariant TSC support, the OS may use the TSC for wall clock timer services 
(instead of ACPI or HPET timers). TSC reads are much more efficient and do not incur the overhead associated with 
a ring transition or access to a platform resource.

17.15.2  IA32_TSC_AUX Register and RDTSCP Support

Processors based on Intel microarchitecture code name Nehalem provide an auxiliary TSC register, IA32_TSC_AUX 
that is designed to be used in conjunction with IA32_TSC. IA32_TSC_AUX provides a 32-bit field that is initialized 
by privileged software with a signature value (for example, a logical processor ID). 
The primary usage of IA32_TSC_AUX in conjunction with IA32_TSC is to allow software to read the 64-bit time 
stamp in IA32_TSC and signature value in IA32_TSC_AUX with the instruction RDTSCP in an atomic operation. 
RDTSCP returns the 64-bit time stamp in EDX:EAX and the 32-bit TSC_AUX signature value in ECX. The atomicity 
of RDTSCP ensures that no context switch can occur between the reads of the TSC and TSC_AUX values.
Support for RDTSCP is indicated by CPUID.80000001H:EDX[27]. As with RDTSC instruction, non-ring 0 access is 
controlled by CR4.TSD (Time Stamp Disable flag).
User mode software can use RDTSCP to detect if CPU migration has occurred between successive reads of the TSC. 
It can also be used to adjust for per-CPU differences in TSC values in a NUMA system.

17.15.3  Time-Stamp Counter Adjustment

Software can modify the value of the time-stamp counter (TSC) of a logical processor by using the WRMSR instruc-
tion to write to the IA32_TIME_STAMP_COUNTER MSR (address 10H). Because such a write applies only to that