CentOS 5.4 PerfCTR and PAPI

5 03 2010

This has been a heck of a post. It has taken me lots of time and thanks to AlanBartlett and toracat on the CentOS Forums there is finally a solution!

As stated before, I keep fine tuning and fixing typos in this step-by-step and so to prevent me from cluttering the CentOS forum, I am posting the guide here where I can easily update and edit (over and over and over again….).

Also, these notes were done on a i686 box. If you are on a different system, then adjust accordingly. I have tried to adjust the notes to be copy and paste by adding the `uname -m` but I may have missed something.

S1: I need the Kernel Source http://wiki.centos.org/HowTos/I_need_the_Kernel_Source
S2: I need to Build a Custom Kernel http://wiki.centos.org/HowTos/Custom_Kernel
S3: Perfctr install text (which I didn’t find online, but it is in the tar.gz file here: http://user.it.uu.se/~mikpe/linux/perfctr/2.6/perfctr-2.6.40.tar.gz )

01 Install a lot of build tools [S1-1 and S2-1]

$ yum groupinstall "Development Tools"
$ yum install hmaccalc
$ yum install ncurses-devel
$ yum install kernel-devel
$ yum install rpm-build redhat-rpm-config unifdef

02 Download PerfCTR, extract to home directory, and check for supported kernels[S3]. I used perfctr-2.6.40.

$ mkdir ~/PerfCtr
$ cd ~/PerfCtr
$ tar -zxvf ~/perfctr-2.6.40.tar.gz
$ ls ~/PerfCtr/perfctr-2.6.40/patches

03 Download the latest source RPM that matches one of the perfctr kernel patches for the CentOS plus modified kernel (or make sure that the kernel you want is found in the ls command above).
The output of the ls command in step 2 has “patch-kernel-2.6.18-164.el5-redhat” in it which matches one of the CentOS plus kernels “kernel-2.6.18-164.15.1.el5.centos.plus.src.rpm”. So I used that kernel.

04 Configure an RPM build environment [S1-2.1]

$ echo '%_topdir /home/USER/rpmbuild' > ~/.rpmmacros
$ mkdir -p ~/rpmbuild/{BUILD,RPMS,SRPMS,SPECS,SOURCES}

05 Install source RPM

$rpm -i kernel-2.6.18-164.15.1.el5.centos.plus.src.rpm

**And you don’t have to do it. It just is one less warning, though I did incorrectly blame it for a rpmbuild failure… :-[ Still, it is one less warning**

$ vi ~/rpmbuild/SOURCES/centos-linux-2.6-acpi-early-pdc-bug4139.patch

remove first 10 lines so that the first line is the following:
“diff –git a/drivers/acpi/Makefile b/drivers/acpi/Makefile”

06 Change to the SPECS directory and build sources [S1-2.1]

$ cd ~/rpmbuild/SPECS
$ rpmbuild -bp - -target=`uname -m` kernel-2.6.spec 2> prep-err.log | tee prep-out.log

*Interesting note: There are problems with hmaccalc and two solutions either do as the CentOS wiki says and use –without fips [S2-5] or use Alan’s suggestion from the forum and install the updated package from ELRepo (post #8).

07 Now we need to modify the make script

$ cd ~/rpmbuild/BUILD/ker*/linux-2.6.18.$(uname -m)/scripts/package/
$ vi mkspec

Now append to the very bottom

echo "%post"
echo "if [ \`uname -i\` == \"x86_64\" -o \`uname -i\` == \"i386\" ]; then"
echo " if [ -f /etc/sysconfig/kernel ]; then"
echo " /bin/sed -i -e 's/^DEFAULTKERNEL=kernel-smp$/DEFAULTKERNEL=kernel/' /etc/sysconfig/kernel || exit \$?"
echo " fi"
echo "fi"
echo "/sbin/new-kernel-pkg --package kernel --mkinitrd --depmod --install "$KERNELRELEASE" || exit \$?"
echo ""
echo "%preun"
echo "/sbin/new-kernel-pkg --rminitrd --rmmoddep --remove "$KERNELRELEASE" || exit \$?"
echo ""

08 Now to clean up the build directory and save it

$ cd ~/rpmbuild/BUILD/ker*/linux-2.6.18.$(uname -m)
$ make mrproper
$ cd ~/rpmbuild/BUILD/ker*/
$ mv linux-2.6.18.$(uname -m) ~

09 Clean up rpmbuild directory

$ cd ~/rpmbuild/
$ rm -r *

10 Setup perfctr in our saved kernel directory. If you did not follow my steps and put your directories else where adjust accordingly. If the update-kernel test shows no errors, then run the update. If it shows errors, you will need to fix them first.

$ PDIR=~/PerfCtr/perfctr-2.6.40
$ KDIR=~/linux-2.6.18.$(uname -m)/
$ cd $KDIR
$ $PDIR/update-kernel --test --patch=2.6.18-164.el5-redhat
$ $PDIR/update-kernel --patch=2.6.18-164.el5-redhat

11 Configure the .config file

$ cd $KDIR/configs
$ cp kernel-2.6.18-$(uname -r).config ../.config
$ cd $KDIR
$ vi Makefile
change "EXTRAVERSION = -prep" to "EXTRAVERSION = -perfctr" to

12 Setup old config and answer y to all (unless you want it a kernel module instead then answer m to that one question) [S2-2]. Clarification from toracat: the first time you will have to hit y; the second time you should not be asked any questions! If it does then there is a problem. So yes, run twice!

$ make oldconfig
$ make oldconfig

12.b Your answers should look like the below if you chose all yes. If you chose a kernel module then "CONFIG_KPERFCTR=m" will be set instead.

$ grep -i PERFCTR .config

13 Build your kernel! This will take a while...

make CONFIG_DEBUG_SECTION_MISMATCH=y binrpm-pkg 2> ../build-err.log | tee ../build-out.log

14 Install kernel

$ cd ~/rpmbuild/RPMS/i386
$ rpm -ivh kernel*.rpm

15 Your kernel devel package is your ~/linux-2.6.18.$(uname -m)/ directory. It is advised that you save this.

$ tar -jcf linux-2.6.18.$(uname -m).tar.bz2 linux-2.6.18.$(uname -m)/

That's it! It has worked for me in the i386 test bed I have been using. I am hoping to test it out on the 64 bit system later this week.
Thanks again Alan!



One response

16 05 2010

valuable pointer, which helps me consider using PerfSuite that depends on PAPI rather than OProfile.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s