Jump to content



Photo

[n00b Guide]Compiling Upstream Kernel with CPU Optimizations


  • This topic is locked This topic is locked
16 replies to this topic

#1 +ChuckFinley

ChuckFinley

    member_id=28229

  • Joined: 14-May 03

Posted 22 April 2013 - 18:57

OK So below is my guide for you to all compile the latest Linux Kernel from https://www.kernel.org/ built with your CPU in mind.

This is intended for guys like me who were curious about this kind of thing, Meant to be as simple as possible so you can practically copy and paste the commands to your terminal.

*All the following you MUST be run as root. on Ubuntu

sudo -su
*This works on the latest versions of Ubuntu.


First lets install all the pre reqs.

sudo apt-get install kernel-package fakeroot build-essential ncurses-dev

After you have installed all the pre reqs, You need to set your optimizations.

To check your processor ...


cat /proc/cpuinfo



In your terminal. Read this and pick out your CPU Type and Adjust Accordingly. For Mine it is an i7 :D

http://gcc.gnu.org/o...64-Options.html

export CONCURRENCY_LEVEL=8
export CFLAGS="-march=corei7-avx -O3 -pipe"
export CXXFLAGS="$CFLAGS"

I will explain these:

CONCURRENCY_LEVEL, for some programs, mainly the program we will be using to build the kernel the "debian" way, it is capable of using multiple cores, with this variable set to the number of cores of your CPU, it will use all of them when compiling the kernel.

CHOST, this variable is for gcc, the compiler used in Linux. This line tells gcc what architecture to build for. this is currently set for Intel/AMD x86_64 cpu's and 64 bit distro's, if you are building for a 32 bit distro, use CHOST="i686-pc-Linux-gnu", instead. This flag isn't always needed, you can exclude it if you want. * I have removed this as its not needed

CFLAGS, these are compile flags, mainly for optimization for the binary. -march, the family of your CPU, latest versions of GCC can auto detect these features, setting it to native is suitable in most cases. Setting -march allows GCC to compile the code to take advantage of any feature of your CPU. -O2 and -pipe, are another optimization flag. There are more flags, but these are "generic" ones used, that offer a decent amount of benefits, I'm afraid going into more detail, is beyond the scope of this guide.

CXXFLAGS, extra flags for GCC, typically you can set them to CFLAGS, which has be done here.

Keep the terminal open, as everything you will be doing will require it. (if you close the terminal, you will need to export those variables again.)


Next Make a tmp directory. This will be used to unpack and build the kernel. Wherever you like. A suggestion is....

mkdir ~/tmp
cd ~/tmp

Download the latest Kernel from Kernel.org.

wget https://www.kernel.org/pub/linux/kernel/v3.x/testing/linux-3.9-rc8.tar.xz

Unpack it....

tar xvf linux-3.9-rc8.tar.xz


Move into your directory and build your config file. Now here I suggested building your default one. I have heavily modified mine and taken alot of the stuff out to make it as stream lined as possible. You will be asked a lot of questions, How many depends on what version you are building. If in doubt, pick the default answer (i.e. hit enter). If really in doubt, use post here.

cd linux-3.9-rc8/
cat /boot/config-`uname -r`>.config
make oldconfig
make-kpkg clean

For the more adventerous amongst you, I suggest you familiarize yourself with the Menu Config. If I remember I will post my .config file for you to download. However it is built for a Sony VAIO Laptop. So... if you want to make any specific changes to the kernel (e.g. add support for certain devices) ...

make menuconfig

Then the fun part. Building the kernel.

time fakeroot make-kpkg -j8 --initrd kernel_image kernel_header
*As usual 8 is the number of threads you wish to launch -- make it equal to the number of cores that you have for optimum performance.
If you get it under 30mins on an i7 You are doing well. Sit back and enjoy...
After all the good stuff, Install your new shiny built kernel.

cd ..
sudo dpkg -i linux-image-*.deb
sudo dpkg -i linux-headers-*.deb

You should also see it update the GRUB Boot loader so it boots right into your new kernel. Reboot and enjoy.

You can see here on how to test your performance...http://www.neowin.net/forum/topic/1148290-cpu-optimizations/

Further Reading ...

http://freecode.com/...myths-and-facts

v1.0 - Created :)




#2 fusi0n

fusi0n

    Don't call it a come back

  • Tech Issues Solved: 3
  • Joined: 08-July 04
  • OS: OSX 10.9\Elementary OS
  • Phone: LG G3

Posted 22 April 2013 - 19:03

Great work!!!!

#3 OP +ChuckFinley

ChuckFinley

    member_id=28229

  • Joined: 14-May 03

Posted 22 April 2013 - 19:31

Thanks! Hopefully someone will find it useful.

#4 +Majesticmerc

Majesticmerc

    Resident Idealist

  • Tech Issues Solved: 8
  • Joined: 24-August 05
  • Location: United Kingdom
  • OS: Arch Linux / Win 7
  • Phone: HTC One X

Posted 22 April 2013 - 21:41

Nice work dude! Might give this a try at some point. Have you noticed any significant improvement?

#5 OP +ChuckFinley

ChuckFinley

    member_id=28229

  • Joined: 14-May 03

Posted 23 April 2013 - 07:35

I can honestly say that my system feels much more snappier loading programs up. Not that it was slow in the first place. My true test is going to be when I am doing BOINC work for example.

#6 OP +ChuckFinley

ChuckFinley

    member_id=28229

  • Joined: 14-May 03

Posted 23 April 2013 - 18:45

Just noticed

[s]time fakeroot make-kpkg -j8 --initrd kernel_image kernel_header[/s]

Should read

time fakeroot make-kpkg -j8 --initrd kernel_image kernel_headers


#7 OP +ChuckFinley

ChuckFinley

    member_id=28229

  • Joined: 14-May 03

Posted 30 April 2013 - 10:34

Any chance we could make this a Sticky?

#8 +Karl L.

Karl L.

    xorangekiller

  • Tech Issues Solved: 15
  • Joined: 24-January 09
  • Location: Virginia, USA
  • OS: Debian Testing

Posted 30 April 2013 - 15:41

Any chance we could make this a Sticky?


I think you would need to PM a mod for that... or a mod could visit this thread and see your comment, but there are not may mods who visit this subforum AFAIK. While useful, I don't think that this guide should be made a sticky. It would be nice to move it to the "HOW TO & FAQ Guides" subforum of this subforum though; then it would be with all of the other useful guides and easier to find in the future (which I think was your goal with making it a sticky).

#9 ir0nw0lf

ir0nw0lf

    Neowinian Fanatic

  • Joined: 22-August 01
  • Location: Pensacola, FL, USA

Posted 30 April 2013 - 15:49

OP, 2nd link in your post is borked... "http://gcc.gnu.org/o...4-Options.html"

#10 sean.ferguson

sean.ferguson

    Anonymous

  • Joined: 25-June 05
  • Location: Scotland
  • OS: GNU/Linux

Posted 30 April 2013 - 18:43

Good work Chuck, hopefully this will help people who often distro jump just for a newer kernel :)

I agree with xorangekiller not really worthy of a sticky, but definitely should be moved to the HowTo subforum.

#11 OP +ChuckFinley

ChuckFinley

    member_id=28229

  • Joined: 14-May 03

Posted 01 May 2013 - 10:00

I think you would need to PM a mod for that... or a mod could visit this thread and see your comment, but there are not may mods who visit this subforum AFAIK. While useful, I don't think that this guide should be made a sticky. It would be nice to move it to the "HOW TO & FAQ Guides" subforum of this subforum though; then it would be with all of the other useful guides and easier to find in the future (which I think was your goal with making it a sticky).

Good work Chuck, hopefully this will help people who often distro jump just for a newer kernel :)

I agree with xorangekiller not really worthy of a sticky, but definitely should be moved to the HowTo subforum.



Yeah makes sense!

OP, 2nd link in your post is borked... "http://gcc.gnu.org/o...4-Options.html"


For some reason I cant edit it. But this is the link.

http://gcc.gnu.org/o...64-Options.html

#12 OP +ChuckFinley

ChuckFinley

    member_id=28229

  • Joined: 14-May 03

Posted 25 August 2013 - 10:11

Bumping this as I am using it to compile the Kernel on ElementaryOS. However the newer kernels have trackpad bugs on my Sony VAIO :-(



#13 OP +ChuckFinley

ChuckFinley

    member_id=28229

  • Joined: 14-May 03

Posted 01 April 2014 - 20:04

Bump! 

 

This method still works well with newer kernels too. 



#14 Mindovermaster

Mindovermaster

    Neowinian Senior

  • Tech Issues Solved: 10
  • Joined: 25-January 07
  • Location: /USA/Wisconsin/
  • OS: Mint Debian LMDE
  • Phone: HTC ONE V

Posted 01 April 2014 - 20:22

Why bump this? I see you are the OP, but still. It's almost a year old.



#15 OP +ChuckFinley

ChuckFinley

    member_id=28229

  • Joined: 14-May 03

Posted 01 April 2014 - 20:31

Incase anyone else finds it useful! :-p Things tend to get lost.