Difference between pages "Building a Kernel from Source" and "Benchmarking"

From Funtoo
(Difference between pages)
Jump to navigation Jump to search
m (add instructions to sanitize sources, add instructions to insert configs to sanitized source directory, fancy to not so much, tt 2 code, link 2 make.conf)
 
 
Line 1: Line 1:
Setting up a proper kernel yourself - lean, mean and tailored to your hardware,  is the challenge by which a linux user can graduate to becoming a Funtoo knight ;-)
== Power usage ==
 
<code>sys-power/powertop</code> can guess the computer's current power usage in watts. You have to be on battery power for watt usage to show up.
Even though many of us are using enterprise-ready kernels in datacenters, there is almost nobody who hasn't at least considered building a kernel for his laptop / PC.
We are showing here how an intermediate Linux user can use an alternative to the standard beginners "genkernel" approach,  to compile a custom kernel,  in a relatively speedy and easy set up.
 
== Minimum Requirements ==
* '''Understand the command line'''
* '''Know where the kernel files are located'''
 
== Assumptions ==
You start from an installed Funtoo system on the disk, or at least, you are on stage3 in a chrooted environment from a live cd, following somehow the Funto [[Installation (Tutorial)|Installation Tutorial]].
 
== Less advanced version ==
=== Emerging the kernel sources ===
To begin, we have to figure out which kernel sources we will use. If you are unsure about which sources are available and what their benefits and drawbacks are, check out the [[Funtoo_Linux_Kernels| Kernels]] page.
 
After you have made a decsion as to which kernel you want to install, emerge it:
<console>
###i## emerge sys-kernel/[kernel-name]
</console>
Portage will now go about installing the sources to ''/usr/src''. However, it is preferable to also create a symlink with eselect as such:
<console>
<console>
###i## eselect kernel set 1
###i## powertop
Power usage (ACPI estimate): 15.7W (0.5 hours)
</console>
</console>
You may use
<console>
###i## eselect kernel list
</console>
to display a list of kernels currently installed.
Using the above command is useful, because it allows you to always be able to go to the directory "/usr/src/linux" and find your current working kernel and build files.
The "/usr/src/linux" directory is simply a symlink to the kernel you selected with eselect, in the "/usr/src" directory.
Note that portage can also set this up for you automatically, by setting the "symlink" USE flag for your kernel.


=== Configuring the kernel ===
== CPU ==
Now that the kernel sources are on your system, you should configure them. To do this, change your directory to ''/usr/src/linux''
=== Compiler performance ===
<console>
<console>
###i## cd /usr/src/linux
###i## time emerge -1 coreutils
real    2m17.574s
user    1m46.572s
sys    0m53.450s
</console>
</console>


We are now in the kernel sources directory, next sanitize the sources:
== RAM ==
{{warning|this will delete your .config}}
=== ramspeed ===
<console>###i## make clean && make distclean && make mrproper</console>
 
Copy configurations if you have previous configurations to copy:
<console>###i## cp /boot/config-3.13.7 .config</console>
 
We can run a script that allows us to modify the configuration. Run:
<console>
<console>
###i## make menuconfig
###i## emerge -av ramspeed
$##bl## ramspeed -b2 -m4 && ramspeed -b1 -m4
INTEGER & READING      2048 Kb block: 5027.82 MB/s
INTEGER & READING      4096 Kb block: 4999.53 MB/s
...
INTEGER & WRITING      2048 Kb block: 2003.86 MB/s
INTEGER & WRITING      4096 Kb block: 1951.05 MB/s
</console>
</console>


While you edit the sources, keep the following in mind:
== Hard drive ==
* To build something into your kernel, press y when you have it selected.
=== hdparm ===
* To exclude something from your kernel, press n when you have it selected.
* To build something as a module, press m.
 
 
Things that you may need to include in your kernel:
 
as '''modules''':
 
