qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "wangyanan (Y)" <wangyanan55@huawei.com>
To: Andrew Jones <drjones@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Thomas Huth" <thuth@redhat.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	wanghaibin.wang@huawei.com,
	"Richard Henderson" <richard.henderson@linaro.org>,
	qemu-devel@nongnu.org, "Greg Kurz" <groug@kaod.org>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	yuzenghui@huawei.com, "Paolo Bonzini" <pbonzini@redhat.com>,
	"David Gibson" <david@gibson.dropbear.id.au>
Subject: Re: [PATCH for-6.2 v2 10/11] machine: Split out the smp parsing code
Date: Thu, 22 Jul 2021 14:24:03 +0800	[thread overview]
Message-ID: <d040bdbf-47f5-da25-9aae-8285530a0948@huawei.com> (raw)
In-Reply-To: <20210719172009.yujvlk4mu2xcl25g@gator>

On 2021/7/20 1:20, Andrew Jones wrote:
> On Mon, Jul 19, 2021 at 11:20:42AM +0800, Yanan Wang wrote:
>> We are going to introduce an unit test for the parser smp_parse()
>> in hw/core/machine.c, but now machine.c is only built in softmmu.
>>
>> In order to solve the build dependency on the smp parsing code and
>> avoid building unrelated stuff for the unit tests, move the related
>> code from machine.c into a new common file, i.e., machine-smp.c.
>>
>> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
>> ---
>>   MAINTAINERS           |   1 +
>>   hw/core/machine-smp.c | 124 ++++++++++++++++++++++++++++++++++++++++++
>>   hw/core/machine.c     | 109 -------------------------------------
>>   hw/core/meson.build   |   1 +
>>   include/hw/boards.h   |   1 +
>>   5 files changed, 127 insertions(+), 109 deletions(-)
>>   create mode 100644 hw/core/machine-smp.c
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 9100f9a043..70633e3bf4 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -1626,6 +1626,7 @@ F: cpu.c
>>   F: hw/core/cpu.c
>>   F: hw/core/machine-qmp-cmds.c
>>   F: hw/core/machine.c
>> +F: hw/core/machine-smp.c
>>   F: hw/core/null-machine.c
>>   F: hw/core/numa.c
>>   F: hw/cpu/cluster.c
>> diff --git a/hw/core/machine-smp.c b/hw/core/machine-smp.c
>> new file mode 100644
>> index 0000000000..6a00cfe44a
>> --- /dev/null
>> +++ b/hw/core/machine-smp.c
>> @@ -0,0 +1,124 @@
>> +/*
>> + * QEMU Machine (related to SMP configuration)
>> + *
>> + * Copyright (C) 2014 Red Hat Inc
>> + *
>> + * Authors:
>> + *   Marcel Apfelbaum <marcel.a@redhat.com>
> This header was obviously copy+pasted without being updated.
Yes, the header was kept unchanged.

But actually I'm not completely sure which field should be updated. :)
Should I add "Copyright (C) 2021, Huawei, Inc." and also the authorship
"Yanan Wang <wangyanan55@huawei.com>" behind the existing ones
or just replace them?
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
>> + * See the COPYING file in the top-level directory.
>> + */
>> +
>> +#include "qemu/osdep.h"
>> +#include "hw/boards.h"
>> +#include "qapi/error.h"
>> +
>> +/*
>> + * smp_parse - Generic function used to parse the given SMP configuration
>> + *
>> + * The topology parameters must be specified equal to or great than one
>> + * or just omitted, explicit configuration like "cpus=0" is not allowed.
>> + * The omitted parameters will be calculated based on the provided ones.
>> + *
>> + * maxcpus will default to the value of cpus if omitted and will be used
>> + * to compute the missing sockets/cores/threads. cpus will be calculated
>> + * from the computed parametrs if omitted.
>> + *
>> + * In calculation of omitted arch-netural sockets/cores/threads, we prefer
>> + * sockets over cores over threads before 6.2, while prefer cores over
>> + * sockets over threads since 6.2 on. The arch-specific dies will directly
>> + * default to 1 if omitted.
>> + */
>> +void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp)
>> +{
>> +    MachineClass *mc = MACHINE_GET_CLASS(ms);
>> +    unsigned cpus    = config->has_cpus ? config->cpus : 0;
>> +    unsigned sockets = config->has_sockets ? config->sockets : 0;
>> +    unsigned dies    = config->has_dies ? config->dies : 1;
>> +    unsigned cores   = config->has_cores ? config->cores : 0;
>> +    unsigned threads = config->has_threads ? config->threads : 0;
>> +    unsigned maxcpus = config->has_maxcpus ? config->maxcpus : 0;
>> +
>> +    if ((config->has_cpus && config->cpus == 0) ||
>> +        (config->has_sockets && config->sockets == 0) ||
>> +        (config->has_dies && config->dies == 0) ||
>> +        (config->has_cores && config->cores == 0) ||
>> +        (config->has_threads && config->threads == 0) ||
>> +        (config->has_maxcpus && config->maxcpus == 0)) {
>> +        error_setg(errp, "parameters must be equal to or greater than one"
>> +                   "if provided");
>> +        return;
>> +    }
>> +
>> +    if (!mc->smp_dies_supported && dies > 1) {
>> +        error_setg(errp, "dies not supported by this machine's CPU topology");
>> +        return;
>> +    }
>> +
>> +    maxcpus = maxcpus > 0 ? maxcpus : cpus;
>> +
>> +    /* prefer sockets over cores over threads before 6.2 */
>> +    if (mc->smp_prefer_sockets) {
>> +        if (sockets == 0) {
>> +            cores = cores > 0 ? cores : 1;
>> +            threads = threads > 0 ? threads : 1;
>> +            sockets = maxcpus / (dies * cores * threads);
>> +            sockets = sockets > 0 ? sockets : 1;
>> +        } else if (cores == 0) {
>> +            threads = threads > 0 ? threads : 1;
>> +            cores = maxcpus / (sockets * dies * threads);
>> +            cores = cores > 0 ? cores : 1;
>> +        } else if (threads == 0) {
>> +            threads = maxcpus / (sockets * dies * cores);
>> +            threads = threads > 0 ? threads : 1;
>> +        }
>> +    /* prefer cores over sockets over threads since 6.2 */
>> +    } else {
>> +        if (cores == 0) {
>> +            sockets = sockets > 0 ? sockets : 1;
>> +            threads = threads > 0 ? threads : 1;
>> +            cores = maxcpus / (sockets * dies * threads);
>> +            cores = cores > 0 ? cores : 1;
>> +        } else if (sockets == 0) {
>> +            threads = threads > 0 ? threads : 1;
>> +            sockets = maxcpus / (dies * cores * threads);
>> +            sockets = sockets > 0 ? sockets : 1;
>> +        } else if (threads == 0) {
>> +            threads = maxcpus / (sockets * dies * cores);
>> +            threads = threads > 0 ? threads : 1;
>> +        }
>> +    }
>> +
>> +    /* use the computed parameters to calculate the omitted cpus */
>> +    cpus = cpus > 0 ? cpus : sockets * dies * cores * threads;
>> +    maxcpus = maxcpus > 0 ? maxcpus : cpus;
>> +
>> +    if (sockets * dies * cores * threads != maxcpus) {
>> +        g_autofree char *dies_msg = g_strdup_printf(
>> +            mc->smp_dies_supported ? " * dies (%u)" : "", dies);
>> +        error_setg(errp, "Invalid CPU topology: "
>> +                   "sockets (%u)%s * cores (%u) * threads (%u) "
>> +                   "!= maxcpus (%u)",
>> +                   sockets, dies_msg, cores, threads,
>> +                   maxcpus);
>> +        return;
>> +    }
>> +
>> +    if (sockets * dies * cores * threads < cpus) {
>> +        g_autofree char *dies_msg = g_strdup_printf(
>> +            mc->smp_dies_supported ? " * dies (%u)" : "", dies);
>> +        error_setg(errp, "Invalid CPU topology: "
>> +                   "sockets (%u)%s * cores (%u) * threads (%u) < "
>> +                   "smp_cpus (%u)",
>> +                   sockets, dies_msg, cores, threads, cpus);
>> +        return;
>> +    }
>> +
>> +    ms->smp.cpus = cpus;
>> +    ms->smp.sockets = sockets;
>> +    ms->smp.dies = dies;
>> +    ms->smp.cores = cores;
>> +    ms->smp.threads = threads;
>> +    ms->smp.max_cpus = maxcpus;
>> +}
>> diff --git a/hw/core/machine.c b/hw/core/machine.c
>> index 9d24b67ef3..61be266b6c 100644
>> --- a/hw/core/machine.c
>> +++ b/hw/core/machine.c
>> @@ -744,115 +744,6 @@ void machine_set_cpu_numa_node(MachineState *machine,
>>       }
>>   }
>>   
>> -/*
>> - * smp_parse - Generic function used to parse the given SMP configuration
>> - *
>> - * The topology parameters must be specified equal to or great than one
>> - * or just omitted, explicit configuration like "cpus=0" is not allowed.
>> - * The omitted parameters will be calculated based on the provided ones.
>> - *
>> - * maxcpus will default to the value of cpus if omitted and will be used
>> - * to compute the missing sockets/cores/threads. cpus will be calculated
>> - * from the computed parametrs if omitted.
>> - *
>> - * In calculation of omitted arch-netural sockets/cores/threads, we prefer
>> - * sockets over cores over threads before 6.2, while prefer cores over
>> - * sockets over threads since 6.2 on. The arch-specific dies will directly
>> - * default to 1 if omitted.
>> - */
>> -static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp)
>> -{
>> -    MachineClass *mc = MACHINE_GET_CLASS(ms);
>> -    unsigned cpus    = config->has_cpus ? config->cpus : 0;
>> -    unsigned sockets = config->has_sockets ? config->sockets : 0;
>> -    unsigned dies    = config->has_dies ? config->dies : 1;
>> -    unsigned cores   = config->has_cores ? config->cores : 0;
>> -    unsigned threads = config->has_threads ? config->threads : 0;
>> -    unsigned maxcpus = config->has_maxcpus ? config->maxcpus : 0;
>> -
>> -    if ((config->has_cpus && config->cpus == 0) ||
>> -        (config->has_sockets && config->sockets == 0) ||
>> -        (config->has_dies && config->dies == 0) ||
>> -        (config->has_cores && config->cores == 0) ||
>> -        (config->has_threads && config->threads == 0) ||
>> -        (config->has_maxcpus && config->maxcpus == 0)) {
>> -        error_setg(errp, "parameters must be equal to or greater than one"
>> -                   "if provided");
>> -        return;
>> -    }
>> -
>> -    if (!mc->smp_dies_supported && dies > 1) {
>> -        error_setg(errp, "dies not supported by this machine's CPU topology");
>> -        return;
>> -    }
>> -
>> -    maxcpus = maxcpus > 0 ? maxcpus : cpus;
>> -
>> -    /* prefer sockets over cores over threads before 6.2 */
>> -    if (mc->smp_prefer_sockets) {
>> -        if (sockets == 0) {
>> -            cores = cores > 0 ? cores : 1;
>> -            threads = threads > 0 ? threads : 1;
>> -            sockets = maxcpus / (dies * cores * threads);
>> -            sockets = sockets > 0 ? sockets : 1;
>> -        } else if (cores == 0) {
>> -            threads = threads > 0 ? threads : 1;
>> -            cores = maxcpus / (sockets * dies * threads);
>> -            cores = cores > 0 ? cores : 1;
>> -        } else if (threads == 0) {
>> -            threads = maxcpus / (sockets * dies * cores);
>> -            threads = threads > 0 ? threads : 1;
>> -        }
>> -    /* prefer cores over sockets over threads since 6.2 */
>> -    } else {
>> -        if (cores == 0) {
>> -            sockets = sockets > 0 ? sockets : 1;
>> -            threads = threads > 0 ? threads : 1;
>> -            cores = maxcpus / (sockets * dies * threads);
>> -            cores = cores > 0 ? cores : 1;
>> -        } else if (sockets == 0) {
>> -            threads = threads > 0 ? threads : 1;
>> -            sockets = maxcpus / (dies * cores * threads);
>> -            sockets = sockets > 0 ? sockets : 1;
>> -        } else if (threads == 0) {
>> -            threads = maxcpus / (sockets * dies * cores);
>> -            threads = threads > 0 ? threads : 1;
>> -        }
>> -    }
>> -
>> -    /* use the computed parameters to calculate the omitted cpus */
>> -    cpus = cpus > 0 ? cpus : sockets * dies * cores * threads;
>> -    maxcpus = maxcpus > 0 ? maxcpus : cpus;
>> -
>> -    if (sockets * dies * cores * threads != maxcpus) {
>> -        g_autofree char *dies_msg = g_strdup_printf(
>> -            mc->smp_dies_supported ? " * dies (%u)" : "", dies);
>> -        error_setg(errp, "Invalid CPU topology: "
>> -                   "sockets (%u)%s * cores (%u) * threads (%u) "
>> -                   "!= maxcpus (%u)",
>> -                   sockets, dies_msg, cores, threads,
>> -                   maxcpus);
>> -        return;
>> -    }
>> -
>> -    if (sockets * dies * cores * threads < cpus) {
>> -        g_autofree char *dies_msg = g_strdup_printf(
>> -            mc->smp_dies_supported ? " * dies (%u)" : "", dies);
>> -        error_setg(errp, "Invalid CPU topology: "
>> -                   "sockets (%u)%s * cores (%u) * threads (%u) < "
>> -                   "smp_cpus (%u)",
>> -                   sockets, dies_msg, cores, threads, cpus);
>> -        return;
>> -    }
>> -
>> -    ms->smp.cpus = cpus;
>> -    ms->smp.sockets = sockets;
>> -    ms->smp.dies = dies;
>> -    ms->smp.cores = cores;
>> -    ms->smp.threads = threads;
>> -    ms->smp.max_cpus = maxcpus;
>> -}
>> -
>>   static void machine_get_smp(Object *obj, Visitor *v, const char *name,
>>                               void *opaque, Error **errp)
>>   {
>> diff --git a/hw/core/meson.build b/hw/core/meson.build
>> index 18f44fb7c2..6d727c7742 100644
>> --- a/hw/core/meson.build
>> +++ b/hw/core/meson.build
>> @@ -14,6 +14,7 @@ hwcore_files = files(
>>   )
>>   
>>   common_ss.add(files('cpu-common.c'))
>> +common_ss.add(files('machine-smp.c'))
>>   common_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c'))
>>   common_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: files('generic-loader.c'))
>>   common_ss.add(when: ['CONFIG_GUEST_LOADER', fdt], if_true: files('guest-loader.c'))
>> diff --git a/include/hw/boards.h b/include/hw/boards.h
>> index 12ab0f5968..071eec1e74 100644
>> --- a/include/hw/boards.h
>> +++ b/include/hw/boards.h
>> @@ -34,6 +34,7 @@ HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
>>   void machine_set_cpu_numa_node(MachineState *machine,
>>                                  const CpuInstanceProperties *props,
>>                                  Error **errp);
>> +void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp);
>>   
>>   /**
>>    * machine_class_allow_dynamic_sysbus_dev: Add type to list of valid devices
>> -- 
>> 2.19.1
>>
> Otherwise
>
> Reviewed-by: Andrew Jones <drjones@redhat.com>
>
Thanks,
Yanan
.



  reply	other threads:[~2021-07-22  6:24 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-19  3:20 [PATCH for-6.2 v2 00/11] machine: smp parsing fixes and improvement Yanan Wang
2021-07-19  3:20 ` [PATCH for-6.2 v2 01/11] machine: Disallow specifying topology parameters as zero Yanan Wang
2021-07-19 16:11   ` Andrew Jones
2021-07-21 12:34     ` wangyanan (Y)
2021-07-19 16:46   ` Daniel P. Berrangé
2021-07-21 12:35     ` wangyanan (Y)
2021-07-19  3:20 ` [PATCH for-6.2 v2 02/11] machine: Make smp_parse generic enough for all arches Yanan Wang
2021-07-19 16:28   ` Andrew Jones
2021-07-19 16:36     ` Daniel P. Berrangé
2021-07-19 16:48       ` Andrew Jones
2021-07-19 16:50         ` Daniel P. Berrangé
2021-07-19 16:53   ` Daniel P. Berrangé
2021-07-22  7:18     ` wangyanan (Y)
2021-07-20  6:57   ` Cornelia Huck
2021-07-22  7:12     ` wangyanan (Y)
2021-07-19  3:20 ` [PATCH for-6.2 v2 03/11] machine: Uniformly use maxcpus to calculate the omitted parameters Yanan Wang
2021-07-19 16:36   ` Andrew Jones
2021-07-22  3:00     ` wangyanan (Y)
2021-07-19  3:20 ` [PATCH for-6.2 v2 04/11] machine: Use the computed parameters to calculate omitted cpus Yanan Wang
2021-07-19 16:42   ` Andrew Jones
2021-07-22  4:42     ` wangyanan (Y)
2021-07-22 12:27       ` Andrew Jones
2021-07-22 14:59         ` wangyanan (Y)
2021-07-22 15:05           ` Andrew Jones
2021-07-22 15:45             ` wangyanan (Y)
2021-07-19  3:20 ` [PATCH for-6.2 v2 05/11] machine: Improve the error reporting of smp parsing Yanan Wang
2021-07-19 16:53   ` Andrew Jones
2021-07-22  8:10     ` wangyanan (Y)
2021-07-22 12:47       ` Andrew Jones
2021-07-19  3:20 ` [PATCH for-6.2 v2 06/11] hw: Add compat machines for 6.2 Yanan Wang
2021-07-19  3:38   ` David Gibson
2021-07-19 17:00   ` Andrew Jones
2021-07-19 17:03   ` Cornelia Huck
2021-07-19 23:45   ` Pankaj Gupta
2021-07-19  3:20 ` [PATCH for-6.2 v2 07/11] machine: Prefer cores over sockets in smp parsing since 6.2 Yanan Wang
2021-07-19  3:40   ` David Gibson
2021-07-22  5:22     ` wangyanan (Y)
2021-07-19 17:13   ` Andrew Jones
2021-07-22  5:32     ` wangyanan (Y)
2021-07-19  3:20 ` [PATCH for-6.2 v2 08/11] machine: Use ms instead of global current_machine in sanity-check Yanan Wang
2021-07-19 17:14   ` Andrew Jones
2021-07-19  3:20 ` [PATCH for-6.2 v2 09/11] machine: Tweak the order of topology members in struct CpuTopology Yanan Wang
2021-07-19  3:20 ` [PATCH for-6.2 v2 10/11] machine: Split out the smp parsing code Yanan Wang
2021-07-19 17:20   ` Andrew Jones
2021-07-22  6:24     ` wangyanan (Y) [this message]
2021-07-22 13:07       ` Andrew Jones
2021-07-22 14:29         ` wangyanan (Y)
2021-07-19  3:20 ` [PATCH for-6.2 v2 11/11] tests/unit: Add a unit test for smp parsing Yanan Wang
2021-07-19 18:57   ` Andrew Jones
2021-07-22  6:15     ` wangyanan (Y)
2021-07-22 13:12       ` Andrew Jones
2021-07-22 14:18         ` wangyanan (Y)
2021-07-19 16:57 ` [PATCH for-6.2 v2 00/11] machine: smp parsing fixes and improvement Cornelia Huck
2021-07-21 12:38   ` wangyanan (Y)
2021-07-21 13:52     ` Pankaj Gupta
2021-07-22  2:22       ` wangyanan (Y)
2021-07-22  7:51     ` Pierre Morel
2021-07-22  8:32       ` wangyanan (Y)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d040bdbf-47f5-da25-9aae-8285530a0948@huawei.com \
    --to=wangyanan55@huawei.com \
    --cc=berrange@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=drjones@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=groug@kaod.org \
    --cc=imammedo@redhat.com \
    --cc=mst@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    --cc=wanghaibin.wang@huawei.com \
    --cc=yuzenghui@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).