
Building the Oprofile Kernel Module from Source
-----------------------------------------------
There are two ways to go about this: (1) building the kernel by hand,
and (2) using the Debian package 'kernel-package'.  For those that
typically use the kernels provided by the Debian archive, the latter
method is preferred.  If you build your own kernels often, you probably
know what to do already -- and probably have to use the first option.

You will either have to have root permission from here on out, our
have your system administrator follow these steps to install oprofile.

Credit for much of the ia64 text below goes to Alex Tsariounov,
the project lead for prospect, a performance tool that uses oprofile
(see http://prospect.sourceforge.net for details).


The OProfile Kernel Module and Linux 2.6
----------------------------------------
You do NOT have to build an oprofile module if you are using a Debian
'kernel-image' package.  It is included as part of the 'kernel-image'
package by default.  If you are building a 2.6 kernel from source,
you will need to make sure that CONFIG_OPROFILE is set (OProfile is
part of the 2.6 kernel source).  You will only need to create an 
OProfile kernel module with the 'oprofile-source' package when using
non-Debian kernels prior to 2.5.


Building OProfile Using kernel-package
--------------------------------------
To build the oprofile kernel module from the contents of the
oprofile-source package, follow these steps:

   1) Install your kernel sources by installing these packages:
      kernel-image-2.4.20-mckinley-smp, kernel-source-2.4.20, and
      kernel-patch-2.4.20-ia64.  This can be done with:

      # apt-get install kernel-image-2.4.20-mckinley-smp
      # apt-get install kernel-source-2.4.20
      # apt-get install kernel-patch-2.4.20-ia64

      NOTE: the 2.4.17 kernel will not work with oprofile since it does
      not contain an up-to-date version of perfmon.  The current ia64
      stable release (woody) does not have a kernel-image package
      available greater than 2.4.17.  You need to use at least a
      2.4.18 kernel, and the 2.4.20 kernel is highly recommended
      (using a Debian ia64 release of sarge/testing or sid/unstable
      will make a usable kernel-image available).  Note, too, that the
      '-mckinley-smp' tag shown above is only meant to be indicative;
      that string may be different for the kernel you're using.
      The instructions that follow assume that we're working with
      the 2.4.20-mckinley-smp kernel, using at least sarge/testing.

   2) To make sure you can build a kernel, make sure the right tools
      are already installed:

      # apt-get build-dep kernel-source-2.4.20
      # apt-get install build-essential

      This will pick up everything necessary to build a kernel
      from source.

   3) You may have to correct one of the patches. Change directory to 
      the kernel patch files (cd to /usr/src/kernel-patch/ia64/apply)
      and edit the file "2hplosl".  
   
      Change line 9 to read: 
               PATCHFILE=CVS2420_EM18-V2420_ia64_021210.diff.gz
      Instead of:
               PATCHFILE=CVS2420_EM17-V2420_ia64_021210.diff.gz

      Note the different version number "EM18" instead of the old
      "EM17" in the patch names above.  
      
      If, upon editing this file, you see that line 9 lists the
      correct file "CVS242_EM18....", or a version greater than 18,
      or is in a format similar to "patch-2.4.20-em20.gz", then the
      kernel-patch package has been fixed and editing the 2hplosl
      file is not necessary.

   4) Unpack the kernel source:

      # cd /usr/src
      # tar xvjf kernel-source-2.4.20.tar.bz2

      This will create and populate the directory 
      /usr/src/kernel-source-2.4.20.

   5) Install the oprofile-source package so that we can build the kernel
      module needed:

      # apt-get install oprofile-source

      If doing this from a deb file:

      # apt-get install libpopt-dev
      # dpkg -i oprofile-source_0.5.3-3_ia64.deb

      You will also have to unpack the source file for the module:

      # cd /usr/src
      # tar xvzf oprofile-source.tar.gz

      This will create /usr/src/modules/oprofile, the directory containing
      the needed module source.

   6) Install all the tools that oprofile-source needs to build a module:

      # apt-get build-dep oprofile-source
      # apt-get install automake1.9

      You may need to reset automake so that the default is the 1.9
      version.  Run the command:

      # update-alternatives --config automake

      and see what it reports as default.  Make sure that the 1.9
      version is selected, not 1.4.

      If you installed directly from a deb file, the apt-get will not
      work.  You'll need to do the following instead:

      # apt-get install debhelper kernel-package automake1.9 libpopt-dev

      Some of these may have already been installed by this point, but
      it can't hurt to be sure.

   7) Create or copy in a config file.  You can use the config file
      from your running kernel:

      # cd /usr/src/kernel-2.4.20
      # cp /boot/config-2.4.20-mckinley-smp .config

      Or, the config file from the patch directory:

      # cp ../kernel-patches/ia64/config.mckinley-smp .config

   8) Modify the kernel debian/changelog file to reflect the kernel
      you're building (if it hasn't been changed already):

      # cd /usr/src/kernel-source-2.4.20
      # vi debian/changelog
      
      The very first part of the very first line of text may say
      "kernel-source-2.4.20" but needs to reflect the kernel you're
      building for; in our case, change that part of the line to
      "kernel-source-2.4.20-mckinley-smp".

      If you do not have a 'debian' subdirectory, you'll need to first
      run the following commands, and the edit the changelog:

      # cd /usr/src/kernel-source-2.4.20
      # PATCH_THE_KERNEL=YES make-kpkg debian

   9) Build the oprofile module for your kernel

      # cd /usr/src/kernel-source-2.4.20
      # PATCH_THE_KERNEL=YES make-kpkg --append-to-version=-mckinley-smp \
           modules_image

      When done, there will be a .deb file containing the newly built
      oprofile kernel module in the directory /usr/src/modules.
      The resulting package for what we've done so far will be
      called 'oprofile-modules-2.4.20-mckinley-smp_0.5.3-4_ia64.deb'
      (the '0.5.3-4' part is the oprofile version number, and the
      '2.4.20-mckinley-smp' is the kernel version, so you may see
      something slightly different).

  10) Install and use the oprofile kernel module just built:

      # dpkg -i oprofile-modules-2.4.20-mckinley-smp_0.5.3-4_ia64.deb



