[tip:tools/kvm] kvm tools: Update max VCPU limit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  e3fbb040502eea324b2b2af59c49873f104c0df6
Gitweb:     http://git.kernel.org/tip/e3fbb040502eea324b2b2af59c49873f104c0df6
Author:     Sasha Levin <levinsasha928@xxxxxxxxx>
AuthorDate: Wed, 20 Jul 2011 14:21:12 +0300
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Wed, 20 Jul 2011 14:55:57 +0300

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 <levinsasha928@xxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 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 af2e089..3345bf8 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 8792af2..eeb55b6 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 248eaf4..107a922 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, };
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux