I want to disable 3 CPU cores and run my processor on a single core. I have used command:maxcpus=1. But after this I executed this command ls /sys/devices/system/cpu. It still shows cpu0,cpu1,cpu2,cpu3.

I also tried :echo 0 > /sys/devices/system/cpu3/online but I get the following error: no such file or directory.

  • It is unclear where you put the maxcpus=1 commmand? Did you put that string in grub.cfg as a boot option? (Please update your question instead of answering in comments). – Anthon Jul 21 '14 at 7:24
  • I am using freescale IMx6 sabreauto board on linux OS.I executed the command on a terminal emulator "gtkterm" – user3818847 Jul 21 '14 at 7:41
  • With this command echo 0 > /sys/devices/system/cpu3/online I am able to see cpu3 shutdown. Now what I want know is, should I reboot the system for the changes to effect or I can continue without rebooting – user3818847 Jul 21 '14 at 7:45
  • AFAIK you should specify maxcpus=1 as a parameter to the kernel (i.e. when you are in grub). Edit '/etc/defaults/grub' to add it to the kernel parameters, run 'update-grub' and reboot. That will make things persistent, i.e. with only one CPU on Linux startup. – Anthon Jul 21 '14 at 8:55
  • 2
    @user3818847 what distro are you using? Modifying the boot parameters (to pass maxcpus=1) varies by distro. Also the /sys path you have is simply the wrong one, the correct path is /sys/devices/system/cpu/cpu3/online. – phemmer Jul 21 '14 at 13:00

As Patrick has indicated in a comment, you got the path under /sys wrong.

echo 0 > /sys/devices/system/cpu/cpu3/online

If you want to switch all CPUs off except cpu0:

for x in /sys/devices/system/cpu/cpu[1-9]*/online; do
  echo 0 >"$x"

Typing maxcpus=1 at a shell prompt has no effect. More precisely, it sets the variable maxcpus to the value 1 in that shell, which doesn't have any other effect. You can set the number of CPUs at boot time by passing maxcpus as a kernel parameter. For that, you have to change your bootloader configuration (e.g. to change the kernel command line in U-Boot).

  • Thank you for the suggestions. It worked with the command suggested by you – user3818847 Jul 22 '14 at 9:25
  • This is at least somewhat kernel-specific. I'm running kernel 3.6.6, and there's no such files; you instead use the single /sys/devices/system/cpu/online and ./offline files to control all the cores. – Daniel Griscom May 9 '17 at 21:22
  • @Gilles - Is there a way to know how much time it takes to turn a core on and off? – Chetan Arvind Patil Feb 2 '19 at 0:42
  • @ChetanArvindPatil Time it. I think the time would be dominated by RAM access if the code involved isn't already in the L2 cache and by the time to switch the core off otherwise, but it very much depends on the CPU and OS. – Gilles 'SO- stop being evil' Feb 2 '19 at 7:07
  • 2
    @Xofo When the kernel switches off a core, that core is running kernel code, so no thread is scheduled on that particular core at that moment. After the core is off, threads are no longer scheduled on that core. I don't know what happens if a thread's affinity restricts it to a set of cores that are all off. – Gilles 'SO- stop being evil' Dec 4 '19 at 17:37

you do not necessarily turn off or disable cores.

you would use cpusets and taskset


A cpuset defines a list of CPUs and memory nodes...

The cpuset filesystem is a pseudo-filesystem interface to the kernel cpuset mechanism, which is used to control the processor placement and memory placement of processes. It is commonly mounted at /dev/cpuset.

On systems with kernels compiled with built in support for cpusets, all processes are attached to a cpuset, and cpusets are always present. If a system supports cpusets, then it will have the entry nodev cpuset in the file /proc/filesystems. By mounting the cpuset filesystem (see the EXAMPLE section below), the administrator can configure the cpusets on a system to control the processor and memory placement of processes on that system. By default, if the cpuset configuration on a system is not modified or if the cpuset filesystem is not even mounted, then the cpuset mechanism, though present, has no effect on the system's behavior.

The CPUs of a system include all the logical processing units on which a process can execute, including, if present, multiple processor cores within a package and Hyper-Threads within a processor core. Memory nodes include all distinct banks of main memory; small and SMP systems typically have just one memory node that contains all the system's main memory, while NUMA (non-uniform memory access) systems have multiple memory nodes.

In short, if you have 1 cpu having 6 cores you would configure cpusets and launch your process in a cpuset that is configured on just one core, say core #3 for example. If it was a parallel process it would all be confined to that one core such that if you launched 4 processes in a given cpuset having just one core defined, then each of the 4 processes would get 25% cpu utilization on core #3.

Building off of that, what typically happens is a cpuset is configured such that

  • in a 200+ core system for example, cpusetA is cores 0..60 wherever those might be located, cpusetB is cores 61..70; cpusetC is cores 71..80; and so on however an admin/architect chooses to configure.
  • cpusetA is allocated to certain users and/or specific software programs; cpusetB is allocated to different users/programs; and so on.
  • a user launches a job (process) which would request N cores... within a given cpuset, and now those multiple (parallel) processes are confined to that given cpuset. And for those N parallel confined to a given cpuset, each of those processes would/should make use of processor affinity or cpu affinity so those parallel processes do not thrash around on different cores within the cpuset.

also: https://linux.die.net/man/1/taskset

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