Building By Hand on ia64
------------------------
To build the oprofile kernel module from the contents of the
oprofile-source package, follow these steps:

   1) Install your kernel sources by installing these packages:
      kernel-image-2.4.20-mckinley-smp, kernel-source-2.4.20, and
      kernel-patch-2.4.20-ia64.  This can be done with:

      # apt-get install kernel-image-2.4.20-mckinley-smp
      # apt-get install kernel-source-2.4.20
      # apt-get install kernel-patch-2.4.20-ia64

      NOTE: the 2.4.17 kernel will not work with oprofile since it does
      not contain an up-to-date version of perfmon.  The current ia64
      stable release (woody) does not have a kernel-image package
      available greater than 2.4.17.  You need to use at least a
      2.4.18 kernel, and the 2.4.20 kernel is highly recommended
      (using a Debian ia64 release of sarge/testing or sid/unstable
      will make a usable kernel-image available).  Note, too, that the
      '-mckinley-smp' tag shown above is only meant to be indicative;
      that string may be different for the kernel you're using.
      The instructions that follow assume that we're working with
      the 2.4.20-mckinley-smp kernel, using at least sarge/testing.

   2) To make sure you can build a kernel, make sure the right tools
      are already installed:

      # apt-get build-dep kernel-source-2.4.20
      # apt-get install build-essential

      This will pick up everything necessary to build a kernel
      from source.

   3) You may have to correct one of the patches. Change directory to 
      the kernel patch files (cd to /usr/src/kernel-patch/ia64/apply)
      and edit the file "2hplosl".  
   
      Change line 9 to read: 
               PATCHFILE=CVS2420_EM18-V2420_ia64_021210.diff.gz
      Instead of:
               PATCHFILE=CVS2420_EM17-V2420_ia64_021210.diff.gz

      Note the different version number "EM18" instead of the old
      "EM17" in the patch names above.  
      
      If, upon editing this file, you see that line 9 lists the
      correct file "CVS242_EM18....", or a version greater than 18,
      or is in a format similar to "patch-2.4.20-em20.gz", then the
      kernel-patch package has been fixed and editing the 2hplosl
      file is not necessary.

   4) Unpack the kernel source:

      # cd /usr/src
      # tar xvjf kernel-source-2.4.20.tar.bz2

      This will create and populate the directory 
      /usr/src/kernel-source-2.4.20.

   5) Apply the kernel patches.  This is done with:

      # cd /usr/src/kernel-2.4.20
      # make distclean
      # for ii in ../kernel-patches/ia64/apply/*; do $ii; done

      If the patch package a recent repaired version, you're done
      with this step.  If, on the other hand, you get this message
      from the last patch indicating it failed:

      Reversed (or previously applied) patch detected!  Assume -R? [n]

      Choose the default action of [n] (just hit return, and then hit
      return again when patch asks to apply anyway, thus choosing to
      *not* apply the patch).

   6) Edit the kernel Makefile.  In order to make sure we build a usable
      version of oprofile, we need to set up the Makefile so that the
      kernel version matches the results of `uname -r` for the machine
      we'll be running on.
      
      # cd /usr/src/kernel-2.4.20
      # vi Makefile
        Edit the fourth line in the Makefile
            from: EXTRAVERSION = 
              to: EXTRAVERSION = -mckinley-smp

   7) Create or copy in a config file.  You can use the config file
      from your running kernel:

      # cd /usr/src/kernel-2.4.20
      # make mrproper
      # cp /boot/config-2.4.20-mckinley-smp .config

      Or, the config file from the patch directory:

      # cp ../kernel-patches/ia64/config.mckinley-smp .config

   8) Configure the kernel source tree properly:

      # cd /usr/src/kernel-2.4.20
      # make oldconfig
      # make dep

      This is all that needs to be done to the actual kernel source
      tree.  It is not necessary to actually rebuild the kernel.

   9) Install the oprofile-source package so that we can build the kernel
      module needed:

      # apt-get install oprofile-source

      If doing this from a deb file:

      # apt-get install libpopt-dev
      # dpkg -i oprofile-source_0.5.3-3_ia64.deb

  10) Install all the tools that oprofile-source needs to build a module:

      # apt-get build-dep oprofile-source

      If you installed directly from a deb file, the apt-get will not
      work.  You'll need to do the following instead:

      # apt-get install debhelper kernel-package automake1.9 libpopt-dev

      Some of these may have already been installed by this point, but
      it can't hurt to be sure.

  11) Build the oprofile module for your kernel

      # cd /usr/src/modules/oprofile
      # debian/rules binary-modules

      When done, there will be a .deb file containing the newly built
      oprofile kernel module in the directory /usr/src/modules.
      The resulting package for what we've done so far will be
      called 'oprofile-modules-2.4.20-mckinley-smp_0.5.3-3_ia64.deb'
      (the '0.5.3-3' part is the oprofile version number, and the
      '2.4.20-mckinley-smp' is the kernel version, so you may see
      something slightly different).

  12) Install and use the oprofile kernel module just built:

      # dpkg -i oprofile-modules-2.4.20-mckinley-smp_0.5.3-4_ia64.deb



 -- Al Stone <ahs3@debian.org>, Tue, 17 June 16:13:29 -0600
