Linux Kernel compilation and perfctr module Installation

Source: Internet
Author: User

Linux Kernel compilation and perfctr module Installation

 

Requirement Description

Papi is required to obtain hardware-level data, that is, data related to micro-commands, such as L1/L2 cache miss, TLB miss, and cycle. Papi requires perfctr (performance-monitoring counters Support) the kernel does not have the perfctr module by default, and perfctr is only supported on some kernels. It is actually a patch of the kernel and needs to be re-compiled, install patches to run the perfctr module on the kernel. For more information, see the install file of Papi and perfctr.

I. Environment Introduction
Intel (r) Xeon (r) CPU, x86_64 platform;
Physical Machine <we recommend that you do not try it on a virtual machine. Otherwise, problems may occur, which will be introduced later>

Centos release 5.4 (final)

Kernel version is 2.6.18-164. el5-x86_64

 

View kernel and platform information <br/> # uname-A <br/> Linux gc04vm13 2.6.18-164. EL5 <original kernel> #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux <br/> View the operating system version <br/> # Cat/etc/issue <br /> centos release 5.4 (final) <br/> View CPU Information <br/> CAT/proc/cpuinfo | grep name | cut-F2-D: | uniq-C <br/> 1 Intel (r) xeon (r) CPU e5520 @ 2.27 GHz <only one CPU is allocated to the Virtual Machine>

2. Preparations
(I) download Papi that can be in the http://icl.cs.utk.edu/papi/custom/index.html? Download Papi of each version on lid = 51 & slid = 69, Here download papi-3.6.0.

