From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjVNf-0006Ni-Pd for qemu-devel@nongnu.org; Thu, 21 Nov 2013 09:37:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VjVNZ-00083q-Rx for qemu-devel@nongnu.org; Thu, 21 Nov 2013 09:37:19 -0500 Received: from mx.ipv6.kamp.de ([2a02:248:0:51::16]:42971 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VjVNZ-00083V-Gk for qemu-devel@nongnu.org; Thu, 21 Nov 2013 09:37:13 -0500 From: Peter Lieven Date: Thu, 21 Nov 2013 15:37:05 +0100 Message-Id: <1385044625-31006-1-git-send-email-pl@kamp.de> Subject: [Qemu-devel] [PATCH] vl: verify if combination of cpus, sockets, cores and threads is sane List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, aliguori@us.ibm.com, Peter Lieven Signed-off-by: Peter Lieven --- 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