thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
9ae3a8
From 453a94cf85a041792086990022d182bcc4f939cb Mon Sep 17 00:00:00 2001
9ae3a8
From: Andrew Jones <drjones@redhat.com>
9ae3a8
Date: Tue, 24 Sep 2013 13:29:36 +0200
9ae3a8
Subject: [PATCH 05/11] kvm: warn if num cpus is greater than num recommended
9ae3a8
9ae3a8
RH-Author: Andrew Jones <drjones@redhat.com>
9ae3a8
Message-id: <1380029376-20391-1-git-send-email-drjones@redhat.com>
9ae3a8
Patchwork-id: 54526
9ae3a8
O-Subject: [RHEL7.0 qemu-kvm PATCH] kvm: warn if num cpus is greater than num recommended
9ae3a8
Bugzilla: 1010881
9ae3a8
RH-Acked-by: Radim Krcmar <rkrcmar@redhat.com>
9ae3a8
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1010881
9ae3a8
Brewing: https://brewweb.devel.redhat.com/taskinfo?taskID=6322066
9ae3a8
9ae3a8
(cherry picked from commit 670436ced08738802e15764039d03ab0dbab2bf3
9ae3a8
 of uq/master)
9ae3a8
9ae3a8
===
9ae3a8
9ae3a8
The comment in kvm_max_vcpus() states that it's using the recommended
9ae3a8
procedure from the kernel API documentation to get the max number
9ae3a8
of vcpus that kvm supports. It is, but by always returning the
9ae3a8
maximum number supported. The maximum number should only be used
9ae3a8
for development purposes. qemu should check KVM_CAP_NR_VCPUS for
9ae3a8
the recommended number of vcpus. This patch adds a warning if a user
9ae3a8
specifies a number of cpus between the recommended and max.
9ae3a8
9ae3a8
Signed-off-by: Andrew Jones <drjones@redhat.com>
9ae3a8
Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
9ae3a8
Signed-off-by: Gleb Natapov <gleb@redhat.com>
9ae3a8
---
9ae3a8
 kvm-all.c | 69 ++++++++++++++++++++++++++++++++++++---------------------------
9ae3a8
 1 file changed, 40 insertions(+), 29 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 kvm-all.c |   69 +++++++++++++++++++++++++++++++++++-------------------------
9ae3a8
 1 files changed, 40 insertions(+), 29 deletions(-)
9ae3a8
9ae3a8
diff --git a/kvm-all.c b/kvm-all.c
9ae3a8
index d0a7c21..f2f68d6 100644
9ae3a8
--- a/kvm-all.c
9ae3a8
+++ b/kvm-all.c
9ae3a8
@@ -1280,24 +1280,20 @@ static int kvm_irqchip_create(KVMState *s)
9ae3a8
     return 0;
9ae3a8
 }
9ae3a8
 
9ae3a8
-static int kvm_max_vcpus(KVMState *s)
9ae3a8
+/* Find number of supported CPUs using the recommended
9ae3a8
+ * procedure from the kernel API documentation to cope with
9ae3a8
+ * older kernels that may be missing capabilities.
9ae3a8
+ */
9ae3a8
+static int kvm_recommended_vcpus(KVMState *s)
9ae3a8
 {
9ae3a8
-    int ret;
9ae3a8
-
9ae3a8
-    /* Find number of supported CPUs using the recommended
9ae3a8
-     * procedure from the kernel API documentation to cope with
9ae3a8
-     * older kernels that may be missing capabilities.
9ae3a8
-     */
9ae3a8
-    ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
9ae3a8
-    if (ret) {
9ae3a8
-        return ret;
9ae3a8
-    }
9ae3a8
-    ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);
9ae3a8
-    if (ret) {
9ae3a8
-        return ret;
9ae3a8
-    }
9ae3a8
+    int ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);
9ae3a8
+    return (ret) ? ret : 4;
9ae3a8
+}
9ae3a8
 
9ae3a8
-    return 4;
9ae3a8
+static int kvm_max_vcpus(KVMState *s)
9ae3a8
+{
9ae3a8
+    int ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
9ae3a8
+    return (ret) ? ret : kvm_recommended_vcpus(s);
9ae3a8
 }
9ae3a8
 
9ae3a8
 int kvm_init(void)
9ae3a8
@@ -1305,11 +1301,19 @@ int kvm_init(void)
9ae3a8
     static const char upgrade_note[] =
9ae3a8
         "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n"
9ae3a8
         "(see http://sourceforge.net/projects/kvm).\n";
9ae3a8
+    struct {
9ae3a8
+        const char *name;
9ae3a8
+        int num;
9ae3a8
+    } num_cpus[] = {
9ae3a8
+        { "SMP",          smp_cpus },
9ae3a8
+        { "hotpluggable", max_cpus },
9ae3a8
+        { NULL, }
9ae3a8
+    }, *nc = num_cpus;
9ae3a8
+    int soft_vcpus_limit, hard_vcpus_limit;
9ae3a8
     KVMState *s;
9ae3a8
     const KVMCapabilityInfo *missing_cap;
9ae3a8
     int ret;
9ae3a8
     int i;
9ae3a8
-    int max_vcpus;
9ae3a8
 
9ae3a8
     s = g_malloc0(sizeof(KVMState));
9ae3a8
 
9ae3a8
@@ -1350,19 +1354,26 @@ int kvm_init(void)
9ae3a8
         goto err;
9ae3a8
     }
9ae3a8
 
9ae3a8
-    max_vcpus = kvm_max_vcpus(s);
9ae3a8
-    if (smp_cpus > max_vcpus) {
9ae3a8
-        ret = -EINVAL;
9ae3a8
-        fprintf(stderr, "Number of SMP cpus requested (%d) exceeds max cpus "
9ae3a8
-                "supported by KVM (%d)\n", smp_cpus, max_vcpus);
9ae3a8
-        goto err;
9ae3a8
-    }
9ae3a8
+    /* check the vcpu limits */
9ae3a8
+    soft_vcpus_limit = kvm_recommended_vcpus(s);
9ae3a8
+    hard_vcpus_limit = kvm_max_vcpus(s);
9ae3a8
 
9ae3a8
-    if (max_cpus > max_vcpus) {
9ae3a8
-        ret = -EINVAL;
9ae3a8
-        fprintf(stderr, "Number of hotpluggable cpus requested (%d) exceeds max cpus "
9ae3a8
-                "supported by KVM (%d)\n", max_cpus, max_vcpus);
9ae3a8
-        goto err;
9ae3a8
+    while (nc->name) {
9ae3a8
+        if (nc->num > soft_vcpus_limit) {
9ae3a8
+            fprintf(stderr,
9ae3a8
+                    "Warning: Number of %s cpus requested (%d) exceeds "
9ae3a8
+                    "the recommended cpus supported by KVM (%d)\n",
9ae3a8
+                    nc->name, nc->num, soft_vcpus_limit);
9ae3a8
+
9ae3a8
+            if (nc->num > hard_vcpus_limit) {
9ae3a8
+                ret = -EINVAL;
9ae3a8
+                fprintf(stderr, "Number of %s cpus requested (%d) exceeds "
9ae3a8
+                        "the maximum cpus supported by KVM (%d)\n",
9ae3a8
+                        nc->name, nc->num, hard_vcpus_limit);
9ae3a8
+                goto err;
9ae3a8
+            }
9ae3a8
+        }
9ae3a8
+        nc++;
9ae3a8
     }
9ae3a8
 
9ae3a8
     s->vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0);
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8