disabling cpu cores on quad core processor on linux
Solution 1
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"
done
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).
Solution 2
you do not necessarily turn off or disable cores.
you would use cpusets and taskset
http://man7.org/linux/man-pages/man7/cpuset.7.html
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
Related videos on Youtube
user3818847
Updated on September 18, 2022Comments
-
user3818847 over 1 year
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 commandls /sys/devices/system/cpu
. It still showscpu0,cpu1,cpu2,cpu3
.I also tried :
echo 0 > /sys/devices/system/cpu3/online
but I get the following error:no such file or directory
.-
Anthon almost 10 yearsIt is unclear where you put the
maxcpus=1
commmand? Did you put that string ingrub.cfg
as a boot option? (Please update your question instead of answering in comments). -
user3818847 almost 10 yearsI am using freescale IMx6 sabreauto board on linux OS.I executed the command on a terminal emulator "gtkterm"
-
user3818847 almost 10 yearsWith 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
-
Anthon almost 10 yearsAFAIK 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 almost 10 yearsIf your system uses grub, find out where it gets its parameters linux kernel parameters from
-
phemmer almost 10 years@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
.
-
-
Daniel Griscom about 7 yearsThis 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. -
Chetan Arvind Patil over 5 years@Gilles - Is there a way to know how much time it takes to turn a
core
on and off? -
Gilles 'SO- stop being evil' over 5 years@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.
-
Chetan Arvind Patil over 5 years@Gilles - I agree with timing analysis. But wondering where (kernel or user space?) and how? Any suggestions or pointers please?
-
TaborKelly almost 5 yearsGood answer, but on some kernels cpu0 can indeed be turned off. I just did it on 4.9.177 running on an Amlogic S922X (armv8).
-
Xofo over 4 yearsCan you add some details on what happens to processes running on the cores?