KVM max vcpu allocation
来源:互联网 发布:mac将图标放在桌面 编辑:程序博客网 时间:2024/05/16 07:20
From https://kernel.org/doc/Documentation/virtual/kvm/api.txt we can see,
"The maximum possible value for max_vcpus can be retrieved using the
KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
cpus max.
If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
same as the value returned from KVM_CAP_NR_VCPUS."
The following c program is written according to the documentation above to retrieve KVM max vcpu directly from KVM and should give the same result as virsh maxvcpus kvm does. When given a arg "Recommended", it returns the recommended max vcpus.
#include <stdio.h>
#include <fcntl.h>
#include <linux/kvm.h>
static int kvmMaxVCPUs(int type) {
int maxvcpus = -1;
int r, fd;
fd = open("/dev/kvm", O_RDONLY);
if (fd < 0) {
printf("Unable to open /dev/kvm, max vcpu default 4");
return 4;
}
if(type)
r = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS);
else
r = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_MAX_VCPUS);
if (r > 0)
maxvcpus = r;
close(fd);
return maxvcpus;
}
int main ( int argc, char *argv[] )
{
if(argc > 1 && !strcmp(argv[1], "Recommended"))
printf("recommended max vcpus: %d \n", kvmMaxVCPUs(1));
else
printf("max vcpus: %d \n", kvmMaxVCPUs(0));
"The maximum possible value for max_vcpus can be retrieved using the
KVM_CAP_MAX_VCPUS of the KVM_CHECK_EXTENSION ioctl() at run-time.
If the KVM_CAP_NR_VCPUS does not exist, you should assume that max_vcpus is 4
cpus max.
If the KVM_CAP_MAX_VCPUS does not exist, you should assume that max_vcpus is
same as the value returned from KVM_CAP_NR_VCPUS."
The following c program is written according to the documentation above to retrieve KVM max vcpu directly from KVM and should give the same result as virsh maxvcpus kvm does. When given a arg "Recommended", it returns the recommended max vcpus.
#include <stdio.h>
#include <fcntl.h>
#include <linux/kvm.h>
static int kvmMaxVCPUs(int type) {
int maxvcpus = -1;
int r, fd;
fd = open("/dev/kvm", O_RDONLY);
if (fd < 0) {
printf("Unable to open /dev/kvm, max vcpu default 4");
return 4;
}
if(type)
r = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS);
else
r = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_MAX_VCPUS);
if (r > 0)
maxvcpus = r;
close(fd);
return maxvcpus;
}
int main ( int argc, char *argv[] )
{
if(argc > 1 && !strcmp(argv[1], "Recommended"))
printf("recommended max vcpus: %d \n", kvmMaxVCPUs(1));
else
printf("max vcpus: %d \n", kvmMaxVCPUs(0));
}
Below is some detail on how this value is returned from the kernel, which also explains the findings of your initial research.
Call sequence in kernel space in response to the ioctl system call above,
kvm_dev_ioctl -> kvm_dev_ioctl_check_extension_generic -> kvm_dev_ioctl_check_extension
It eventually returns the macro you found,
https://github.com/Canonical-kernel/Ubuntu-kernel/blob/v3.2.13/arch/x86/kvm/x86.c#L2113
Registration of the char dev ops,
static struct file_operations kvm_chardev_ops = {
.unlocked_ioctl = kvm_dev_ioctl,
.compat_ioctl = kvm_dev_ioctl,
.llseek = noop_llseek,
};
static struct miscdevice kvm_dev = {
KVM_MINOR,
"kvm",
&kvm_chardev_ops,
};
0 0
- KVM max vcpu allocation
- KVM max memory allocation
- KVM VCPU创建过程
- KVM VCPU RUN
- KVM vCPU创建过程
- KVM下vcpu描述
- kvm-vcpu 文件接口
- KVM VCPU线程执行流程图
- kvm虚拟机vcpu资源绑定
- kvm module之create vcpu
- kvm module之run vcpu
- KVM上如何绑定虚拟机vcpu与物理CPU?
- 绑定KVM虚拟机的vcpu与物理CPU
- kvm代码中vcpu_vmx、vcpu、vmcs、cpu的关系
- 基于x86的KVM实现之vcpu建立过程
- kernel 3.10代码分析--KVM相关--虚拟机创建\VCPU创建\虚拟机运行
- vcpu & xen
- vmware vcpu
- axis2 所需jar
- Android签名总结(转载)
- 进程间数据传递载体——Parcel(二)
- 读书笔记--View的事件体系(二)
- MyEclipse 2014 对于java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I错误解决
- KVM max vcpu allocation
- 2015年11月总结
- datagrid 合并行之后 第一行行高出好多
- Android入门:使用Android自带媒体库读取MP3文件
- CCF-CSP-2015年3月-题解
- Scala学习第十九天 正则表达式、与模式匹配结合的的Reg代码实战
- 打印乘法表
- 【转载】Android样式的开发:shape篇
- LightOJ-1008 Fibsieve`s Fantabulous Birthday