Papi contains perfctr, the user does not need to download perfctr, (of course, you can also download separately, the URL is http://user.it.uu.se /~ Mikpe/Linux/perfctr). Select perfctr of version 2.6.
Decompress Papi and read the install file under the papi-3.6.0/src/perfctr-2.6.x Directory, which says "This version of perfctr applies to linux kernels of the following versions: Under the papi-3.6.0/src/perfctr-2.6.x/patches directory, if the patch-kernel-* patch exists, it indicates that it applies to the * version of Linux kernel. We select the 2.6.19 version of Linux kernel.

Note: The perfctr version does not correspond to the Linux kernel version, for example, the ompi built-in perfctr-2.6.x can be applied to many versions of the Linux kernel, such as 2.4.26 version of the kernel.

(Ii)download linux-2.6.19.tar.bz2, you can download any version of Linux kernel on the website http://www.kernel.org/pub/linux/kernel.

Generally, the current kernel version is X. y. * ** the new kernel version compiled is preferably X. y. * ** version, for example, do not upgrade from 2.4.x to 2.6.x, because the difference is large, generally [Master]. the kernel with the same version number can be upgraded smoothly [times.

(Iii) carefully read the install file of perfctr, which details the installation steps and tests.

Iii. Installation Steps

(1) decompress the kernel
Bzip2-D linux-2.6.19.tar.bz2
Tar xvf linux-2.6.19.tar
Generate linux-2.6.19 directory

(2) copy the kernel to the/usr/src directory.
CP-r linux-2.6.19/usr/src/

(3) decompress papi to the/OPT directory,

Tar zxvf papi-3.6.0.tar.gz

CP papi-3.6.0/opt/

(4)
CD/usr/src/linux-2.6.19
Make mrproper

(5) execute Update-kernel in the kernel directory
CD/usr/src/linux-2.6.19
/Opt/papi-3.6.0/src/perfctr-2.6.x/update-Kernel
<It must be executed in the kernel directory. Otherwise, the perctr cannot be found when selecting the kernel module.>

If the kernel version is faulty, the following information appears:
Error: no suitable patch found for Kernel 2.6.19zkl-perfctr
See perfctr-2.6.x/patches/for supported kernel versions,

You can view the kernel versions supported under the perfctr-2.6.x/patches.

(6) You can skip or do this.

Copy the. config of the original kernel to the current kernel directory.
CD/usr/src/linux-2.6.19
CP/usr/src/kernels/2.6.18-164. el5-x86_64/. config.
(7) configure and select the kernel module

CD/usr/src/linux-2.6.19
Make menuconfig

Select a module:

View the install file under the perfctr-2.6.x Directory, which has the following content, meaning that you must select these modules:
(I) Under the loadable module support option, this module is generally used by default. The function of this module is to help the system dynamically load modules.


(Ii)Performance-monitoring counters support under Processor type and features options(Perfctr ),

This must be selected. In my experiment, I thought we should select perfctr as (M), and select * as its sub-item to compile it into a module that can be dynamically loaded. Please select as follows.


Note:
When I started my experiment, I first chose perfctr as *, compiled it into the kernel, and finally installed it. The perfectr instance cannot be executed, view the system directory/lib/modules/'uname-R'/drivers without the perfectr module. You cannot view the perfctr module by using lsmod. Now that the module is compiled into the kernel, you can see it, why? You cannot use the modprobe perfctr command to load a module (because it is not loaded in the form of a dynamic module). It may be related to the failure to set the perfctr module to M.

Select the operation mode for the kernel module:
If you select a module, Press Y to display *, press m to display m, and press n to cancel the selection. You can also press the Space key to switch from * to none. uppercase M (uppercase m under the key) indicates compiling to a Dynamically Loaded module, and * Indicates compiling to the kernel.
(Iii) Kernel support for APIC
In addition, you must ensure that the kernel supports APIC (Advanced Programmable Interrupt Controller advanced programmable interrupt controller). This is because papi is to be used later, so ensure that you have selected APIC related items. You can press "/", then, type APIC and search for the following related modules. This module is actually selected under the processor type and features option, you can use the command grep PIC/usr/src/linux-2.6.19 /. config: Check whether the APIC is selected. If you select config_x86_good_apic = Y, it should be displayed. In the install file of Papi, this option is selected by default for "SMP (multi-core, symmetric multi-processor, but it is not selected by default on up (single processor ".

Bytes ----------------------------------------------------------------------------------------
The following is an install file from perfctr:
You shoshould either configure with modules (config_modules = Y) and module
Versions (config_modversions = Y), or completely without modules
(Config_modules = N). modules without module versions is an inherently
Unsafe configuration which is not recommended.

Loadable module support options

You shoshould also enable at least config_perfctr, config_perfctr_virtual,
And config_perfctr_global.

All the performance-monitoring counters support (perfctr) Options under Processor type and features are selected

You may also select config_perfctr = m to build the bulk of the driver (or set it to m and compile it into a Dynamically Loaded module)
As a loadable kernel module; the module will be named 'perfctr '.

Note: The perfctr kernel patch adds one word to the 'thread _ struct'
Type, which makes the patched kernel binary incompatible with
Unpatched one. This is why it is important to distinguish the patched
Kernel via extraversion and config_modversions.
Bytes ----------------------------------------------------------------------------------------

(7) Modify/usr/src/linux-2.6.19/makefile and add the extension version number to mark the kernel,
Extraversion =-zkl-perfctr
After you compile the kernel, your kernel version is the linux-2.6.19-zkl-perfctr.

(8) Compile the kernel

First approach========================================================== ========================================================== =

#Make clean
#Make vmlinux modules<Use this command to compile the kernel and module> after the action is completed, a module-related file is generated under/usr/src/linux-2.6.19/. For example, there are many related files in drivers.
#Make modules_installInstall the module, which is compiled using the module-related files generated above in/usr/src/linux-2.6.19, generate a module in the system directory/lib/modules/2.6.19-zkl-perfctr. For example, you can see the perfctr module in drivers.
#Make bzimageCompile the Kernel File,/usr/src/linux-2.6.19/ARCH/x86_64/boot/directory to generate the Kernel File bzimage
#Make installRun this command to ensure that the Kernel File bzimage is generated before
SH/usr/src/linux-2.6.19/ARCH/x86_64/boot/install. Sh 2.6.19-zkl-perfctr ARCH/x86_64/boot/bzimage system. Map "/Boot"
This command is equivalent to (e) in the second method, except that the make install command will automatically complete several actions in e to enable Multiple kernel startup.
========================================================== ========================================================== =====

 

Or

 

Second approach

<Recommended first type>
========================================================== ========================================================

(A) Make clean: Delete the previously generated. o file, so that there will be no errors between the new and old versions.

(B) Make bzimage
If the command is successfully executed, the following message is displayed, and the Kernel File bzimage is generated in the/usr/src/linux-2.6.19/ARCH/x86_64/boot/directory.
Root device is (8, 3)
Boot Sector 512 bytes.
Setup is 7252 bytes.
System is 1794 KB
Kernel: ARCH/x86_64/boot/bzimage is ready (#1)

(C) Make modules to produce module-Related Files

(D) Make modules_install installation Module

(E) Multiple kernel startup

CP/usr/src/linux-2.6.19/ARCH/x86_64/boot/bzimage/(/indicates that a command is too long, line feed)
>/Boot/vmlinux-2.6.19-zkl-perfctr

CP/usr/src/linux-2.6.19/system. MAP/
>/Boot/system. map-2.6.19-zkl-perfctr

Manually generate the initrd-2.6.19-zkl-perfctr.img file to the/boot directory:
CD/usr/src/linux-2.6.19
[Root @ gc04vm13 linux-2.6.19] # mkinitrd/boot/initrd-2.6.19zkl-perfctr.img 2.6.19-zkl-perfctr (note that the kernel is 2.6.19-zkl-perfctr because the version extension number in makefile was modified earlier, this command will generate a initrd-2.6.19zkl-perfctr.img file under the/boot directory)

Edit the system kernel Startup File
Vim/boot/GRUB/menu. lst

# Grub. conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# Notice: You have a/boot partition. This means that
# All kernel and initrd paths are relative to/boot/, eg.
# Root (hd0, 0)
# Kernel/vmlinuz-version Ro root =/dev/volgroup00/logvol00
# Initrd-version.img/initrd
# Boot =/dev/SDA
Default = 0 # corresponds to the first title
Timeout = 10 # system kernel selection latency
Splashimage = (hd0, 0)/GRUB/splash.xpm.gz
Hiddenmenu
Title centos (2.6.18-164. EL5)
Root (hd0, 0)
Kernel/vmlinuz-2.6.18-164.el5 Ro root =/dev/volgroup00/logvol00
Initrd/initrd-2.6.18-164.el5.img
# Add the following statement to start the new kernel
Title centos (2.6.19-zkl-perfctr)
Root (hd0, 0)
Kernel/vmlinuz-2.6.19-zkl-perfctr Ro root =/dev/volgroup00/logvol00 # This is indicating that the kernel file is/boot/vmlinux-2.6.19-zkl-perfctr
Initrd/initrd-2.6.19-zkl-perfctr.img # This is the file generated before/boot/initrd-2.6.19zkl-perfctr.img

========================================================== ========================================================== =

(10) restart the system,
Two kernel options are displayed in the boot menu. Use the upper and lower buttons to select a new kernel boot.
Or
Set the new kernel to start the kernel by default, that is, modify default = 1 in the above File

(11) after the system is restarted, run the command to check whether the perfctr module is installed,
# Modprobe perfctrLoad Module
Lsmod Display Module
Rmmod perfctr remove Module
If the perfctr module is successfully installed, you will see the perfctr module, and you can see the perfctr module perfctr. KO in/lib/modules/2.6.19-zkl-perfctr/kernel/Drivers/perfctr.

 

(12) Compile and install perfctr,

# Cd/Opt/papi-3.6.0/src/perfctr-2.6.x
# Make
# Mknod/dev/perfctr C 10 108 <a message may be prompted that an existing file exists. delete the file and create it again.>
# Chmod 644/dev/perfctr
# Make prefix =/usr/local install

So far, the installation is complete. perfctr-related files are installed under bin, include, and Lib in/usr/local.

 

(13) test

The example below the test perfctr-2.6.x appears to prove that perfctr is successfully installed

[Root @ gc04vm13 perfctr-2.6.x] # examples/global/Global

Perfctr info:
Abi_version 0x05010501
Driver_version 2.6.32 debug
Cpu_type 5 (?)
Cpu_features 0x7 (rdpmc, rdtsc, pcint)
Cpu_khz 2259879
Tsc_to_cpu_mult 1
Cpu_nrctrs 0
CPUs [0], total: 1
Cpus_forbidden [], total: 0
CPU type 5 (?) Not Supported

Not Supported. This is because I completed the above steps in the vmwarevm. it would be okay if I switched to a physical machine. Normally, it would be refreshed every five seconds after the operation.

 

 

 

 

Involved commands: </P> <p> CP-r papi-3.6.0/opt/<br/> CP linux-2.6.20.tar.gz/usr/src/kernels <br/> Cd/usr/src/kernels <br/> tar zxvf linux-2.6.20.tar.gz <br/> Cd linux-2.6.20 <br/> # Make clean <The current kernel is not compiled and does not need to execute this command> <br/> # Make mrproper <The current kernel is not this command is not required during compilation> <br/>/opt/papi-3.6.0/src/perfctr-2.6.x/update-kernel <br/> CP current kernel directory /. config. <copy. config file to the current directory> <br/> make menuconfig <br/> make the following options: <br/> (1) processo Performance-monitoring counters support under the R type and features options, that is, you must support hardware counters <br/> (2) Search for the APIC options and check whether y is selected, if not, select <br/> (you can also use grep APIC after exiting menuconfig. <br/> exit menuconfig and save. </P> <p> make modules <br/> make modules_install <br/> make bzimage <br/> make install </P> <p> after completion, select a new kernel. start <br/> after the new kernel is started <br/> modprobe perfctr <br/> lsmod | grep perfctr <br/> Cd/opt/papi-3.6.0/src/perfctr-2.6.x/<br/> make <br/> examples/perfex-I <br/> examples/global/Global checks whether perfctr works properly, if an error occurs, restart the system <br/> mknod/dev/perfctr C 10 108 <br/> chmod 644/dev/perfctr <br/> make prefix =/usr/local install, library, and executable commands to/usr/local <br/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.