hw/acpi-build: Fix ACPI SRAT Memory Affinity building
v5 cover hw/acpi-build: Fix ACPI SRAT Memory Affinity building
v4 --> v5:
- Replace the original way with Eduardo's method.
- rewrite the testcase.
- Drop the SLIT date
- 2.11 develop tree is opened, So, Add the third patch for re-posting it.
v3 --> v4:
-add a new testcase.
This patchset fixs an ACPI building bug which caused by no RAM in the first NUAM node. and also add a new testcase for the bug.
Dou Liyang (2):
ACPI/unit-test: Add a new testcase for RAM allocation in numa node
NUMA: Replace MAX_NODES with nb_numa_nodes in for loop
Eduardo Habkost (1):
hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
hw/i386/acpi-build.c | 30 +++++++++++++++++++++++------- numa.c | 2 +- tests/acpi-test-data/pc/DSDT.numamem | Bin 0 -> 5104 bytes tests/acpi-test-data/pc/SRAT.numamem | Bin 0 -> 224 bytes tests/acpi-test-data/q35/DSDT.numamem | Bin 0 -> 7788 bytes tests/acpi-test-data/q35/SRAT.numamem | Bin 0 -> 224 bytes tests/bios-tables-test.c | 24 ++++++++++++++++++++++++ 7 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 tests/acpi-test-data/pc/DSDT.numamem create mode 100644 tests/acpi-test-data/pc/SRAT.numamem create mode 100644 tests/acpi-test-data/q35/DSDT.numamem create mode 100644 tests/acpi-test-data/q35/SRAT.numamem
Signature · 1 line
2.5.5
PATCH v5 1/3 hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
From: Eduardo Habkost <[email protected]>
Currently, Using the fisrt node without memory on the machine makes QEMU unhappy. With this example command line:
... \
-m 1024M,slots=4,maxmem=32G \
-numa node,nodeid=0 \
-numa node,mem=1024M,nodeid=1 \
-numa node,nodeid=2 \
-numa node,nodeid=3 \
Guest reports "No NUMA configuration found" and the NUMA topology is wrong.
This is because when QEMU builds ACPI SRAT, it regards node 0 as the default node to deal with the memory hole(640K-1M). this means the node0 must have some memory(>1M), but, actually it can have no memory.
Fix this problem by cut out the 640K hole in the same way the PCI 4G hole does. Also do some cleanup.
--- hw/i386/acpi-build.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)
hw/i386/acpi-build.c +23 -7
@@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker) (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL); } +#define HOLE_640K_START (640 * 1024) +#define HOLE_640K_END (1024 * 1024) +static void build_srat (GArray *table_data,BIOSLinker *linker,MachineState *machine) {
@@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) next_base =0 ; numa_start = table_data->len; - numamem =acpi_data_push (table_data,sizeof *numamem); -build_srat_memory (numamem,0 ,640 *1024 ,0 ,MEM_AFFINITY_ENABLED ); - next_base =1024 *1024 ;for (i =1 ; i < pcms->numa_nodes +1 ; ++i) { mem_base = next_base; mem_len = pcms->node_mem[i -1 ]; -if (i ==1 ) { - mem_len -=1024 *1024 ; - } next_base = mem_base + mem_len; +/* Cut out the 640K hole */ +if (mem_base <=HOLE_640K_START && + next_base >HOLE_640K_START ) { + mem_len -= next_base -HOLE_640K_START ; +if (mem_len >0 ) { + numamem =acpi_data_push (table_data,sizeof *numamem); +build_srat_memory (numamem, mem_base, mem_len, i -1 , +MEM_AFFINITY_ENABLED ); + } + +/* Check for the rare case: 640K < RAM < 1M */ +if (next_base <=HOLE_640K_END ) { + next_base =HOLE_640K_END ; +continue ; + } + mem_base =HOLE_640K_END ; + mem_len = next_base -HOLE_640K_END ; + } +/* Cut out the ACPI_PCI hole */ if (mem_base <= pcms->below_4g_mem_size && next_base > pcms->below_4g_mem_size) {
@@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) } mem_base =1ULL <<32 ; mem_len = next_base - pcms->below_4g_mem_size; - next_base += (1ULL <<32 ) - pcms->below_4g_mem_size; + next_base = mem_base + mem_len; } numamem =acpi_data_push (table_data,sizeof *numamem); build_srat_memory(numamem, mem_base, mem_len, i - 1,
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
Quoted 79 lines · Dou Liyang
From: Eduardo Habkost <[email protected]>
Currently, Using the fisrt node without memory on the machine makes QEMU unhappy. With this example command line:
... \
-m 1024M,slots=4,maxmem=32G \
-numa node,nodeid=0 \
-numa node,mem=1024M,nodeid=1 \
-numa node,nodeid=2 \
-numa node,nodeid=3 \
Guest reports "No NUMA configuration found" and the NUMA topology is wrong.This is because when QEMU builds ACPI SRAT, it regards node 0 as the default node to deal with the memory hole(640K-1M). this means the node0 must have some memory(>1M), but, actually it can have no memory.
Fix this problem by cut out the 640K hole in the same way the PCI 4G hole does. Also do some cleanup.
Signed-off-by Eduardo Habkost <[email protected]>Signed-off-by Dou Liyang <[email protected]>--- hw/i386/acpi-build.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)hw/i386/acpi-build.c +22
-6@@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker) (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL); } +#define HOLE_640K_START (640 * 1024) +#define HOLE_640K_END (1024 * 1024) +static void build_srat (GArray *table_data,BIOSLinker *linker,MachineState *machine) {@@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) next_base =0 ; numa_start = table_data->len; - numamem =acpi_data_push (table_data,sizeof *numamem); -build_srat_memory (numamem,0 ,640 *1024 ,0 ,MEM_AFFINITY_ENABLED ); - next_base =1024 *1024 ;for (i =1 ; i < pcms->numa_nodes +1 ; ++i) { mem_base = next_base; mem_len = pcms->node_mem[i -1 ]; -if (i ==1 ) { - mem_len -=1024 *1024 ; - } next_base = mem_base + mem_len; +/* Cut out the 640K hole */ +if (mem_base <=HOLE_640K_START && + next_base >HOLE_640K_START ) { + mem_len -= next_base -HOLE_640K_START ; +if (mem_len >0 ) { + numamem =acpi_data_push (table_data,sizeof *numamem); +build_srat_memory (numamem, mem_base, mem_len, i -1 , +MEM_AFFINITY_ENABLED ); + } + +/* Check for the rare case: 640K < RAM < 1M */ +if (next_base <=HOLE_640K_END ) { + next_base =HOLE_640K_END ; +continue ; + } + mem_base =HOLE_640K_END ; + mem_len = next_base -HOLE_640K_END ; + } +/* Cut out the ACPI_PCI hole */ if (mem_base <= pcms->below_4g_mem_size && next_base > pcms->below_4g_mem_size) {
hw/i386/acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) · line 2414
Quoted 5 lines
hw/i386/acpi-build.c +1
-1@@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) } mem_base =1ULL <<32 ; mem_len = next_base - pcms->below_4g_mem_size; - next_base += (1ULL <<32 ) - pcms->below_4g_mem_size; + next_base = mem_base + mem_len;
Is this extra change intentional?
I find the code more readable with it, but it should go in a separate patch because it is unrelated to the bug fix.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
Hi, Eduardo
Quoted 79 lines · Eduardo Habkost
Quoted 78 lines · Dou Liyang
From: Eduardo Habkost <[email protected]>
Currently, Using the fisrt node without memory on the machine makes QEMU unhappy. With this example command line:
... \
-m 1024M,slots=4,maxmem=32G \
-numa node,nodeid=0 \
-numa node,mem=1024M,nodeid=1 \
-numa node,nodeid=2 \
-numa node,nodeid=3 \
Guest reports "No NUMA configuration found" and the NUMA topology is wrong.This is because when QEMU builds ACPI SRAT, it regards node 0 as the default node to deal with the memory hole(640K-1M). this means the node0 must have some memory(>1M), but, actually it can have no memory.
Fix this problem by cut out the 640K hole in the same way the PCI 4G hole does. Also do some cleanup.
Signed-off-by Eduardo Habkost <[email protected]>Signed-off-by Dou Liyang <[email protected]>--- hw/i386/acpi-build.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)hw/i386/acpi-build.c +22
-6@@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker) (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL); } +#define HOLE_640K_START (640 * 1024) +#define HOLE_640K_END (1024 * 1024) +static void build_srat (GArray *table_data,BIOSLinker *linker,MachineState *machine) {@@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) next_base =0 ; numa_start = table_data->len; - numamem =acpi_data_push (table_data,sizeof *numamem); -build_srat_memory (numamem,0 ,640 *1024 ,0 ,MEM_AFFINITY_ENABLED ); - next_base =1024 *1024 ;for (i =1 ; i < pcms->numa_nodes +1 ; ++i) { mem_base = next_base; mem_len = pcms->node_mem[i -1 ]; -if (i ==1 ) { - mem_len -=1024 *1024 ; - } next_base = mem_base + mem_len; +/* Cut out the 640K hole */ +if (mem_base <=HOLE_640K_START && + next_base >HOLE_640K_START ) { + mem_len -= next_base -HOLE_640K_START ; +if (mem_len >0 ) { + numamem =acpi_data_push (table_data,sizeof *numamem); +build_srat_memory (numamem, mem_base, mem_len, i -1 , +MEM_AFFINITY_ENABLED ); + } + +/* Check for the rare case: 640K < RAM < 1M */ +if (next_base <=HOLE_640K_END ) { + next_base =HOLE_640K_END ; +continue ; + } + mem_base =HOLE_640K_END ; + mem_len = next_base -HOLE_640K_END ; + } +/* Cut out the ACPI_PCI hole */ if (mem_base <= pcms->below_4g_mem_size && next_base > pcms->below_4g_mem_size) {
Quoted 9 lines
hw/i386/acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) · line 2414
Quoted 6 lines
hw/i386/acpi-build.c +1
-1@@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) } mem_base =1ULL <<32 ; mem_len = next_base - pcms->below_4g_mem_size; - next_base += (1ULL <<32 ) - pcms->below_4g_mem_size; + next_base = mem_base + mem_len;Is this extra change intentional?
Yes, it is, Just for readability. :-)
Quoted 3 lines
I find the code more readable with it, but it should go in a separate patch because it is unrelated to the bug fix.
Indeed, I will split it out.
Thanks,
dou.
Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
In reply to Dou LiyangQuoted 59 lines · On Thu, 31 Aug 2017 20:04:26 +0800 Dou Liyang <[email protected]> wrote:
From: Eduardo Habkost <[email protected]>
Currently, Using the fisrt node without memory on the machine makes QEMU unhappy. With this example command line:
... \
-m 1024M,slots=4,maxmem=32G \
-numa node,nodeid=0 \
-numa node,mem=1024M,nodeid=1 \
-numa node,nodeid=2 \
-numa node,nodeid=3 \
Guest reports "No NUMA configuration found" and the NUMA topology is wrong.This is because when QEMU builds ACPI SRAT, it regards node 0 as the default node to deal with the memory hole(640K-1M). this means the node0 must have some memory(>1M), but, actually it can have no memory.
Fix this problem by cut out the 640K hole in the same way the PCI 4G hole does. Also do some cleanup.
Signed-off-by Eduardo Habkost <[email protected]>Signed-off-by Dou Liyang <[email protected]>--- hw/i386/acpi-build.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)hw/i386/acpi-build.c +6
-6@@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker) (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL); } +#define HOLE_640K_START (640 * 1024) +#define HOLE_640K_END (1024 * 1024) +static void build_srat (GArray *table_data,BIOSLinker *linker,MachineState *machine) {@@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) next_base =0 ; numa_start = table_data->len; - numamem =acpi_data_push (table_data,sizeof *numamem); -build_srat_memory (numamem,0 ,640 *1024 ,0 ,MEM_AFFINITY_ENABLED ); - next_base =1024 *1024 ;for (i =1 ; i < pcms->numa_nodes +1 ; ++i) { mem_base = next_base; mem_len = pcms->node_mem[i -1 ]; -if (i ==1 ) { - mem_len -=1024 *1024 ; - } next_base = mem_base + mem_len; +/* Cut out the 640K hole */ +if (mem_base <=HOLE_640K_START && + next_base >HOLE_640K_START ) {
hw/i386/acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) · line 2396
Quoted 10 lines
hw/i386/acpi-build.c +10
-0+ mem_len -= next_base -HOLE_640K_START ; +if (mem_len >0 ) { + numamem =acpi_data_push (table_data,sizeof *numamem); +build_srat_memory (numamem, mem_base, mem_len, i -1 , +MEM_AFFINITY_ENABLED ); + } + +/* Check for the rare case: 640K < RAM < 1M */ +if (next_base <=HOLE_640K_END ) { + next_base =HOLE_640K_END ;
Is this assignment really necessary?
it seems that next_base will be set at the start of the loop.
Quoted 18 lines
hw/i386/acpi-build.c +7
-1+continue ; + } + mem_base =HOLE_640K_END ; + mem_len = next_base -HOLE_640K_END ; + } +/* Cut out the ACPI_PCI hole */ if (mem_base <= pcms->below_4g_mem_size && next_base > pcms->below_4g_mem_size) {@@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) } mem_base =1ULL <<32 ; mem_len = next_base - pcms->below_4g_mem_size; - next_base += (1ULL <<32 ) - pcms->below_4g_mem_size; + next_base = mem_base + mem_len; } numamem =acpi_data_push (table_data,sizeof *numamem); build_srat_memory(numamem, mem_base, mem_len, i - 1,
Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
Quoted 59 lines · Igor Mammedov
Quoted 56 lines · On Thu, 31 Aug 2017 20:04:26 +0800 Dou Liyang <[email protected]> wrote:
From: Eduardo Habkost <[email protected]>
Currently, Using the fisrt node without memory on the machine makes QEMU unhappy. With this example command line:
... \
-m 1024M,slots=4,maxmem=32G \
-numa node,nodeid=0 \
-numa node,mem=1024M,nodeid=1 \
-numa node,nodeid=2 \
-numa node,nodeid=3 \
Guest reports "No NUMA configuration found" and the NUMA topology is wrong.This is because when QEMU builds ACPI SRAT, it regards node 0 as the default node to deal with the memory hole(640K-1M). this means the node0 must have some memory(>1M), but, actually it can have no memory.
Fix this problem by cut out the 640K hole in the same way the PCI 4G hole does. Also do some cleanup.
Signed-off-by Eduardo Habkost <[email protected]>Signed-off-by Dou Liyang <[email protected]>--- hw/i386/acpi-build.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)hw/i386/acpi-build.c +3
-6@@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker) (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL); } +#define HOLE_640K_START (640 * 1024) +#define HOLE_640K_END (1024 * 1024) +static void build_srat (GArray *table_data,BIOSLinker *linker,MachineState *machine) {@@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) next_base =0 ; numa_start = table_data->len; - numamem =acpi_data_push (table_data,sizeof *numamem); -build_srat_memory (numamem,0 ,640 *1024 ,0 ,MEM_AFFINITY_ENABLED ); - next_base =1024 *1024 ;for (i =1 ; i < pcms->numa_nodes +1 ; ++i) { mem_base = next_base; mem_len = pcms->node_mem[i -1 ]; -if (i ==1 ) { - mem_len -=1024 *1024 ; - } next_base = mem_base + mem_len;
Quoted 15 lines
hw/i386/acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) · line 2396
Quoted 13 lines
hw/i386/acpi-build.c +13
-0+/* Cut out the 640K hole */ +if (mem_base <=HOLE_640K_START && + next_base >HOLE_640K_START ) { + mem_len -= next_base -HOLE_640K_START ; +if (mem_len >0 ) { + numamem =acpi_data_push (table_data,sizeof *numamem); +build_srat_memory (numamem, mem_base, mem_len, i -1 , +MEM_AFFINITY_ENABLED ); + } + +/* Check for the rare case: 640K < RAM < 1M */ +if (next_base <=HOLE_640K_END ) { + next_base =HOLE_640K_END ;Is this assignment really necessary?
It is necessary, because we set mem_base to next_base before setting next_base;
But, I can refine it:
MEM_AFFINITY_ENABLED);
}+ mem_base = HOLE_640K_END;
/* Check for the rare case: 640K < RAM < 1M */
if (next_base <= HOLE_640K_END) {
- next_base = HOLE_640K_END;
continue;
}
- mem_base = HOLE_640K_END;
mem_len = next_base - HOLE_640K_END;
}Is it?
Thanks,
dou.
Quoted 26 lines
it seems that
next_basewill be set at the start of the loop.Quoted 18 lines
hw/i386/acpi-build.c +7
-1+continue ; + } + mem_base =HOLE_640K_END ; + mem_len = next_base -HOLE_640K_END ; + } +/* Cut out the ACPI_PCI hole */ if (mem_base <= pcms->below_4g_mem_size && next_base > pcms->below_4g_mem_size) {@@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) } mem_base =1ULL <<32 ; mem_len = next_base - pcms->below_4g_mem_size; - next_base += (1ULL <<32 ) - pcms->below_4g_mem_size; + next_base = mem_base + mem_len; } numamem =acpi_data_push (table_data,sizeof *numamem); build_srat_memory(numamem, mem_base, mem_len, i - 1,
Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
Quoted 94 lines · On Mon, 4 Sep 2017 18:16:31 +0800 Dou Liyang <[email protected]> wrote:
Quoted 59 lines · Igor Mammedov
Quoted 56 lines · On Thu, 31 Aug 2017 20:04:26 +0800 Dou Liyang <[email protected]> wrote:
From: Eduardo Habkost <[email protected]>
Currently, Using the fisrt node without memory on the machine makes QEMU unhappy. With this example command line:
... \
-m 1024M,slots=4,maxmem=32G \
-numa node,nodeid=0 \
-numa node,mem=1024M,nodeid=1 \
-numa node,nodeid=2 \
-numa node,nodeid=3 \
Guest reports "No NUMA configuration found" and the NUMA topology is wrong.This is because when QEMU builds ACPI SRAT, it regards node 0 as the default node to deal with the memory hole(640K-1M). this means the node0 must have some memory(>1M), but, actually it can have no memory.
Fix this problem by cut out the 640K hole in the same way the PCI 4G hole does. Also do some cleanup.
Signed-off-by Eduardo Habkost <[email protected]>Signed-off-by Dou Liyang <[email protected]>--- hw/i386/acpi-build.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-)hw/i386/acpi-build.c +3
-6@@ -2318,6 +2318,9 @@ build_tpm2(GArray *table_data, BIOSLinker *linker) (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL); } +#define HOLE_640K_START (640 * 1024) +#define HOLE_640K_END (1024 * 1024) +static void build_srat (GArray *table_data,BIOSLinker *linker,MachineState *machine) {@@ -2373,17 +2376,30 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) next_base =0 ; numa_start = table_data->len; - numamem =acpi_data_push (table_data,sizeof *numamem); -build_srat_memory (numamem,0 ,640 *1024 ,0 ,MEM_AFFINITY_ENABLED ); - next_base =1024 *1024 ;for (i =1 ; i < pcms->numa_nodes +1 ; ++i) { mem_base = next_base; mem_len = pcms->node_mem[i -1 ]; -if (i ==1 ) { - mem_len -=1024 *1024 ; - } next_base = mem_base + mem_len;Quoted 15 lines
hw/i386/acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) · line 2396
Quoted 13 lines
hw/i386/acpi-build.c +13
-0+/* Cut out the 640K hole */ +if (mem_base <=HOLE_640K_START && + next_base >HOLE_640K_START ) { + mem_len -= next_base -HOLE_640K_START ; +if (mem_len >0 ) { + numamem =acpi_data_push (table_data,sizeof *numamem); +build_srat_memory (numamem, mem_base, mem_len, i -1 , +MEM_AFFINITY_ENABLED ); + } + +/* Check for the rare case: 640K < RAM < 1M */ +if (next_base <=HOLE_640K_END ) { + next_base =HOLE_640K_END ;Is this assignment really necessary?
It is necessary, because we set
mem_basetonext_basebefore settingnext_base;But, I can refine it:
MEM_AFFINITY_ENABLED); }(quoted diff) +1
-2+ mem_base = HOLE_640K_END; /* Check for the rare case: 640K < RAM < 1M */ if (next_base <= HOLE_640K_END) { - next_base = HOLE_640K_END; continue; } - mem_base = HOLE_640K_END; mem_len = next_base - HOLE_640K_END; }
Quoted 1 line
Is it?
I was wrong, so just leave it as it is now.
Quoted 32 lines
Thanks,
dou.Quoted 26 lines
it seems that
next_basewill be set at the start of the loop.Quoted 18 lines
hw/i386/acpi-build.c +7
-1+continue ; + } + mem_base =HOLE_640K_END ; + mem_len = next_base -HOLE_640K_END ; + } +/* Cut out the ACPI_PCI hole */ if (mem_base <= pcms->below_4g_mem_size && next_base > pcms->below_4g_mem_size) {@@ -2395,7 +2411,7 @@ build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) } mem_base =1ULL <<32 ; mem_len = next_base - pcms->below_4g_mem_size; - next_base += (1ULL <<32 ) - pcms->below_4g_mem_size; + next_base = mem_base + mem_len; } numamem =acpi_data_push (table_data,sizeof *numamem); build_srat_memory(numamem, mem_base, mem_len, i - 1,
Re: [Qemu-devel] [PATCH v5 1/3] hw/acpi-build: Fix SRAT memory building in case of node 0 without RAM
Hi Igor,
At 09/04/2017 07:11 PM, Igor Mammedov wrote:
[...]
Quoted 33 lines
Quoted 33 lines
Quoted 12 lines
hw/i386/acpi-build.c build_srat(GArray *table_data, BIOSLinker *linker, MachineState *machine) · line 2396
Quoted 12 lines
hw/i386/acpi-build.c +12
-0+if (mem_base <=HOLE_640K_START && + next_base >HOLE_640K_START ) { + mem_len -= next_base -HOLE_640K_START ; +if (mem_len >0 ) { + numamem =acpi_data_push (table_data,sizeof *numamem); +build_srat_memory (numamem, mem_base, mem_len, i -1 , +MEM_AFFINITY_ENABLED ); + } + +/* Check for the rare case: 640K < RAM < 1M */ +if (next_base <=HOLE_640K_END ) { + next_base =HOLE_640K_END ;Quoted 2 lines
Is this assignment really necessary?
It is necessary, because we set
mem_basetonext_basebefore settingnext_base;But, I can refine it:
MEM_AFFINITY_ENABLED); }(quoted diff) +1
-2+ mem_base = HOLE_640K_END; /* Check for the rare case: 640K < RAM < 1M */ if (next_base <= HOLE_640K_END) { - next_base = HOLE_640K_END; continue; } - mem_base = HOLE_640K_END; mem_len = next_base - HOLE_640K_END; }
Quoted 3 lines
Quoted 1 line
Is it?
I was wrong, so just leave it as it is now.
OK, I see.
Thanks,
dou.
PATCH v5 2/3 ACPI/unit-test: Add a new testcase for RAM allocation in numa node
In reply to Dou LiyangAs QEMU supports the memory-less node, it is possible that there is no RAM in the first numa node(also be called as node0). eg:
... \
-m 128,slots=3,maxmem=1G \
-numa node -numa node,mem=128M \
But, this makes it hard for QEMU to build a known-to-work ACPI SRAT table. Only fixing it is not enough.
Add a testcase for this situation to make sure the ACPI table is correct for guest.
--- tests/acpi-test-data/pc/DSDT.numamem | Bin 0 -> 5104 bytes tests/acpi-test-data/pc/SRAT.numamem | Bin 0 -> 224 bytes tests/acpi-test-data/q35/DSDT.numamem | Bin 0 -> 7788 bytes tests/acpi-test-data/q35/SRAT.numamem | Bin 0 -> 224 bytes tests/bios-tables-test.c | 24 ++++++++++++++++++++++++ 5 files changed, 24 insertions(+) create mode 100644 tests/acpi-test-data/pc/DSDT.numamem create mode 100644 tests/acpi-test-data/pc/SRAT.numamem create mode 100644 tests/acpi-test-data/q35/DSDT.numamem create mode 100644 tests/acpi-test-data/q35/SRAT.numamem
tests/acpi-test-data/pc/DSDT.numamem new file binary +0 -0
tests/acpi-test-data/pc/SRAT.numamem new file binary +0 -0
tests/acpi-test-data/q35/DSDT.numamem new file binary +0 -0
tests/acpi-test-data/q35/SRAT.numamem new file binary +0 -0
tests/bios-tables-test.c +24 -0
@@ -808,6 +808,28 @@ static void test_acpi_piix4_tcg_memhp(void)free_test_data (&data); } +static void test_acpi_q35_tcg_numamem (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_Q35 ; + data.variant =".numamem" ; +test_acpi_one (" -numa node -numa node,mem=128" , &data); +free_test_data (&data); +} + +static void test_acpi_piix4_tcg_numamem (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_PC ; + data.variant =".numamem" ; +test_acpi_one (" -numa node -numa node,mem=128" , &data); +free_test_data (&data); +} +int main (int argc,char *argv[]) {const char *arch =qtest_get_arch ();
@@ -830,6 +852,8 @@ int main(int argc, char *argv[])qtest_add_func ("acpi/q35/cpuhp" , test_acpi_q35_tcg_cphp);qtest_add_func ("acpi/piix4/memhp" , test_acpi_piix4_tcg_memhp);qtest_add_func ("acpi/q35/memhp" , test_acpi_q35_tcg_memhp); +qtest_add_func ("acpi/piix4/numamem" , test_acpi_piix4_tcg_numamem); +qtest_add_func ("acpi/q35/numamem" , test_acpi_q35_tcg_numamem); } ret =g_test_run ();boot_sector_cleanup (disk);
Signature · 1 line
2.5.5
PATCH v5 3/3 NUMA: Replace MAX_NODES with nb_numa_nodes in for loop
In reply to Dou LiyangIn QEMU, the number of the NUMA nodes is determined by parse_numa_opts(). Then, QEMU uses it for iteration, for example:
for (i = 0; i < nb_numa_nodes; i++)
However, in memory_region_allocate_system_memory(), it uses MAX_NODES not nb_numa_nodes.
So, replace MAX_NODES with nb_numa_nodes to keep code consistency and reduce the loop times.
--- numa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
numa.c +1 -1
@@ -567,7 +567,7 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner, }memory_region_init (mr, owner, name, ram_size); -for (i =0 ; i <MAX_NODES ; i++) { +for (i =0 ; i < nb_numa_nodes; i++) {uint64_t size = numa_info[i].node_mem;HostMemoryBackend *backend = numa_info[i].node_memdev;if (!backend) {
Signature · 1 line
2.5.5