Wednesday, 24 October 2012

PAPI 5.0.1 installation on ubuntu guide


Over the week, I am thinking of profiling some C code to compare with.
Surprisingly there is not much tools I can choose from.

For linux, many suggested gprof which is a gnu profiler.
I am not really into the time of execution.

One researcher in the lab suggested objdump, which is helpful
for application file size and probably ram usage, still not what things I wanted.

Then I saw some stack overflower suggested PAPI.
In his/her description, seems like I can specified where to
start counter and where to stop to get the parameter I want.

The cycles count and instructions count.

other tools been suggested are.

google-perftools - I have no idea of it, but many people suggested, it seems capable to do cpu profiling.

perf - A kernel side profiling. I tried it, very nice and simple to use. But I am not really need profiling for
running my apps in linux, just to find out what the instructions count and cycle changes for different implementation.

I bang myself into PAPI and found many things to setup, or maybe just lack of knowledge in linux.

Here is the manual I created during the Installation.

Hope it help.

PS: Compiling kernel is not fun, avoid at all cost.
As usual RTFM. (papi-5.0.1/INSTALL and papi-5.0.1/src/perfctr-2.6.x or 2.7.x).



---------------- Introduction ------------------------
PAPI (Performance Application Programming Interface)
provides the tool designer and application engineer with
a consistent interface and methodology for use of the
performance counter hardware found in most major
microprocessors. PAPI enables software engineers
to see, in near real time, the relation between software
performance and processor events.

In addition Component PAPI provides access to a collection
of components that expose performance measurement
opportunites across the hardware and software stack.


-----------------Installation Requirements -----------

Installation done on Linux 2.6.32-38-generic
ubuntu lucid 10.04 LTS(long term support).Check version with
# uname -a

This is my vm workstation.
////////////////////////////////////////
Linux leon-desktop 2.6.32-38-generic #83-Ubuntu SMP Wed Jan 4 11:13:04 UTC 2012 i686 GNU/Linux
////////////////////////////////////////



VMware workstation 9 requirement
- Host machine must support intel virtualization technology.(Recent processor)
- machine setting, processor ->
  enable virtualize cpu performance counters

compiling kernel might not be required. Refering to INSTALL manual
of papi, kernel 2.6.31 and above can use perf_events.

perf_events might need the linux-tools-<kernel version>
# sudo apt-get install linux-tools-<kernel version>

or linux-tools-common
# sudo apt-get install linux-tools-common

--------------------- PAPI and patches -----------------------------
download Papi 5.01 and extract to folder
copy papi5.01.patch to papi extract folder

patching for intel cpu problems error regarding exceed size of res1.
////////////////////////////////////////////////////////////////////////

diff -up papi-5.0.1/src/libpfm4/lib/pfmlib_intel_snbep_unc_perf_event.c.i686 papi-5.0.1/src/libpfm4/lib/pfmlib_intel_snbep_unc_perf_event.c
diff -up papi-5.0.1/src/libpfm4/lib/pfmlib_intel_snbep_unc_priv.h.i686 papi-5.0.1/src/libpfm4/lib/pfmlib_intel_snbep_unc_priv.h
--- papi-5.0.1/src/libpfm4/lib/pfmlib_intel_snbep_unc_priv.h.i686 2012-09-21 19:51:56.700000553 -0400
+++ papi-5.0.1/src/libpfm4/lib/pfmlib_intel_snbep_unc_priv.h 2012-09-21 19:52:18.967000007 -0400
@@ -166,7 +166,8 @@ typedef union {
  } ha_addr;
  struct {
  unsigned long opc:6; /* opcode match */
- unsigned long res1:58; /* reserved */
+ unsigned long res1:26; /* reserved */
+ unsigned long res2:32; /* reserved */
  } ha_opc;
 } pfm_snbep_unc_reg_t;

//////////////////////////////////////////////////////////////////////

create a .patch and paste above content(withoud top and btm), here we name it papi-5.01.patch

apply patch dry run, which only test patching
# patch -p1 --dry-run < papi-5.01.patch
if success in dry run, then apply the patch
# patch -p1 < papi-5.01.patch

--------------------- Patch perfctr and Compile kernel--------------
note: if changing and patch kernel need to be done, seperate kernel
must be compiled instead of current running kernel to avoid some issues.

login as root
get the tools.
# apt-get install kernel-package libncurses5-dev fakeroot wget bzip2

download kernel from ubuntu.
http://kernel.ubuntu.com/~kernel-ppa/mainline/
for this installation we use 2.6.32
get the source file, which is a .dep file.
# dpkg -i <kernel source>.dep

go to /usr/src, another tar.gz file. extract it.
go into the file. clear source first
# make mrproper

---- patch perfctr ----
locate the perfctr patch which is usually at
papi/src/perctr-2.6.x/patches.
go to kernel source folder /usr/src/<kernel source folder>
# update-kernel <path to papi>/src/perctr-2.6.x/patches

------------------- New Kernel Configuration ---------------
copy current kernel configuration to new kernel
# cp /boot/config-`uname -r` ./.config
# make menuconfig
load configuration first.

enable all module in

processor type and features/performance-monitoring support

and also

power managements and ACPI options/
ACPI(Advanced Configuration and Power Interface) support/
Debug Statements

# make-kpkg clean
# fakeroot make-kpkg --initrd --append-to-version=-papi kernel_image kernel_headers
wait for several hour for the kernel to compile.
--append-to-version can be change to better identify different kernel.

dpkg -i linux-image-<kernel version>.deb
dpkg -i linux-header-<kernel version>.deb

# update-grub
Check if the new kernel and initrd image is there.

if initrd.img is not detected for papi kernel, build one.
# update-initramfs -u -k 2.6.32-papi
# update-grub

refer to perfctr INSTALL
install perf
go to papi/src/perfctr-2.6.x
# make PREFIX=$PREFIX install

-------------------Install papi ----------------------
follow the general instruction in INSTALL manual for papi
test will pass with warning
full test will pass with warning