Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 340e01248478ba8b78a6d4d1809b1eff > files > 343

kvm-83-270.el5_11.src.rpm

From 5ccd361c169f69e66a564286a28a93eab29a4b25 Mon Sep 17 00:00:00 2001
From: Eduardo Habkost <ehabkost@redhat.com>
Date: Fri, 2 Oct 2009 14:15:29 -0300
Subject: [PATCH 04/10] extend -smp parsing to include cores= and threads= options

RH-Author: Gleb Natapov <gleb@redhat.com>
Message-id: <1253608839-4319-5-git-send-email-gleb@redhat.com>
Patchwork-id: 3489
O-Subject: [PATCH 4/7] extend -smp parsing to include cores= and threads= options
Bugzilla: 508040
RH-Acked-by: Mark McLoughlin <markmc@redhat.com>
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>

For injecting multi-core and multi-threading CPU topology into guests
extend the -smp syntax to accommodate cores and threads specification.
Syntax: -smp smp_value[,cores=nr_cores][,threads=nr_threads]\
[,socket=nr_sockets][,maxcpus=max_cpus]
smp_value is the legacy value specifying the total number of vCPUs for
the guest. If you specify one of cores, threads or sockets this value
can be omitted. Missing values will be computed to fulfill:
smp_value = nr_cores * nr_threads * nr_sockets
where it will favour sockets over cores over threads (to mimic the
current behavior, which will only inject multiple sockets.)
So -smp 4,threads=2 will inject two sockets with 2 threads each,
-smp cores=4 is an abbreviation for -smp 4,cores=4,threads=1,sockets=1.
If max_cpus (the number of hotpluggable CPUs) is omitted, it will
be set to smp_value.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
 qemu/cpu-defs.h           |    2 +
 qemu/sysemu.h             |    2 +
 qemu/target-i386/helper.c |    4 +++
 qemu/vl.c                 |   49 ++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 56 insertions(+), 1 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qemu/cpu-defs.h           |    2 +
 qemu/sysemu.h             |    2 +
 qemu/target-i386/helper.c |    4 +++
 qemu/vl.c                 |   49 ++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/qemu/cpu-defs.h b/qemu/cpu-defs.h
index acbe380..45cd93f 100644
--- a/qemu/cpu-defs.h
+++ b/qemu/cpu-defs.h
@@ -220,6 +220,8 @@ struct KVMCPUState {
                                                                         \
     void *next_cpu; /* next CPU sharing TB cache */                     \
     int cpu_index; /* CPU index (informative) */                        \
+    int nr_cores; /* number of cores within this CPU package */         \
+    int nr_threads; /* number of threads within this CPU */             \
     int running; /* Nonzero if cpu is currently running(usermode).  */  \
     int thread_id;							\
     /* user data */                                                     \
diff --git a/qemu/sysemu.h b/qemu/sysemu.h
index ea84039..626d882 100644
--- a/qemu/sysemu.h
+++ b/qemu/sysemu.h
@@ -106,6 +106,8 @@ extern int alt_grab;
 extern int usb_enabled;
 extern int virtio_balloon;
 extern int smp_cpus;
+extern int smp_cores;
+extern int smp_threads;
 extern int cursor_hide;
 extern int graphic_rotate;
 extern int no_quit;
diff --git a/qemu/target-i386/helper.c b/qemu/target-i386/helper.c
index f09bf13..aae9ad1 100644
--- a/qemu/target-i386/helper.c
+++ b/qemu/target-i386/helper.c
@@ -29,6 +29,7 @@
 #include "exec-all.h"
 #include "qemu-common.h"
 #include "kvm.h"
+#include "sysemu.h"
 
 #include "qemu-kvm.h"
 
@@ -1650,5 +1651,8 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
 #ifdef USE_KQEMU
     kqemu_init(env);
 #endif
+    env->nr_cores = smp_cores;
+    env->nr_threads = smp_threads;
+
     return env;
 }
diff --git a/qemu/vl.c b/qemu/vl.c
index 0c52166..a89a373 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -232,6 +232,8 @@ int usb_enabled = 0;
 const char *assigned_devices[MAX_DEV_ASSIGN_CMDLINE];
 int assigned_devices_index;
 int smp_cpus = 1;
+int smp_cores = 1;
+int smp_threads = 1;
 const char *vnc_display;
 int acpi_enabled = 1;
 int no_hpet = 1;
@@ -2744,6 +2746,51 @@ int drives_reopen(void)
      return 0;
  }
 
+static void smp_parse(const char *optarg)
+{
+    int smp, sockets = 0, threads = 0, cores = 0;
+    char *endptr;
+    char option[128];
+
+    smp = strtoul(optarg, &endptr, 10);
+    if (endptr != optarg) {
+        if (*endptr == ',') {
+            endptr++;
+        }
+    }
+    if (get_param_value(option, 128, "sockets", endptr) != 0)
+        sockets = strtoull(option, NULL, 10);
+    if (get_param_value(option, 128, "cores", endptr) != 0)
+        cores = strtoull(option, NULL, 10);
+    if (get_param_value(option, 128, "threads", endptr) != 0)
+        threads = strtoull(option, NULL, 10);
+
+    /* compute missing values, prefer sockets over cores over threads */
+    if (smp == 0 || sockets == 0) {
+        sockets = sockets > 0 ? sockets : 1;
+        cores = cores > 0 ? cores : 1;
+        threads = threads > 0 ? threads : 1;
+        if (smp == 0) {
+            smp = cores * threads * sockets;
+        } else {
+            sockets = smp / (cores * threads);
+        }
+    } else {
+        if (cores == 0) {
+            threads = threads > 0 ? threads : 1;
+            cores = smp / (sockets * threads);
+        } else {
+            if (sockets == 0) {
+                sockets = smp / (cores * threads);
+            } else {
+                threads = smp / (cores * sockets);
+            }
+        }
+    }
+    smp_cpus = smp;
+    smp_cores = cores > 0 ? cores : 1;
+    smp_threads = threads > 0 ? threads : 1;
+}
 
 /***********************************************************/
 /* USB devices */
@@ -5756,7 +5803,7 @@ int main(int argc, char **argv, char **envp)
                 usb_devices_index++;
                 break;
             case QEMU_OPTION_smp:
-                smp_cpus = atoi(optarg);
+                smp_parse(optarg);
                 if (smp_cpus < 1) {
                     fprintf(stderr, "Invalid number of CPUs\n");
                     exit(1);
-- 
1.6.3.rc4.29.g8146