【KVM新概念】-虚拟机CPU热拔插


【KVM新概念】-虚拟机CPU热拔插
 
背景
CPU和内存热拔插其实很早被目前主流的操作系统支持了,微软从Windows Server 2008开始支持,Linux从3.2.0的内核开始支持。
 
状态
Qemu也是很早就规划了CPU热拔插特性,但是一直没有合入主干版本,因为实现中相关的bug和限制很多。最新的cpu热拔插分支是:https://github.com/imammedo/qemu/tree/cpu_add.v2,目前仅仅实现了vcpu热插,还不能支持热拔。我仅仅在Fedora 18的客户机中验证了CPU hot-plug.
 
步骤
我为Fedora 18专门优化qemu-kvm, 主要是将qemu就IA 64, KVM和Linux做优化,目的是提高qemu-kvm的稳定性和性能,git仓库是https://github.com/luohao-brian/qemu-kvm, 欢迎大家试用。
 
Checkout branch qemu.dev.cpu_add and build qemu-kvm rpm packages;
$ git clone https://github.com/luohao-brian/qemu-kvm
$ git checkout -b cpu_add remotes/origin/qemu.dev.cpu_add
$ cp qemu-kvm.spec ~/rpmbuild/SPECS/
$ rpmbuild -ba ~/rpmbuild/SPECS/qemu-kvm.spec
$ rpm -Uvh qemu-common-1.4.0-10000.x86_64.rpm qemu-kvm-1.4.0-10000.x86_64.rpm qemu-img-1.4.0-10000.x86_64.rpm
Launch a guest which supports cpu hotplug like F18 or Win 2008 with a qemu qmp server:
$ qemu-kvm -cpu host -enable-kvm -m 1024 -smp 2,maxcpus=4 -drive file=/root/f18-live.iso -qmp tcp:localhost:4444,server
 
Connect to the qmp server using telnet
$ telnet localhost 4444
 
Issue the json command as follows to check qmp capabilities, otherwise the following cpu-add command does not work.
INPUT: { "execute": "qmp_capabilities" }
OUTPUT: {"return": {}}
 
Issue the json commands to add vcpus to the guest:
INPUT: { "execute": "cpu-add", "arguments": { "id": 2} }
OUTPUT: {"return": {}}
INPUT: { "execute": "cpu-add", "arguments": { "id": 3} }
OUTPUT: {"return": {}}
 
Go check the guest, and if it is a linux, you will see 2 cpus have been made available under /sys/devices/system/cpu/. To activate either of them, issue a command like:
$ echo 1 > /sys/devices/system/cpu/cpu2/online
 

相关内容

    暂无相关文章