qemu-arm.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, qemu-arm@nongnu.org
Cc: peter.maydell@linaro.org, ehabkost@redhat.com, agraf@suse.de,
	pbonzini@redhat.com, dgibson@redhat.com, imammedo@redhat.com,
	david@gibson.dropbear.id.au
Subject: [Qemu-arm] [PATCH RFC 06/16] vl: move smp parsing to machine pre_init
Date: Fri, 10 Jun 2016 19:40:17 +0200	[thread overview]
Message-ID: <1465580427-13596-7-git-send-email-drjones@redhat.com> (raw)
In-Reply-To: <1465580427-13596-1-git-send-email-drjones@redhat.com>

Move the guts of smp_parse() into hw/core/machine.c to operate on
smp machine properties, and to eventually allow it to be overridden
by machines. We leave the smp_parse function behind to handle the
(now deprecated) -smp option, but now it only needs to set the
machine properties.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 hw/core/machine.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 vl.c              | 111 ++++++++++++++++-------------------------------------
 2 files changed, 142 insertions(+), 82 deletions(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index 2625044002e57..75c5a1fdd7de1 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -17,6 +17,7 @@
 #include "qapi/visitor.h"
 #include "hw/sysbus.h"
 #include "sysemu/sysemu.h"
+#include "sysemu/replay.h"
 #include "qemu/error-report.h"
 #include "qemu/cutils.h"
 
@@ -417,16 +418,122 @@ static void machine_init_notify(Notifier *notifier, void *data)
 
 static void machine_set_smp_parameters(MachineState *ms)
 {
-    if (ms->sockets != -1 || ms->cores != -1 || ms->threads != -1 ||
-        ms->maxcpus != -1 || ms->cpus != -1) {
+    int sockets = ms->sockets;
+    int cores   = ms->cores;
+    int threads = ms->threads;
+    int maxcpus = ms->maxcpus;
+    int cpus    = ms->cpus;
+    bool sockets_input = sockets > 0;
+
+    if (sockets == -1 && cores == -1 && threads == -1 &&
+        maxcpus == -1 && cpus == -1) {
+        ms->sockets = 1;
+        ms->cores   = 1;
+        ms->threads = 1;
+        ms->maxcpus = 1;
+        ms->cpus    = 1;
+        return;
+    }
+
+    if (sockets == -1 || cores == -1 || threads == -1 ||
+        maxcpus == -1 || cpus == -1) {
+        error_report("cpu topology: "
+                     "all machine properties must be specified");
+        exit(1);
+    }
+
+    /* If the deprecated -smp option was used without complete input,
+     * or a user input zeros (why would they do that?), then we compute
+     * missing values, preferring sockets over cores over threads.
+     */
+    if (cpus == 0 || sockets == 0) {
+        sockets = sockets > 0 ? sockets : 1;
+        cores = cores > 0 ? cores : 1;
+        threads = threads > 0 ? threads : 1;
+        if (cpus == 0) {
+            cpus = cores * threads * sockets;
+        }
+    } else if (cores == 0) {
+        threads = threads > 0 ? threads : 1;
+        cores = cpus / (sockets * threads);
+    } else if (threads == 0) {
+        threads = cpus / (cores * sockets);
+    } else if (sockets * cores * threads < cpus) {
+        error_report("cpu topology: "
+                     "sockets (%u) * cores (%u) * threads (%u) < "
+                     "smp_cpus (%u)",
+                     sockets, cores, threads, cpus);
+        exit(1);
+    }
+
+    maxcpus = maxcpus > 0 ? maxcpus : cpus;
+
+    if (maxcpus > MAX_CPUMASK_BITS) {
+        error_report("unsupported number of maxcpus");
+        exit(1);
+    }
+
+    if (maxcpus < cpus) {
+        error_report("maxcpus must be equal to or greater than smp");
+        exit(1);
+    }
+
+    if (sockets * cores * threads > maxcpus) {
+        error_report("cpu topology: "
+                     "sockets (%u) * cores (%u) * threads (%u) > "
+                     "maxcpus (%u)",
+                     sockets, cores, threads, maxcpus);
+        exit(1);
+    }
+
+    if (sockets_input && sockets * cores * threads != maxcpus) {
+        unsigned sockets_rounded = DIV_ROUND_UP(maxcpus, cores * threads);
+
         error_report("warning: cpu topology: "
-                     "machine properties currently ignored");
+                     "sockets (%u) * cores (%u) * threads (%u) != "
+                     "maxcpus (%u). Trying sockets=%u.",
+                     sockets, cores, threads, maxcpus, sockets_rounded);
+        sockets = sockets_rounded;
+
+        if (sockets * cores * threads > maxcpus) {
+            error_report("cpu topology: "
+                         "sockets (%u) * cores (%u) * threads (%u) > "
+                         "maxcpus (%u)",
+                         sockets, cores, threads, maxcpus);
+            exit(1);
+        }
     }
+
+    ms->sockets = sockets;
+    ms->cores   = cores;
+    ms->threads = threads;
+    ms->maxcpus = maxcpus;
+    ms->cpus    = cpus;
 }
 
 static void machine_pre_init(MachineState *ms)
 {
+    MachineClass *mc = MACHINE_CLASS(object_get_class(OBJECT(ms)));
+
     machine_set_smp_parameters(ms);
+    smp_cores   = ms->cores;
+    smp_threads = ms->threads;
+    max_cpus    = ms->maxcpus;
+    smp_cpus    = ms->cpus;
+
+    mc->max_cpus = mc->max_cpus ?: 1; /* Default to UP */
+    if (ms->maxcpus > mc->max_cpus) {
+        error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
+                     "supported by machine '%s' (%d)", ms->maxcpus, mc->name,
+                     mc->max_cpus);
+        exit(1);
+    }
+
+    if (ms->cpus > 1) {
+        Error *blocker = NULL;
+        error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp");
+        replay_add_blocker(blocker);
+    }
 }
 
 static void machine_class_init(ObjectClass *oc, void *data)
