Performance Monitoring

Perfmon / Pfmon: Utilize hardware performance counters


Pfmon is a tool to measure the runtime architectural parameters by utilizing the hardware performance counters. Perfmon2 is the kernel module that interacts with Performance Monitoring Units (PMU) of the processors using libpfm library. The features and usage of pfmon-3.0 are described here. I list few basic steps to build and use pfmon based on my experience with the tool.
Steps to build pfmon

1. Mymachine: Linux Kernel 2.6.29 Ubuntu i686 GNU/Linux
Processor: Intel(R) Core(TM)2 Duo CPU E7200 @ 2.53GHz
gcc version: 4.4.5

2. Download the following files.
(a) ELF Library libelf-0.8.10.tar.gz
(b) Perfmon2 Library libpfm-3.9.tar.gz
(c) Pfmon pfmon-3.8.tar.gz
(d) Linux Kernel linux-2.6.29.tar.bz2,
(e) Perfmon2 Kernel Patchperfmon-new-base-090622.tar.gz

3. I installed the packages at '/usr/local/'. Install 2(a), (b) and (c) with
#tar zxf *.gz
#cd into_respective_dir
#make
#make install

4. Check if libpfm installed properly by running few already built examples for eg. check_events and whichpmu

root@aravali:/usr/local/libpfm-3.9/examples_v2.x# ./check_events
PMU model: Intel Core
5 counters available
PMC16=0xaa
PMD17
PMD16

root@aravali:/usr/local/libpfm-3.9/examples_v2.x# ./whichpmu
PMU model detected by pfmlib: Intel Core
number of implemented PMD registers : 5
implemented PMD registers : [ 0 1 16 17 18 ]
number of available PMD registers : 5
available PMD registers : [ 0 1 16 17 18 ]
number of implemented PMC registers : 4
implemented PMC registers : [ 0 1 16 17 ]
number of available PMC registers : 4
available PMC registers : [ 0 1 16 17 ]
number of counters : 5
implemented counters : [ 0 1 16 17 18 ]
number of available counters : 5
available counters : [ 0 1 16 17 18 ]
hardware counter width : 32
number of events supported : 130

5. Check if pfmon installed properly by running
root@aravali:/usr/local/libpfm-3.9/examples_v2.x# pfmon ls

(a) If you get the error "pfmon: error while loading shared libraries: libpfm.so.3: cannot open shared object file: No such file or directory" then follow this.
-- create "/etc/ld.so.conf.d/libpfm.conf" and that should contain: /usr/local/lib/
-- run ldconfig

(b) If you get "Cannot determine host kernel perfmon version, check /sys/kernel/perfmon" then it means kernel is not built yet. Go to step 6.

(c) If you get the ouput, means you have successfully installed pfmon.

6. Untar Linux kernel and patch with the perfmon2 kernel patch.
#tar zxf linux-2.6.29.tar.bz2
#tar zxf perfmon-new-base-090622.tar.gz
#cd ./linux-2.6.29/
#cat ../perfmon-new-base-090219/*.diff | patch -p1

7. Build the Linux kernel as
#make
#make modules
#make modules_install
#make install
#cd /boot
#update-initramfs -u -k 2.6.29

8. Update grub (#update-grub) and boot into the newly built kernel to run pfmon. Now pfmon should be successfully running. Go to step 5 to confirm.

Phase Detection using pfmon

I used pfmon to generate the phases of SPALSH2 benchmarks. The IPC of the benchmarks at an interval of 10000 cycles is plotted againts time to identify the phases. To view the results click here.