Re: [Qemu-devel] [PATCH v5 6/8] hmat acpi: Build Memory Subsystem Address Range Structure(s) in ACPI HMAT

2019-07-08 Thread Tao Xu

On 7/8/2019 5:09 PM, Igor Mammedov wrote:

On Tue, 2 Jul 2019 16:50:24 +0800
Tao Xu  wrote:


On 7/1/2019 7:25 PM, Igor Mammedov wrote:

On Fri, 14 Jun 2019 23:56:24 +0800
Tao Xu  wrote:
   

...

@@ -2710,6 +2711,8 @@ void acpi_build(AcpiBuildTables *tables, MachineState 
*machine)
   acpi_add_table(table_offsets, tables_blob);
   build_slit(tables_blob, tables->linker, machine);
   }
+acpi_add_table(table_offsets, tables_blob);
+build_hmat(tables_blob, tables->linker, machine);

I'm not sure if we should add it unconditionally.
Is this table used in any meaningful manner by guest when
it's incomplete (i.e. populated only with SPA records)?
   

Hi Igor,

In ACPI 6.2, the linux kernel use it to show the memory ranges'
node-id(Proximity Domain). In ACPI 6.3, the linux kernel use it to show
the numa node's closest initiator(Generic Initiator or Processor, directly
attached). It is useful for a memory only numa node, because with
SPA(renamed as "Memory Proximity Domain Attributes Structure" in ACPI
6.3) the user-space can know the topology of hardware heterogeneous
memory. I think I should add a doc to describe the use case in QEMU.

Could you point out to me the specific kernel code that parses and uses HMAT?



OK, it is in drivers/acpi/hmat/hmat.c



Therefore, the numa CLI may be lack of a input which can indicate the
Initiator of a memory only numa node. Dan suggested me to add a new
parameter for that[1].

Maybe like:
-numa node,mem=4G,nodeid=2,initiator=0

[1] https://patchwork.kernel.org/cover/10934417/

Thanks

Tao



















Re: [Qemu-devel] [PATCH v5 6/8] hmat acpi: Build Memory Subsystem Address Range Structure(s) in ACPI HMAT

2019-07-08 Thread Igor Mammedov
On Tue, 2 Jul 2019 16:50:24 +0800
Tao Xu  wrote:

> On 7/1/2019 7:25 PM, Igor Mammedov wrote:
> > On Fri, 14 Jun 2019 23:56:24 +0800
> > Tao Xu  wrote:
> >   
> ...
> >> @@ -2710,6 +2711,8 @@ void acpi_build(AcpiBuildTables *tables, 
> >> MachineState *machine)
> >>   acpi_add_table(table_offsets, tables_blob);
> >>   build_slit(tables_blob, tables->linker, machine);
> >>   }
> >> +acpi_add_table(table_offsets, tables_blob);
> >> +build_hmat(tables_blob, tables->linker, machine);  
> > I'm not sure if we should add it unconditionally.
> > Is this table used in any meaningful manner by guest when
> > it's incomplete (i.e. populated only with SPA records)?
> >   
> Hi Igor,
> 
> In ACPI 6.2, the linux kernel use it to show the memory ranges' 
> node-id(Proximity Domain). In ACPI 6.3, the linux kernel use it to show 
> the numa node's closest initiator(Generic Initiator or Processor, directly
> attached). It is useful for a memory only numa node, because with 
> SPA(renamed as "Memory Proximity Domain Attributes Structure" in ACPI 
> 6.3) the user-space can know the topology of hardware heterogeneous 
> memory. I think I should add a doc to describe the use case in QEMU.
Could you point out to me the specific kernel code that parses and uses HMAT?

> 
> Therefore, the numa CLI may be lack of a input which can indicate the 
> Initiator of a memory only numa node. Dan suggested me to add a new 
> parameter for that[1].
> 
> Maybe like:
> -numa node,mem=4G,nodeid=2,initiator=0
> 
> [1] https://patchwork.kernel.org/cover/10934417/
> 
> Thanks
> 
> Tao
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 




