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: 40430 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AFD5F218C0 for ; Fri, 7 Nov 2014 16:06:59 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id n3sf2096348wiv.1 for ; Fri, 07 Nov 2014 08:06:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=WmzNCvcJkUDfcFQ+44r2xOgTb2pyBmI41HiMrxEVzbI=; b=l47QTiGb7p1GTBBPOy1nmbFAnK9X1KBUr0ATMXIbT2+3epveAz1x0nc1ni06lS4gTy ktFs/5KXpWoclhxy1511SAht8c2/tV2ZTInM//VVpJmZ+99VA8pHe29DkMjy4u42WU3p 5mZLoQCRvX+42zkWqUILzHd0BsQAA3a8GNKliXA97YKpUDaZgZZMY8bwj+vE8FSN9DCo Mb6+o/VnwRAk+Wo9T8ydVVy7fK/enLPbLh82i2dBajd9ee3QNA+yTKgII4lvjzlqzHGD VbD4fZ82uFjk9OnUYCTtMFGbcnWOCIEkIv+DUEw7vS9mTcoYZvSzttURH7jfuZ0iR23l y5TQ== X-Gm-Message-State: ALoCoQmyylLfa75Bicy+gQx5Sdv5A29RngAhpWLtnaZWqWTGbhWujjUY2CQr+MtxQz5pbhgfY1FB X-Received: by 10.112.89.195 with SMTP id bq3mr2162060lbb.9.1415376419033; Fri, 07 Nov 2014 08:06:59 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.4 with SMTP id x4ls233778lag.42.gmail; Fri, 07 Nov 2014 08:06:58 -0800 (PST) X-Received: by 10.152.120.199 with SMTP id le7mr11826539lab.67.1415376418631; Fri, 07 Nov 2014 08:06:58 -0800 (PST) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id ui10si15581397lbb.62.2014.11.07.08.06.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Nov 2014 08:06:58 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id ge10so4696602lab.36 for ; Fri, 07 Nov 2014 08:06:58 -0800 (PST) X-Received: by 10.152.42.226 with SMTP id r2mr12070834lal.29.1415376418550; Fri, 07 Nov 2014 08:06:58 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp224312lbc; Fri, 7 Nov 2014 08:06:58 -0800 (PST) X-Received: by 10.180.207.77 with SMTP id lu13mr6628545wic.12.1415376417871; Fri, 07 Nov 2014 08:06:57 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id eh5si4369309wic.3.2014.11.07.08.06.56 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 07 Nov 2014 08:06:56 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:60852 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xmm3q-0000yr-Q3 for patch@linaro.org; Fri, 07 Nov 2014 11:06:54 -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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: drjones@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 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; }