Received: by 2002:a19:ee0d:0:0:0:0:0 with SMTP id g13csp1213494lfb; Wed, 28 Apr 2021 19:14:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywmgtclWCMMZHh3uJVahITxGa1HhZHQe2Z1W35xUxfzyD2PQgduMf+WmrbkjNHemT3j5Gw X-Received: by 2002:a5d:81c8:: with SMTP id t8mr26698448iol.19.1619662497460; Wed, 28 Apr 2021 19:14:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619662497; cv=none; d=google.com; s=arc-20160816; b=UfDzZA0P9l74BJeHJ1Coj6B5Z3WqBCY8fMIfzfeA1TbfewIzTWgJgLnczmo93a2Ib8 JXQAy1bW2oD1DrtDZN61pCpJSmjhJH5HY6kdafrIdz5t8RWIxILFS9EHBF5KhpX3UtMT M5Lk6S+iEAQ30JgNC1kobKFdfXFRT87AJp9NcB4by6Z5fskzFHoLgd5DEL93VHLb1LQF tHXJ8d6XruvkAsgjtXAFRPQAhWoCQ+6wDh1lQDhYljFrSFlr73M6Jyf64f2Sg0vCs9hR 2OUSaa+KVp71IO+H0YkuV5+ohmeppMbA19VP2CEL/OxvJj39jgGMcA3mwBUBNmuKcdFb QPYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=iRs+fxuvdinuiRytCUyamiXp6Qv6q/Y4ON2EO+UIJ2c=; b=E+Hw3y8zzD2/onjbjvfWbuq0UYVyA64CKsYBGXL33EG+jInG0sR3BLkr1TFrsZ8V90 QRDgiMxVEOFt0Spq/5nYqfupy9wD2tctGxjKl8WpzESLnHqHm0uYtiTpU6zeS3VlGH9Z ioepFqNHYDGyEg7r6JMQ4IeUzcKIITBckRALclVnz2k+HL9BIcOiq34Xiox3+H4el+Se cdkh6VYz5Qz+pqUwxiwq57FgcoiHXn6/a3t2SKnthmF4ugduakcjJdLOkfcNObmgXIfT lFEAZGXntG0rFKFk9/+/cnHsA9/jyRWho5070jiVmIlLYpMzt7p/Nd0hhHVPis4Kw4j8 EyAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s4si2136914ilv.29.2021.04.28.19.14.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Apr 2021 19:14:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: from localhost ([::1]:60022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lbwCe-0006CL-OS for alex.bennee@linaro.org; Wed, 28 Apr 2021 22:14:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbwCV-0006C8-Vx; Wed, 28 Apr 2021 22:14:48 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2976) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lbwCS-0005YY-Of; Wed, 28 Apr 2021 22:14:47 -0400 Received: from dggeml757-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4FVzXj1lMLzYbhZ; Thu, 29 Apr 2021 10:12:21 +0800 (CST) Received: from dggpemm500023.china.huawei.com (7.185.36.83) by dggeml757-chm.china.huawei.com (10.1.199.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 29 Apr 2021 10:14:38 +0800 Received: from [10.174.187.128] (10.174.187.128) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Thu, 29 Apr 2021 10:14:37 +0800 Subject: Re: [RFC PATCH v2 2/4] hw/arm/virt: Parse -smp cluster parameter in virt_smp_parse To: Andrew Jones References: <20210413083147.34236-1-wangyanan55@huawei.com> <20210413083147.34236-3-wangyanan55@huawei.com> <20210428103141.5qfhzcqko6hxhxee@gator> From: "wangyanan (Y)" Message-ID: <262dba57-437c-36aa-7a86-8f0c59751887@huawei.com> Date: Thu, 29 Apr 2021 10:14:37 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <20210428103141.5qfhzcqko6hxhxee@gator> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.174.187.128] X-ClientProxiedBy: dggeme701-chm.china.huawei.com (10.1.199.97) To dggpemm500023.china.huawei.com (7.185.36.83) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.187; envelope-from=wangyanan55@huawei.com; helo=szxga01-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Barry Song , Peter Maydell , "Michael S . Tsirkin" , wanghaibin.wang@huawei.com, qemu-devel@nongnu.org, yangyicong@huawei.com, Shannon Zhao , qemu-arm@nongnu.org, Alistair Francis , prime.zeng@hisilicon.com, Igor Mammedov , yuzenghui@huawei.com, Paolo Bonzini , zhukeqian1@huawei.com, Jiajie Li , David Gibson Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: hEEgD7fLw2VO Hi Drew, On 2021/4/28 18:31, Andrew Jones wrote: > On Tue, Apr 13, 2021 at 04:31:45PM +0800, Yanan Wang wrote: >> There is a separate function virt_smp_parse() in hw/virt/arm.c used >> to parse cpu topology for the ARM machines. So add parsing of -smp >> cluster parameter in it, then total number of logical cpus will be >> calculated like: max_cpus = sockets * clusters * cores * threads. >> >> In virt_smp_parse(), the computing logic of missing values prefers >> cores over sockets over threads. And for compatibility, the value >> of clusters will be set as default 1 if not explicitly specified. >> >> Signed-off-by: Yanan Wang >> --- >> hw/arm/virt.c | 32 ++++++++++++++++++-------------- >> 1 file changed, 18 insertions(+), 14 deletions(-) >> >> diff --git a/hw/arm/virt.c b/hw/arm/virt.c >> index 57ef961cb5..51797628db 100644 >> --- a/hw/arm/virt.c >> +++ b/hw/arm/virt.c >> @@ -2639,35 +2639,38 @@ static void virt_smp_parse(MachineState *ms, QemuOpts *opts) >> if (opts) { >> unsigned cpus = qemu_opt_get_number(opts, "cpus", 0); >> unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); >> + unsigned clusters = qemu_opt_get_number(opts, "clusters", 1); >> unsigned cores = qemu_opt_get_number(opts, "cores", 0); >> unsigned threads = qemu_opt_get_number(opts, "threads", 0); >> + VirtMachineState *vms = VIRT_MACHINE(ms); >> >> /* >> - * Compute missing values; prefer cores over sockets and >> - * sockets over threads. >> + * Compute missing values; prefer cores over sockets and sockets >> + * over threads. For compatibility, value of clusters will have >> + * been set as default 1 if not explicitly specified. >> */ >> if (cpus == 0 || cores == 0) { >> sockets = sockets > 0 ? sockets : 1; >> threads = threads > 0 ? threads : 1; >> if (cpus == 0) { >> cores = cores > 0 ? cores : 1; >> - cpus = cores * threads * sockets; >> + cpus = sockets * clusters * cores * threads; >> } else { >> ms->smp.max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus); >> - cores = ms->smp.max_cpus / (sockets * threads); >> + cores = ms->smp.max_cpus / (sockets * clusters * threads); >> } >> } else if (sockets == 0) { >> threads = threads > 0 ? threads : 1; >> - sockets = cpus / (cores * threads); >> + sockets = cpus / (clusters * cores * threads); >> sockets = sockets > 0 ? sockets : 1; > If we initialize clusters to zero instead of one and add lines in > 'cpus == 0 || cores == 0' and 'sockets == 0' like > 'clusters = clusters > 0 ? clusters : 1' as needed, then I think we can > add > > } else if (clusters == 0) { > threads = threads > 0 ? threads : 1; > clusters = cpus / (sockets * cores * thread); > clusters = clusters > 0 ? clusters : 1; > } > > here. I have thought about this kind of format before, but there is a little bit difference between these two ways. Let's chose the better and more reasonable one of the two. Way A currently in this patch: If value of clusters is not explicitly specified in -smp command line, we assume that users don't want to support clusters, for compatibility we initialized the value to 1. So that with cmdline "-smp cpus=24, sockets=2, cores=6", we will parse out the topology description like below: cpus=24, sockets=2, clusters=1, cores=6, threads=2 Way B that you suggested for this patch: Whether value of clusters is explicitly specified in -smp command line or not, we assume that clusters are supported and calculate the value. So that with cmdline "-smp cpus=24, sockets=2, cores=6", we will parse out the topology description like below: cpus =24, sockets=2, clusters=2, cores=6, threads=1 But I think maybe we should not assume too much about what users think through the -smp command line. We should just assume that all levels of cpu topology are supported and calculate them, and users should be more careful if they want to get the expected results with not so complete cmdline. If I'm right, then Way B should be better. :) Thanks, Yanan >> } else if (threads == 0) { >> - threads = cpus / (cores * sockets); >> + threads = cpus / (sockets * clusters * cores); >> threads = threads > 0 ? threads : 1; >> - } else if (sockets * cores * threads < cpus) { >> + } else if (sockets * clusters * cores * threads < cpus) { >> error_report("cpu topology: " >> - "sockets (%u) * cores (%u) * threads (%u) < " >> - "smp_cpus (%u)", >> - sockets, cores, threads, cpus); >> + "sockets (%u) * clusters (%u) * cores (%u) * " >> + "threads (%u) < smp_cpus (%u)", >> + sockets, clusters, cores, threads, cpus); >> exit(1); >> } >> >> @@ -2678,11 +2681,11 @@ static void virt_smp_parse(MachineState *ms, QemuOpts *opts) >> exit(1); >> } >> >> - if (sockets * cores * threads != ms->smp.max_cpus) { >> + if (sockets * clusters * cores * threads != ms->smp.max_cpus) { >> error_report("cpu topology: " >> - "sockets (%u) * cores (%u) * threads (%u)" >> - "!= maxcpus (%u)", >> - sockets, cores, threads, >> + "sockets (%u) * clusters (%u) * cores (%u) * " >> + "threads (%u) != maxcpus (%u)", >> + sockets, clusters, cores, threads, >> ms->smp.max_cpus); >> exit(1); >> } >> @@ -2691,6 +2694,7 @@ static void virt_smp_parse(MachineState *ms, QemuOpts *opts) >> ms->smp.cores = cores; >> ms->smp.threads = threads; >> ms->smp.sockets = sockets; >> + vms->smp_clusters = clusters; >> } >> >> if (ms->smp.cpus > 1) { >> -- >> 2.19.1 >> > Thanks, > drew > > .