Re: [Qemu-devel] [PATCH v5 6/8] hmat acpi: Build Memory Subsystem Address Range Structure(s) in ACPI HMAT

2019-07-02 Thread Tao Xu

On 7/1/2019 7:25 PM, Igor Mammedov wrote:

On Fri, 14 Jun 2019 23:56:24 +0800
Tao Xu  wrote:


...

@@ -2710,6 +2711,8 @@ void acpi_build(AcpiBuildTables *tables, MachineState 
*machine)
  acpi_add_table(table_offsets, tables_blob);
  build_slit(tables_blob, tables->linker, machine);
  }
+acpi_add_table(table_offsets, tables_blob);
+build_hmat(tables_blob, tables->linker, machine);

I'm not sure if we should add it unconditionally.
Is this table used in any meaningful manner by guest when
it's incomplete (i.e. populated only with SPA records)?


Hi Igor,

In ACPI 6.2, the linux kernel use it to show the memory ranges' 
node-id(Proximity Domain). In ACPI 6.3, the linux kernel use it to show 
the numa node's closest initiator(Generic Initiator or Processor, directly
attached). It is useful for a memory only numa node, because with 
SPA(renamed as "Memory Proximity Domain Attributes Structure" in ACPI 
6.3) the user-space can know the topology of hardware heterogeneous 
memory. I think I should add a doc to describe the use case in QEMU.


Therefore, the numa CLI may be lack of a input which can indicate the 
Initiator of a memory only numa node. Dan suggested me to add a new 
parameter for that[1].


Maybe like:
-numa node,mem=4G,nodeid=2,initiator=0

[1] https://patchwork.kernel.org/cover/10934417/

Thanks

Tao














Re: [Qemu-devel] [PATCH v5 6/8] hmat acpi: Build Memory Subsystem Address Range Structure(s) in ACPI HMAT

2019-07-01 Thread Tao Xu

On 7/1/2019 7:25 PM, Igor Mammedov wrote:

On Fri, 14 Jun 2019 23:56:24 +0800
Tao Xu  wrote:


From: Liu Jingqi 

HMAT is defined in ACPI 6.2: 5.2.27 Heterogeneous Memory Attribute Table (HMAT).
The specification references below link:
http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf

It describes the memory attributes, such as memory side cache
attributes and bandwidth and latency details, related to the
System Physical Address (SPA) Memory Ranges. The software is
expected to use this information as hint for optimization.

This structure describes the System Physical Address(SPA) range
occupied by memory subsystem and its associativity with processor
proximity domain as well as hint for memory usage.

Signed-off-by: Liu Jingqi 
Signed-off-by: Tao Xu 
---

Changes in v5 -> v4:
 - Add more descriptions from ACPI spec (Igor)
 - Remove all the dependcy on PCMachineState (Igor)
---
  hw/acpi/Kconfig   |   5 ++
  hw/acpi/Makefile.objs |   1 +
  hw/acpi/hmat.c| 153 ++
  hw/acpi/hmat.h|  43 
  hw/core/machine.c |   2 +
  hw/i386/acpi-build.c  |   3 +
  include/sysemu/numa.h |   2 +
  numa.c|   6 ++
  8 files changed, 215 insertions(+)
  create mode 100644 hw/acpi/hmat.c
  create mode 100644 hw/acpi/hmat.h

diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig
index 7c59cf900b..039bb99efa 100644
--- a/hw/acpi/Kconfig
+++ b/hw/acpi/Kconfig
@@ -7,6 +7,7 @@ config ACPI_X86
  select ACPI_NVDIMM
  select ACPI_CPU_HOTPLUG
  select ACPI_MEMORY_HOTPLUG
+select ACPI_HMAT
  
  config ACPI_X86_ICH

  bool
@@ -31,3 +32,7 @@ config ACPI_VMGENID
  bool
  default y
  depends on PC
