Kernel 3.1
I built the 64bit kernel 3.1 for my Kubuntu 11.10 desktop optimized for i7. Here is the screenshot of the kernel in action
Feel of the new kernel 3.1 seems to be very exciting. Kubuntu booted to login screen within 10 seconds. (With default kernel it took more than 20 seconds to boot Kubuntu 11.10 unlike ubuntu 11.10 which was faster to boot)
Here is how I built the kernel 3.1 Ubuntu way (in short 7 steps)
In brief
- Install build dependencies
- Download kernel source and ubuntu patches
- Extract and apply ubuntu patches
- Create a new flavour and tweak kernel config
- Modify Makefile for optimization
- Build
- Reboot and Enjoy
In detail
Install build dependencies
Open terminal/konsole and execute the following apt-get commands if you don't have essential build packages necessary for building kernel from source in Ubuntu
#Install Build essential to build kernel
sudo apt-get install fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge libncurses5 binutils-dev libelf-dev libdw-dev libnewt-dev libncurses5-dev
sudo apt-get --no-install-recommends install asciidoc xmlto
Download kernel source and ubuntu patches
Download the source of newly released linux kernel 3.1. The following wget -c makes it simple to download from commandline
#Download kernel source
wget -c http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.1.tar.bz2
Here is how to download the 3.1 ubuntu patches
#Download ubuntu patches
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.1-oneiric/0001-base-packaging.patch
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.1-oneiric/0002-debian-changelog.patch
wget -c http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.1-oneiric/0003-default-configs.patch
Extract and apply ubuntu patches
Extract downloaded kernel source and apply patches. Here I used tar to unzip the bzip tarball and patch to apply the patch
#Extract kernel source
tar xjvf linux-3.1.tar.bz2
#Create a soft link
ln -s linux-3.1 linux
#Enter linux directory
cd linux
#Apply the patches
patch -p1 < ../0001-base-packaging.patch
patch -p1 < ../0002-debian-changelog.patch
patch -p1 < ../0003-default-configs.patch
Create a new flavour and tweak kernel config
Before creating a new flavor, give execute permissions to debian build scripts for building the kernel properly
#make debian/rules as executable
chmod -Rv +x debian/rules
#make debian/scripts directory executable
chmod -Rv +x debian/scripts/
To create a new flavour, just clone from generic flavor, here is how
#create i7 flavor
cp debian.master/config/amd64/config.flavour.generic debian.master/config/amd64/config.flavour.i7
Do the kernel configuration, I selected processor type as CORE2 and kernel frequency to 1000HZ (just give y only to the newly created flavor when executing editconfigs)
#clean
fakeroot debian/rules clean
fakeroot debian/rules updateconfigs
#give y only to i7 flavor, leave the rest untouched
fakeroot debian/rules editconfigs
Copy the abi related files from existing generic flavor and tweak to reflect the newly created flavor
#copy the abi entries for i7 flavor and add i7 entries in vars and amd64.mk
cp debian.master/abi/3.0.0-12.20/amd64/generic debian.master/abi/3.0.0-12.20/amd64/i7
cp debian.master/abi/3.0.0-12.20/amd64/generic.modules debian.master/abi/3.0.0-12.20/amd64/i7.modules
sed -i s/getall\ amd64\ generic\ server\ virtual/getall\ amd64\ generic\ server\ virtual\ i7/g debian.master/etc/getabis
sed -i s/\=\ generic\ server\ virtual/\=\ generic\ server\ virtual\ i7/g debian.master/rules.d/amd64.mk
cp debian.master/control.d/vars.generic debian.master/control.d/vars.i7
sed -i s/\"Generic\"/\"core\ i7\"/g debian.master/control.d/vars.i7
Modify Makefile for optimization
This is the place where we apply the optimizations. Ubuntu 11.10 comes with gcc 4.6 which has added new architectue corei7
#edit arch/x86/Makefile and arch/x86/Makefile_32.cpu if you want to tweak the march and mtune params of gcc
vi Makefile
vi arch/x86/Makefile
vi arch/x86/Makefile_32.cpu
In the main makefile, I changed HOSTCC and HOSTCXX to look as follows
HOSTCC = gcc -march=corei7 -mtune=corei7 -pipe
HOSTCXX = g++ -march=corei7 -mtune=corei7 -pipe
In other makefiles, replace lowercased core2 with corei7 (simple isn't it?)
Build
Do a clean build
#clean and build
fakeroot debian/rules clean
The following builds the common header and source debs
skipabi=true skipmodule=true fakeroot debian/rules binary-indep
The following builds the newly created flavor. Note I added no_dumpfile=yes as it was not building the dumpfile.
time skipabi=true skipmodule=true no_dumpfile=yes fakeroot debian/rules binary-i7
Wait for sometime (depends on speed of your processor). No need to tweak concurrency settings, which are taken care automatically. Install the newly built debs as follows after going one directory above
cd ..
sudo dpkg -i linux-headers-3.1.0-030100_3.1.0-030100.201110241006_all.deb linux-headers-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb linux-image-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb
Reboot and Enjoy
To test the newly built kernel, reboot and select the newly installed kernel from grub. If the newly installed kernel does not boot for some reason, do not panic, select the old ubuntu kernel and boot. (Grub2 does not wait beyond 3 seconds if there is no other OS present and very annoying, press escape within first 3 seconds to display the grub menu if it does not display) Follow this to know more about how to customize grub2 http://maketecheasier.com/mastering-grub-2-the-easy-way/2009/11/19
or
https://wiki.ubuntu.com/Grub2
or
https://wiki.ubuntu.com/Grub2
sudo reboot
Download links
I have uploaded the kernel 3.1 debs which I built and use. If you don't want to build yourself you can try these.
Here are the SHA256SUM checksum
8d1c58d614056b3cb2e05562d1108cd0a25aa7900ea02f602e8da7a6ead00c83 buildscript.sh
3cbd100b33734330f6b4da7a25cce5c0a45db9cee16bf609c554cbc9cd7b3f98 linux-headers-3.1.0-030100_3.1.0-030100.201110241006_all.deb
6ad9338017182590ef791ed12bbcaf0857090fb6028ec90b6d81ea04c38948f5 linux-headers-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb
e1d62da1add7bfc0b9976fac7d8be32512da8eb09c5b41a6ab66b8c43d12b52e linux-image-3.1.0-030100-i7_3.1.0-030100.201110241006_amd64.deb
Here are the download links
And of course don't forget to run "sudo update-grub" before rebooting. It will save you some valuable time I just found out ;)
ReplyDeleteWorked perfectly! Thanks.
ReplyDeleteGreat blog! I have an i3-380m processor running linux mint debian, are there any changes that I need to perform to the above to install the 3.1 custom kernel. At present I use the 2.6.32-5 kernel it's stable but slow.
ReplyDeleteYou need to call sudo update-grub after calling sudo update-initramfs
ReplyDeleteyou could give this kernel a try, this maybe fast, but debian's kernel, well there is no match for anything coming out from debian they are solid, strong and fast
ReplyDeleteMain advantage I see in this kernel 3.1 (or 2.6.33 and above) over 2.6.32 is TRIM is enabled for SSD. Autogroup scheduling is another big feature. No big Kernel lock in latest kernels. Lots and lots of such advantages.
ReplyDeleteThanks for the tech advice, i'll give the 3.1 custom a try!
ReplyDeleteHaving hard time follow how u do kernel build.
ReplyDeleteJust wishing/wanting simple step by step process how it done .
using Debian 6.03 amd64 with Core2dual cpu
can show how compile also kde 4.7.3 for i7?
ReplyDeleteI will give it a try though i doesnt seem that simple...
ReplyDeletethanks for kernel linux install guides in my ubuntu.
ReplyDeleteCan you please give some instructions on how to apply these optimizations on an official debian kernel ? I'm using instructions found on the debian wiki to recompile the kernel : http://wiki.debian.org/HowToRebuildAnOfficialDebianKernelPackage
ReplyDeleteThank you
Ok, I will check the wiki, need some time to install debian directly or inside virtualbox
ReplyDeleteInstalled Debian Squeeze 6.0.4, using live usb image,:)
ReplyDeleteNow need to download all build essentials before proceeding to build kernel ... will update soon
I noticed that if I compile the kernel the Core i7 frequency don't go to it's minimum while idle that's 800MHz. it stays, even idle, at 2.2GHz and with TurboBoost enabled, so it will make the dynamic overclock, but it wont underclock
ReplyDeleteStock kernel underclocks normally, while the compiled even with untouched configs not. I used i7z to check frequencies and PowerTOP V2.0 and proved the underclock problem. Forgot to say it on the previous post.
DeleteWhat I detected is this. I have two different readings for the same processor but one comes from cpuinfo_cur_freq and the other one comes from scaling_cur_freq as seen below:
ReplyDeletesudo cat scaling_cur_freq; sudo cat cpuinfo_cur_freq
800000
1800000
What's the true reading? Why with stock kernel it don't happen the frequencies match!
Can you check acpi_cpufreq and cpufreq_ondemand are modprobed
ReplyDeleteEven on stock, lsmod doesn't show the acpi_cpufreq and cpufreq_ondemand in the list. So I'm not sure how to check it.
DeleteIs it what you asked for?
Deletecat scaling_driver; cat scaling_governor
acpi-cpufreq
ondemand
cat time_in_state
Delete2201000 57624
2200000 2875
2000000 2297
1900000 631
1800000 620
1700000 709
1600000 659
1500000 789
1400000 793
1300000 822
1200000 801
1100000 977
1000000 1142
900000 705
800000 842189
With stock kernel, just for comparison, as you can see it's more logical and the readings match, even the one that shows the time_in_state.
ReplyDeletesudo cat scaling_cur_freq; sudo cat cpuinfo_cur_freq
800000
800000
cat scaling_driver; cat scaling_governor
acpi-cpufreq
ondemand
cat time_in_state
2201000 22259
2200000 50
2000000 28
1900000 57
1800000 42
1700000 53
1600000 55
1500000 112
1400000 241
1300000 280
1200000 355
1100000 296
1000000 403
900000 1642
800000 145615
I am compiling Kernel 3.3.6 in Ubuntu 12.04, will install and test this ...
ReplyDeleteFYI /proc/cpuinfo
ReplyDeleteprocessor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Core(TM) i7-2670QM CPU @ 2.20GHz
stepping : 7
microcode : 0x23
cpu MHz : 800.000
cache size : 6144 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid
bogomips : 4390.25
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
I guess I found out the reason for this difference between stock kernel and compiled kernel.
ReplyDeleteThough I assumed ubuntu patches for the version of kernel compiled will have all the options of stock kernel, and I am sure it is wrong
A stock kernel has more sane and tested config options whereas though ubuntu patches are applied for consecutive kernel may not have!!
did a diff of ubuntu patched 3.3.6 and stock 3.2.0.24
diff /boot/config-3.3.6-030306-i7 /boot/config-3.2.0-24-generic
there are lots of differences, guess we should copy stock kernel config and start from there...
this should be better if we use base config as LTS kernel config!!
This comment has been removed by the author.
DeleteBut did you check the same difference in reported frequencies from the scaling governor and from the processor in your computer too? Or your compiled kernel matched the reported speeds?
DeleteDelete
will check now and update
Deletein stock, it is like this
sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ; sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
1596000
1596000
sankaran@sankaran-desktop:~$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ; sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
Delete[sudo] password for sankaran:
2661000
2661000
sankaran@sankaran-desktop:~$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ; sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
1596000
1596000
sankaran@sankaran-desktop:~$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ; sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
2661000
1596000
sankaran@sankaran-desktop:~$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ; sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
1596000
1596000
sankaran@sankaran-desktop:~$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ; sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
1596000
1596000
sankaran@sankaran-desktop:~$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ; sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
1596000
1596000
sankaran@sankaran-desktop:~$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ; sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
1596000
1596000
sankaran@sankaran-desktop:~$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ; sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
1596000
1596000
sankaran@sankaran-desktop:~$ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ; sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
1596000
1596000
sankaran@sankaran-desktop:~$
The above is with i7 optimized 3.3.6 kernel
Deleteuname -a
Linux sankaran-desktop 3.3.6-030306-i7 #201205121335 SMP Wed May 16 22:08:56 IST 2012 x86_64 x86_64 x86_64 GNU/Linux
I see background image is rendered very very crisp and color representation is superb with i7 optimized kernel, maybe it is my placebo effect
DeleteI wrote a script to print all 8 cpu differences,
Deletefor i in 0 1 2 3 4 5 6 7; do echo "CPU $i"; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_cur_freq; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/cpuinfo_cur_freq; echo "*** *** ***"; done
output is
-----------------------------
CPU 0
1596000
1596000
*** *** ***
CPU 1
1596000
1596000
*** *** ***
CPU 2
1596000
1596000
*** *** ***
CPU 3
1596000
1596000
*** *** ***
CPU 4
1596000
1596000
*** *** ***
CPU 5
1596000
1596000
*** *** ***
CPU 6
1596000
1596000
*** *** ***
CPU 7
1596000
2661000
*** *** ***
some more iterations ...
Deletesankaran@sankaran-desktop:~$ for i in 0 1 2 3 4 5 6 7; do echo "CPU $i"; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_cur_freq; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/cpuinfo_cur_freq; echo "*** *** ***"; done
CPU 0
1596000
1596000
*** *** ***
CPU 1
1596000
1596000
*** *** ***
CPU 2
1596000
2661000
*** *** ***
CPU 3
2661000
1596000
*** *** ***
CPU 4
1596000
2661000
*** *** ***
CPU 5
2661000
2661000
*** *** ***
CPU 6
1596000
2661000
*** *** ***
CPU 7
2661000
1596000
*** *** ***
sankaran@sankaran-desktop:~$ for i in 0 1 2 3 4 5 6 7; do echo "CPU $i"; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_cur_freq; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/cpuinfo_cur_freq; echo "*** *** ***"; done
CPU 0
1596000
1596000
*** *** ***
CPU 1
1596000
1596000
*** *** ***
CPU 2
1596000
1596000
*** *** ***
CPU 3
2661000
1596000
*** *** ***
CPU 4
1596000
1596000
*** *** ***
CPU 5
1596000
2661000
*** *** ***
CPU 6
1596000
1596000
*** *** ***
CPU 7
1596000
1596000
*** *** ***
sankaran@sankaran-desktop:~$ for i in 0 1 2 3 4 5 6 7; do echo "CPU $i"; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_cur_freq; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/cpuinfo_cur_freq; echo "*** *** ***"; done
CPU 0
1596000
1596000
*** *** ***
CPU 1
1596000
1596000
*** *** ***
CPU 2
1596000
1596000
*** *** ***
CPU 3
1596000
1596000
*** *** ***
CPU 4
1596000
1596000
*** *** ***
CPU 5
1596000
2661000
*** *** ***
CPU 6
1596000
1596000
*** *** ***
CPU 7
1596000
1596000
*** *** ***
sankaran@sankaran-desktop:~$
know what, the reading has human error, between one print and another print, frequency of cpu would have hopped ... so there is a difference
DeleteTill then use LTS kernel, that should be the best kernel next to EL6 kernel
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI made three iteractions of your script. It only asked me about new options that appeared from 3.2.0 kernel to 3.3.6. I'm using config-3.2.0-24-generic original from pricise to compile the 3.3.6 kernel, but I defaulted all of the new options and the difference still appearing.
ReplyDeleteleandro@leandro-Dell-L502X: for i in 0 1 2 3 4 5 6 7; do echo "CPU $i"; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_cur_freq; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/cpuinfo_cur_freq; echo "*** *** ***"; done
CPU 0
800000
1800000
*** *** ***
CPU 1
2201000
2201000
*** *** ***
CPU 2
800000
1800000
*** *** ***
CPU 3
800000
2201000
*** *** ***
CPU 4
800000
1800000
*** *** ***
CPU 5
800000
1800000
*** *** ***
CPU 6
800000
1800000
*** *** ***
CPU 7
2201000
2201000
*** *** ***
leandro@leandro-Dell-L502X:/sys/devices/system/cpu$ for i in 0 1 2 3 4 5 6 7; do echo "CPU $i"; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_cur_freq; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/cpuinfo_cur_freq; echo "*** *** ***"; done
CPU 0
2201000
2201000
*** *** ***
CPU 1
800000
1800000
*** *** ***
CPU 2
2201000
2201000
*** *** ***
CPU 3
2201000
1800000
*** *** ***
CPU 4
800000
1800000
*** *** ***
CPU 5
2201000
2201000
*** *** ***
CPU 6
800000
2201000
*** *** ***
CPU 7
800000
2201000
*** *** ***
leandro@leandro-Dell-L502X:/sys/devices/system/cpu$ for i in 0 1 2 3 4 5 6 7; do echo "CPU $i"; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_cur_freq; sudo cat /sys/devices/system/cpu/cpu$i/cpufreq/cpuinfo_cur_freq; echo "*** *** ***"; done
CPU 0
800000
1800000
*** *** ***
CPU 1
2201000
1800000
*** *** ***
CPU 2
800000
2201000
*** *** ***
CPU 3
800000
1800000
*** *** ***
CPU 4
800000
1800000
*** *** ***
CPU 5
2201000
1800000
*** *** ***
CPU 6
800000
1800000
*** *** ***
CPU 7
800000
1800000
*** *** ***
Difference is prone to come, as even a millisecond delay is more than enough for CPU to jump from one frequency to another. There should be more than 10 ms of delay between printing cpuinfo_cur_freq and scaling_cur_freq at the least, so the only way you can confirm is change the governor of cpu to userspace, set to a fixed frequency and see if it is changing
ReplyDeletei made what you told, I set to 800MHz, the minimun for my CPU. Even setting manually, it doesn't go below 1.8GHz. If I set to the maximum frequency, the TurboBoost, one it goes normally to 2.9GHz and every other frequency I set it will obey but the ones below 1.8GHz.
DeleteThis comment has been removed by the author.
DeleteSomebody on OpenSUSE forum that had the same problem gave me this tip and it simply worked, now the processor scale down to 800MHz
Deleteadd the kernel boot options: i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1 pcie_aspm=force
Hi there!
ReplyDeleteI've been following this blog for a long time, because I have a core i7-Q720 and I run Ubuntu 13.04, and I thank you very much for your efforts to make everything reader-friendly in a tutorial-like manner.
Yesterday, I came upon a huge news for me: AMD has released (march this year, though) a huge amount of patches concerning power management and hardware acceleration. But these won't be implemented before kernel 3.11, which is already the latest stable kernel out there. I was wondering if these patches had already been implemented or they have yet to be implemented manually.
I'm sorry if I am asking too much, but would it be possible for you to compile this for me or give the directions for me to compile it myself?
Thank you in advance,
Pedro Lacerda
I am using Kernel 3.10, I will compile 3.11 kernel and upload it
DeleteIt is not a problem, had been stuck for long due to graphics drivers issue, I know how it feels ...
I built the kernel 3.11 but have not tested it (have not yet rebooted)
DeleteI have created a blog of the same with download links, which you can test
http://duopetalflower.blogspot.in/2013/09/custom-64bit-kernel-311-optimized-for-i7.html