Documentacion Install Papi and Custom kernel on UbuntuUSC

This note is used for installing PAPI (a well-known software tool from Univ. of Tennessee that provides APIs for accessing various hardware performance counters) on i386 architecture (Nehalem Gainestown processor) running Ubuntu 10.04 LTS (the Lucid Lynx) with Linux kernel version 2.6.32 (x32).

Índice

Required software

 For my machine, I downloaded PerfCtr 2.6.40.

Instructions

Part 1: Patch Linux kernel with PerfCtr

First, the Linux kernel must be customized with either PerfCtr patch to enable various hardware counter accesses. So let's get the linux kernel source code and patch it.

  • Prepare the Linux kernel source
sudo apt-get install build-essential fakeroot kernel-package
  • Get the Ubuntu official kernel (source will be put as an archive in /usr/src)
sudo apt-get install linux-source

Or alternatively, get the Linux kernel from: http://www.kernel.org.

  • Extract the kernel source somewhere, let's call this directory 'kdir'
cd ~ 
mkdir kdir
cd kdir
tar -xvjf /usr/src/linux-2.6.*.tar.bz2
cd linux-2.6.*
make mrproper
cp /boot/config-`uname -r` .config
Prepare the PerfCtr source
  • Extract the PerfCtr source somewhere, let's call this directory 'pdir'
  • Apply the patch for PerfCtr
    • First test the patching
~/pdir/update-kernel --test --patch=2.6.* 
# This does nothing but testing. If the test fails, try a different version
# (--patch=<version>). All available versions can be seen in pdir/patches
  • If the test looks OK, let's apply the patch
~/pdir/update-kernel --patch=2.6.*
Setup and build the new Linux kernel
cd ~/kdir/linux-2.6.*
make menuconfig
  • Find: Processor type and features
  • For PerfCtr
  • Find: Performance-monitoring counters support
  • Include: Performance monitoring counters support
  • Include: Virtual performance counters support
  • Include: Global performance counters support

And finally we have to compile the kernel

export CONCURRENCY_LEVEL=9
fakeroot make-kpkg clean
fakeroot make-kpkg --append-to-version=-perfctr --initrd binary

This will generate two deb files to install at our Debian-based systems so we can install them on our computer.

sudo dpkg -i ../linux-image*.deb
sudo dpkg -i ../linux-headers*.deb

Part 2: Install PerfCtr or perfmon2 library

  • Install PerfCtr library
cd ~/pdir
make
  • I chose to install to directory 'usr' in my home directory
make PREFIX=$HOME/usr install
  • Install perfmon2 library
cd ~/pdir
make
  • I chose to install to directory 'usr' in my home directory
make PREFIX=$HOME/usr install

Part 3: Install PAPI library

  • Install PAPI library
tar -xvzf papi-4.0.0.tar.gz
cd papi-4.0.0
  • Apply the latest PAPI patch (I used PAPI 4.0.0 patch 3)
patch -p1 < ../papi400patch3.diff
cd src
  • I chose to install to directory 'usr' in my home directory
./configure --prefix=$HOME/usr --with-perfctr-prefix=$HOME/usr
make
  • Test the built PAPI first before installation
make test
  • If you get good counts, you can optionally run extra tests
./run_tests.sh
make install

Done! It's all built now. PAPI header files are in $HOME/usr/include and PAPI libraries are in $HOME/usr/lib.