Change the boot arguments to use ony n number of CPU cores instead of m cores which are actually present, PROVIDED n
a) Add "maxcpus=n" in the bootargs during boot time:
linux /boot/vmlinuz-2.6.31-21-generic root=UUID=2ebbae04-b641-44e9-935f-8964159d79cb ro quiet splash maxcpus=nThis will not be persistent across subsequent boots.
b) To make it permanent, modify/edit /etc/default/grub and add "maxcpus=n" in the following line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash maxcpus=n"
Method 2: "Enable/Disable a CPU core on the fly"
On a Linux machine you can get the CPU information from /proc/cpuinfo file. On a dual core machine, you will get the output like this:
$ cat /proc/cpuinfoTo disable a core run the following command on a Ubuntu machine:
processor : 0
vendor_id : GenuineIntel
........
.....
processor : 1
vendor_id : GenuineIntel
........
.....
$ sudo sh -c "echo 'n' > /sys/devices/system/cpu/cpu1/online"Test if the core is disabled or not, check the /proc/cpuinfo file.
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
........
.....
Now which method to choose from?
Method 1. is recommended since maxcpus=n should optimize some locks and instructions.
Choose Method 2. if you can't afford to restart your machine.
Happy Hacking!!
P.S. These instructions are only tested on a Dual core machine so I have no clue how they will behave on a multi-core(>2) environment.
References:
http://en.kioskea.net/faq/616-multicore-cpu-how-to-disable-a-core#procedure-when-using-linux
http://linux.derkeiler.com/Mailing-Lists/Kernel/2008-03/msg09472.html
Tested on eight core Intel(R) Core(TM) i7 CPU Q 740 @ 1.73GHz running the 2.6.32-220.4.1.el6.x86_64 kernel. Needed to modify the command to echo '0'.
ReplyDelete$ sudo sh -c "echo '0' > /sys/devices/system/cpu/cpu6/online"
It works on Debian 6, on an HP Mini netbook, with an Intel Atom 450 processor (dual). 2012-06-03
ReplyDelete$ sudo sh -c "echo '0' > /sys/devices/system/cpu/cpu6/online"
Tested on Intel(R) Core(TM) i7-3610QM CPU. It works.
ReplyDelete# for i in /sys/devices/system/cpu/cpu{1,2,3,4,5,6,7}/online ; do echo 0 > $i ; done
Disable all CPU cores except the first one which does not honor online attribute:
ReplyDeletefor i in /sys/devices/system/cpu/cpu*/online; do echo 0 > $i; done
Thank you ^_^
ReplyDeleteThis even works on my Tegra2 smartphone (rooted). Thank you!
ReplyDeleteI also use 'chcpu' from util-linux. chcpu -d 1
ReplyDelete