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

Table Of Contents
18-112 Vol. 3
DEBUGGING AND PERFORMANCE MONITORING
18.18.6.8 Generating an Interrupt on Overflow
Any performance counter can be configured to generate a performance monitor
interrupt (PMI) if the counter overflows. The PMI interrupt service routine can then
collect information about the state of the processor or program when overflow
occurred. This information can then be used with a tool like the Intel
®
VTune™
Performance Analyzer to analyze and tune program performance.
To enable an interrupt on counter overflow, the OVR_PMI flag in the counter’s associ-
ated CCCR MSR must be set. When overflow occurs, a PMI is generated through the
local APIC. (Here, the performance counter entry in the local vector table [LVT] is set
up to deliver the interrupt generated by the PMI to the processor.)
The PMI service routine can use the OVF flag to determine which counter overflowed
when multiple counters have been configured to generate PMIs. Also, note that these
processors mask PMIs upon receiving an interrupt. Clear this condition before leaving
the interrupt handler.
When generating interrupts on overflow, the performance counter being used should
be preset to value that will cause an overflow after a specified number of events are
counted plus 1. The simplest way to select the preset value is to write a negative
number into the counter, as described in Section 18.18.6.6, “Cascading Counters.
Here, however, if an interrupt is to be generated after 100 event counts, the counter
should be preset to minus 100 plus 1 (-100 + 1), or -99. The counter will then over-
flow after it counts 99 events and generate an interrupt on the next (100th) event
counted. The difference of 1 for this count enables the interrupt to be generated
immediately after the selected event count has been reached, instead of waiting for
the overflow to be propagation through the counter.
Because of latency in the microarchitecture between the generation of events and
the generation of interrupts on overflow, it is sometimes difficult to generate an
interrupt close to an event that caused it. In these situations, the FORCE_OVF flag in
the CCCR can be used to improve reporting. Setting this flag causes the counter to
overflow on every counter increment, which in turn triggers an interrupt after every
counter increment.
18.18.6.9 Counter Usage Guideline
There are some instances where the user must take care to configure counting logic
properly, so that it is not powered down. To use any ESCR, even when it is being used
just for tagging, (any) one of the counters that the particular ESCR (or its paired
ESCR) can be connected to should be enabled. If this is not done, 0 counts may
result. Likewise, to use any counter, there must be some event selected in a corre-
sponding ESCR (other than no_event, which generally has a select value of 0).