QEMU 的 CPU 配置

根据前面描述 CPU 的基本知识, 可以知道 CPU 有物理 CPU, 多核 CPU, 超线程 CPU 之分.

事实上, QEMU 支持所有这些配置, 下面一一举例来说明如何模拟这些 CPU.

基本的 CPU 模拟

下面的指令模拟了一个具有 1 个物理 CPU, 两个逻辑 CPU 的系统

$ qemu -enable-kvm -m 1024 ArchLinux.img -smp 2,sockets=1

在 guest 上看看 cpuinfo 的信息:

$ cat /proc/cpuinfo
processor   : 0 physical id : 0 siblings    : 2 core id : 0 cpu cores   : 2  
processor   : 1 physical id : 0 siblings    : 2 core id : 1 cpu cores   : 2

可以看到两个逻辑 CPU 是双核的, 没有使用超线程技术.



指定核心数

模拟一个具有 1 个物理 CPU(双核), 四个逻辑 CPU 的系统. 此时为了满足双核 四线程的概念, 得启用超线程技术, 如下

$ qemu -enable-kvm -m 1024 ArchLinux.img -smp 4,sockets=1,cores=2
$ cat /proc/cpuinfo
processor   : 0 physical id : 0 siblings    : 4 core id : 0 cpu cores   : 2  
processor   : 1 physical id : 0 siblings    : 4 core id : 0 cpu cores   : 2  
processor   : 2 physical id : 0 siblings    : 4 core id : 1 cpu cores   : 2  
processor   : 3 physical id : 0 siblings    : 4 core id : 1 cpu cores   : 2


指定 thread 数

模拟一个具有 2 个物理 CPU, 四个逻辑 CPU 的系统, 启用超线程技术, 每个核心两个 线程. 不难算出, 此时每个 CPU 都是单核的(4 = 2*2*1).

$ qemu -enable-kvm -m 1024 ArchLinux.img -smp 4,sockets=2,threads=2
$ cat /proc/cpuinfo
processor   : 0 physical id : 0 siblings    : 2 core id : 0 cpu cores   : 1  
processor   : 1 physical id : 0 siblings    : 2 core id : 0 cpu cores   : 1  
processor   : 2 physical id : 1 siblings    : 2 core id : 0 cpu cores   : 1  
processor   : 3 physical id : 1 siblings    : 2 core id : 0 cpu cores   : 1


其它

事实上, QEMU 还有更强大的 CPU 的配置, 比如配置 CPU 指令级, 配置 NUMA, 等等, 这里不一一列举.


http://blog.chinaunix.net/uid-26000137-id-3957724.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值