I'm trying to understand how to program the performance counters, when HyperThreading (HTT) is enabled, to be able to separate the counts by Logical Processor (LP).
Back in the P4 days, if I wanted to have LP-specific counts, I programmed 2 counters to count the same event, I set the AnyThread CCCR bits to 11b (any thread), set the T0_OS/USR bits in one ESCR (to count on LP0 only), and set the T1_OS/USR bits in the other ESCR (to count on LP1 only).
Reading the Nehalem docs it's a bit confusing how to do the above. The only thread control available is the ANY bit (bit 21) in the PerfEvtSel registers. According to the manual (Software Developer's Manual, Vol. 3B, page 18-54):
When set to 1, it enables counting the associated event conditions (including matching the threads CPL with the
OS/USR setting of IA32_PERFEVTSELx) occurring across all logical processors sharing a processor core. When bit
21 is 0, the counter only increments the associated event conditions (including matching the threads CPL with the
OS/USR setting of IA32_PERFEVTSELx) occurring in the logical processor which programmed the
Does that mean that
- The hardware "remembers" which LP programmed the counter?
(and the meaning of PerfEvtSelX.ANY=0 is really "this" LP only)
- To program a counter to count events for a specific LP the code that programs the counter must run on that LP?
For example, if I want to count INST_RETIRED.ANY_P by LP, do I have to program a different counter on each LP, while running on that LP, and set PerfEvtSelX.ANY=0 for each counter?
Setting PerfEvtSelX.ANY=1 would not be what I want because that would give the aggregate instructions retired count for *both* LPs (the core). The only other choice is to set PerfEvtSelX.ANY=0, but that doesn't offer the choice of which LP will/should increment the counter.
The same seems to be true for the Fixed-Function counters. Setting the ANY bit(s) in IA32_FIXED_CTR_CTRL_MSR has the same effect as the ANY bit in the PerfEvtSelX registers, which makes sense.
Any clarifications would be appreciated.