Skip to contentSkip to conversation

vl: Ensure two functions in the appropriate location

PATCH Applied Dou Liyang 2 participants 8 messages Jan 17, 2017 – Jan 18, 2017

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Dou Liyang

author
#0 lore raw

cover vl: Ensure two functions in the appropriate location

I found and try to fix a bug, which shows below.

[Problem]
---------

As I use this command:

./x86_64-softmmu/qemu-system-x86_64 \
	-hda /image/fedora.img \
	-m 1G,slots=4,maxmem=4G \
	-enable-kvm \
	-smp 2,maxcpus=8,sockets=2,cores=2,threads=2 \
	-device qemu64-x86_64-cpu,id=cpu1,socket-id=0,core-id=1,thread-id=0 \
	-device qemu64-x86_64-cpu,id=cpu2,socket-id=0,core-id=1,thread-id=1 \
	-device qemu64-x86_64-cpu,id=cpu3,socket-id=1,core-id=0,thread-id=0 \
	-device qemu64-x86_64-cpu,id=cpu4,socket-id=1,core-id=0,thread-id=1 \
	-device qemu64-x86_64-cpu,id=cpu5,socket-id=1,core-id=1,thread-id=0 \
	-device qemu64-x86_64-cpu,id=cpu6,socket-id=1,core-id=1,thread-id=1 \
	-numa node,nodeid=0,cpus=0-1 \
	-numa node,nodeid=1,cpus=2-3 \
	-numa node,nodeid=2,cpus=4-5 \
	-numa node,nodeid=3,cpus=6-7 \
	-monitor stdio \

In Qemu monitor:

(qemu) info numa

4 nodes
node 0 cpus: 0 1 2 3 4 5 6 7
node 0 size: 256 MB
node 1 cpus:
node 1 size: 256 MB
node 2 cpus:
node 2 size: 256 MB
node 3 cpus:
node 3 size: 256 MB

* It is amazing that the cpus are all in node one. *

Then, I used the "numactl -H" in the guest, and found that the mapping is right. So I guess it is not big problem, may has some bugs in the initialization. I followed the initialization process and found it out.

[Solution]
----------

Ensure the numa_post_machine_init func in the appropriate location.

After the patches:

(qemu) info numa
4 nodes
node 0 cpus: 0 1
node 0 size: 256 MB
node 1 cpus: 2 3
node 1 size: 256 MB
node 2 cpus: 4 5
node 2 size: 256 MB
node 3 cpus: 6 7
node 3 size: 256 MB

Dou Liyang (2):
vl: Ensure the numa_post_machine_init func in the appropriate location
vl: Ensure the cpu_synchronize_all_post_init func in the appropriate
location

 vl.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
Signature · 1 line
2.5.5
author
#1 lore raw

PATCH 1/2 vl: Ensure the numa_post_machine_init func in the appropriate location

In the numa_post_machine_init(), we use CPU_FOREACH macro to set all CPUs' namu_node. So, we should make sure that we call it after Qemu has already initialied all the CPUs.

As we all know, the CPUs can be created by "-smp"(pc_new_cpu) or "-device"(qdev_device_add) command. But, before the device init, Qemu execute the numa_post_machine_init earlier. It makes the mapping of NUMA nodes and CPUs incorrect.

The patch move the numa_post_machine_init func in the appropriate location.

---
 vl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
vl.c +3 -2
index c643d3f..f38b0e2 100644
@@ -4549,8 +4549,6 @@ int main(int argc, char **argv, char **envp)
 
     cpu_synchronize_all_post_init();
 
-    numa_post_machine_init();
-
     if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
                           parse_fw_cfg, fw_cfg_find(), NULL) != 0) {
         exit(1);
@@ -4571,6 +4569,9 @@ int main(int argc, char **argv, char **envp)
                           device_init_func, NULL, NULL)) {
         exit(1);
     }
+
+    numa_post_machine_init();
+
     rom_reset_order_override();
 
     /* Did we create any drives that we failed to create a device for? */
Signature · 1 line
2.5.5
Reviewed-by on v1 1/2 Applied
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl: Ensure the numa_post_machine_init func in the appropriate location

Quoted 9 lines · Dou Liyang

In the numa_post_machine_init(), we use CPU_FOREACH macro to set all CPUs' namu_node. So, we should make sure that we call it after Qemu has already initialied all the CPUs.

