- Support for AMD64 (
x86_64, Intelia64and AMDamd64), ARM64 (aarch64), and RISC-V (riscv). - Support for reading and writing to the MSR register of the Performance Monitoring Unit (PMU).
- Support for reading and writing the Performance Monitoring Counter (PMC) value.
- Support enable user space access to high resolution timers.
"MRS %0, PMCCNTR_EL0for ARM64 chips.rdcyclefor RISC-V chips.
- Support for reading the Performance Monitoring Event (PME).
- For
x86_64ia64chips, the PME is getting from the intel/perfmon - For
x86_64amd64andaarch64chips, the PME is getting from the Linux Perf tool.
- For
Read the following sections for more details.
Currently, only Linux is supported. The library does not rely on any other library. It uses only standard C functionality.
# Building the kernel module requires the kernel headers of the kernel. On Ubuntu or Debian, they can be installed by running
# The kernel module can be built by running
sudo apt install linux-headers-$(uname -r)
make unload load
# Additionally step for x86_64 chips machines
sudo modprobe msr # load msr module
# For RISC-V or ARM chips with linux kernel version >= 6.6, enable userspace access to perf
echo 1 | sudo tee /proc/sys/kernel/perf_user_access
# https://github.com/torvalds/linux/blob/master/drivers/perf/riscv_pmu_sbi.cChange the directory to scripts and run *utils.py for your architecture.
# build the PMU Event Header for x86-64 chips (for `ia64` and `amd64` architectures), or for ARM chips
cd scripts
python3 pmu_init.py
# or for intel chips with hybrid core
python3 pmu_init.py --hybridcore
# equal to `python3 pmu_intel_utils.py --hybridcore`
# then you could see the PMU header: `ia64_pmu_event.h`, `amd64_pmu_event.h`, or `arm_pmu_event.h`
# just include the header in your c or c++ projectYet another way to get the PMU event header is to use perf tool.
sudo perf list -j > this-cpu-pmu-events.jsonRefer to the tests directory for more details about how to use the library.
Copy the header file (*.h) in header to your project include path or add the path of header to CFLAGS, after that, include the pmu_utils.h.
#include <pmu_utils.h>See tests/src/x86_64/basic.c for more details.
See tests/src/aarch64/basic.c for more details.
See tests/src/riscv64/basic.c for more details.
Seen in tests directory.
make test test_verbose- Intel® 64 and IA-32 Architectures Software Developer Manuals
- AMD64 Architecture Programmer's Manual, Volumes 1-5 | AMD
- Arm A-profile A64 Instruction Set Architecture
- RISC-V Ratified Specifications
- misc0110/PTEditor: A small library to modify all page-table levels of all processes from user space for x86_64 and ARMv8.
- mattferroni/msr-driver: A simple kernel module to read MSRs on Intel machines.
- IAIK/transientfail: Website and PoC collection for transient execution attacks
- andikleen/pmu-tools: Intel PMU profiling tools
- dadaKh/pmu-reader: PMU-reader for Linux
- cpredef/predef: Pre-defined Compiler Macros wiki