We could get into situation to either disable or enable one or more CPU on a running Linux server (without reboot) and the Linux kernel does support that feature. The reason could be for improving the performance of server or for saving some computing power.
To check the list of CPUs available:
[root@hostxyz ]# cat /proc/cpuinfo
[root@hostxyz ~]# cd /sys/devices/system/cpu
[root@hostxyz cpu]# pwd
/sys/devices/system/cpu
[root@hostxyz cpu]# ls -l
total 0
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu0
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu1
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu2
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu3
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu4
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu5
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu6
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu7
-rw-r--r-- 1 root root 4096 Mar 6 00:30 sched_mc_power_savings
[root@hostxyz cpu]#
In the above /proc output, you could see the CPU5 has gone !!!!!!!!!
To check the list of CPUs available:
[root@hostxyz ]# cat /proc/cpuinfo
[root@hostxyz ~]# cd /sys/devices/system/cpu
[root@hostxyz cpu]# pwd
/sys/devices/system/cpu
[root@hostxyz cpu]# ls -l
total 0
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu0
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu1
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu2
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu3
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu4
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu5
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu6
drwxr-xr-x 4 root root 0 Mar 6 00:30 cpu7
-rw-r--r-- 1 root root 4096 Mar 6 00:30 sched_mc_power_savings
[root@hostxyz cpu]#
Suppose I want to disable the CPU no 5:
[root@hostxyz cpu]# cd cpu5
[root@hostxyz cpu5]# ls
cache crash_notes online topology
[root@hostxyz cpu5]# cat online
1
[root@hostxyz cpu5]# echo 0 > online
[root@hostxyz cpu5]# cat /proc/cpuinfo | grep -i 'Processor'
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 6
processor : 7
[root@hostxyz cpu5]#
[root@hostxyz cpu5]# cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3 CPU4 CPU6 CPU7
0: 346882565 0 0 0 0 0 0 IO-APIC-edge timer
1: 0 0 0 0 0 0 0 IO-APIC-edge i8042
8: 0 0 0 0 0 0 0 IO-APIC-edge rtc
9: 0 0 0 0 0 0 0 IO-APIC-level acpi
14: 0 0 0 0 0 0 0 IO-APIC-edge ata_piix
15: 0 0 0 0 0 0 0 IO-APIC-edge ata_piix
66: 19 0 0 0 0 0 0 IO-APIC-level ehci_hcd:usb1
74: 0 0 0 0 0 0 0 IO-APIC-level uhci_hcd:usb2
82: 49 0 0 0 0 0 0 IO-APIC-level uhci_hcd:usb3
90: 0 0 0 0 0 0 0 IO-APIC-level uhci_hcd:usb4
98: 1647 431 0 380368 0 53 0 IO-APIC-level lpfc
106: 1667 53 0 380346 0 374 0 IO-APIC-level lpfc
122: 3359627 0 0 0 0 0 0 PCI-MSI eth0
169: 4954 4701 0 404864 0 0 0 IO-APIC-level ioc0
NMI: 4505 2316 2389 2332 2882 2164 2909
LOC: 339979108 339988403 339978966 339984061 339983989 339992274 339992202
ERR: 0
MIS: 0
[root@hostxyz cpu5]#
In the above /proc output, you could see the CPU5 has gone !!!!!!!!!
[root@hostxyz cpu5]# cat online
0
Enabling the CPU 5 back:
[root@hostxyz cpu5]# echo 1 > online
[root@hostxyz cpu5]# cat /proc/cpuinfo | grep -i 'Processor'
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
processor : 5
processor : 6
processor : 7
[root@hostxyz cpu5]#
[root@hostxyz cpu5]# cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3 CPU4 CPU5 CPU6 CPU7
0: 346920869 0 0 0 0 0 0 0 IO-APIC-edge timer
1: 0 0 0 0 0 0 0 0 IO-APIC-edge i8042
8: 0 0 0 0 0 0 0 0 IO-APIC-edge rtc
9: 0 0 0 0 0 0 0 0 IO-APIC-level acpi
14: 0 0 0 0 0 0 0 0 IO-APIC-edge ata_piix
15: 0 0 0 0 0 0 0 0 IO-APIC-edge ata_piix
66: 19 0 0 0 0 0 0 0 IO-APIC-level ehci_hcd:usb1
74: 0 0 0 0 0 0 0 0 IO-APIC-level uhci_hcd:usb2
82: 49 0 0 0 0 0 0 0 IO-APIC-level uhci_hcd:usb3
90: 0 0 0 0 0 0 0 0 IO-APIC-level uhci_hcd:usb4
98: 1647 431 0 380412 0 0 53 0 IO-APIC-level lpfc
106: 1667 53 0 380390 0 0 374 0 IO-APIC-level lpfc
122: 3360061 0 0 0 0 0 0 0 PCI-MSI eth0
169: 4954 4703 0 404921 0 0 0 0 IO-APIC-level ioc0
NMI: 4505 2317 2389 2332 2883 2428 2164 2910
LOC: 340016644 340025946 340016502 340021607 340021535 339927925 340029818 340029746
ERR: 0
MIS: 0
[root@hostxyz cpu5]#
In the above /proc output, you can see that I brought back the CPU 5 back.
This is a cool article .
ReplyDeleteI am not too sure that whether this works for a Virtual Machines or not . This will work for Physical machines though..
Good point. Even I haven't tested on Virtual machines. Will get it tested for sure.
DeleteTested in VMware Virtual Machines and it works.
Delete