* Wireless/LAN drivers
* Support for your graphics card
* Support for your audio card
* Support for USB devices
 
 
as '''built in''':
* scsi sata & or ata controllers
* file system used
 
{{note|1=
Many pages on the wiki will tell you the kernel requirements for the application that they are about. Keep your eyes open for the blue background, white text sections of pages. Like on this one: [[uvesafb| uvesafb]]}}
 
=== Building and installing the kernel sources ===
After you finish configuring your kernel sources, you will need to build them. To build your sources, run the following:
<console>
<console>
###i## make
###i## hdparm -tT /dev/sda
/dev/sda:
Timing cached reads:  2318 MB in  2.00 seconds = 1159.52 MB/sec
Timing buffered disk reads: 648 MB in  3.00 seconds = 215.92 MB/sec
</console>
</console>
{{tip|1=
You can add -j<number of processing cores + 1> after make to build the kernel more quickly.}}


When the kernel and its modules finish building, install them:
=== dd ===
<console>
<console>
###i## make modules_install && make install
$##bl## dd bs=1M count=512 if=/dev/zero of=temp conv=fdatasync
###i## echo 3 > /proc/sys/vm/drop_caches
$##bl## dd bs=1M count=512 if=temp of=/dev/null
536870912 bytes (537 MB) copied, 3.13319 s, 171 MB/s
..
536870912 bytes (537 MB) copied, 2.17444 s, 247 MB/s
$##bl## rm temp
</console>
</console>
Now that you have installed your kernel and modules, it is a good idea to install an [[Building_a_Kernel_from_Source#Initramfs| Initramfs]].
* If your system has a separate ''/usr'' partition, is encrypted, or uses some other non-standard configuration, it will probably not boot without an initramfs.
* If your system is unencrypted, with file system, and hard drive controllers compiled in rather than as modules, it will not need an initramfs.
== Advanced version ==
=== Getting ready to start ===
{{note|In this case we are building a kernel that is booting root in LVM over encrypted LUKS container.
If you don't have this setup, don't worry, you just don't need all the modules, but everything else is similar.}}
First, there is the decision which linux kernel sources we need.
There are plenty of them in the repositories around, often it is not easy to distinguish between them.
I would always trust my distribution of choice and take what is has to offer - and funtoo has a lot to offer!
I really do recommend (especially if it is your first time) to build a debian-sourced genkernel like described in chapter 5 "Using Debian-Sources with Genkernel" in the [[Funtoo_Linux_Kernels| Funtoo Kernels Tutorial]].
From there you should have a running system booting nicely from your own build (just little bit bloated) kernel. This is more than you can expect from any other ready to go distribution.
{{note|1=
We are using Red Hat's dracut in order to build a nice initramfs (containing all the necessary tools and extra drivers our kernel might need to start the system). Although dracut is the way to go, more sophisticated and not as buggy as gentoo's genkernel approach, more and more funtoo geeks start using slashbeast's better-initramfs, which we will cover at the end of this howto! So after having set up a genkernel from debian or gentoo sources we are going to build a kernel with either (or both) dracut or/and better-initramfs. So gentoo sources with genkernel is always my backup if anything is not working correctly on my system. For the slightly more geeky approach with my own initram I am using pf-sources, ck-sources or any other more or less heavily patched sources.}}
Let's go!
=== Kernel Sources ===
The source you use on your system is up to you. For a laptop or desktop system, the following are recommended:
* '''{{Package|sys-kernel/pf-sources}}'''
* '''{{Package|sys-kernel/ck-sources}}'''
* '''{{Package|sys-kernel/gentoo-sources}}'''
* '''{{Package|sys-kernel/git-sources}}'''
* '''{{Package|sys-kernel/sysrescue-std-sources}}'''
* '''{{Package|sys-kernel/debian-sources}}'''
{{note|If you are unsure of which sources you would like to use, emerge <code>gentoo-sources</code>. That's always a safe bet for a general system. For more information on available kernels, check out: [[Funtoo Linux Kernels]]}}
=== Prerequisites ===
Regardless of the tools you already have installed, it is recommended to follow the steps below, even if you find them to be redundant.
First, we edit our <code>/etc/portage/[[make.conf]]</code>:
<pre>
#These compiler flags are just tweaking (optimazation) and NOT necessary:
CFLAGS="-O2 -pipe -march=native -ftracer -fforce-addr"
CXXFLAGS="${CFLAGS} -fpermissive -fomit-frame-pointer"
KDIR=/usr/src/linux
KERNEL="symlink build"
USE="$KERNEL ....here are your use flags...."
## These modules are available:
## DRACUT_MODULES="dracut_modules_biosdevname dracut_modules_btrfs dracut_modules_caps dracut_modules_crypt dracut_modules_crypt-gpg dracut_modules_dmraid dracut_modules_dmsquash-live dracut_modules_gensplash dracut_modules_iscsi dracut_modules_livenet dracut_modules_lvm dracut_modules_mdraid dracut_modules_multipath dracut_modules_nbd dracut_modules_nfs dracut_modules_plymouth dracut_modules_ssh-client dracut_modules_syslog"
## We will use these modules for LVM / LUKS:
DRACUT_MODULES="crypt lvm plymouth biosdevname dmraid crypt-gpg dmsquash-live ssh-client syslog"
</pre>
Next, we set the package keywords by adding the following to <code>/etc/portage/package.use</code>:
<pre>
sys-kernel/dracut dm net device-mapper crypt lvm
</pre>
{{note|If you don't have lvm over encrypted LUKS you just add the "net" keyword here, or "selinux".}}


Next, we build our packages:
== GPU ==
=== Warsow ===
==== Install ====
<console>
<console>
###i## emerge -av app-portage/gentoolkit sys-kernel/pf-sources sys-kernel/dracut sys-boot/plymouth sys-boot/plymouth-openrc-plugin
###i## emerge -av warsow
$##bl## mkdir -p ~/.warsow-1.0/basewsw/demos
$##bl## cd ~/.warsow-1.0/basewsw/demos
$##bl## wget http://www.phoronix-test-suite.com/benchmark-files/pts-warsow-10-1.zip
$##bl## unzip pts-warsow-10-1.zip
</console>
</console>
 
==== Benchmark ====
=== Preparing the kernel ===
 
We go now to the sources directory and enter the following commands to update the kernel's  .config  file:
<console>
<console>
###i## cd /usr/src/linux/
$##bl## warsow +exec profiles/high+.cfg +timedemo 1 +cg_showFPS 1 +cl_maxfps 999 +demo pts-demo10 +next "quit" +r_mode -1
###i## make clean
899 frames, 76.4 seconds: 11.8 fps
  CLEAN  .
  CLEAN  arch/x86/kernel/acpi/realmode
  CLEAN  arch/x86/kernel/cpu
  CLEAN  arch/x86/kernel
  CLEAN  arch/x86/vdso
  CLEAN  arch/x86/lib
  CLEAN  drivers/gpu/drm/radeon
  CLEAN  drivers/net/wan
  CLEAN  drivers/scsi/aic7xxx
  CLEAN  drivers/tty/vt
  CLEAN  drivers/video/logo
  CLEAN  firmware
  CLEAN  kernel
  CLEAN  lib/raid6
  CLEAN  lib
  CLEAN  security/apparmor
  CLEAN  security/selinux
  CLEAN  usr
  CLEAN  arch/x86/boot/compressed
  CLEAN  arch/x86/boot
  CLEAN  .tmp_versions
  CLEAN  vmlinux System.map .tmp_kallsyms2.S .tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms1.S .tmp_vmlinux1 .tmp_vmlinux2 .tmp_System.map
###i## zcat /proc/config.gz > /usr/src/linux/.config
</console>
</console>


Next, we run <code>make localmodconfig</code>. You will get some questions which you can answer mostly with either M (compiled as a module) or Y (compiled directly into the kernel). If you are not sure what to choose, press enter, and the default option will be selected.
=== Nexuiz ===
<console>
<console>
###i## make localmodconfig
###i## emerge -av nexuiz
Enable different security models (SECURITY) [Y/n/?] y
$##bl## nexuiz-glx -benchmark demos/demo1 -nosound 2>&1 {{!}} egrep -e '[0-9]+ frames'
Enable the securityfs filesystem (SECURITYFS) [Y/?] y
1910 frames 42.0330749 seconds 45.4404063 fps, one-second fps min/avg/max: 35 46 63 (90 seconds)
Socket and Networking Security Hooks (SECURITY_NETWORK) [Y/?] y
Security hooks for pathname based access control (SECURITY_PATH) [Y/?] y
Low address space for LSM to protect from user allocation (LSM_MMAP_MIN_ADDR) [65536] 65536
NSA SELinux Support (SECURITY_SELINUX) [Y/n/?] y
  NSA SELinux boot parameter (SECURITY_SELINUX_BOOTPARAM) [N/y/?] n
  NSA SELinux runtime disable (SECURITY_SELINUX_DISABLE) [N/y/?] n
  NSA SELinux Development Support (SECURITY_SELINUX_DEVELOP) [Y/n/?] y
  NSA SELinux AVC Statistics (SECURITY_SELINUX_AVC_STATS) [Y/n/?] y
  NSA SELinux checkreqprot default value (SECURITY_SELINUX_CHECKREQPROT_VALUE) [1] 1
  NSA SELinux maximum supported policy format version (SECURITY_SELINUX_POLICYDB_VERSION_MAX) [Y/n/?] y
    NSA SELinux maximum supported policy format version value (SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE) [19] 19
TOMOYO Linux Support (SECURITY_TOMOYO) [Y/n/?] y
  Default maximal count for learning mode (SECURITY_TOMOYO_MAX_ACCEPT_ENTRY) [2048] 2048
  Default maximal count for audit log (SECURITY_TOMOYO_MAX_AUDIT_LOG) [1024] 1024
  Activate without calling userspace policy loader. (SECURITY_TOMOYO_OMIT_USERSPACE_LOADER) [Y/n/?] y
AppArmor support (SECURITY_APPARMOR) [Y/n/?] y
  AppArmor boot parameter default value (SECURITY_APPARMOR_BOOTPARAM_VALUE) [1] 1
Integrity Measurement Architecture(IMA) (IMA) [Y/n/?] y
EVM support (EVM) [N/y/?] (NEW)
Default security module
  1. SELinux (DEFAULT_SECURITY_SELINUX)
  2. TOMOYO (DEFAULT_SECURITY_TOMOYO)
  3. AppArmor (DEFAULT_SECURITY_APPARMOR)
> 4. Unix Discretionary Access Controls (DEFAULT_SECURITY_DAC)
choice[1-4?]: 4
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
#
# configuration written to .config
#
warning: (GFS2_FS) selects DLM which has unmet direct dependencies (EXPERIMENTAL && INET && SYSFS && CONFIGFS_FS && (IPV6 || IPV6=n))
warning: (IMA) selects TCG_TPM which has unmet direct dependencies (HAS_IOMEM && EXPERIMENTAL)
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)
</console>
</console>


Now comes the most adventurous part!
=== Xonotic ===
 
=== Building the Kernel ===
<console>
<console>
###i## make -j8  bzImage
###i## emerge -av xonotic
###i## make -j8 modules
$##bl## xonotic-glx -benchmark demos/the-big-keybench 2>&1 {{!}} egrep -e '[0-9]+ frames'
###i## make modules_install
12568 frames 556.0637400 seconds 22.6017255 fps, one-second fps min/avg/max: 19 23 27 (207 seconds)
###i## make install
</console>
</console>


== Initramfs ==
=== Glxgears ===
{{warning|Make sure that you have built and installed your kernel sources / modules before building an initramfs.}}
Note: glxgears is a very basic OpenGL support test, it is not a real benchmark tool!
To get your initramfs up and running, check out the [http://www.funtoo.org/Initramfs Initramfs] page. After following all the directions on the page to get your initramfs set up, continue following the ones here.
 
Update the <code>grub.cfg</code> with boot update, then reboot and see how it works!
<console>
<console>
###i## boot-update -v
###i## emerge -av mesa-progs
###i## reboot
$##bl## vblank_mode=0 glxgears
1583 frames in 5.0 seconds = 316.485 FPS
</console>
</console>


[[Category:HOWTO]]
[[Category:HOWTO]]
[[Category:Featured]]
[[Category:Kernel]]

Revision as of 15:29, October 20, 2014

Power usage

sys-power/powertop can guess the computer's current power usage in watts. You have to be on battery power for watt usage to show up.

root # powertop
Power usage (ACPI estimate): 15.7W (0.5 hours)

CPU

Compiler performance

root # time emerge -1 coreutils
real    2m17.574s
user    1m46.572s
sys     0m53.450s

RAM

ramspeed

root # emerge -av ramspeed
user $ ramspeed -b2 -m4 && ramspeed -b1 -m4
INTEGER & READING      2048 Kb block: 5027.82 MB/s
INTEGER & READING      4096 Kb block: 4999.53 MB/s
...
INTEGER & WRITING      2048 Kb block: 2003.86 MB/s
INTEGER & WRITING      4096 Kb block: 1951.05 MB/s

Hard drive

hdparm

root # hdparm -tT /dev/sda
/dev/sda:
 Timing cached reads:   2318 MB in  2.00 seconds = 1159.52 MB/sec
 Timing buffered disk reads: 648 MB in  3.00 seconds = 215.92 MB/sec

dd

user $ dd bs=1M count=512 if=/dev/zero of=temp conv=fdatasync
root # echo 3 > /proc/sys/vm/drop_caches
user $ dd bs=1M count=512 if=temp of=/dev/null
536870912 bytes (537 MB) copied, 3.13319 s, 171 MB/s
..
536870912 bytes (537 MB) copied, 2.17444 s, 247 MB/s
user $ rm temp

GPU

Warsow

Install

root # emerge -av warsow
user $ mkdir -p ~/.warsow-1.0/basewsw/demos
user $ cd ~/.warsow-1.0/basewsw/demos
user $ wget http://www.phoronix-test-suite.com/benchmark-files/pts-warsow-10-1.zip
user $ unzip pts-warsow-10-1.zip

Benchmark

user $ warsow +exec profiles/high+.cfg +timedemo 1 +cg_showFPS 1 +cl_maxfps 999 +demo pts-demo10 +next "quit" +r_mode -1
899 frames, 76.4 seconds: 11.8 fps

Nexuiz

root # emerge -av nexuiz
user $ nexuiz-glx -benchmark demos/demo1 -nosound 2>&1 {{!}} egrep -e '[0-9]+ frames'
1910 frames 42.0330749 seconds 45.4404063 fps, one-second fps min/avg/max: 35 46 63 (90 seconds)

Xonotic

root # emerge -av xonotic
user $ xonotic-glx -benchmark demos/the-big-keybench 2>&1 {{!}} egrep -e '[0-9]+ frames'
12568 frames 556.0637400 seconds 22.6017255 fps, one-second fps min/avg/max: 19 23 27 (207 seconds)

Glxgears

Note: glxgears is a very basic OpenGL support test, it is not a real benchmark tool!

root # emerge -av mesa-progs
user $ vblank_mode=0 glxgears
1583 frames in 5.0 seconds = 316.485 FPS