From patchwork Fri Nov 7 16:04:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 408200 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1664A1400B7 for ; Sat, 8 Nov 2014 03:06:46 +1100 (AEDT) Received: from localhost ([::1]:60852 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xmm3g-0000yr-6W for incoming@patchwork.ozlabs.org; Fri, 07 Nov 2014 11:06:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xmm1v-00079v-Qu for qemu-devel@nongnu.org; Fri, 07 Nov 2014 11:05:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xmm1p-0003a0-II for qemu-devel@nongnu.org; Fri, 07 Nov 2014 11:04:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51293) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xmm1p-0003Zl-9s for qemu-devel@nongnu.org; Fri, 07 Nov 2014 11:04:49 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sA7G4maL025766 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 7 Nov 2014 11:04:48 -0500 Received: from hawk.usersys.redhat.com (dhcp-1-153.brq.redhat.com [10.34.1.153]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sA7G4iwB027938; Fri, 7 Nov 2014 11:04:47 -0500 From: Andrew Jones To: qemu-devel@nongnu.org Date: Fri, 7 Nov 2014 17:04:39 +0100 Message-Id: <1415376280-14130-3-git-send-email-drjones@redhat.com> In-Reply-To: <1415376280-14130-1-git-send-email-drjones@redhat.com> References: <1415376280-14130-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, ehabkost@redhat.com Subject: [Qemu-devel] [PATCH 2/3] vl: sanity check cpu topology X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org smp_parse allows partial or complete cpu topology to be given. In either case there may be inconsistencies in the input which are currently not sounding any alarms. In some cases the input is even being silently corrected. We shouldn't do this. Add warnings when input isn't adding up right, and even abort when the complete cpu topology has been input, but isn't correct. Signed-off-by: Andrew Jones --- vl.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/vl.c b/vl.c index 9d9855092ab4a..c62fe29aa8075 100644 --- a/vl.c +++ b/vl.c @@ -1288,16 +1288,35 @@ static void smp_parse(QemuOpts *opts) if (cores == 0) { threads = threads > 0 ? threads : 1; cores = cpus / (sockets * threads); - } else { - threads = cpus / (cores * sockets); + if (cpus % (sockets * threads)) { + fprintf(stderr, "cpu topology: warning: " + "Calculation results in fractional cores number. " + "Adjusting.\n"); + cores += 1; + } + } else if (threads == 0) { + threads = cpus / (sockets * cores); + if (cpus % (sockets * cores)) { + fprintf(stderr, "cpu topology: warning: " + "Calculation results in fractional threads number. " + "Adjusting.\n"); + threads += 1; + } } } + if (sockets * cores * threads < cpus) { + fprintf(stderr, "cpu topology: error: " + "sockets (%u) * cores (%u) * threads (%u) < smp_cpus (%u)\n", + sockets, cores, threads, cpus); + exit(1); + } + max_cpus = qemu_opt_get_number(opts, "maxcpus", 0); smp_cpus = cpus; - smp_cores = cores > 0 ? cores : 1; - smp_threads = threads > 0 ? threads : 1; + smp_cores = cores; + smp_threads = threads; }