background image

Vol. 3B 18-91

PERFORMANCE MONITORING

3. Select the number of the counter to be used to count the event from the Counter Numbers Per ESCR field.
4. Determine the name of the counter and the CCCR associated with the counter, and determine the MSR 

addresses of the counter, CCCR, and ESCR from Table 18-63.

5. Use the WRMSR instruction to write the ESCR Event Select and ESCR Event Mask values into the appropriate 

fields in the ESCR. At the same time set or clear the USR and OS flags in the ESCR as desired.

6. Use the WRMSR instruction to write the CCCR Select value into the appropriate field in the CCCR.

NOTE

Typically all the fields and flags of the CCCR will be written with one WRMSR instruction; however, 
in this procedure, several WRMSR writes are used to more clearly demonstrate the uses of the 
various CCCR fields and flags.

This setup procedure is continued in the next section, Section 18.15.5.2, “Filtering Events.”

18.15.5.2   Filtering Events

Each counter receives up to 4 input lines from the processor hardware from which it is counting events. The 
counter treats these inputs as binary inputs (input 0 has a value of 1, input 1 has a value of 2, input 3 has a value 
of 4, and input 3 has a value of 8). When a counter is enabled, it adds this binary input value to the counter value 
on each clock cycle. For each clock cycle, the value added to the counter can then range from 0 (no event) to 15. 
For many events, only the 0 input line is active, so the counter is merely counting the clock cycles during which the 
0 input is asserted. However, for some events two or more input lines are used. Here, the counters threshold 
setting can be used to filter events. The compare, complement, threshold, and edge fields control the filtering of 
counter increments by input value.
If the compare flag is set, then a “greater than” or a “less than or equal to” comparison of the input value vs. a 
threshold value can be made. The complement flag selects “less than or equal to” (flag set) or “greater than” (flag 
clear). The threshold field selects a threshold value of from 0 to 15. For example, if the complement flag is cleared 
and the threshold field is set to 6, than any input value of 7 or greater on the 4 inputs to the counter will cause the 
counter to be incremented by 1, and any value less than 7 will cause an increment of 0 (or no increment) of the 
counter. Conversely, if the complement flag is set, any value from 0 to 6 will increment the counter and any value 
from 7 to 15 will not increment the counter. Note that when a threshold condition has been satisfied, the input to 
the counter is always 1, not the input value that is presented to the threshold filter. 
The edge flag provides further filtering of the counter inputs when a threshold comparison is being made. The edge 
flag is only active when the compare flag is set. When the edge flag is set, the resulting output from the threshold 
filter (a value of 0 or 1) is used as an input to the edge filter. Each clock cycle, the edge filter examines the last and 
current input values and sends a count to the counter only when it detects a “rising edge” event; that is, a false-
to-true transition. Figure 18-46 illustrates rising edge filtering.
The following procedure shows how to configure a CCCR to filter events using the threshold filter and the edge 
filter. This procedure is a continuation of the setup procedure introduced in Section 18.15.5.1, “Selecting Events to 
Count.”
7. (Optional) To set up the counter for threshold filtering, use the WRMSR instruction to write values in the CCCR 

compare and complement flags and the threshold field:
— Set the compare flag.
— Set or clear the complement flag for less than or equal to or greater than comparisons, respectively.
— Enter a value from 0 to 15 in the threshold field.

8. (Optional) Select rising edge filtering by setting the CCCR edge flag.
This setup procedure is continued in the next section, Section 18.15.5.3, “Starting Event Counting.”