Chinaunix首页 | 论坛 | 博客
  • 博客访问: 699499
  • 博文数量: 183
  • 博客积分: 2650
  • 博客等级: 少校
  • 技术积分: 1428
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-22 17:02
文章分类
文章存档

2017年(1)

2015年(46)

2014年(4)

2013年(8)

2012年(2)

2011年(27)

2010年(35)

2009年(60)

分类: 架构设计与优化

2015-04-27 14:47:23

根据前面描述 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 指令级, 配置 , 等等, 这里不一一列举.

阅读(1103) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~