From: Igor Mammedov <imammedo@redhat.com>
To: Tao Xu <tao3.xu@intel.com>
Cc: xiaoguangrong.eric@gmail.com, mst@redhat.com,
jingqi.liu@intel.com, qemu-devel@nongnu.org, ehabkost@redhat.com,
qemu-ppc@nongnu.org, pbonzini@redhat.com,
david@gibson.dropbear.id.au, rth@twiddle.net
Subject: Re: [Qemu-devel] [PATCH v4 03/11] numa: move numa global variable numa_info into MachineState
Date: Thu, 23 May 2019 15:47:43 +0200 [thread overview]
Message-ID: <20190523154743.5fdd4b81@redhat.com> (raw)
In-Reply-To: <20190508061726.27631-4-tao3.xu@intel.com>
On Wed, 8 May 2019 14:17:18 +0800
Tao Xu <tao3.xu@intel.com> wrote:
> The aim of this patch is to move existing numa global numa_info
> (renamed as "nodes") into NumaState.
s/The aim of this patch is to //
there is repeated pattern you use in patches
ms->numa_state ? ms->numa_state->FOO : NULL
which might be not justified and plain use of
ms->numa_state->FOO
would be sufficient.
The places where NULL could be used probably are broken
and should be fixed by not dereferencing
ms->numa_state in the first place.
>
> Reviewed-by: Liu Jingqi <jingqi.liu@intel.com>
> Suggested-by: Igor Mammedov <imammedo@redhat.com>
> Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
> Signed-off-by: Tao Xu <tao3.xu@intel.com>
> ---
>
> Changes in v4 -> v3:
> - send the patch together with HMAT patches
>
> Changes in v3 -> v2:
> - rename the "NumaState::numa_info" as "NumaState::nodes" (Eduardo)
> ---
> exec.c | 2 +-
> hw/acpi/aml-build.c | 6 ++++--
> hw/arm/boot.c | 2 +-
> hw/arm/virt-acpi-build.c | 7 ++++---
> hw/arm/virt.c | 1 +
> hw/i386/pc.c | 4 ++--
> hw/ppc/spapr.c | 8 +++++++-
> hw/ppc/spapr_pci.c | 2 ++
> include/hw/boards.h | 10 ++++++++++
> include/sysemu/numa.h | 8 --------
> numa.c | 15 +++++++++------
> 11 files changed, 41 insertions(+), 24 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index c7eb4af42d..0e30926588 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1763,7 +1763,7 @@ long qemu_minrampagesize(void)
> if (hpsize > mainrampagesize &&
> (ms->numa_state == NULL ||
> ms->numa_state->num_nodes == 0 ||
> - numa_info[0].node_memdev == NULL)) {
> + ms->numa_state->nodes[0].node_memdev == NULL)) {
> static bool warned;
> if (!warned) {
> error_report("Huge page support disabled (n/a for main memory).");
> diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
> index c67f4561a4..b53a55cb56 100644
> --- a/hw/acpi/aml-build.c
> +++ b/hw/acpi/aml-build.c
> @@ -1737,8 +1737,10 @@ void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms)
> build_append_int_noprefix(table_data, nb_numa_nodes, 8);
> for (i = 0; i < nb_numa_nodes; i++) {
> for (j = 0; j < nb_numa_nodes; j++) {
> - assert(numa_info[i].distance[j]);
> - build_append_int_noprefix(table_data, numa_info[i].distance[j], 1);
> + assert(ms->numa_state->nodes[i].distance[j]);
> + build_append_int_noprefix(table_data,
> + ms->numa_state->nodes[i].distance[j],
> + 1);
> }
> }
>
> diff --git a/hw/arm/boot.c b/hw/arm/boot.c
> index 8ff08814fd..845b737ab9 100644
> --- a/hw/arm/boot.c
> +++ b/hw/arm/boot.c
> @@ -602,7 +602,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
> if (nb_numa_nodes > 0) {
> mem_base = binfo->loader_start;
> for (i = 0; i < nb_numa_nodes; i++) {
> - mem_len = numa_info[i].node_mem;
> + mem_len = ms->numa_state->nodes[i].node_mem;
in 1/11 I've suggested to add nb_numa_nodes, but it might be to add
a pointer to MachineState there.
It would also help to simplify arm_load_dtb later as there are other
bits that we copy to arm_boot_info from MachineState.
> rc = fdt_add_memory_node(fdt, acells, mem_base,
> scells, mem_len, i);
> if (rc < 0) {
> diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
> index 65f070843c..b22c3d27ad 100644
> --- a/hw/arm/virt-acpi-build.c
> +++ b/hw/arm/virt-acpi-build.c
> @@ -535,11 +535,12 @@ build_srat(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
>
> mem_base = vms->memmap[VIRT_MEM].base;
> for (i = 0; i < nb_numa_nodes; ++i) {
> - if (numa_info[i].node_mem > 0) {
> + if (ms->numa_state->nodes[i].node_mem > 0) {
> numamem = acpi_data_push(table_data, sizeof(*numamem));
> - build_srat_memory(numamem, mem_base, numa_info[i].node_mem, i,
> + build_srat_memory(numamem, mem_base,
> + ms->numa_state->nodes[i].node_mem, i,
> MEM_AFFINITY_ENABLED);
> - mem_base += numa_info[i].node_mem;
> + mem_base += ms->numa_state->nodes[i].node_mem;
> }
> }
>
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index f0818ef597..853caf606f 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -232,6 +232,7 @@ static void create_fdt(VirtMachineState *vms)
> int size = nb_numa_nodes * nb_numa_nodes * 3 * sizeof(uint32_t);
> uint32_t *matrix = g_malloc0(size);
> int idx, i, j;
> + NodeInfo *numa_info = ms->numa_state->nodes;
>
> for (i = 0; i < nb_numa_nodes; i++) {
> for (j = 0; j < nb_numa_nodes; j++) {
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index 6404ae508e..1c7b2a97bc 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -1043,7 +1043,7 @@ static FWCfgState *bochs_bios_init(AddressSpace *as, PCMachineState *pcms)
> }
> for (i = 0; i < nb_numa_nodes; i++) {
> numa_fw_cfg[pcms->apic_id_limit + 1 + i] =
> - cpu_to_le64(numa_info[i].node_mem);
> + cpu_to_le64(ms->numa_state->nodes[i].node_mem);
> }
> fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, numa_fw_cfg,
> (1 + pcms->apic_id_limit + nb_numa_nodes) *
> @@ -1685,7 +1685,7 @@ void pc_guest_info_init(PCMachineState *pcms)
> pcms->node_mem = g_malloc0(pcms->numa_nodes *
> sizeof *pcms->node_mem);
> for (i = 0; i < nb_numa_nodes; i++) {
> - pcms->node_mem[i] = numa_info[i].node_mem;
> + pcms->node_mem[i] = ms->numa_state->nodes[i].node_mem;
> }
>
> pcms->machine_done.notify = pc_machine_done;
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 4f0a8d4e2e..d577c2025e 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -349,6 +349,7 @@ static hwaddr spapr_node0_size(MachineState *machine)
> int nb_numa_nodes = machine_num_numa_nodes(machine);
> if (nb_numa_nodes) {
> int i;
> + NodeInfo *numa_info = machine->numa_state->nodes;
> for (i = 0; i < nb_numa_nodes; ++i) {
> if (numa_info[i].node_mem) {
> return MIN(pow2floor(numa_info[i].node_mem),
> @@ -396,7 +397,9 @@ static int spapr_populate_memory(SpaprMachineState *spapr, void *fdt)
> int nb_numa_nodes = machine_num_numa_nodes(machine);
> hwaddr mem_start, node_size;
> int i, nb_nodes = nb_numa_nodes;
> - NodeInfo *nodes = numa_info;
> + NodeInfo *nodes = machine->numa_state ?
can machine->numa_state actually be NULL?
> + machine->numa_state->nodes :
> + NULL;
> NodeInfo ramnode;
>
> /* No NUMA nodes, assume there is just one node with whole RAM */
> @@ -2518,6 +2521,9 @@ static void spapr_validate_node_memory(MachineState *machine, Error **errp)
> {
> int i;
> int nb_numa_nodes = machine_num_numa_nodes(machine);
> + NodeInfo *numa_info = machine->numa_state ?
ditto
> + machine->numa_state->nodes :
> + NULL;
Also question to PPC folks,
spapr_validate_node_memory()
seems to be 'broken' in 1 implicit node case since
spapr_populate_memory() 'creates' implicit node info
temporarily but then spapr_validate_node_memory() would use
global nb_numa_nodes which is 0 and skip check.
>
> if (machine->ram_size % SPAPR_MEMORY_BLOCK_SIZE) {
> error_setg(errp, "Memory size 0x" RAM_ADDR_FMT
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index 97961b0128..f4e5c0f5b2 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -1660,6 +1660,8 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp)
> SysBusDevice *s = SYS_BUS_DEVICE(dev);
> SpaprPhbState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
> PCIHostState *phb = PCI_HOST_BRIDGE(s);
> + MachineState *ms = MACHINE(spapr);
> + NodeInfo *numa_info = ms->numa_state ? ms->numa_state->nodes : NULL;
> char *namebuf;
> int i;
> PCIBus *bus;
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index c3c678b7ff..777eed4dd9 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -233,12 +233,22 @@ typedef struct DeviceMemoryState {
> MemoryRegion mr;
> } DeviceMemoryState;
>
> +struct NodeInfo {
> + uint64_t node_mem;
> + struct HostMemoryBackend *node_memdev;
> + bool present;
> + uint8_t distance[MAX_NODES];
> +};
> +
> typedef struct NumaState {
> /* Number of NUMA nodes */
> int num_nodes;
>
> /* Allow setting NUMA distance for different NUMA nodes */
> bool have_numa_distance;
> +
> + /* NUMA nodes information */
> + NodeInfo nodes[MAX_NODES];
> } NumaState;
>
> /**
> diff --git a/include/sysemu/numa.h b/include/sysemu/numa.h
> index 1a29408db9..7b8011f9ea 100644
> --- a/include/sysemu/numa.h
> +++ b/include/sysemu/numa.h
> @@ -6,19 +6,11 @@
> #include "sysemu/hostmem.h"
> #include "hw/boards.h"
>
> -struct NodeInfo {
> - uint64_t node_mem;
> - struct HostMemoryBackend *node_memdev;
> - bool present;
> - uint8_t distance[MAX_NODES];
> -};
> -
> struct NumaNodeMem {
> uint64_t node_mem;
> uint64_t node_plugged_mem;
> };
>
> -extern NodeInfo numa_info[MAX_NODES];
> void parse_numa_opts(MachineState *ms);
> void numa_complete_configuration(MachineState *ms);
> void query_numa_node_mem(NumaNodeMem node_mem[], MachineState *ms);
> diff --git a/numa.c b/numa.c
> index d4f5ff5193..ddea376d72 100644
> --- a/numa.c
> +++ b/numa.c
> @@ -52,8 +52,6 @@ static int have_memdevs = -1;
> static int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
> * For all nodes, nodeid < max_numa_nodeid
> */
> -NodeInfo numa_info[MAX_NODES];
> -
>
> static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
> Error **errp)
> @@ -62,6 +60,7 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
> uint16_t nodenr;
> uint16List *cpus = NULL;
> MachineClass *mc = MACHINE_GET_CLASS(ms);
> + NodeInfo *numa_info = ms->numa_state->nodes;
>
> if (node->has_nodeid) {
> nodenr = node->nodeid;
> @@ -143,6 +142,7 @@ void parse_numa_distance(MachineState *ms, NumaDistOptions *dist, Error **errp)
> uint16_t src = dist->src;
> uint16_t dst = dist->dst;
> uint8_t val = dist->val;
> + NodeInfo *numa_info = ms->numa_state->nodes;
>
> if (src >= MAX_NODES || dst >= MAX_NODES) {
> error_setg(errp, "Parameter '%s' expects an integer between 0 and %d",
> @@ -201,7 +201,7 @@ void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp)
> error_setg(&err, "Missing mandatory node-id property");
> goto end;
> }
> - if (!numa_info[object->u.cpu.node_id].present) {
> + if (!ms->numa_state->nodes[object->u.cpu.node_id].present) {
> error_setg(&err, "Invalid node-id=%" PRId64 ", NUMA node must be "
> "defined with -numa node,nodeid=ID before it's used with "
> "-numa cpu,node-id=ID", object->u.cpu.node_id);
> @@ -261,6 +261,7 @@ static void validate_numa_distance(MachineState *ms)
> int src, dst;
> bool is_asymmetrical = false;
> int nb_numa_nodes = machine_num_numa_nodes(ms);
> + NodeInfo *numa_info = ms->numa_state->nodes;
>
> for (src = 0; src < nb_numa_nodes; src++) {
> for (dst = src; dst < nb_numa_nodes; dst++) {
> @@ -302,6 +303,7 @@ static void complete_init_numa_distance(MachineState *ms)
> {
> int src, dst;
> int nb_numa_nodes = machine_num_numa_nodes(ms);
> + NodeInfo *numa_info = ms->numa_state->nodes;
>
> /* Fixup NUMA distance by symmetric policy because if it is an
> * asymmetric distance table, it should be a complete table and
> @@ -361,6 +363,7 @@ void numa_complete_configuration(MachineState *ms)
> {
> int i;
> MachineClass *mc = MACHINE_GET_CLASS(ms);
> + NodeInfo *numa_info = ms->numa_state->nodes;
>
> /*
> * If memory hotplug is enabled (slots > 0) but without '-numa'
> @@ -532,8 +535,8 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
>
> memory_region_init(mr, owner, name, ram_size);
> for (i = 0; i < nb_numa_nodes; i++) {
> - uint64_t size = numa_info[i].node_mem;
> - HostMemoryBackend *backend = numa_info[i].node_memdev;
> + uint64_t size = ms->numa_state->nodes[i].node_mem;
> + HostMemoryBackend *backend = ms->numa_state->nodes[i].node_memdev;
> if (!backend) {
> continue;
> }
> @@ -599,7 +602,7 @@ void query_numa_node_mem(NumaNodeMem node_mem[], MachineState *ms)
>
> numa_stat_memory_devices(node_mem);
> for (i = 0; i < ms->numa_state->num_nodes; i++) {
> - node_mem[i].node_mem += numa_info[i].node_mem;
> + node_mem[i].node_mem += ms->numa_state->nodes[i].node_mem;
> }
> }
>
next prev parent reply other threads:[~2019-05-23 13:51 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-08 6:17 [Qemu-devel] [PATCH v4 00/11] Build ACPI Heterogeneous Memory Attribute Table (HMAT) Tao Xu
2019-05-08 6:17 ` [Qemu-devel] [PATCH v4 01/11] numa: move numa global variable nb_numa_nodes into MachineState Tao Xu
2019-05-23 13:04 ` Igor Mammedov
2019-05-08 6:17 ` [Qemu-devel] [PATCH v4 02/11] numa: move numa global variable have_numa_distance " Tao Xu
2019-05-23 13:07 ` Igor Mammedov
2019-05-08 6:17 ` [Qemu-devel] [PATCH v4 03/11] numa: move numa global variable numa_info " Tao Xu
2019-05-23 13:47 ` Igor Mammedov [this message]
2019-05-28 7:43 ` Tao Xu
2019-05-08 6:17 ` [Qemu-devel] [PATCH v4 04/11] acpi: introduce AcpiDeviceIfClass.build_mem_ranges hook Tao Xu
2019-05-24 12:35 ` Igor Mammedov
2019-06-06 5:15 ` Tao Xu
2019-06-06 16:25 ` Igor Mammedov
2019-05-08 6:17 ` [Qemu-devel] [PATCH v4 05/11] hmat acpi: Build Memory Subsystem Address Range Structure(s) in ACPI HMAT Tao Xu
2019-05-24 14:16 ` Igor Mammedov
2019-05-08 6:17 ` [Qemu-devel] [PATCH v4 06/11] hmat acpi: Build System Locality Latency and Bandwidth Information " Tao Xu
2019-06-04 14:43 ` Igor Mammedov
2019-05-08 6:17 ` [Qemu-devel] [PATCH v4 07/11] hmat acpi: Build Memory Side Cache " Tao Xu
2019-06-04 15:04 ` Igor Mammedov
2019-06-05 6:04 ` Tao Xu
2019-06-05 12:12 ` Igor Mammedov
2019-06-06 3:00 ` Tao Xu
2019-06-06 16:45 ` Igor Mammedov
2019-06-10 13:39 ` Tao Xu
2019-06-16 19:41 ` Igor Mammedov
2019-05-08 6:17 ` [Qemu-devel] [PATCH v4 08/11] numa: Extend the command-line to provide memory latency and bandwidth information Tao Xu
2019-06-05 14:40 ` Igor Mammedov
2019-06-06 7:47 ` Tao Xu
2019-06-06 13:23 ` Eric Blake
2019-06-06 16:50 ` Igor Mammedov
2019-05-08 6:17 ` [Qemu-devel] [PATCH v4 09/11] numa: Extend the command-line to provide memory side cache information Tao Xu
2019-06-16 19:52 ` Igor Mammedov
2019-05-08 6:17 ` [Qemu-devel] [PATCH v4 10/11] acpi: introduce build_acpi_aml_common for NFIT generalizations Tao Xu
2019-06-06 17:00 ` Igor Mammedov
2019-05-08 6:17 ` [Qemu-devel] [PATCH v4 11/11] hmat acpi: Implement _HMA method to update HMAT at runtime Tao Xu
2019-06-16 20:07 ` Igor Mammedov
2019-06-17 7:19 ` Tao Xu
2019-05-31 4:55 ` [Qemu-devel] [PATCH v4 00/11] Build ACPI Heterogeneous Memory Attribute Table (HMAT) Dan Williams
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=20190523154743.5fdd4b81@redhat.com \
--to=imammedo@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=ehabkost@redhat.com \
--cc=jingqi.liu@intel.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=rth@twiddle.net \
--cc=tao3.xu@intel.com \
--cc=xiaoguangrong.eric@gmail.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).