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
"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