+
+config ACPI_HMAT
+bool
+depends on ACPI
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index 661a9b8c2f..20cc2fb124 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -6,6 +6,7 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
  common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o
  common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o
  common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o
+common-obj-$(CONFIG_ACPI_HMAT) += hmat.o
  common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o
  
  common-obj-y += acpi_interface.o

diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c
new file mode 100644
index 00..6fd434c4d9
--- /dev/null
+++ b/hw/acpi/hmat.c
@@ -0,0 +1,153 @@
+/*
+ * HMAT ACPI Implementation
+ *
+ * Copyright(C) 2019 Intel Corporation.
+ *
+ * Author:
+ *  Liu jingqi 
+ *  Tao Xu 
+ *
+ * HMAT is defined in ACPI 6.2: 5.2.27 Heterogeneous Memory Attribute Table
+ * (HMAT)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see 
+ */
+
+#include "qemu/osdep.h"
+#include "sysemu/numa.h"
+#include "hw/acpi/hmat.h"
+#include "hw/mem/pc-dimm.h"
+
+/* ACPI 6.2: 5.2.27.3 Memory Subsystem Address Range Structure: Table 5-141 */
+static void build_hmat_spa(GArray *table_data, uint16_t flags,
+   uint64_t base, uint64_t length, int node)
+{
+
+/* Memory Subsystem Address Range Structure */
+/* Type */
+build_append_int_noprefix(table_data, 0, 2);
+/* Reserved */
+build_append_int_noprefix(table_data, 0, 2);
+/* Length */
+build_append_int_noprefix(table_data, 40, 4);
+/* Flags */
+build_append_int_noprefix(table_data, flags, 2);
+/* Reserved */
+build_append_int_noprefix(table_data, 0, 2);
+/* Process Proximity Domain */
+build_append_int_noprefix(table_data, node, 4);
+/* Memory Proximity Domain */
+build_append_int_noprefix(table_data, node, 4);
+/* Reserved */
+build_append_int_noprefix(table_data, 0, 4);
+/* System Physical Address Range Base */
+build_append_int_noprefix(table_data, base, 8);
+/* System Physical Address Range Length */
+build_append_int_noprefix(table_data, length, 8);
+}
+
+static int pc_dimm_device_list(Object *obj, void *opaque)
+{
+GSList **list = opaque;
+
+if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+DeviceState *dev = DEVICE(obj);
+if (dev->realized) { /* only realized memory devices matter */
+*list = g_slist_append(*list, DEVICE(obj));
+}
+}
+
+object_child_foreach(obj, pc_dimm_device_list, opaque);
+return 0;
+}
+
+/* Build HMAT sub table structures */
+static void hmat_build

Re: [Qemu-devel] [PATCH v5 6/8] hmat acpi: Build Memory Subsystem Address Range Structure(s) in ACPI HMAT

2019-07-01 Thread Igor Mammedov
On Fri, 14 Jun 2019 23:56:24 +0800
Tao Xu  wrote:

