From e3fbb040502eea324b2b2af59c49873f104c0df6 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Wed, 20 Jul 2011 14:21:12 +0300 Subject: [PATCH] kvm tools: Update max VCPU limit Use the newly introduced KVM_CAP_MAX_VCPUS to determine max VCPU count the kernel side supports. Using more VCPUs than the recommended limit will issue a warning, using more than the absolute maximum will limit it down to the absolute maximum. Note this patch contains a hack to define KVM_CAP_MAX_VCPUS and should be removed when the kernel patch is merged with mainline. Signed-off-by: Sasha Levin Signed-off-by: Pekka Enberg --- tools/kvm/builtin-run.c | 6 +++++- tools/kvm/include/kvm/kvm.h | 1 + tools/kvm/kvm.c | 23 +++++++++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index af2e089c699b..3345bf80e80f 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -478,7 +478,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) struct framebuffer *fb = NULL; unsigned int nr_online_cpus; int exit_code = 0; - int max_cpus; + int max_cpus, recommended_cpus; char *hi; int i; void *ret; @@ -578,10 +578,14 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) ioeventfd__init(); max_cpus = kvm__max_cpus(kvm); + recommended_cpus = kvm__recommended_cpus(kvm); if (nrcpus > max_cpus) { printf(" # Limit the number of CPUs to %d\n", max_cpus); kvm->nrcpus = max_cpus; + } else if (nrcpus > recommended_cpus) { + printf(" # Warning: The maximum recommended amount of VCPUs" + " is %d\n", recommended_cpus); } kvm->nrcpus = nrcpus; diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index 8792af21f7da..eeb55b6f3226 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -51,6 +51,7 @@ struct kvm { }; struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name); +int kvm__recommended_cpus(struct kvm *kvm); int kvm__max_cpus(struct kvm *kvm); void kvm__init_ram(struct kvm *kvm); void kvm__delete(struct kvm *kvm); diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 248eaf4b9e5e..107a9223febe 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -304,17 +304,36 @@ void kvm__init_ram(struct kvm *kvm) } } -int kvm__max_cpus(struct kvm *kvm) +int kvm__recommended_cpus(struct kvm *kvm) { int ret; ret = ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_NR_VCPUS); - if (ret < 0) + if (ret <= 0) die_perror("KVM_CAP_NR_VCPUS"); return ret; } +/* + * The following hack should be removed once 'x86: Raise the hard + * VCPU count limit' makes it's way into the mainline. + */ +#ifndef KVM_CAP_MAX_VCPUS +#define KVM_CAP_MAX_VCPUS 66 +#endif + +int kvm__max_cpus(struct kvm *kvm) +{ + int ret; + + ret = ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_MAX_VCPUS); + if (ret <= 0) + ret = kvm__recommended_cpus(kvm); + + return ret; +} + struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name) { struct kvm_pit_config pit_config = { .flags = 0, }; -- 2.39.5