From patchwork Thu Nov 6 16:09:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 40355 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B336724687 for ; Thu, 6 Nov 2014 16:13:29 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id f15sf881582lbj.7 for ; Thu, 06 Nov 2014 08:13:28 -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: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=biYFOuMaC/ZoBJbzbep4IM4rdJmk7Rz2EBgt+Y+YUN0=; b=ed1q9apZAT5I7Rzv7Ry+9HKVx+aQRHf43Vo2kXwqlNNYg/zvm2Jf2YiXmH6W31maNu jgJoOXeaZc3k3YVObtb67K4A2UwdwZLD4rzG8rAbUXDsne/NfFBNh66qwRXP9anhgfVP rwSX9Oix9cDL6hAwSHZW2Da5b3lxKSC/lhi8WREbcMua2toriUM4jQGYXKZZC7Vld2Xm QYrJtmAHoFqUTN61x4UAIgNdqxB5Jn9VzX6bh1LfVxO5aKLDmK486difgvnz3wDxaeIh oj0GhAf5aVLtZCa+roO7PiJLAjeNWjPdDhSSEeQLbeP5ixyS3SgRSO3NDResljRaHwhN eTwg== X-Gm-Message-State: ALoCoQldM8567UJZULIuz4knJWz8IVcZX7sjBT7NEW2oIrIWp2XvhoA7EX3UiNeBOh6814whNXju X-Received: by 10.112.142.36 with SMTP id rt4mr877458lbb.3.1415290408413; Thu, 06 Nov 2014 08:13:28 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.205.108 with SMTP id lf12ls87758lac.48.gmail; Thu, 06 Nov 2014 08:13:27 -0800 (PST) X-Received: by 10.152.45.1 with SMTP id i1mr5916478lam.7.1415290407904; Thu, 06 Nov 2014 08:13:27 -0800 (PST) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id ac4si12085590lbc.5.2014.11.06.08.13.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Nov 2014 08:13:27 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id gq15so2916274lab.15 for ; Thu, 06 Nov 2014 08:13:27 -0800 (PST) X-Received: by 10.112.52.37 with SMTP id q5mr5929550lbo.32.1415290407776; Thu, 06 Nov 2014 08:13:27 -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 ew9csp68571lbc; Thu, 6 Nov 2014 08:13:27 -0800 (PST) X-Received: by 10.224.21.133 with SMTP id j5mr8228690qab.51.1415290406423; Thu, 06 Nov 2014 08:13:26 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b97si1610740qga.118.2014.11.06.08.13.25 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 06 Nov 2014 08:13:26 -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]:54763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmPgb-0006sc-HI for patch@linaro.org; Thu, 06 Nov 2014 11:13:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmPd8-0005yi-5e for qemu-devel@nongnu.org; Thu, 06 Nov 2014 11:09:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XmPd0-0002aC-Nu for qemu-devel@nongnu.org; Thu, 06 Nov 2014 11:09:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46967) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmPd0-0002a2-Gv for qemu-devel@nongnu.org; Thu, 06 Nov 2014 11:09:42 -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 sA6G9fji011095 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 6 Nov 2014 11:09:41 -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 sA6G9dGo004333; Thu, 6 Nov 2014 11:09:40 -0500 From: Andrew Jones To: qemu-devel@nongnu.org Date: Thu, 6 Nov 2014 17:09:35 +0100 Message-Id: <1415290175-17314-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: ehabkost@redhat.com Subject: [Qemu-devel] [PATCH] vl: rework smp_parse 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.42 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 has a couple problems. First, it should use max_cpus, not smp_cpus when calculating missing topology information. Conversely, if maxcpus is not input, then the topology should dictate max_cpus, as the topology may support more than the input smp_cpus number. Second, smp_parse shouldn't silently adjust the number of threads a user provides, which it currently does in order to ensure the topology supports the number of cpus provided. smp_parse should rather complain and exit when input isn't consistent. This patch fixes those issues and attempts to clarify the code a bit too. I don't believe we need to consider compatibility with the old behaviors. Specifying something like -smp 4,sockets=1,cores=1,threads=1 is wrong, even though it currently works (the number of threads is silently adjusted to 4). And, specifying something like -smp 4,sockets=1,cores=4,threads=1,maxcpus=8 is also wrong, as there's no way to hotplug the additional 4 cpus with this topology. So, any users doing these things should be corrected. The new error message this patch provides should help them do that. Below are some examples with before/after results // topology should support up to max_cpus < -smp 4,sockets=2,maxcpus=8 sockets=2 cores=2 threads=1 smp_cpus=4 max_cpus=8 > -smp 4,sockets=2,maxcpus=8 sockets=2 cores=4 threads=1 smp_cpus=4 max_cpus=8 // topology supports more than smp_cpus, max_cpus should be higher < -smp 4,sockets=4,cores=2 sockets=4 cores=2 threads=1 smp_cpus=4 max_cpus=4 > -smp 4,sockets=4,cores=2 sockets=4 cores=2 threads=1 smp_cpus=4 max_cpus=8 // shouldn't silently adjust threads < -smp 4,sockets=1,cores=2,threads=1 sockets=1 cores=2 threads=2 smp_cpus=4 max_cpus=4 > -smp 4,sockets=1,cores=2,threads=1 "maxcpus must be equal to or greater than smp" < -smp 4,sockets=2,cores=2,threads=4,maxcpus=8 sockets=2 cores=2 threads=1 smp_cpus=4 max_cpus=8 > -smp 4,sockets=2,cores=2,threads=4,maxcpus=8 "cpu topology: sockets (2) * cores (2) * threads (4) != max_cpus (8)" Signed-off-by: Andrew Jones --- vl.c | 59 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/vl.c b/vl.c index f4a6e5e05bce2..23b21a5fbca50 100644 --- a/vl.c +++ b/vl.c @@ -1270,35 +1270,52 @@ 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); + unsigned cpus; + + smp_cpus = qemu_opt_get_number(opts, "cpus", 0); + max_cpus = qemu_opt_get_number(opts, "maxcpus", 0); + + cpus = max_cpus ? max_cpus : smp_cpus; /* compute missing values, prefer sockets over cores over threads */ - if (cpus == 0 || sockets == 0) { - sockets = sockets > 0 ? sockets : 1; - cores = cores > 0 ? cores : 1; - threads = threads > 0 ? threads : 1; - if (cpus == 0) { - cpus = cores * threads * sockets; - } - } else { - if (cores == 0) { - threads = threads > 0 ? threads : 1; - cores = cpus / (sockets * threads); - } else { - threads = cpus / (cores * sockets); - } + if (cpus == 0) { + cpus = sockets ? sockets : 1; + cpus = cpus * cores ? cpus * cores : cpus; + cpus = cpus * threads ? cpus * threads : cpus; } - max_cpus = qemu_opt_get_number(opts, "maxcpus", 0); + if (sockets == 0) { + sockets = 1; + } - smp_cpus = cpus; - smp_cores = cores > 0 ? cores : 1; - smp_threads = threads > 0 ? threads : 1; + if (cores == 0) { + threads = threads ? threads : 1; + cores = cpus / (sockets * threads); + cores = cores ? cores : 1; + } + + if (threads == 0) { + threads = cpus / (sockets * cores); + threads = threads ? threads : 1; + } + + if (max_cpus == 0) { + max_cpus = sockets * cores * threads; + } + if (sockets * cores * threads != max_cpus) { + fprintf(stderr, "cpu topology: " + "sockets (%u) * cores (%u) * threads (%u) != max_cpus (%u)\n", + sockets, cores, threads, max_cpus); + exit(1); + } + + smp_cpus = smp_cpus ? smp_cpus : max_cpus; + smp_cores = cores; + smp_threads = threads; } if (max_cpus == 0) { @@ -1309,11 +1326,11 @@ static void smp_parse(QemuOpts *opts) 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 realtime_init(void)