Hotplug CPU

Hotplug CPU

In case you are wondering where you can enable or disable a CPU dynamically in Linux, then the answer is yes. If the BIOS or the Machine provides with a Hotplug CPU then you can enable or disable the CPU in Linux.

The Linux kernel is capable to deal with such functionality. This ensures that you do not have to reboot the machine in order to enable or disable a CPU.

There are instances where Hotplug CPU is used for replacing the failed one, without having the need to stop the current operations on the system.

Another example where you will need a Hotplug CPU, is on larger systems which is shared by different processes. In such case, as the demand for CPU fluctuates over a period of time, depending on the resources required by various processes.

First, you need to list the current CPUs present in the system.

You can use the following command to do that.

[[email protected] ~]# ls -lah /sys/devices/system/cpu/

The output should look something similar (depending on the number of CPU your system has).

total 0
drwxr-xr-x 20 root root    0 Dec 11 15:50 .
drwxr-xr-x  7 root root    0 Dec 11 15:50 ..
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu0
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu1
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu10
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu11
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu12
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu13
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu14
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu15
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu2
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu3
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu4
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu5
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu6
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu7
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu8
drwxr-xr-x  6 root root    0 Dec 11 15:50 cpu9
-rw-r--r--  1 root root 4.0K Dec 11 15:53 sched_mc_power_savings

Under each of the cpuX directory, you “may” find a file named online. If it is not there it should not be any cause of alarm.

Also, on a few Linux distros you will find a file named online under /sys/devices/system/cpu/. This file keeps the record of the current online CPU on the system. This is a file which is updated dynamically.

Do not confuse the online file mentioned above with the online file founder under /sys/devices/system/cpu/.

Hotplug CPU – Disable a CPU

In order to dynamically disable a CPU or dynamically remove a CPU, you will have to execute the following command Syntax.

[[email protected] ~]# echo 0 > /sys/devices/system/cpu/cpuX/online

So in our case we will disable cpu14.

[[email protected] ~]# echo 0 > /sys/devices/system/cpu/cpu14/online

Verify if the CPU is disabled under the /proc/cpuinfo.

[[email protected] ~]# grep processor /proc/cpuinfo

The output should look like below:

processor	: 0
processor	: 1
processor	: 2
processor	: 3
processor	: 4
processor	: 5
processor	: 6
processor	: 7
processor	: 8
processor	: 9
processor	: 10
processor	: 11
processor	: 12
processor	: 13
processor	: 15

On a few distros, where the you find the /sys/devices/system/cpu/online file, the output should look something like below:

[[email protected] ~]# cat /sys/devices/system/cpu/online

Output:

0-13,15

Hotplug CPU – Enable a CPU

Use the following syntax to dynamically enable a CPU or dynamically add a CPU.

[[email protected] ~]# echo 1 > /sys/devices/system/cpu/cpuX/online

In our example, we will now enable the cpu14 back.

[[email protected] ~]# echo 0 > /sys/devices/system/cpu/cpu14/online

Verify if the CPU is enabled under the /proc/cpuinfo.

[[email protected] ~]# grep processor /proc/cpuinfo

The output should look like below:

processor	: 0
processor	: 1
processor	: 2
processor	: 3
processor	: 4
processor	: 5
processor	: 6
processor	: 7
processor	: 8
processor	: 9
processor	: 10
processor	: 11
processor	: 12
processor	: 13
processor	: 14
processor	: 15

Verify the /sys/devices/system/cpu/online file as well (if present).

[[email protected] ~]# cat /sys/devices/system/cpu/online

Output:

0-15

Hotplug CPU – Error troubleshooting

The most common error message encountered by the users is the following:

echo: write error: Invalid argument

In case you happen to encounter the same you have to verify what you are doing.

In case you are trying to enabling or disabling a CPU and face this message, it is very much likely that the CPU in question is already enabled or disabled.

Verify the online CPU via /proc/cpuinfo or /sys/devices/system/cpu/online

Hotplug CPU

No Comments

Post a Comment

Time limit is exhausted. Please reload CAPTCHA.