Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[FAQF] KC14: Kernel compiling, CFLAGS and make.conf settings
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Marel
n00b
n00b


Joined: 29 Apr 2006
Posts: 17
Location: Serbia

PostPosted: Sun May 07, 2006 6:03 pm    Post subject: Reply with quote

I tried
Code:
# export CFLAGS_KERNEL="athlon-xp"
# make V=1

but in output is still only athlon (without xp). Is there something else to do?
Back to top
View user's profile Send private message
Enlight
Advocate
Advocate


Joined: 28 Oct 2004
Posts: 3519
Location: Alsace (France)

PostPosted: Wed May 31, 2006 5:13 pm    Post subject: Reply with quote

https://forums.gentoo.org/viewtopic-p-3350460-highlight-.html#3350460

It's in french but should be understanble. You just have to apply the commands.

BTW the march option is defined by menuconfig. Theese few commands should allow you to build your kernel with the CFLAGS from the make.conf
Back to top
View user's profile Send private message
charlie
n00b
n00b


Joined: 21 Oct 2007
Posts: 36

PostPosted: Tue Jul 02, 2013 4:54 am    Post subject: Reply with quote

This function, that you can paste into your .bashrc file, uses the MAKEOPTS and CFLAGS variables from /etc/portage/make.conf to compile your kernel with.

Code:
cdku () {
JOBS=`cat /etc/portage/make.conf | grep ^MAKEOPTS | sed 's@MAKEOPTS="\(.*\)"$@\1@1'`
cd /usr/src/linux &&
mv -v Makefile{,.orig} &&
cat Makefile.orig | sed 's@CFLAGS_KERNEL =@CFLAGS_KERNEL +=@1' > Makefile &&
export CFLAGS_KERNEL=`cat /etc/portage/make.conf | grep ^CFLAGS | sed 's@CFLAGS="\(.*\)"$@\1@1'` &&
sed -i "s@\(export.*INSTALL_PATH\) ?= /boot@\1=/boot@g" Makefile ;
make all ${JOBS} && make modules_install && make firmware && make firmware_install && make install ;
sed -i "s@\(export.*INSTALL_PATH\)=/boot@\1 ?= /boot@g" Makefile
}


If using lilo--the sed instruction changing the INSTALL_PATH line in "Makefile" is there just in case you are compiling the kernel from git and don't want to have a modified Makefile interfering with your "git pull".
Back to top
View user's profile Send private message
Massimo B.
Veteran
Veteran


Joined: 09 Feb 2005
Posts: 1810
Location: PB, Germany

PostPosted: Tue Apr 04, 2017 9:34 am    Post subject: Reply with quote

Is the guide about exporting CFLAGS_KERNEL still valid today?
I was warned to change anything on the kernel CFLAGS as the kernel is very restrictive about that and rarely uses floating point arithmetic at all, however there have been drivers reported to use that..

Anyway, usually I would prefer some -march=native, but as distcc isn't compatible with that I have set the explicit CFLAGS in make.conf, that would be applied by -march=native:
Code:
# gcc -march=native -v -E - < /dev/null 2>&1 | grep cc1 | perl -pe 's/ -mno-\S+//g; s/^.* - //g;'

-march=sandybridge -mmmx -msse -msse2 -msse3 -mssse3 -mcx16 -msahf -maes -mpclmul -mpopcnt -mavx -msse4.2 -msse4.1 -mfxsr -mxsave -mxsaveopt --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=4096 -mtune=sandybridge -fstack-protector-strong

Using distcc for the kernel build as well, I guess the CONFIG_MNATIVE wouldn't work there either, so I plan to use some
Code:
export CFLAGS_KERNEL="-march=sandybridge -mmmx -msse -msse2 -msse3 -mssse3 -mcx16 -msahf -maes -mpclmul -mpopcnt -mavx -msse4.2 -msse4.1 -mfxsr -mxsave -mxsaveopt --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=4096 -mtune=sandybridge -fstack-protector-strong
..though discouraged on the ##kernel channel. Just trying, this is Gentoo.

Anyone with comments or experience about that?

How would I pass that to genkernel, could that work in a command like this or is there some better place to set the build environment?
Code:
CFLAGS_KERNEL="-march=sandybridge -mmmx -msse -msse2 -msse3 -mssse3 -mcx16 -msahf -maes -mpclmul -mpopcnt -mavx -msse4.2 -msse4.1 -mfxsr -mxsave -mxsaveopt --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=4096 -mtune=sandybridge -fstack-protector-strong"     pump genkernel all --kernel-cc=distcc --makeopts="-j7 -l2" --loglevel=4 && grub-mkconfig -o /boot/grub/grub.cfg

_________________
HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770
Back to top
View user's profile Send private message
Sadako
Advocate
Advocate


Joined: 05 Aug 2004
Posts: 3792
Location: sleeping in the bathtub

PostPosted: Tue Apr 04, 2017 6:06 pm    Post subject: Reply with quote

There is a kernel patch to let you specify a more precise processor/family, and enable the relevant -march flag, might be worth trying;
https://github.com/graysky2/kernel_gcc_patch

Been meaning to try it myself, just haven't gotten around to it yet.

BTW, for most options the only thing missing from the proper -march setting that march=native adds is the param options for specifying cache sizes.
_________________
"You have to invite me in"
Back to top
View user's profile Send private message
Massimo B.
Veteran
Veteran


Joined: 09 Feb 2005
Posts: 1810
Location: PB, Germany

PostPosted: Thu Apr 06, 2017 12:39 pm    Post subject: Reply with quote

I guess this is done by USE="experimental", but alas ck-sources don't have that. For comparison I emerged gentoo-sources with that experimental, but I can't see any more features in make menuconfig around CONFIG_MSANDYBRIDGE=y.
Anyway I just patched the Makefile for a try:
Code:
# egrep "HOSTC.*?FLAGS.* = " /usr/src/linux-4.10.8-ck/Makefile

HOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes -std=gnu89   -O2 -pipe -fomit-frame-pointer     -march=sandybridge -mmmx -msse -msse2 -msse3 -mssse3 -mcx16 -msahf -maes -mpclmul -mpopcnt -mavx -msse4.2 -msse4 -mfxsr -mxsave -mxsaveopt --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=4096 -mtune=sandybridge -fstack-protector-strong
HOSTCXXFLAGS = -O2 -pipe -fomit-frame-pointer     -march=sandybridge -mmmx -msse -msse2 -msse3 -mssse3 -mcx16 -msahf -maes -mpclmul -mpopcnt -mavx -msse4.2 -msse4 -mfxsr -mxsave -mxsaveopt --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=4096 -mtune=sandybridge -fstack-protector-strong  -fvisibility-inlines-hidden

A kernel made like this runs fine currently, does my kernel have the CFLAGS applied now?

I wondered that -march=sandybridge sets a lot less than -march=native.
In the past there was also --help=target to make the settings visible, but due to a old bug 39851 --help=target is a liar:
Code:
vimdiff <(gcc -march=native -Q --help=target) <(gcc -march=sandybridge -Q --help=target)

_________________
HP ZBook Power 15.6" G8 i7-11800H|HP EliteDesk 800G1 i7-4790|HP Compaq Pro 6300 i7-3770
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum