[n00b Guide]Compiling Upstream Kernel with CPU Optimizations


Recommended Posts

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.

  Quote

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

sudo -su[/CODE]

*This works on the latest versions of Ubuntu.

First lets install all the pre reqs.

[CODE]sudo apt-get install kernel-package fakeroot build-essential ncurses-dev[/CODE]

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

To check your processor ...

[CODE]

cat /proc/cpuinfo


[/CODE]

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

[CODE]export CONCURRENCY_LEVEL=8
export CFLAGS="-march=corei7-avx -O3 -pipe"
export CXXFLAGS="$CFLAGS"[/CODE]

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....

[CODE]mkdir ~/tmp
cd ~/tmp[/CODE]

Download the latest Kernel from Kernel.org.

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

Unpack it....

[CODE]tar xvf linux-3.9-rc8.tar.xz[/CODE]

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.

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

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) ...

[CODE]make menuconfig[/CODE]

Then the fun part. Building the kernel.

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

*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.

[CODE]
cd ..
sudo dpkg -i linux-image-*.deb
sudo dpkg -i linux-headers-*.deb
[/CODE]

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...https://www.neowin.net/forum/topic/1148290-cpu-optimizations/

Further Reading ...

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

  Quote
v1.0 - Created :)
  On 30/04/2013 at 10:34, ChuckFinley said:

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).

  • Like 2

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.

  On 30/04/2013 at 15:41, xorangekiller said:

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).

  On 30/04/2013 at 18:43, sean.ferguson said:

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!

  On 30/04/2013 at 15:49, ir0nw0lf said:

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

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

http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html

  • 3 months later...
  • 7 months later...
  • 4 months later...

way too complex and i suspect no one interested in kernel updates would go this long and uneasy to follow tutorial.

either use the mainline ubuntu ppa kernels where you just need to download and dpkg 3 files then reboot, or someone finally makes the kernelpatcher tool which was running fine till the 2.6 kernels up2date....

 

i think especially stuff like kernel update needs to be implemented in an easy usable tool. no one has an interest to copy and paste endless lines into the terminal and even additionally open links in his webbrowser.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I assume he would make the same statement in those cases as well.
    • Looks like an alien. Probably is an alien. First it was aaaaallll Azure and drop everything else. Now its aaaaallll AI and drop everything else. Narrow-minded. I really loathe this guy. He's good for shareholders but absolutely nothing else. Dry as desert sand and evil to the bone.
    • Don’t care about a wrestling union. No normal person should care. 
    • Limassol, Cyprus. Just south of Turkey. NOT Russia.
    • Hello, Given the reports of Chinese Mini PCs shipping with malware, I would recommend wiping the machine and performing a clean install of Windows on it before use.  From what I can infer from the reports, the Mini PCs that shipped with malware were not the result of targeted purposeful action on the part of the device manufacturers (which is something that has happened with low-cost Android smartphones and TV boxes from China) but rather due to lax security in the manufacturing process.   Getting back to the subject at hand, there are a few steps you will want to go through before wiping the Mini PC: You can start preparing even before the Mini PC arrives.  Once you have ordered it and know the brand and model, go to the manufacturer's website and download all of the latest device drivers, BIOS (UEFI) firmware updates, machine-specific software (if any), and manuals.  Many Mini PC manufacturers do not do a lot of customization of their device drivers, just shipping whatever device drivers the the silicon vendors provide.  I still recommend downloading them, though, just in case there are some customizations or for initial install since those are the drivers you know the manufacturer validated for the Mini PC.  Store these in a safe place, so you have them ready when the Mini PC arrives. Use Microsoft's Windows Media Creation Tool to create an installation USB.  You can also create a directory on installation USB--like C:\DRIVERS\ or whatnot--and store the extracted device drivers there in case you need them while or after installing Windows. Once the Mini PC arrives, and you have your Windows installation USB available, you can proceed with wiping the PC and doing the clean install.  Here's how you do that, step-by-step: Check the computer and make sure you know how to boot it from a USB flash drive (may be a specific key you have to press when the computer is powered on, or a change to the BIOS (UEFI) firmware settings.  The PC may tell you what key combination you need to press to boot from another drive, or the manual for the PC may it. Plug the USB flash drive into the computer and power it up using the means to have it boot from the Windows install USB. Once the computer finishes booting, it should be at a Windows installation screen. Do not agree to any prompts, copyright licenses, or click on any buttons. Press the Shift + F10 keys together to open a Command Prompt. Run DISKPART to start the command-line disk partitioning utility. The command line prompt will change to DISKPART>. At the DISKPART> prompt, type LIST DISK to get the numbers of all drives installed in the system. Make a note of what number is assigned to what drive (if the Mini PC has more than one drive).  At the DISKPART> prompt, type SEL DISK n  where n is the number of the drive containing Windows. At the DISKPART> prompt, type CLEAN and this will erase the GPT/MBR code from the beginning of the drive. *WARNING:* After performing the clean operation, the drive now be blank/erased, and everything on it will be gone (all files, etc.).  You can exit DiskPart and just continue with the Windows installation as you normally would.  If needed, you can install the device drivers you put on the Windows install media to get your network connection up and running, and from there run Windows Update to get the operating system and device drivers up to date Regards, Aryeh Goretsky
  • Recent Achievements

    • Week One Done
      cac1lll earned a badge
      Week One Done
    • One Month Later
      Falcon.ai earned a badge
      One Month Later
    • Week One Done
      Falcon.ai earned a badge
      Week One Done
    • Dedicated
      EYEREX earned a badge
      Dedicated
    • First Post
      Electronic Person earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      627
    2. 2
      ATLien_0
      238
    3. 3
      Xenon
      166
    4. 4
      neufuse
      143
    5. 5
      +FloatingFatMan
      123
  • Tell a friend

    Love Neowin? Tell a friend!