diff --git a/vl.c b/vl.c
index 4849dd465d667..843b7a9dff753 100644
--- a/vl.c
+++ b/vl.c
@@ -1222,81 +1222,41 @@ static QemuOptsList qemu_smp_opts = {
 
 static void smp_parse(QemuOpts *opts)
 {
-    if (opts) {
-        unsigned cpus    = qemu_opt_get_number(opts, "cpus", 0);
-        unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
-        unsigned cores   = qemu_opt_get_number(opts, "cores", 0);
-        unsigned threads = qemu_opt_get_number(opts, "threads", 0);
-        bool sockets_input = sockets > 0;
-
-        /* compute missing values, prefer sockets over cores over threads */
-        if (cpus == 0 || sockets == 0) {
-            sockets = sockets > 0 ? sockets : 1;
-            cores = cores > 0 ? cores : 1;
-            threads = threads > 0 ? threads : 1;
-            if (cpus == 0) {
-                cpus = cores * threads * sockets;
-            }
-        } else if (cores == 0) {
-            threads = threads > 0 ? threads : 1;
-            cores = cpus / (sockets * threads);
-        } else if (threads == 0) {
-            threads = cpus / (cores * sockets);
-        } else if (sockets * cores * threads < cpus) {
-            error_report("cpu topology: "
-                         "sockets (%u) * cores (%u) * threads (%u) < "
-                         "smp_cpus (%u)",
-                         sockets, cores, threads, cpus);
-            exit(1);
-        }
-
-        max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus);
-
-        if (max_cpus > MAX_CPUMASK_BITS) {
-            error_report("unsupported number of maxcpus");
-            exit(1);
-        }
-
-        if (max_cpus < cpus) {
-            error_report("maxcpus must be equal to or greater than smp");
-            exit(1);
-        }
+    Object *machine_obj = OBJECT(current_machine);
+    int sockets, cores, threads, maxcpus, cpus;
 
-        if (sockets * cores * threads > max_cpus) {
-            error_report("cpu topology: "
-                         "sockets (%u) * cores (%u) * threads (%u) > "
-                         "maxcpus (%u)",
-                         sockets, cores, threads, max_cpus);
-            exit(1);
-        }
+    if (!opts) {
+        return;
+    }
 
-        if (sockets_input && sockets * cores * threads != max_cpus) {
-            unsigned sockets_rounded = DIV_ROUND_UP(max_cpus, cores * threads);
+    sockets = object_property_get_int(machine_obj, "sockets", NULL);
+    cores   = object_property_get_int(machine_obj, "cores",   NULL);
+    threads = object_property_get_int(machine_obj, "threads", NULL);
+    maxcpus = object_property_get_int(machine_obj, "maxcpus", NULL);
+    cpus    = object_property_get_int(machine_obj, "cpus",    NULL);
 
-            error_report("warning: cpu topology: "
-                         "sockets (%u) * cores (%u) * threads (%u) != "
-                         "maxcpus (%u). Trying sockets=%u.",
-                         sockets, cores, threads, max_cpus, sockets_rounded);
-            sockets = sockets_rounded;
+    if (sockets == -1 && cores == -1 && threads == -1 &&
+        maxcpus == -1 && cpus == -1) {
 
-            if (sockets * cores * threads > max_cpus) {
-                error_report("cpu topology: "
-                             "sockets (%u) * cores (%u) * threads (%u) > "
-                             "maxcpus (%u)",
-                             sockets, cores, threads, max_cpus);
-                exit(1);
-            }
-        }
+        error_report("warning: cpu topology: "
+                     "using deprecated -smp option. "
+                     "Use machine properties instead");
 
-        smp_cpus = cpus;
-        smp_cores = cores;
-        smp_threads = threads;
-    }
+        cpus    = qemu_opt_get_number(opts, "cpus",    0);
+        sockets = qemu_opt_get_number(opts, "sockets", 0);
+        cores   = qemu_opt_get_number(opts, "cores",   0);
+        threads = qemu_opt_get_number(opts, "threads", 0);
+        maxcpus = qemu_opt_get_number(opts, "maxcpus", cpus);
 
-    if (smp_cpus > 1) {
-        Error *blocker = NULL;
-        error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp");
-        replay_add_blocker(blocker);
+        object_property_set_int(machine_obj, sockets, "sockets", NULL);
+        object_property_set_int(machine_obj, cores,   "cores",   NULL);
+        object_property_set_int(machine_obj, threads, "threads", NULL);
+        object_property_set_int(machine_obj, maxcpus, "maxcpus", NULL);
+        object_property_set_int(machine_obj, cpus,    "cpus",    NULL);
+    } else {
+        error_report("warning: cpu topology: "
+                     "both machine properties and -smp option provided. "
+                     "Ignoring the deprecated -smp option");
     }
 }
 
@@ -4106,16 +4066,6 @@ int main(int argc, char **argv, char **envp)
         data_dir[data_dir_idx++] = CONFIG_QEMU_DATADIR;
     }
 
