[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH for-6.2 v3 04/11] machine: Improve the error reporting of smp
From: |
Andrew Jones |
Subject: |
Re: [PATCH for-6.2 v3 04/11] machine: Improve the error reporting of smp parsing |
Date: |
Wed, 28 Jul 2021 22:24:56 +0200 |
On Wed, Jul 28, 2021 at 11:48:41AM +0800, Yanan Wang wrote:
> We have two requirements for a valid SMP configuration:
> the product of "sockets * cores * threads" must represent all the
> possible cpus, i.e., max_cpus, and then must include the initially
> present cpus, i.e., smp_cpus.
>
> So we only need to ensure 1) "sockets * cores * threads == maxcpus"
> at first and then ensure 2) "maxcpus >= cpus". With a reasonable
> order of the sanity check, we can simplify the error reporting code.
> When reporting an error message we also report the exact value of
> each topology member to make users easily see what's going on.
>
> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
> ---
> hw/core/machine.c | 22 +++++++++-------------
> hw/i386/pc.c | 24 ++++++++++--------------
> 2 files changed, 19 insertions(+), 27 deletions(-)
>
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 958e6e7107..e879163c3b 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -777,25 +777,21 @@ static void smp_parse(MachineState *ms,
> SMPConfiguration *config, Error **errp)
> maxcpus = maxcpus > 0 ? maxcpus : sockets * cores * threads;
> cpus = cpus > 0 ? cpus : maxcpus;
>
> - if (sockets * cores * threads < cpus) {
> - error_setg(errp, "cpu topology: "
> - "sockets (%u) * cores (%u) * threads (%u) < "
> - "smp_cpus (%u)",
> - sockets, cores, threads, cpus);
> + if (sockets * cores * threads != maxcpus) {
> + error_setg(errp, "Invalid CPU topology: "
> + "product of the hierarchy must match maxcpus: "
> + "sockets (%u) * cores (%u) * threads (%u) "
> + "!= maxcpus (%u)",
> + sockets, cores, threads, maxcpus);
> return;
> }
>
> if (maxcpus < cpus) {
> - error_setg(errp, "maxcpus must be equal to or greater than smp");
> - return;
> - }
> -
> - if (sockets * cores * threads != maxcpus) {
> error_setg(errp, "Invalid CPU topology: "
> + "maxcpus must be equal to or greater than smp: "
> "sockets (%u) * cores (%u) * threads (%u) "
> - "!= maxcpus (%u)",
> - sockets, cores, threads,
> - maxcpus);
> + "== maxcpus (%u) < smp_cpus (%u)",
> + sockets, cores, threads, maxcpus, cpus);
> return;
> }
>
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index 9ad7ae5254..3e403a7129 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -747,25 +747,21 @@ static void pc_smp_parse(MachineState *ms,
> SMPConfiguration *config, Error **err
> maxcpus = maxcpus > 0 ? maxcpus : sockets * dies * cores * threads;
> cpus = cpus > 0 ? cpus : maxcpus;
>
> - if (sockets * dies * cores * threads < cpus) {
> - error_setg(errp, "cpu topology: "
> - "sockets (%u) * dies (%u) * cores (%u) * threads (%u) < "
> - "smp_cpus (%u)",
> - sockets, dies, cores, threads, cpus);
> + if (sockets * cores * threads != maxcpus) {
> + error_setg(errp, "Invalid CPU topology: "
> + "product of the hierarchy must match maxcpus: "
> + "sockets (%u) * dies (%u) * cores (%u) * threads (%u) "
> + "!= maxcpus (%u)",
> + sockets, dies, cores, threads, maxcpus);
> return;
> }
>
> if (maxcpus < cpus) {
> - error_setg(errp, "maxcpus must be equal to or greater than smp");
> - return;
> - }
> -
> - if (sockets * dies * cores * threads != maxcpus) {
> - error_setg(errp, "Invalid CPU topology deprecated: "
> + error_setg(errp, "Invalid CPU topology: "
> + "maxcpus must be equal to or greater than smp: "
> "sockets (%u) * dies (%u) * cores (%u) * threads (%u) "
> - "!= maxcpus (%u)",
> - sockets, dies, cores, threads,
> - maxcpus);
> + "== maxcpus (%u) < smp_cpus (%u)",
> + sockets, dies, cores, threads, maxcpus, cpus);
> return;
> }
>
> --
> 2.19.1
>
Reviewed-by: Andrew Jones <drjones@redhat.com>
- [PATCH for-6.2 v3 00/11] machine: smp parsing fixes and improvement, Yanan Wang, 2021/07/27
- [PATCH for-6.2 v3 05/11] hw: Add compat machines for 6.2, Yanan Wang, 2021/07/27
- [PATCH for-6.2 v3 01/11] machine: Minor refactor/cleanup for the smp parsers, Yanan Wang, 2021/07/27
- [PATCH for-6.2 v3 08/11] machine: Tweak the order of topology members in struct CpuTopology, Yanan Wang, 2021/07/27
- [PATCH for-6.2 v3 04/11] machine: Improve the error reporting of smp parsing, Yanan Wang, 2021/07/27
- Re: [PATCH for-6.2 v3 04/11] machine: Improve the error reporting of smp parsing,
Andrew Jones <=
- [PATCH for-6.2 v3 02/11] machine: Uniformly use maxcpus to calculate the omitted parameters, Yanan Wang, 2021/07/27
- [PATCH for-6.2 v3 07/11] machine: Use ms instead of global current_machine in sanity-check, Yanan Wang, 2021/07/27
- [PATCH for-6.2 v3 10/11] machine: Remove smp_parse callback from MachineClass, Yanan Wang, 2021/07/27
- [PATCH for-6.2 v3 09/11] machine: Make smp_parse generic enough for all arches, Yanan Wang, 2021/07/27
- [PATCH for-6.2 v3 03/11] machine: Set the value of cpus to match maxcpus if it's omitted, Yanan Wang, 2021/07/27