> From: Liu Jingqi 
> 
> HMAT is defined in ACPI 6.2: 5.2.27 Heterogeneous Memory Attribute Table 
> (HMAT).
> The specification references below link:
> http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf
> 
> It describes the memory attributes, such as memory side cache
> attributes and bandwidth and latency details, related to the
> System Physical Address (SPA) Memory Ranges. The software is
> expected to use this information as hint for optimization.
> 
> This structure describes the System Physical Address(SPA) range
> occupied by memory subsystem and its associativity with processor
> proximity domain as well as hint for memory usage.
> 
> Signed-off-by: Liu Jingqi 
> Signed-off-by: Tao Xu 
> ---
> 
> Changes in v5 -> v4:
> - Add more descriptions from ACPI spec (Igor)
> - Remove all the dependcy on PCMachineState (Igor)
> ---
>  hw/acpi/Kconfig   |   5 ++
>  hw/acpi/Makefile.objs |   1 +
>  hw/acpi/hmat.c| 153 ++
>  hw/acpi/hmat.h|  43 
>  hw/core/machine.c |   2 +
>  hw/i386/acpi-build.c  |   3 +
>  include/sysemu/numa.h |   2 +
>  numa.c|   6 ++
>  8 files changed, 215 insertions(+)
>  create mode 100644 hw/acpi/hmat.c
>  create mode 100644 hw/acpi/hmat.h
> 
> diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig
> index 7c59cf900b..039bb99efa 100644
> --- a/hw/acpi/Kconfig
> +++ b/hw/acpi/Kconfig
> @@ -7,6 +7,7 @@ config ACPI_X86
>  select ACPI_NVDIMM
>  select ACPI_CPU_HOTPLUG
>  select ACPI_MEMORY_HOTPLUG
> +select ACPI_HMAT
>  
>  config ACPI_X86_ICH
>  bool
> @@ -31,3 +32,7 @@ config ACPI_VMGENID
>  bool
>  default y
>  depends on PC
> +
> +config ACPI_HMAT
> +bool
> +depends on ACPI
> diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
> index 661a9b8c2f..20cc2fb124 100644
> --- a/hw/acpi/Makefile.objs
> +++ b/hw/acpi/Makefile.objs
> @@ -6,6 +6,7 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
>  common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o
>  common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o
>  common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o
> +common-obj-$(CONFIG_ACPI_HMAT) += hmat.o
>  common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o
>  
>  common-obj-y += acpi_interface.o
> diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c
> new file mode 100644
> index 00..6fd434c4d9
> --- /dev/null
> +++ b/hw/acpi/hmat.c
> @@ -0,0 +1,153 @@
> +/*
> + * HMAT ACPI Implementation
> + *
> + * Copyright(C) 2019 Intel Corporation.
> + *
> + * Author:
> + *  Liu jingqi 
> + *  Tao Xu 
> + *
> + * HMAT is defined in ACPI 6.2: 5.2.27 Heterogeneous Memory Attribute Table
> + * (HMAT)
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, see 
> 
> + */
> +
> +#include "qemu/osdep.h"
> +#include "sysemu/numa.h"
> +#include "hw/acpi/hmat.h"
> +#include "hw/mem/pc-dimm.h"
> +
> +/* ACPI 6.2: 5.2.27.3 Memory Subsystem Address Range Structure: Table 5-141 
> */
> +static void build_hmat_spa(GArray *table_data, uint16_t flags,
> +   uint64_t base, uint64_t length, int node)
> +{
> +
> +/* Memory Subsystem Address Range Structure */
> +/* Type */
> +build_append_int_noprefix(table_data, 0, 2);
> +/* Reserved */
> +build_append_int_noprefix(table_data, 0, 2);
> +/* Length */
> +build_append_int_noprefix(table_data, 40, 4);
> +/* Flags */
> +build_append_int_noprefix(table_data, flags, 2);
> +/* Reserved */
> +build_append_int_noprefix(table_data, 0, 2);
> +/* Process Proximity Domain */
> +build_append_int_noprefix(table_data, node, 4);
> +/* Memory Proximity Domain */
> +build_append_int_noprefix(table_data, node, 4);
> +/* Reserved */
> +build_append_int_noprefix(table_data, 0, 4);
> +/* System Physical Address Range Base */
> +build_append_int_noprefix(table_data, base, 8);
> +/* System Physical Address Range Length */
> +build_append_int_noprefix(table_data, length, 8);
> +}
> +
> +static int pc_dimm_device_list(Object *obj, void *opaque)
> +{
> +GSList **list = opaque;
> +
> +if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
> +DeviceState *dev = DEVICE(obj);
> +if (dev->realized) { /* only realized memory devices matter */
> + 

Re: [Qemu-devel] [PATCH v5 6/8] hmat acpi: Build Memory Subsystem Address Range Structure(s) in ACPI HMAT

2019-06-30 Thread Tao Xu

On 6/27/2019 11:56 PM, Jonathan Cameron wrote:

On Fri, 14 Jun 2019 23:56:24 +0800
Tao Xu  wrote:


From: Liu Jingqi 

HMAT is defined in ACPI 6.2: 5.2.27 Heterogeneous Memory Attribute Table (HMAT).
The specification references below link:
http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf

It describes the memory attributes, such as memory side cache
attributes and bandwidth and latency details, related to the
System Physical Address (SPA) Memory Ranges. The software is
expected to use this information as hint for optimization.

This structure describes the System Physical Address(SPA) range
occupied by memory subsystem and its associativity with processor
proximity domain as well as hint for memory usage.

Signed-off-by: Liu Jingqi 
Signed-off-by: Tao Xu 


Hi Tao,

Apologies if I missed an earlier discussion on this...

It's probably not letting an secrets out to say that there are very few
real hardware systems out there using the 6.2 version of HMAT.

Does it make sense to implement it rather than the somewhat tidied
up version in ACPI 6.3?

I would go so far as to say that one of the pushes behind making those
changes was that it shouldn't have much impact as no one was shipping
a firmware using the 6.2 version.  So any chance we can avoid
qemu effectively doing so, or at least defaulting to doing so?

I'm entirely in favor of the patch set in general btw as it's much
more useful than having to override with a hand crafted table, when
wanting to test unusual topologies.

Thanks,

Jonathan

Thanks for your suggestion. After discussion, we decide to use ACPI 6.3 
in next version.






Re: [Qemu-devel] [PATCH v5 6/8] hmat acpi: Build Memory Subsystem Address Range Structure(s) in ACPI HMAT

2019-06-27 Thread Jonathan Cameron
On Fri, 14 Jun 2019 23:56:24 +0800
Tao Xu  wrote:

> From: Liu Jingqi 
> 
> HMAT is defined in ACPI 6.2: 5.2.27 Heterogeneous Memory Attribute Table 
> (HMAT).
> The specification references below link:
> http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf
> 
> It describes the memory attributes, such as memory side cache
> attributes and bandwidth and latency details, related to the
> System Physical Address (SPA) Memory Ranges. The software is
> expected to use this information as hint for optimization.
> 
> This structure describes the System Physical Address(SPA) range
> occupied by memory subsystem and its associativity with processor
> proximity domain as well as hint for memory usage.
> 
> Signed-off-by: Liu Jingqi 
> Signed-off-by: Tao Xu 

Hi Tao,

Apologies if I missed an earlier discussion on this...

It's probably not letting an secrets out to say that there are very few
real hardware systems out there using the 6.2 version of HMAT.

Does it make sense to implement it rather than the somewhat tidied
up version in ACPI 6.3?

I would go so far as to say that one of the pushes behind making those
changes was that it shouldn't have much impact as no one was shipping
a firmware using the 6.2 version.  So any chance we can avoid
qemu effectively doing so, or at least defaulting to doing so?

I'm entirely in favor of the patch set in general btw as it's much
more useful than having to override with a hand crafted table, when
wanting to test unusual topologies.

Thanks,

Jonathan 

> ---
> 
> Changes in v5 -> v4:
> - Add more descriptions from ACPI spec (Igor)
> - Remove all the dependcy on PCMachineState (Igor)
> ---
>  hw/acpi/Kconfig   |   5 ++
>  hw/acpi/Makefile.objs |   1 +
>  hw/acpi/hmat.c| 153 ++
>  hw/acpi/hmat.h|  43 
>  hw/core/machine.c |   2 +
>  hw/i386/acpi-build.c  |   3 +
>  include/sysemu/numa.h |   2 +
>  numa.c|   6 ++
>  8 files changed, 215 insertions(+)
>  create mode 100644 hw/acpi/hmat.c
>  create mode 100644 hw/acpi/hmat.h
> 
> diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig
> index 7c59cf900b..039bb99efa 100644
> --- a/hw/acpi/Kconfig
> +++ b/hw/acpi/Kconfig
> @@ -7,6 +7,7 @@ config ACPI_X86
>  select ACPI_NVDIMM
>  select ACPI_CPU_HOTPLUG
>  select ACPI_MEMORY_HOTPLUG
> +select ACPI_HMAT
>  
>  config ACPI_X86_ICH
>  bool
> @@ -31,3 +32,7 @@ config ACPI_VMGENID
>  bool
>  default y
>  depends on PC
> +
> +config ACPI_HMAT
> +bool
> +depends on ACPI
> diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
> index 661a9b8c2f..20cc2fb124 100644
> --- a/hw/acpi/Makefile.objs
> +++ b/hw/acpi/Makefile.objs
> @@ -6,6 +6,7 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
>  common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o
>  common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o
>  common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o
> +common-obj-$(CONFIG_ACPI_HMAT) += hmat.o
>  common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o
>  
>  common-obj-y += acpi_interface.o
> diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c
> new file mode 100644
> index 00..6fd434c4d9
> --- /dev/null
> +++ b/hw/acpi/hmat.c
> @@ -0,0 +1,153 @@
> +/*
> + * HMAT ACPI Implementation
> + *
> + * Copyright(C) 2019 Intel Corporation.
> + *
> + * Author:
> + *  Liu jingqi 
> + *  Tao Xu 
> + *
> + * HMAT is defined in ACPI 6.2: 5.2.27 Heterogeneous Memory Attribute Table
> + * (HMAT)
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, see 
> 
> + */
> +
> +#include "qemu/osdep.h"
> +#include "sysemu/numa.h"
> +#include "hw/acpi/hmat.h"
> +#include "hw/mem/pc-dimm.h"
> +
> +/* ACPI 6.2: 5.2.27.3 Memory Subsystem Address Range Structure: Table 5-141 
> */
> +static void build_hmat_spa(GArray *table_data, uint16_t flags,
> +   uint64_t base, uint64_t length, int node)
> +{
> +
> +/* Memory Subsystem Address Range Structure */
> +/* Type */
> +build_append_int_noprefix(table_data, 0, 2);
> +/* Reserved */
> +build_append_int_noprefix(table_data, 0, 2);
> +/* Length */
> +build_append_int_noprefix(table_data, 40, 4);
> +/* Flags */
> +build_append_int_noprefix(table_data, flags, 2);
> +/* Reserved */
> +build_append_int_noprefix(table_data, 0, 2);
> + 

[Qemu-devel] [PATCH v5 6/8] hmat acpi: Build Memory Subsystem Address Range Structure(s) in ACPI HMAT

2019-06-14 Thread Tao Xu
From: Liu Jingqi 

HMAT is defined in ACPI 6.2: 5.2.27 Heterogeneous Memory Attribute Table (HMAT).
The specification references below link:
http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf

It describes the memory attributes, such as memory side cache
attributes and bandwidth and latency details, related to the
System Physical Address (SPA) Memory Ranges. The software is
expected to use this information as hint for optimization.

This structure describes the System Physical Address(SPA) range
occupied by memory subsystem and its associativity with processor
proximity domain as well as hint for memory usage.

Signed-off-by: Liu Jingqi 
Signed-off-by: Tao Xu 
---

Changes in v5 -> v4:
- Add more descriptions from ACPI spec (Igor)
- Remove all the dependcy on PCMachineState (Igor)
---
 hw/acpi/Kconfig   |   5 ++
 hw/acpi/Makefile.objs |   1 +
 hw/acpi/hmat.c| 153 ++
 hw/acpi/hmat.h|  43 
 hw/core/machine.c |   2 +
 hw/i386/acpi-build.c  |   3 +
 include/sysemu/numa.h |   2 +
 numa.c|   6 ++
 8 files changed, 215 insertions(+)
 create mode 100644 hw/acpi/hmat.c
 create mode 100644 hw/acpi/hmat.h

diff --git a/hw/acpi/Kconfig b/hw/acpi/Kconfig
index 7c59cf900b..039bb99efa 100644
--- a/hw/acpi/Kconfig
+++ b/hw/acpi/Kconfig
@@ -7,6 +7,7 @@ config ACPI_X86
 select ACPI_NVDIMM
 select ACPI_CPU_HOTPLUG
 select ACPI_MEMORY_HOTPLUG
+select ACPI_HMAT
 
 config ACPI_X86_ICH
 bool
@@ -31,3 +32,7 @@ config ACPI_VMGENID
 bool
 default y
 depends on PC
+
+config ACPI_HMAT
+bool
+depends on ACPI
diff --git a/hw/acpi/Makefile.objs b/hw/acpi/Makefile.objs
index 661a9b8c2f..20cc2fb124 100644
--- a/hw/acpi/Makefile.objs
+++ b/hw/acpi/Makefile.objs
@@ -6,6 +6,7 @@ common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o
 common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu.o
 common-obj-$(CONFIG_ACPI_NVDIMM) += nvdimm.o
 common-obj-$(CONFIG_ACPI_VMGENID) += vmgenid.o
+common-obj-$(CONFIG_ACPI_HMAT) += hmat.o
 common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o
 
 common-obj-y += acpi_interface.o
diff --git a/hw/acpi/hmat.c b/hw/acpi/hmat.c
new file mode 100644
index 00..6fd434c4d9
--- /dev/null
+++ b/hw/acpi/hmat.c
@@ -0,0 +1,153 @@
+/*
+ * HMAT ACPI Implementation
+ *
+ * Copyright(C) 2019 Intel Corporation.
+ *
+ * Author:
+ *  Liu jingqi 
+ *  Tao Xu 
+ *
+ * HMAT is defined in ACPI 6.2: 5.2.27 Heterogeneous Memory Attribute Table
+ * (HMAT)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see 
+ */
+
+#include "qemu/osdep.h"
+#include "sysemu/numa.h"
+#include "hw/acpi/hmat.h"
+#include "hw/mem/pc-dimm.h"
+
+/* ACPI 6.2: 5.2.27.3 Memory Subsystem Address Range Structure: Table 5-141 */
+static void build_hmat_spa(GArray *table_data, uint16_t flags,
+   uint64_t base, uint64_t length, int node)
+{
+
+/* Memory Subsystem Address Range Structure */
+/* Type */
+build_append_int_noprefix(table_data, 0, 2);
+/* Reserved */
+build_append_int_noprefix(table_data, 0, 2);
+/* Length */
+build_append_int_noprefix(table_data, 40, 4);
+/* Flags */
+build_append_int_noprefix(table_data, flags, 2);
+/* Reserved */
+build_append_int_noprefix(table_data, 0, 2);
+/* Process Proximity Domain */
+build_append_int_noprefix(table_data, node, 4);
+/* Memory Proximity Domain */
+build_append_int_noprefix(table_data, node, 4);
+/* Reserved */
+build_append_int_noprefix(table_data, 0, 4);
+/* System Physical Address Range Base */
+build_append_int_noprefix(table_data, base, 8);
+/* System Physical Address Range Length */
+build_append_int_noprefix(table_data, length, 8);
+}
+
+static int pc_dimm_device_list(Object *obj, void *opaque)
+{
+GSList **list = opaque;
+
+if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+DeviceState *dev = DEVICE(obj);
+if (dev->realized) { /* only realized memory devices matter */
+*list = g_slist_append(*list, DEVICE(obj));
+}
+}
+
+object_child_foreach(obj, pc_dimm_device_list, opaque);
+return 0;
+}
+
+/* Build HMAT sub table structures */
+static void hmat_build_table_structs(GArray *table_data, MachineState *ms)
+{
+GSList *device_list = NULL;
+uint16_t flags;
+uint64_t me