Tuesday, March 18, 2014

Hot Plug a CPU in Linux

There are cases where application needs more performance during a period of time. In those times it is always good if we have an option to add additional Processing System with out a System Reboot. In this article we will see how we can add a additional CPU to the existing ones with out a System reboot.

Some times applications include Instant Capacity on Demand where extra CPUs are present in a system but aren't activated. This is useful for customers that predict growth and therefore the need for more computing power but do not have at the time of purchase the means to afford.

Check How many CPU are currently UP and running,

[root@vx111a cpu]# grep "processor" /proc/cpuinfo
processor : 0
processor : 1
processor : 2
processor : 3

We can see that we have 0-3 CPU up and running. So now if we want to make a CPU 3 to disable like,

[root@vx111a ~]# cd /sys/devices/system/cpu

[root@vx111a cpu]# ll
total 0
drwxr-xr-x. 8 root root    0 Mar 11 17:56 cpu0
drwxr-xr-x. 8 root root    0 Mar 11 17:56 cpu1
drwxr-xr-x. 8 root root    0 Mar 11 17:56 cpu2
drwxr-xr-x. 8 root root    0 Mar 11 17:56 cpu3
drwxr-xr-x. 3 root root    0 Mar 11 18:00 cpufreq
drwxr-xr-x. 2 root root    0 Mar 11 18:00 cpuidle
-r--r--r--. 1 root root 4096 Mar 11 18:00 kernel_max
-r--r--r--. 1 root root 4096 Mar 11 18:00 offline
-r--r--r--. 1 root root 4096 Mar 11 18:00 online
-r--r--r--. 1 root root 4096 Mar 11 18:00 possible
-r--r--r--. 1 root root 4096 Mar 11 18:00 present
-rw-r--r--. 1 root root 4096 Mar 11 17:56 sched_smt_power_savings

Now when we see the we can see directories cpu0 – cpu3. In order to disable a CPU (consider cpu3) .

[root@vx111a cpu]# cd  cpu3/
[root@vx111a cpu3]# ll
total 0
drwxr-xr-x. 6 root root    0 Mar 11 17:56 cache
drwxr-xr-x. 3 root root    0 Mar 11 17:56 cpufreq
drwxr-xr-x. 6 root root    0 Mar 11 18:08 cpuidle
-r--------. 1 root root 4096 Mar 11 18:08 crash_notes
drwxr-xr-x. 2 root root    0 Mar 11 18:08 microcode
-rw-r--r--. 1 root root 4096 Mar 11 17:56 online
drwxr-xr-x. 2 root root    0 Mar 11 18:08 thermal_throttle
drwxr-xr-x. 2 root root    0 Mar 11 17:56 topology

We can see a file called online , when we check the value we see
[root@vx111a cpu3]# cat online
1

Now send ‘0’ to the same file

[root@vx111a cpu3]# echo 0 > ./online

Now if we check the CPU available now again. We see
[root@vx111a cpu]# grep "processor" /proc/cpuinfo
processor : 0
processor : 1
processor : 2

The last cpu 3 is disabled. We don’t need a reboot. We just need to send the value of the online file that exists in every cpu directory.


More to Come, Happy learning
J