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

*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

v1.0 - Created :)

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.

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...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 have not even heard of that game. will take a look
    • Chasys Photo 5.41.01 by Razvan Serea Chasys Photo is a suite of image editing applications including a layer-based image editor with adjustment layers, linked layers, timeline and frame-based animation, icon editing, image stacking and comprehensive plug-in support (Chasys Photo Editor), a fast image viewer (Chasys Photo Viewer) and a fast multi-threaded image file converter (Chasys Photo Converter) , with RAW image support in all components. It supports the native file formats of several competitors including Adobe Photoshop, Affinity Photo, ArtWeaver, Corel PhotoPaint, FireAlpaca, GIMP, Krita, Paint.NET, PaintShop Pro and Pixlr, and the whole suite is designed to make effective use of multi-core processors, touch-screens and pen-input devices. Designed under the mantra of “unique, flexible and powerful”, Chasys Photo takes a radically different approach to image editing with the aim of opening up new possibilities for those who dare to be different. Chasys Photo key features: Free-style layering with blending modes Adjustment layers with multiple adjustments per layer Linked layers (a.k.a Linked Smart Objects) Composite, Image List, Frame Animation and Object Animation image modes Animation, both frame-based and object-based (timeline animation) Animation Composer engine Image Stacking for noise reduction, super-resolution, etc. Tablet/Pen-input/Stylus support with pressure control Touch-screen support with gestures including pitch-to-zoom and multi-finger panning Support for the native formats of Adobe Photoshop, Affinity Photo, ArtWeaver, Corel PhotoPaint, FireAlpaca, GIMP, Krita, Paint.NET, PaintShop Pro and Pixlr Support for common formats such as JPEG, animated PNG, animated GIF, TIFF, PICT, WebP, HEIF, DDS, JPEG-2000, JPEG-XR, JPEG-XL, AVI video, etc. Support for the OpenRaster interchange file format and rare formats such as QOI, MNG/JNG and DPX Support for older formats such as PPM/PGM/PBM, PCX/DCX, PCD, TGA, COKE, etc. Comprehensive Camera RAW file support with live adjustment Extensive plug-in support with streamlined SDKs Support for Photoshop Filter Plug-ins (.8BF) Advanced printing and scanning engines PDF document generation Icon and cursor editing, import and export, including Vista-style and Mac-OS icons Screen Capture, including Video Screen Capture with multiple triggering modes Video capture from devices (e.g. TV/Video) Supports multi-core processors, High-DPI displays and Multiple Display setups Integrated File Browser, Bluetooth OBEX and in-built utilities (Calculator, Notepad) Shell integration with thumbnails and conflict detection Unlimited Undo/Redo and Asynchronous Auto-Save, with Just-in-time memory compression to save space Fully re-editable text with advanced styling and effects (TextArt) Full alpha channel through out the workflow with Alpha protection (a.k.a. transparency protection) Multiple language support with user-editable language files and translation assistant (Chasys Photo Language Studio) Anti-aliasing and super-sampling support in tools and paths* Smart-resizing (similar to seam-carving) Best-in-class post-edit heuristics anti-aliasing engine Physical measurement specification with display size detection via EDID Uses the latest CD5 specification with animation and multi-resolution Super-fast internal graphics engine (JpDRAW2) Full UNICODE support in all components Metadata save, restore and scale to imitate vector art Configurable Guides and Grids with Snap-to-Grid Smart-dither to custom palette Asynchronous preview rendering engine Pantone equivalent palettes for PMS 100 to 814-2x Automatic color naming ... and many more! Chasys Photo 5.41.01 changelog: New Features Layered images with multiple pages (Composite/Multi-page) Additional templates to support template-centric workflow New Layer Blend Mode: Inverse Luma Mask Horizon detection in Rotate Transform Cropping option when importing video Orientation options in QR Code Generator plug-in Solved angle ambiguities (CCW versus CW) Internal Improvements Improved graphics engine (JpDRAW2™ v26.05) Improved CD5 codec (v4.10, improved ACSC compression) Improved interpolation when downsizing images Improved motion detection in Video Capture Slightly lower memory usage (RAM is getting expensive!) File Support and Bug Fixes Improved PXZ file support (placeholders, blanks) [bug-fix] Memory leak in flt_JPEG.dll Download: Chasys Photo 5.41.01 | 46.1 MB (Freeware) View: Chasys Photo Home Page | Wikipedia Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • We don't need stars for the word, just use the word "CSAM"
    • If they want to do business in the UK then they can't ignore it. thats why Imgur pulled out of the UK
  • Recent Achievements

    • Very Popular
      Captain_Eric earned a badge
      Very Popular
    • One Month Later
      amusc earned a badge
      One Month Later
    • One Month Later
      DJC50PLUS earned a badge
      One Month Later
    • Week One Done
      DJC50PLUS earned a badge
      Week One Done
    • Proficient
      Eric Biran went up a rank
      Proficient
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      PsYcHoKiLLa
      220
    3. 3
      ATLien_0
      92
    4. 4
      +Edouard
      90
    5. 5
      Steven P.
      83
  • Tell a friend

    Love Neowin? Tell a friend!