zoukankan      html  css  js  c++  java
  • 【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, 欢迎大家试用。

    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
  • 相关阅读:
    构建之法阅读笔记02
    4.7-4.13 第八周总结
    构建之法阅读笔记01
    顶会热词统计
    结对作业-四则运算升级版
    3.31-4.5 第七周总结
    大道至简阅读笔记03
    3.23-3.30 第六周总结
    第7周总结
    人月神话阅读笔记之三
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3002724.html
Copyright © 2011-2022 走看看