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

【KVM新概念】虚拟机CPU热拔插,第1张

背景

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, 欢迎大家试用。

  1. 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

  2. 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

  3. Connect to the qmp server using telnet
    $ telnet localhost 4444

  4. 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": {}}

  5. 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": {}}

  6. 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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/2085115.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-07-22
下一篇 2022-07-22

发表评论

登录后才能评论

评论列表(0条)

保存