qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Andrew Jones <drjones@redhat.com>
Cc: Shannon Zhao <zhaoshenglong@huawei.com>,
	peter.maydell@linaro.org, david.daney@cavium.com,
	peter.huangpeng@huawei.com, qemu-devel@nongnu.org,
	qemu-arm@nongnu.org, shannon.zhao@linaro.org
Subject: Re: [Qemu-devel] [PATCH v5 5/5] hw/arm/virt-acpi-build: Generate SRAT table
Date: Mon, 25 Apr 2016 12:44:55 +0200	[thread overview]
Message-ID: <20160425124455.43eee760@nial.brq.redhat.com> (raw)
In-Reply-To: <20160422132605.gjyuda3magcoktyf@hawk.localdomain>

On Fri, 22 Apr 2016 15:26:05 +0200
Andrew Jones <drjones@redhat.com> wrote:

> On Thu, Apr 21, 2016 at 02:23:54PM +0800, Shannon Zhao wrote:
> > From: Shannon Zhao <shannon.zhao@linaro.org>
> > 
> > To support NUMA, it needs to generate SRAT ACPI table.
> > 
> > Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> > ---
> >  hw/arm/virt-acpi-build.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 58 insertions(+)
> > 
> > diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
> > index f51fe39..a618210 100644
> > --- a/hw/arm/virt-acpi-build.c
> > +++ b/hw/arm/virt-acpi-build.c
> > @@ -43,6 +43,7 @@
> >  #include "hw/acpi/aml-build.h"
> >  #include "hw/pci/pcie_host.h"
> >  #include "hw/pci/pci.h"
> > +#include "sysemu/numa.h"
> >  
> >  #define ARM_SPI_BASE 32
> >  #define ACPI_POWER_BUTTON_DEVICE "PWRB"
> > @@ -414,6 +415,58 @@ build_spcr(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
> >  }
> >  
> >  static void
> > +build_srat(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
> > +{
> > +    AcpiSystemResourceAffinityTable *srat;
> > +    AcpiSratProcessorGiccAffinity *core;
> > +    AcpiSratMemoryAffinity *numamem;
> > +    int i, j, srat_start;
> > +    uint64_t mem_len, mem_base;
> > +    uint32_t *cpu_node = g_malloc0(guest_info->smp_cpus * sizeof *cpu_node);  
> 
> nit1: the majority of qemu code uses () with sizeof
> nit2: sizeof(uint32_t) might be nicer than the cyclic reference
> 
> > +
> > +    for (i = 0; i < guest_info->smp_cpus; i++) {
> > +        for (j = 0; j < nb_numa_nodes; j++) {
> > +            if (test_bit(i, numa_info[j].node_cpu)) {
> > +                cpu_node[i] = j;
> > +                break;
> > +            }
> > +        }
> > +    }
> > +
> > +    srat_start = table_data->len;
> > +    srat = acpi_data_push(table_data, sizeof *srat);
> > +    srat->reserved1 = cpu_to_le32(1);
> > +
> > +    for (i = 0; i < guest_info->smp_cpus; ++i) {
> > +        core = acpi_data_push(table_data, sizeof *core);
> > +        core->type = ACPI_SRAT_PROCESSOR_GICC;
> > +        core->length = sizeof(*core);
> > +        core->proximity = cpu_node[i];
> > +        core->acpi_processor_uid = i;  
> 
> We'll want to use get_arch_id() here (after I implement it as part of
> the cpu topology work I keep promising).
> 
> > +        core->flags = cpu_to_le32(1);
> > +    }
> > +    g_free(cpu_node);
> > +
> > +    mem_base = guest_info->memmap[VIRT_MEM].base;
> > +    for (i = 0; i < nb_numa_nodes; ++i) {
> > +        mem_len = numa_info[i].node_mem;
> > +        numamem = acpi_data_push(table_data, sizeof *numamem);
> > +        numamem->type = ACPI_SRAT_MEMORY;
> > +        numamem->length = sizeof(*numamem);
> > +        memset(numamem->proximity, 0, 4);
> > +        numamem->proximity[0] = i;  
> 
> This is weird (but I see x86 does it too). The spec says proximity is
> "Integer that represents the proximity domain to which the processor
>  belongs", and its 4 bytes. So why doesn't the structure define it as
> a uint32_t and then we'd just do
> 
>   numamem->proximity = cpu_to_le32(i);
It's probably just some legacy code and should be fixed as you're suggesting.


> 
> (adding Igor)
> 
> > +        numamem->flags = cpu_to_le32(1);
> > +        numamem->base_addr = cpu_to_le64(mem_base);
> > +        numamem->range_length = cpu_to_le64(mem_len);  
> 
> How about moving acpi_build_srat_memory from hw/i386/acpi-build.c to
> somewhere in hw/acpi and reusing it?
> 
> > +        mem_base += mem_len;
> > +    }
> > +
> > +    build_header(linker, table_data,
> > +                 (void *)(table_data->data + srat_start), "SRAT",
> > +                 table_data->len - srat_start, 3, NULL, NULL);
> > +}
> > +
> > +static void
> >  build_mcfg(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info)
> >  {
> >      AcpiTableMcfg *mcfg;
> > @@ -638,6 +691,11 @@ void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables)
> >      acpi_add_table(table_offsets, tables_blob);
> >      build_spcr(tables_blob, tables->linker, guest_info);
> >  
> > +    if (nb_numa_nodes > 0) {
> > +        acpi_add_table(table_offsets, tables_blob);
> > +        build_srat(tables_blob, tables->linker, guest_info);
> > +    }
> > +
> >      /* RSDT is pointed to by RSDP */
> >      rsdt = tables_blob->len;
> >      build_rsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
> > -- 
> > 2.0.4
> > 
> >  
> 
> Thanks,
> drew 
> 

      parent reply	other threads:[~2016-04-25 10:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-21  6:23 [Qemu-devel] [PATCH v5 0/5] ARM: Add NUMA support for machine virt Shannon Zhao
2016-04-21  6:23 ` [Qemu-devel] [PATCH v5 1/5] ARM: Virt: Add /distance-map node for NUMA Shannon Zhao
2016-04-22 12:25   ` Andrew Jones
2016-04-23  1:17     ` Shannon Zhao
2016-04-23  7:03       ` Andrew Jones
2016-04-23  7:27         ` Shannon Zhao
2016-04-21  6:23 ` [Qemu-devel] [PATCH v5 2/5] ARM: Virt: Set numa-node-id for CPUs Shannon Zhao
2016-04-22 12:34   ` Andrew Jones
2016-04-21  6:23 ` [Qemu-devel] [PATCH v5 3/5] ARM: Add numa-node-id for /memory node Shannon Zhao
2016-04-22 12:48   ` Andrew Jones
2016-04-23  1:16     ` Shannon Zhao
2016-04-23  7:45       ` Andrew Jones
2016-04-23  8:02         ` Shannon Zhao
2016-04-21  6:23 ` [Qemu-devel] [PATCH v5 4/5] include/hw/acpi/acpi-defs: Add GICC Affinity Structure Shannon Zhao
2016-04-22 13:26   ` Andrew Jones
2016-04-21  6:23 ` [Qemu-devel] [PATCH v5 5/5] hw/arm/virt-acpi-build: Generate SRAT table Shannon Zhao
2016-04-22 13:26   ` Andrew Jones
2016-04-23  1:08     ` Shannon Zhao
2016-04-25 10:44     ` Igor Mammedov [this message]

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=20160425124455.43eee760@nial.brq.redhat.com \
    --to=imammedo@redhat.com \
    --cc=david.daney@cavium.com \
    --cc=drjones@redhat.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=shannon.zhao@linaro.org \
    --cc=zhaoshenglong@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).