From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, aliguori@us.ibm.com, Peter Lieven <pl@kamp.de>
Subject: [Qemu-devel] [PATCH] vl: verify if combination of cpus, sockets, cores and threads is sane
Date: Thu, 21 Nov 2013 15:37:05 +0100 [thread overview]
Message-ID: <1385044625-31006-1-git-send-email-pl@kamp.de> (raw)
Signed-off-by: Peter Lieven <pl@kamp.de>
---
vl.c | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/vl.c b/vl.c
index 8d5d874..dc0b41a 100644
--- a/vl.c
+++ b/vl.c
@@ -1385,35 +1385,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);
/* compute missing values, prefer sockets over cores over threads */
- if (cpus == 0 || sockets == 0) {
+ if (cpus == 0) {
sockets = sockets > 0 ? sockets : 1;
cores = cores > 0 ? cores : 1;
threads = threads > 0 ? threads : 1;
- if (cpus == 0) {
- cpus = cores * threads * sockets;
- }
+ cpus = cores * threads * sockets;
+ } else if (sockets == 0) {
+ cores = cores > 0 ? cores : 1;
+ threads = threads > 0 ? threads : 1;
+ sockets = cpus / (cores * threads);
+ } else if (cores == 0) {
+ threads = threads > 0 ? threads : 1;
+ cores = cpus / (sockets * threads);
} else {
- if (cores == 0) {
- threads = threads > 0 ? threads : 1;
- cores = cpus / (sockets * threads);
- } else {
- threads = cpus / (cores * sockets);
- }
+ threads = cpus / (sockets * cores);
}
- max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
+ if (cpus != sockets * cores * threads) {
+ fprintf(stderr, "Illegal CPU layout: %d cpus with %d sockets,"
+ " %d cores per socket and %d threads per core"
+ " (cpus != sockets * cores * threads)\n",
+ cpus, sockets, cores, threads);
+ exit(1);
+ }
smp_cpus = cpus;
- smp_cores = cores > 0 ? cores : 1;
- smp_threads = threads > 0 ? threads : 1;
+ smp_cores = cores;
+ smp_threads = threads;
+ max_cpus = qemu_opt_get_number(opts, "maxcpus", 0);
}
if (max_cpus == 0) {
--
1.7.9.5
next reply other threads:[~2013-11-21 14:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-21 14:37 Peter Lieven [this message]
2013-11-22 10:16 ` [Qemu-devel] [PATCH] vl: verify if combination of cpus, sockets, cores and threads is sane Paolo Bonzini
2013-11-22 11:13 ` Peter Lieven
2013-11-22 11:20 ` Paolo Bonzini
2013-11-22 14:43 ` Andreas Färber
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=1385044625-31006-1-git-send-email-pl@kamp.de \
--to=pl@kamp.de \
--cc=aliguori@us.ibm.com \
--cc=pbonzini@redhat.com \
--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).