10

Is it possible to disable a CPU, not a core? I want to do a test to verify if the performance could make a big difference or not.

I'm using Ubuntu 10.10.

10

Besides doing this in your BIOS grub has an option called maxcpus.

You can edit this option in when selecting your grub boot option by adding maxcpus=1 to the parameters. Random grub picture:

enter image description here

Choose 'e' and you get to a command line where you can add options.

You can also create permanent boot option in grub by making a copy of your current boot option and add maxcpus=1 to the boot parameters. You can name this 'Ubuntu, kernel 2.5.12-9-386 (1 cpu)' and have it amongst the other boot options like the picture shows.

You can verify running on 1 cpu by issuing:

cat /proc/cpuinfo | grep processor this should show something like this:

processor    : 0
processor    : 1

And the 2nd line should disappear after booting with 1 CPU.

7
  • 1
    this question would also make a very mean practical joke! :D
    – Alvar
    May 30 '11 at 15:36
  • What happens if you set maxcpus=0? :P
    – crazy2be
    May 30 '11 at 23:15
  • @Rinzwind I did exactly what you said, but the result seems weird, I got 12 processors info before adding "maxcpus=1" to the parameters when do grepping, but I only got 1 processor info after modification, it seems only one core in all 12 cores is activated. Note: My computer has two six-core CPUs. May 31 '11 at 2:56
  • @crazy2be guessing: the 1st processor is called 0 so you end up using one? :D
    – Rinzwind
    Jun 1 '11 at 12:49
  • @LeoYuan88 袁力皓 can you edit it the output of cat /proc/cpuinfo | grep processor before and after you boot with maxcpus=1?
    – Rinzwind
    Jun 1 '11 at 12:51
7

You can dynamically disable CPUs via /sys/devices/system/cpu/cpuN/online, for example to disable CPU 1, use:

echo 0 | sudo tee /sys/devices/system/cpu/cpu1/online

and to re-enable, use:

echo 1 | sudo tee /sys/devices/system/cpu/cpu1/online
1
  • 1
    This seems to disable an lcore, not a CPU. I have one of these directories for each logical core on my system.
    – sudo
    Apr 14 '17 at 22:09
1

You can always unplug the CPU from its socket. It's brute force, but you're guaranteed to get the test you want, and you don't have to worry if the kernel/BIOS/whatever switch is really doing what you hope it's doing.

My company has large installations of server farms in various locations around the world. In our lab we'll sometimes remove CPUs from sockets for just such a test.

There's an interesting variation on this test that you can do with multi-CPU NUMA systems. On those types of motherboards you can remove all of the memory DIMMs that are controlled by one physical CPU. The system will still boot just fine, and you can then run tests with your application pinned to various cores which will allow you to measure the affects of "local" or "remote" memory.

1
  • Sorry, I still don't know how to unplug the CPU from its socket, could you show me how to do the job ? May 31 '11 at 2:45
0

Would like to see the performance of a multithreaded application along with number of cores? If that is the case, you can use taskset utility. I guess that you have a NUMA machine. You can install numactl utility and by using it you can find which cores corresponding to which CPU. For example, your machine has two quad-core CPUS (chips). By using taskset utility you can make cores of one CPU as a set and allocate these to your application. Then your application uses only one CPU/Chip (four cores). Please let me know if you need more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.