-    smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
-
-    machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
-    if (max_cpus > machine_class->max_cpus) {
-        error_report("Number of SMP CPUs requested (%d) exceeds max CPUs "
-                     "supported by machine '%s' (%d)", max_cpus,
-                     machine_class->name, machine_class->max_cpus);
-        exit(1);
-    }
-
     /*
      * Get the default machine options from the machine if it is not already
      * specified either by the configuration file or by the command line.
@@ -4308,6 +4258,9 @@ int main(int argc, char **argv, char **envp)
         qtest_init(qtest_chrdev, qtest_log, &error_fatal);
     }
 
+    /* smp_parse must come after qemu_opt_foreach(machine_opts, ...) */
+    smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
+
     machine_opts = qemu_get_machine_opts();
     kernel_filename = qemu_opt_get(machine_opts, "kernel");
     initrd_filename = qemu_opt_get(machine_opts, "initrd");
-- 
2.4.11


  parent reply	other threads:[~2016-06-10 17:41 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-10 17:40 [Qemu-arm] [PATCH RFC 00/16] Rework SMP parameters Andrew Jones
2016-06-10 17:40 ` [Qemu-arm] [PATCH RFC 01/16] vl: smp_parse: cleanups Andrew Jones
2016-06-14  1:15   ` David Gibson
2016-06-10 17:40 ` [Qemu-arm] [PATCH RFC 02/16] vl: smp: add checks for maxcpus based topologies Andrew Jones
2016-06-14  1:28   ` David Gibson
2016-06-14  6:43     ` [Qemu-arm] [Qemu-devel] " Andrew Jones
2016-06-10 17:40 ` [Qemu-arm] [PATCH RFC 03/16] hw/smbios/smbios: fix number of sockets calculation Andrew Jones
2016-07-11 14:23   ` Igor Mammedov
2016-06-10 17:40 ` [Qemu-arm] [PATCH RFC 04/16] hw/core/machine: Introduce pre_init Andrew Jones
2016-06-14  1:30   ` David Gibson
2016-06-14  5:58     ` [Qemu-arm] [Qemu-devel] " Andrew Jones
2016-07-14 20:10       ` Eduardo Habkost
2016-07-15  6:26         ` Andrew Jones
2016-06-10 17:40 ` [Qemu-arm] [PATCH RFC 05/16] hw/core/machine: add smp properites Andrew Jones
2016-06-14  2:00   ` David Gibson
2016-06-14  6:08     ` [Qemu-arm] [Qemu-devel] " Andrew Jones
2016-06-15  0:37       ` David Gibson
2016-06-15  7:11         ` Andrew Jones
2016-07-14 20:18           ` Eduardo Habkost
2016-07-15  6:29             ` Andrew Jones
2016-06-10 17:40 ` Andrew Jones [this message]
2016-06-13 17:04   ` [Qemu-arm] [PATCH RFC 06/16] vl: move smp parsing to machine pre_init Paolo Bonzini
2016-06-13 20:35     ` [Qemu-arm] [Qemu-devel] " Andrew Jones
2016-06-14  8:17       ` Paolo Bonzini
2016-06-14 11:39         ` [Qemu-arm] " Andrew Jones
2016-06-14 11:53           ` [Qemu-arm] " Paolo Bonzini
2016-06-14 14:03             ` [Qemu-devel] " Andrew Jones
2016-06-14 14:05               ` [Qemu-arm] " Paolo Bonzini
2016-06-15  0:51               ` David Gibson
2016-06-15  7:19                 ` Andrew Jones
2016-06-15  0:43         ` [Qemu-arm] " David Gibson
2016-06-10 17:40 ` [Qemu-devel] [PATCH RFC 07/16] qom/cpu: make nr-cores, nr-threads real properties Andrew Jones
2016-06-11  6:54   ` [Qemu-arm] " Thomas Huth
2016-06-12 13:48     ` Andrew Jones
2016-06-14  2:12       ` David Gibson
2016-06-14  6:19         ` Andrew Jones
2016-06-15  0:56           ` David Gibson
2016-07-14 20:07             ` Eduardo Habkost
2016-07-15  6:35               ` Andrew Jones
2016-07-15  9:11                 ` Igor Mammedov
2016-07-15 16:10                   ` [Qemu-devel] QOM: best way for parents to pass information to children? (was Re: [PATCH RFC 07/16] qom/cpu: make nr-cores, nr-threads real properties) Eduardo Habkost
2016-07-15 16:10                     ` [Qemu-arm] QOM: best way for parents to pass information to children? (was Re: [Qemu-devel] " Eduardo Habkost
2016-07-15 16:30                     ` [Qemu-devel] QOM: best way for parents to pass information to children? (was " Andreas Färber
2016-07-15 16:30                       ` [Qemu-arm] QOM: best way for parents to pass information to children? (was Re: [Qemu-devel] " Andreas Färber
2016-07-15 17:43                       ` [Qemu-devel] QOM: best way for parents to pass information to children? (was " Eduardo Habkost
2016-07-15 17:43                         ` [Qemu-arm] QOM: best way for parents to pass information to children? (was Re: [Qemu-devel] " Eduardo Habkost
2016-07-15 18:38                         ` [Qemu-arm] [Qemu-devel] QOM: best way for parents to pass information to children? (was " Igor Mammedov
2016-07-15 21:33                           ` Eduardo Habkost
2016-07-16 15:30                             ` Andrew Jones
2016-07-19 11:54                               ` Eduardo Habkost
2016-07-18  7:23                             ` Igor Mammedov
2016-07-19 11:59                               ` Eduardo Habkost
2016-07-19 12:21                                 ` Paolo Bonzini
2016-07-19 13:29                                   ` Igor Mammedov
2016-07-19 13:39                                     ` Paolo Bonzini
2016-06-10 17:40 ` [Qemu-devel] [PATCH RFC 08/16] hw/core/machine: set cpu global nr_cores, nr_threads in pre_init Andrew Jones
2016-06-10 17:40 ` [Qemu-arm] [PATCH RFC 09/16] hw/i386/pc: don't use smp_cores, smp_threads Andrew Jones
2016-07-14 20:33   ` [Qemu-devel] " Eduardo Habkost
2016-06-10 17:40 ` [Qemu-arm] [PATCH RFC 10/16] hw/ppc/spapr: " Andrew Jones
2016-06-14  3:03   ` David Gibson
2016-06-14  6:23     ` [Qemu-arm] [Qemu-devel] " Andrew Jones
2016-06-15  0:59       ` David Gibson
2016-06-15  7:34         ` Andrew Jones
2016-06-10 17:40 ` [Qemu-arm] [PATCH RFC 11/16] target-ppc: don't use smp_threads Andrew Jones
2016-06-10 17:40 ` [Qemu-devel] [PATCH RFC 12/16] hw/arm/virt: rename *.smp_cpus to *.cpus Andrew Jones
2016-06-10 17:40 ` [Qemu-arm] [PATCH RFC 13/16] hw/arm/virt: don't use smp_cpus, max_cpus Andrew Jones
2016-06-10 17:40 ` [Qemu-arm] [PATCH RFC 14/16] hw/arm/virt: stash cpu topo info in VirtGuestInfo Andrew Jones
2016-07-14 20:43   ` [Qemu-arm] [Qemu-devel] " Eduardo Habkost
2016-07-15  6:40     ` Andrew Jones
2016-06-10 17:40 ` [Qemu-devel] [PATCH RFC 15/16] smbios: don't use smp_cores, smp_threads Andrew Jones
2016-07-14 20:51   ` [Qemu-arm] " Eduardo Habkost
2016-07-15  6:45     ` Andrew Jones
2016-06-10 17:40 ` [Qemu-arm] [PATCH RFC 16/16] sysemu/cpus: bye, bye " Andrew Jones
2016-06-11  6:42 ` [Qemu-arm] [Qemu-devel] [PATCH RFC 00/16] Rework SMP parameters Thomas Huth
2016-06-12 13:58   ` Andrew Jones
2016-06-12 14:03 ` Andrew Jones
2016-07-14  9:16 ` Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1465580427-13596-7-git-send-email-drjones@redhat.com \
    --to=drjones@redhat.com \
    --cc=agraf@suse.de \
    --cc=david@gibson.dropbear.id.au \
    --cc=dgibson@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).