Intel 64 and IA-32 Architectures Software Developers Manual Volume 3B, System Programming Guide Part 2

Table Of Contents
18-148 Vol. 3
DEBUGGING AND PERFORMANCE MONITORING
When interrupted by a counter overflow, the interrupt handler needs to perform the
following actions:
Save the instruction pointer (EIP register), code-segment selector, TSS segment
selector, counter values and other relevant information at the time of the
interrupt.
Reset the counter to its initial setting and return from the interrupt.
An event monitor application utility or another application program can read the
information collected for analysis of the performance of the profiled application.
18.26 PERFORMANCE MONITORING (PENTIUM
PROCESSORS)
The Pentium processor provides two 40-bit performance counters, which can be used
to count events or measure duration. The counters are supported by three MSRs: the
control and event select MSR (CESR) and the performance counter MSRs (CTR0 and
CTR1). These can be read from and written to using the RDMSR and WRMSR instruc-
tions, respectively. They can be accessed using these instructions only when oper-
ating at privilege level 0.
Each counter has an associated external pin (PM0/BP0 and PM1/BP1), which can be
used to indicate the state of the counter to external hardware.
NOTES
The CESR, CTR0, and CTR1 MSRs and the events listed in Table A-19
are model-specific for the Pentium processor.
The performance-monitoring events listed in Appendix A are
intended to be used as guides for performance tuning. Counter
values reported are not guaranteed to be accurate and should be
used as a relative guide for tuning. Known discrepancies are
documented where applicable.
18.26.1 Control and Event Select Register (CESR)
The 32-bit control and event select MSR (CESR) controls the operation of perfor-
mance-monitoring counters CTR0 and CTR1 and the associated pins (see
Figure 18-59). To control each counter, the CESR register contains a 6-bit event
select field (ES0 and ES1), a pin control flag (PC0 and PC1), and a 3-bit counter
control field (CC0 and CC1). The functions of these fields are as follows:
ES0 and ES1 (event select) fields (bits 0-5, bits 16-21) — Selects (by
entering an event code in the field) up to two events to be monitored. See Table
A-19 for a list of available event codes.