首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > 云计算 >

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

2013-04-07 
【KVM新概念】 -虚拟机CPU热拔插背景CPU和内存热拔插其实很早被目前主流的操作系统支持了,微软从Windows Ser

【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

结语cpu hotplug的邮件列表,请参考:http://lists.gnu.org/archive/html/qemu-devel/2013-04/msg01156.html有任何关于我qemu-kvm的问题,欢迎在我博客上留言,或者将问题直接报告在github issue: https://github.com/luohao-brian/qemu-kvm/issues

热点排行