QEMU 的 CPU 配置

转载:

http://mathslinux.org/?p=277

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

 

CPU 基本知识

以下是 CPU 中比较容易混淆的概念:

socket

可以理解为主板上的一个插座, 用来连接物理 CPU 芯片到主板上, 简单讲, 有多少个 socket 就有多少个物理 CPU.

core

core 的概念涉及到 多核心技术 是将多个一样的 CPU 放置于一个封装内(或直接将两个 CPU 做成一个芯片), 每个这样的 CPU 叫做一个 core, 每个 core 是一个的独立的 执行单元.

thread

thread 涉及到 超线程技术 , 简单的讲, 就是把两个逻辑内核模拟成两个物理芯片, 让单个处理器都能使用线程级并行计算.

逻辑 CPU 数量

综上, CPU 的数量不能简单的通过物理 CPU 的数量(或者 socket 的数量) 来判断, 如果用了多核技术, 则需要计算全部 core 的数量, 如果用了超线程, 则需要加上 所有 CPU 线程. 所以每一个 CPU(包括 core 或者 thread) 都叫一个逻辑 CPU.

Linux 下的 CPU 计算

在 Linux 下, kernel 抛出了一个统计了 CPU 一般信息的文件 /proc/cpuinfo, 通过这个文件, 可以知道本机的 CPU 信息, 包括厂商, CPU 型号, CPU 缓存, 核心, 超线程等等信息.

下面以一台 intel 酷睿双核为例说明:

gentoo-company tmp # 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

我省略的不必要的输出, 对以上信息做一个解释

processor
这个表示逻辑 CPU 的 ID
physical id
物理 CPU(socket) 的 ID, 具有相同 physical id 的逻辑 CPU 在同一个 CPU 封装内.
siblings
同一个 CPU 封装(socket)里的逻辑 CPU 数量, 这个数字表示在该物理 CPU 里面有多少个逻辑 CPU
core id
核心 ID, 具有相同 core id 的逻辑 CPU 在同一个 core 里, 即是使用 了超线程的逻辑 CPU
cpu cores
CPU 核心数, 在该物理 CPU 内封装的 core 数目.

通过上面的说明, 该机器有一个物理 CPU(只有一个 physical id), 用了双核技术(cpu cores 为2), 没有使用超线程技术(没有相同的 core id)

 

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, 等等, 这里不一一列举.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值