C program optimization
  • Introduction
  • Measurement
    • Use perf to Measure Cache Miss and TLB Miss
  • Program optimization techniques
    • Branch Prediction Friendliness
    • Loop Unrolling
    • Turning Random Access to Sequential Access
  • References
Powered by GitBook
On this page
  • Installation
  • Usage
  • Example

Was this helpful?

  1. Measurement

Use perf to Measure Cache Miss and TLB Miss

PreviousMeasurementNextProgram optimization techniques

Last updated 2 months ago

Was this helpful?

Installation

Note that if you use perf on department linux9 servers, there is no need to install. Just in case, this is how to install perf on your Ubuntu VM (though not so useful):

sudo apt-get install linux-tools-common linux-tools-5.15.0-130-generic

Note that you may need to change the version number to your system's.

Usage

To measure branch miss:

perf stat -e branch-misses <command>

To measure cache miss:

perf stat -e cache-misses <command>

To collect TLB miss:

perf stat -e dTLB-load-misses,iTLB-load-misses <command>

Example

perf stat -e branch-misses ls > /dev/null
perf stat -e cache-misses ls > /dev/null
perf stat -e dTLB-load-misses,iTLB-load-misses ls > /dev/null