Friday, November 20, 2009

CPU Hotswapping and how to disable processors

Here's something awesome I found mostly by accident:
In recent kernels the support for hotswapping CPUs works on x86/amd64 architectures.

I stumbled over it in the 2.6.32 menuconfig and couldn't wonder if it actually works.

So I had a look and found this gem:
# cat /proc/interrupts | grep CPU
            CPU0       CPU1       CPU2       CPU3

Very boring, 4 processors.
# echo 0 > /sys/devices/system/cpu/cpu3/online

And we just knocked out one!

We see that in dmesg:
kvm: disabling virtualization on CPU3
CPU 3 is now offline
Hmm, are you thinking what I'm thinking? 
kvm: disabling virtualization on CPU2
CPU 2 is now offline                                      
kvm: disabling virtualization on CPU1
CPU 1 is now offline
SMP alternatives: switching to UP code
Wheeee. I just castrated it to a single core! I actually didn't check if the kernel lets me take CPU0 offline. That would be hilarious. Anyway ... 
# echo 0 > /sys/devices/system/cpu/cpu1/online
And we just gained a CPU: 
SMP alternatives: switching to SMP code
Booting processor 1 APIC 0x1 ip 0x6000
Initializing CPU#1
Calibrating delay using timer specific routine.. 5200.20 BogoMIPS (lpj=10400418)
CPU: L1 I Cache: 64K (64 bytes/line), D cache 64K (64 bytes/line)
CPU: L2 Cache: 512K (64 bytes/line)
CPU 1/0x1 -> Node 0
CPU: Physical Processor ID: 0
CPU: Processor Core ID: 1
CPU1: AMD Phenom(tm) 9950 Quad-Core Processor stepping 03
checking TSC synchronization [CPU#0 -> CPU#1]: passed.
kvm: enabling virtualization on CPU1
This is seriously wicked. Now I just need to figure out how to bolt that onto powermanagement so that the machine knocks out cores when idle and powersaves. Linux never gets boring ...

No comments:

Post a Comment