What is Performance counter?

A hardware counter in the CPU that tallies events such as instructions executed, cache misses and branch mispredictions.

Field: Performance Analysis

Japanese name: 性能カウンタ

Counting and sampling

A CPU's performance monitoring unit (PMU) has dedicated counters for things like cycles plus a small number of general-purpose counters whose event can be selected. In counting mode, the selected events are totaled while the program runs and reported at the end, as Linux perf stat does. In sampling mode, the counter raises an interrupt each time it reaches a set count, and the address of the instruction running at that moment is recorded. Aggregating those samples shows where events occur, such as which functions incur the most cache misses.

Reading the numbers

Ratios say more than raw counts. A low IPC, instructions divided by cycles, shows that the CPU spends much of its time waiting. Adding cache misses per thousand instructions (MPKI) and the branch misprediction rate helps tell whether the waiting comes from memory or from branches. The available events differ between CPU designs, and events with the same name may be counted differently, so care is needed when comparing numbers across CPUs.

Practical caveats

Because general-purpose counters are few, requesting many events at once makes the OS time-multiplex the counters and scale the results into estimates. The address recorded by sampling may also be a few instructions away from the one that caused the event, an effect called skid; some CPUs offer precise sampling features that record the exact address. Programming the counters requires privilege, so ordinary programs use them through an OS interface such as Linux perf_event.

Try it: questions about Performance counter

Which is an example of what CPU performance counters (the PMU) can count?

  1. AInstructions executed, cache misses, branch mispredictions and the like
  2. BThe number of people who wrote the program
  3. CThe number of keys on the keyboard
Show answer and explanation

Answer: A. Instructions executed, cache misses, branch mispredictions and the like

Performance counters are hardware counters that tally various events inside the CPU. Cycle and instruction counts give IPC, and counts of cache misses at each level, TLB misses, branch mispredictions and more are available. Tools such as Linux perf collect them while a program runs, providing clues to whether time is going to memory, branches or the computation itself.

Performance counters show a program's IPC is very low at 0.3, with many last-level cache misses. Which pairs the likely situation with a remedy?

  1. AThe CPU spends much time stalled on memory; change data layout or apply blocking to use caches effectively
  2. BComputation is too fast; raise the frequency
  3. CThere are too few branches; add more
Show answer and explanation

Answer: A. The CPU spends much time stalled on memory; change data layout or apply blocking to use caches effectively

Many CPUs can execute several instructions per cycle, so an IPC of 0.3 means they are waiting most of the time. Many last-level cache misses suggest long waits for data from main memory. Effective remedies reduce cache misses: laying data out at consecutive addresses, reordering loops, or blocking so data is reused many times.

Questions that mention Performance counter (6)

Performance counter appears in 8 practice questions across 2 topics, including Performance Analysis, Memory Hierarchy.

  1. Performance counters reveal very frequent branch mispredictions. Which is a suitable remedy?
  2. In top-down microarchitecture analysis using performance counters, which are the major categories into which CPU issue slots are divided?
  3. Why must cache designs be compared by average memory access time rather than miss rate alone?
  4. To check whether a program is compute-bound or memory-bound, its run time is measured at different CPU frequencies. What is the typical result if it is memory-bound?
  5. What is the phenomenon called in which adding a mechanism to measure performance changes the behavior of the program being measured?
  6. What is the most appropriate way to proceed when improving program performance?

Books on Performance Analysis Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary