Gentoo Archives: gentoo-user

From: Andrew Savchenko <bircoph@g.o>
To: gentoo-user@l.g.o
Cc: Ralf <ralf+gentoo@×××××××××××××××××××.de>
Subject: Re: [gentoo-user] CFLAGs for kernel compilation
Date: Thu, 30 Apr 2015 09:38:58
Message-Id: 20150430123819.b72d8b39bd60a912b7c7fde5@gentoo.org
In Reply to: [gentoo-user] CFLAGs for kernel compilation by Ralf
1 On Wed, 29 Apr 2015 13:31:13 +0200 Ralf wrote:
2 > Hi,
3 >
4 > just a short question: I don't like genkernel, I always compile my
5 > kernel manually using menuconfig.
6 > So the CFLAGs of my make.conf won't get applied.
7 >
8 > What is the best way to (persistently) set the CFLAGs for the kernel
9 > compilation?
10 >
11 > - I don't like invoking 'CFLAGS="-O2 -march=foo"make'
12 > - I don't want to set CFLAGS as a persistent environment variable.
13 > - I don't want to modify the kernel Makefile
14 >
15 > Does it actually make sense to set an optimization level and -march?
16
17 Short answer: don't even try to use general CFLAGS for a kernel,
18 you'll badly damage its performance.
19
20 Long answer: context switching between integer and floating point
21 is very expensive, that's why kernel is integer only, any
22 non-integer calculations are implemented using fixed point (integer
23 numbers from CPU's POW). That's why kernel makes sure that no
24 floating point instructions sneaks in using CFLAGS, you may see a
25 lot of -mno-${intrucion_set} flags when running make -V. Futhermore
26 kernel needs several memory alignment flags which should not be
27 removed as well.
28
29 The proper way to fine-tune CFLAGS for a local CPU support will be
30 to use kernel-gcc-patches[1], as was pointed in other reply already.
31 This code will ensure that proper CPU support is enabled while
32 keeping all floating point instructions disabled. Just apply a
33 patch and select native arch in CPU arch menu.
34
35 [1] https://github.com/graysky2/kernel_gcc_patch
36
37 Best regards,
38 Andrew Savchenko

Replies

Subject Author
[gentoo-user] Re: CFLAGs for kernel compilation Martin Vaeth <martin@×××××.de>