As we all know, the CPUs can be created by "-smp"(pc_new_cpu) or "-device"(qdev_device_add) command. But, before the device init, Qemu execute the numa_post_machine_init earlier. It makes the mapping of NUMA nodes and CPUs incorrect.

Quoted 4 lines

The patch move the numa_post_machine_init func in the appropriate location.

I would like to move cpu_index initialization to qom/cpu.c:cpu_common_realizefn(), and remove numa_post_machine_init() completely. But this fixes the bug while we don't do that.

Queued on numa-next. Thanks!

Quoted 32 lines
---
 vl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
vl.c +3 -2
index c643d3f..f38b0e2 100644
@@ -4549,8 +4549,6 @@ int main(int argc, char **argv, char **envp)
 
     cpu_synchronize_all_post_init();
 
-    numa_post_machine_init();
-
     if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
                           parse_fw_cfg, fw_cfg_find(), NULL) != 0) {
         exit(1);
@@ -4571,6 +4569,9 @@ int main(int argc, char **argv, char **envp)
                           device_init_func, NULL, NULL)) {
         exit(1);
     }
+
+    numa_post_machine_init();
+
     rom_reset_order_override();
 
     /* Did we create any drives that we failed to create a device for? */
Signature · 1 line
2.5.5
Signature · 1 line
Eduardo
author
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl: Ensure the numa_post_machine_init func in the appropriate location

Hi, Eduardo

Quoted 10 lines · Eduardo Habkost
Quoted 9 lines · Dou Liyang

In the numa_post_machine_init(), we use CPU_FOREACH macro to set all CPUs' namu_node. So, we should make sure that we call it after Qemu has already initialied all the CPUs.

As we all know, the CPUs can be created by "-smp"(pc_new_cpu) or "-device"(qdev_device_add) command. But, before the device init, Qemu execute the numa_post_machine_init earlier. It makes the mapping of NUMA nodes and CPUs incorrect.

Quoted 8 lines
Quoted 4 lines

The patch move the numa_post_machine_init func in the appropriate location.

I would like to move cpu_index initialization to
qom/cpu.c:cpu_common_realizefn(), and remove
numa_post_machine_init() completely.

Thanks, it is a good idea. I will try it later.

But, I hope to know that:

If you may want to say the cpu->**numa_node** initialization? Because the **cpu_index** initialization is in pc_cpu_pre_plug() currently, like that: cs->cpu_index = idx;

OR

You want to move both of them in cpu_common_realizefn() ?

Thanks,
Liyang.

But this fixes the bug while

Quoted 39 lines

we don't do that.

Queued on numa-next. Thanks!

Quoted 32 lines
---
 vl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
vl.c +3 -3
index c643d3f..f38b0e2 100644
@@ -4549,8 +4549,6 @@ int main(int argc, char **argv, char **envp)
 
     cpu_synchronize_all_post_init();
 
-    numa_post_machine_init();
-
     if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
                           parse_fw_cfg, fw_cfg_find(), NULL) != 0) {
         exit(1);
@@ -4571,6 +4569,9 @@ int main(int argc, char **argv, char **envp)
                           device_init_func, NULL, NULL)) {
         exit(1);
     }
+
+    numa_post_machine_init();
+
     rom_reset_order_override();
 
     /* Did we create any drives that we failed to create a device for? */
--

2.5.5

#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] vl: Ensure the numa_post_machine_init func in the appropriate location

Quoted 22 lines · Dou Liyang

Hi, Eduardo

Quoted 10 lines · Eduardo Habkost
Quoted 9 lines · Dou Liyang

In the numa_post_machine_init(), we use CPU_FOREACH macro to set all CPUs' namu_node. So, we should make sure that we call it after Qemu has already initialied all the CPUs.

As we all know, the CPUs can be created by "-smp"(pc_new_cpu) or "-device"(qdev_device_add) command. But, before the device init, Qemu execute the numa_post_machine_init earlier. It makes the mapping of NUMA nodes and CPUs incorrect.

Quoted 8 lines
Quoted 4 lines

The patch move the numa_post_machine_init func in the appropriate location.

I would like to move cpu_index initialization to
qom/cpu.c:cpu_common_realizefn(), and remove
numa_post_machine_init() completely.

Quoted 7 lines

Thanks, it is a good idea. I will try it later.

But, I hope to know that:

If you may want to say the cpu->**numa_node** initialization? Because the **cpu_index** initialization is in pc_cpu_pre_plug() currently, like that: cs->cpu_index = idx;

