今天做演示时在dom0执行 xm vcpu-pin 0 1 1,结果总是报错 -22 Invalid argument 最后怀疑可能由于启动xen时,指定了dom0_max_vcpus dom0_vcpus_pin参数。去掉之后重启dom0,执行成功
如果不指定dom0_max_vcpus,会查看/etc/xen/xend-config.sxp,其中
# In SMP system, dom0 will use dom0-cpus # of CPUS
# If dom0-cpus = 0, dom0 will take all cpus available
(dom0-cpus 0)
这是dom0会起和物理CPU个数相同的VCPU,在16核的服务器上,可以看到
Name ID VCPU CPU State Time(s) CPU Affinity
Domain-0 0 0 6 -b- 33.8 any cpu
Domain-0 0 1 13 -b- 108.6 any cpu
Domain-0 0 2 11 -b- 73.7 any cpu
Domain-0 0 3 10 -b- 41.7 any cpu
Domain-0 0 4 10 -b- 32.3 any cpu
Domain-0 0 5 4 -b- 25.4 any cpu
Domain-0 0 6 12 -b- 43.1 any cpu
Domain-0 0 7 0 -b- 18.9 any cpu
Domain-0 0 8 14 -b- 27.2 any cpu
Domain-0 0 9 15 -b- 59.4 any cpu
Domain-0 0 10 9 r-- 52.2 any cpu
Domain-0 0 11 5 -b- 136.6 any cpu
Domain-0 0 12 7 -b- 35.7 any cpu
Domain-0 0 13 3 -b- 74.3 any cpu
Domain-0 0 14 1 -b- 37.1 any cpu
Domain-0 0 15 8 -b- 26.8 any cpu
如果指定dom0_max_vcpus=4,则
Name ID VCPU CPU State Time(s) CPU Affinity
Domain-0 0 0 5 -b- 9.0 any cpu
Domain-0 0 1 0 -b- 9.5 any cpu
Domain-0 0 2 6 -b- 22.5 any cpu
Domain-0 0 3 12 r-- 6.5 any cpu
这时没有CPU Affinity, 可以看到任何时刻会有随机4个物理核提供给dom0
如果这时 xm vcpu-set 2,则会有两个VCPU进入pause状态,而且奇怪的是,再次调xm vcpu-set 4无法恢复
Name ID VCPU CPU State Time(s) CPU Affinity
Domain-0 0 0 9 r-- 14.1 any cpu
Domain-0 0 1 10 -b- 15.2 any cpu
Domain-0 0 2 - --p 28.4 any cpu
Domain-0 0 3 - --p 10.3 any cpu
如果在指定dom0_max_vcpus的同时又指定了dom0_vcpus_pin,那么每个VCPU会有一个物理CPU被affinity,而且是一一对应
Name ID VCPU CPU State Time(s) CPU Affinity
Domain-0 0 0 0 -b- 1406012.2 0
Domain-0 0 1 1 -b- 397252.5 1
Domain-0 0 2 2 -b- 380299.8 2
Domain-0 0 3 3 r-- 432658.6 3
在这种启动时指定了dom0_vcpus_pin的情况下,貌似调用xm vcpu-pin 会报错 -22,如果不指定的话,xm vcpu-pin可以随意指定CPU Affinity
Name ID VCPU CPU State Time(s) CPU Affinity
Domain-0 0 0 2 r-- 40.5 2
Domain-0 0 1 10 r-- 54.4 10