qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org, Anthony Liguori <aliguori@amazon.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Marcelo Tosatti" <mtosatti@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"Igor Mammedov" <imammedo@redhat.com>
Subject: [Qemu-devel] [PATCH v2] vl.c: Unify MAX_CPUMASK_BITS and machine->max_cpus checks
Date: Thu,  8 May 2014 17:02:59 -0300	[thread overview]
Message-ID: <1399579379-8370-1-git-send-email-ehabkost@redhat.com> (raw)

If a given machine have max_cpus set, not just smp_cpus needs to be
limited, but the total number of CPUs (considering CPU hotplug) for the
machine.

We also had yet another max_cpus limit check at smp_parse(), ensuring
that max_cpus < MAX_CPUMASK_BITS.

This patch unifies the machine->max_cpus and MAX_CPUMASK_BITS checks,
and also moves the (smp_cpus <= max_cpus) outside smp_parse(), to keep
all checks in the same place.

With those changes, the new code ensures that:

  1 <= smp_cpus <= max_cpus <= machine->max_cpus <= MAX_CPUMASK_BITS

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Andreas Färber <afaerber@suse.de>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
---
Changes v1 -> v2:
 * v1 was: [PATCH] vl.c: Check max_cpus limit instead of smp_cpus
 * Unify machine->max_cpus and MAX_CPUMASK_BITS check
 * Move all checks outside smp_parse()
 * Add assert() lines ensuring the results are consistent
 * s/machine/machine_class/, after rebase to latest qemu.git
   (commit 6b342cc)
---
 vl.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/vl.c b/vl.c
index 73e0661..434cdc3 100644
--- a/vl.c
+++ b/vl.c
@@ -1425,15 +1425,6 @@ static void smp_parse(QemuOpts *opts)
         max_cpus = smp_cpus;
     }
 
-    if (max_cpus > MAX_CPUMASK_BITS) {
-        fprintf(stderr, "Unsupported number of maxcpus\n");
-        exit(1);
-    }
-    if (max_cpus < smp_cpus) {
-        fprintf(stderr, "maxcpus must be equal to or greater than smp\n");
-        exit(1);
-    }
-
 }
 
 static void configure_realtime(QemuOpts *opts)
@@ -4055,13 +4046,24 @@ int main(int argc, char **argv, char **envp)
     smp_parse(qemu_opts_find(qemu_find_opts("smp-opts"), NULL));
 
     machine_class->max_cpus = machine_class->max_cpus ?: 1; /* Default to UP */
-    if (smp_cpus > machine_class->max_cpus) {
-        fprintf(stderr, "Number of SMP cpus requested (%d), exceeds max cpus "
-                "supported by machine `%s' (%d)\n", smp_cpus,
+    machine_class->max_cpus = MIN(machine_class->max_cpus, MAX_CPUMASK_BITS);
+
+    if (max_cpus < smp_cpus) {
+        fprintf(stderr, "maxcpus must be equal to or greater than smp\n");
+        exit(1);
+    }
+    if (max_cpus > machine_class->max_cpus) {
+        fprintf(stderr, "Total number of CPUs (%d), exceeds maximum "
+                "supported by machine `%s' (%d)\n", max_cpus,
                 machine_class->name, machine_class->max_cpus);
         exit(1);
     }
 
+    assert(1 <= smp_cpus);
+    assert(smp_cpus <= max_cpus);
+    assert(max_cpus <= machine_class->max_cpus);
+    assert(machine_class->max_cpus <= MAX_CPUMASK_BITS);
+
     /*
      * Get the default machine options from the machine if it is not already
      * specified either by the configuration file or by the command line.
-- 
1.9.0

                 reply	other threads:[~2014-05-08 20:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1399579379-8370-1-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@amazon.com \
    --cc=imammedo@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@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).