Oops, I meant the numa_node initialization. :)

Signature · 1 line
Eduardo
author
#5 lore raw

PATCH 2/2 vl: Ensure the cpu_synchronize_all_post_init func in the appropriate location

In reply to Dou Liyang

As the commit a4088c3eecb5f said, In the cpu_synchronize_all_post_init(), we also use CPU_FOREACH macro to set all CPUs' namu_node. So, we should make sure that we call it after Qemu has already initialied all the CPUs.

The patch move the numa_post_machine_init func in the appropriate location.

---
 vl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -2
index f38b0e2..75adc2a 100644
@@ -4547,8 +4547,6 @@ int main(int argc, char **argv, char **envp)
 
     audio_init();
 
-    cpu_synchronize_all_post_init();
-
     if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
                           parse_fw_cfg, fw_cfg_find(), NULL) != 0) {
         exit(1);
@@ -4570,6 +4568,8 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    cpu_synchronize_all_post_init();
+
     numa_post_machine_init();
 
     rom_reset_order_override();
Signature · 1 line
2.5.5
#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] vl: Ensure the cpu_synchronize_all_post_init func in the appropriate location

Quoted 2 lines · Dou Liyang

As the commit a4088c3eecb5f said, In the cpu_synchronize_all_post_init(), we also use CPU_FOREACH macro to set all CPUs' namu_node.

I can't find commit a4088c3eecb5f, is it the commit ID of your previous patch on your local tree? I don't see any NUMA-related code triggered cpu_synchronize_all_post_init().

Quoted 6 lines

So, we should
make sure that we call it after Qemu has already initialied all the CPUs.

The patch move the numa_post_machine_init func in the appropriate location.

This patch moves cpu_synchronize_all_post_init(), not numa_post_machine_init(). Could you describe which bug you are fixing, exactly? It doesn't seem to be related to NUMA.

Quoted 33 lines
---
 vl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -2
index f38b0e2..75adc2a 100644
@@ -4547,8 +4547,6 @@ int main(int argc, char **argv, char **envp)
 
     audio_init();
 
-    cpu_synchronize_all_post_init();
-
     if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
                           parse_fw_cfg, fw_cfg_find(), NULL) != 0) {
         exit(1);
@@ -4570,6 +4568,8 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    cpu_synchronize_all_post_init();
+
     numa_post_machine_init();
 
     rom_reset_order_override();
Signature · 1 line
2.5.5
Signature · 1 line
Eduardo
author
#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] vl: Ensure the cpu_synchronize_all_post_init func in the appropriate location

Hi, Eduardo

To clarify:

This patch is no related to the bug about NUMA.

This patch makes sure that all CPUs can run cpu state synchronization on target vcpu thread, not just the CPUs which created by "-smp 2..." at the beginning.

It is also caused by the execution sequence, So I put it here.

Quoted 8 lines · Eduardo Habkost
Quoted 2 lines · Dou Liyang

As the commit a4088c3eecb5f said, In the cpu_synchronize_all_post_init(), we also use CPU_FOREACH macro to set all CPUs' namu_node.

I can't find commit a4088c3eecb5f, is it the commit ID of your previous patch on your local tree? I don't see any NUMA-related code triggered cpu_synchronize_all_post_init().

Oops, yes. It is the previous patch 1 in my local tree. I will modify it.

Quoted 11 lines
Quoted 6 lines

So, we should
make sure that we call it after Qemu has already initialied all the CPUs.

The patch move the numa_post_machine_init func in the appropriate location.

This patch moves cpu_synchronize_all_post_init(), not numa_post_machine_init(). Could you describe which bug you are fixing, exactly? It doesn't seem to be related to NUMA.

Yes, I will describe it exactly in the next version.

Thanks,
Liyang

Quoted 34 lines
Quoted 33 lines
---
 vl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
vl.c +2 -3
index f38b0e2..75adc2a 100644
@@ -4547,8 +4547,6 @@ int main(int argc, char **argv, char **envp)
 
     audio_init();
 
-    cpu_synchronize_all_post_init();
-
     if (qemu_opts_foreach(qemu_find_opts("fw_cfg"),
                           parse_fw_cfg, fw_cfg_find(), NULL) != 0) {
         exit(1);
@@ -4570,6 +4568,8 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    cpu_synchronize_all_post_init();
+
     numa_post_machine_init();
 
     rom_reset_order_override();
--

2.5.5