Skip to contentSkip to conversation

softmmu/vl.c: fix too slow TCG regression

PATCH Superseded Igor Mammedov 4 participants 5 messages Feb 26, 2020 – Feb 27, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 softmmu/vl.c: fix too slow TCG regression

Commit a1b18df9a4 moved -m option parsing after configure_accelerators() that broke TCG accelerator initialization which accesses global ram_size from size_code_gen_buffer() which is equal to 0 at that moment.

Partially revert a1b18df9a4, by returning set_memory_options() to its original location and only keep 32-bit host VA check and 'memory-backend' size check introduced by fe64d06afc at current place.

---

PS:
This should take care of regression and give more time to think about how to remove size_code_gen_buffer() dependency on ram_size

---
 softmmu/vl.c | 49 +++++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 24 deletions(-)
softmmu/vl.c +25 -24
index a9cce78f45..da7577129c 100644
@@ -2634,29 +2634,6 @@ static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
         exit(EXIT_FAILURE);
     }
 
-    if (current_machine->ram_memdev_id) {
-        Object *backend;
-        ram_addr_t backend_size;
-
-        backend = object_resolve_path_type(current_machine->ram_memdev_id,
-                                           TYPE_MEMORY_BACKEND, NULL);
-        backend_size = object_property_get_uint(backend, "size",  &error_abort);
-        if (mem_str && backend_size != ram_size) {
-                error_report("Size specified by -m option must match size of "
-                             "explicitly specified 'memory-backend' property");
-                exit(EXIT_FAILURE);
-        }
-        ram_size = backend_size;
-    }
-
-    if (!xen_enabled()) {
-        /* On 32-bit hosts, QEMU is limited by virtual address space */
-        if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
-            error_report("at most 2047 MB RAM can be simulated");
-            exit(1);
-        }
-    }
-
     loc_pop(&loc);
 }
 
@@ -3821,6 +3798,8 @@ void qemu_init(int argc, char **argv, char **envp)
     machine_class = select_machine();
     object_set_machine_compat_props(machine_class->compat_props);
 
+    set_memory_options(&ram_slots, &maxram_size, machine_class);
+
     os_daemonize();
 
     /*
@@ -4296,7 +4275,29 @@ void qemu_init(int argc, char **argv, char **envp)
         current_machine->cpu_type = parse_cpu_option(cpu_option);
     }
 
-    set_memory_options(&ram_slots, &maxram_size, machine_class);
+    if (!xen_enabled()) {
+        /* On 32-bit hosts, QEMU is limited by virtual address space */
+        if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
+            error_report("at most 2047 MB RAM can be simulated");
+            exit(1);
+        }
+    }
+
+    if (current_machine->ram_memdev_id) {
+        Object *backend;
+        ram_addr_t backend_size;
+
+        backend = object_resolve_path_type(current_machine->ram_memdev_id,
+                                           TYPE_MEMORY_BACKEND, NULL);
+        backend_size = object_property_get_uint(backend, "size",  &error_abort);
+        if (backend_size != ram_size) {
+                error_report("Size specified by -m option must match size of "
+                             "explicitly specified 'memory-backend' property");
+                exit(EXIT_FAILURE);
+        }
+        ram_size = backend_size;
+    }
+
     current_machine->ram_size = ram_size;
     current_machine->maxram_size = maxram_size;
     current_machine->ram_slots = ram_slots;
Signature · 1 line
2.18.1
Tested-by on v1 1/1
#1 lore raw
Quoted 8 lines · Igor Mammedov

Commit a1b18df9a4 moved -m option parsing after configure_accelerators() that broke TCG accelerator initialization which accesses global ram_size from size_code_gen_buffer() which is equal to 0 at that moment.

Partially revert a1b18df9a4, by returning set_memory_options() to its original location and only keep 32-bit host VA check and 'memory-backend' size check introduced by fe64d06afc at current place.

Quoted 6 lines

---

PS:
This should take care of regression and give more time to think about how to remove size_code_gen_buffer() dependency on ram_size

FWIW I don't think it will take too long to fixup size_code_gen_buffer. See:

Subject: [PATCH v1 0/4] Fix codegen translation cache size
Date: Wed, 26 Feb 2020 18:10:16 +0000
Message-Id: <[email protected]>

Quoted 78 lines
---
 softmmu/vl.c | 49 +++++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 24 deletions(-)
softmmu/vl.c +25 -24
index a9cce78f45..da7577129c 100644
@@ -2634,29 +2634,6 @@ static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,
         exit(EXIT_FAILURE);
     }
 
-    if (current_machine->ram_memdev_id) {
-        Object *backend;
-        ram_addr_t backend_size;
-
-        backend = object_resolve_path_type(current_machine->ram_memdev_id,
-                                           TYPE_MEMORY_BACKEND, NULL);
-        backend_size = object_property_get_uint(backend, "size",  &error_abort);
-        if (mem_str && backend_size != ram_size) {
-                error_report("Size specified by -m option must match size of "
-                             "explicitly specified 'memory-backend' property");
-                exit(EXIT_FAILURE);
-        }
-        ram_size = backend_size;
-    }
-
-    if (!xen_enabled()) {
-        /* On 32-bit hosts, QEMU is limited by virtual address space */
-        if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
-            error_report("at most 2047 MB RAM can be simulated");
-            exit(1);
-        }
-    }
-
     loc_pop(&loc);
 }
 
@@ -3821,6 +3798,8 @@ void qemu_init(int argc, char **argv, char **envp)
     machine_class = select_machine();
     object_set_machine_compat_props(machine_class->compat_props);
 
+    set_memory_options(&ram_slots, &maxram_size, machine_class);
+
     os_daemonize();
 
     /*
@@ -4296,7 +4275,29 @@ void qemu_init(int argc, char **argv, char **envp)
         current_machine->cpu_type = parse_cpu_option(cpu_option);
     }
 
-    set_memory_options(&ram_slots, &maxram_size, machine_class);
+    if (!xen_enabled()) {
+        /* On 32-bit hosts, QEMU is limited by virtual address space */
+        if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
+            error_report("at most 2047 MB RAM can be simulated");
+            exit(1);
+        }
+    }
+
+    if (current_machine->ram_memdev_id) {
+        Object *backend;
+        ram_addr_t backend_size;
+
+        backend = object_resolve_path_type(current_machine->ram_memdev_id,
+                                           TYPE_MEMORY_BACKEND, NULL);
+        backend_size = object_property_get_uint(backend, "size",  &error_abort);
+        if (backend_size != ram_size) {
+                error_report("Size specified by -m option must match size of "
+                             "explicitly specified 'memory-backend' property");
+                exit(EXIT_FAILURE);
+        }
+        ram_size = backend_size;
+    }
+
     current_machine->ram_size = ram_size;
     current_machine->maxram_size = maxram_size;
     current_machine->ram_slots = ram_slots;
Signature · 1 line
Alex Bennée
Tested-by
#2 lore raw

Hello Igor, Alex,

Quoted 11 lines · Alex Bennée
Quoted 8 lines · Igor Mammedov

Commit a1b18df9a4 moved -m option parsing after configure_accelerators() that broke TCG accelerator initialization which accesses global ram_size from size_code_gen_buffer() which is equal to 0 at that moment.

Partially revert a1b18df9a4, by returning set_memory_options() to its original location and only keep 32-bit host VA check and 'memory-backend' size check introduced by fe64d06afc at current place.

Quoted 7 lines
Quoted 6 lines

---

PS:
This should take care of regression and give more time to think about how to remove size_code_gen_buffer() dependency on ram_size

Thanks for your quick response on this! I just applied this patch on top of latest master (db736e0437aa6fd7c1b7e4599c17f9619ab6b837)
and indeed it seems performance is back to normal. The avocado tests for cubieboard are also passing again like before.

So for me:

Quoted 11 lines

FWIW I don't think it will take too long to fixup size_code_gen_buffer. See:

Subject: [PATCH v1 0/4] Fix codegen translation cache size
Date: Wed, 26 Feb 2020 18:10:16 +0000
Message-Id: <[email protected]>

Yeah I saw your patch come by on the list as well Alex. I will try to look

into it as well.

Regards,
Niek

Quoted 92 lines

softmmu/vl.c static void set_memory_options(uint64_t

Quoted 9 lines
---
 softmmu/vl.c | 49 +++++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 24 deletions(-)
softmmu/vl.c +0 -0
index a9cce78f45..da7577129c 100644
@@ -2634,29 +2634,6 @@ static void set_memory_options(uint64_t

*ram_slots, ram_addr_t *maxram_size,

softmmu/vl.c static void set_memory_options(uint64_t *ram_slots, ram_addr_t *maxram_size,

Quoted 8 lines
softmmu/vl.c +0 -5
         exit(EXIT_FAILURE);
     }
 
-    if (current_machine->ram_memdev_id) {
-        Object *backend;
-        ram_addr_t backend_size;
-
-        backend =

object_resolve_path_type(current_machine->ram_memdev_id,

softmmu/vl.c static void set_memory_options(uint64_t · line 2643

Quoted 2 lines
softmmu/vl.c +0 -2
-                                           TYPE_MEMORY_BACKEND, NULL);
-        backend_size = object_property_get_uint(backend, "size",

&error_abort);

softmmu/vl.c static void set_memory_options(uint64_t · line 2645

Quoted 2 lines
softmmu/vl.c +0 -2
-        if (mem_str && backend_size != ram_size) {
-                error_report("Size specified by -m option must match

size of "

softmmu/vl.c static void set_memory_options(uint64_t · line 2646

Quoted 1 line
softmmu/vl.c +0 -1
-                             "explicitly specified 'memory-backend'

property");

Quoted 33 lines
softmmu/vl.c +5 -14
-                exit(EXIT_FAILURE);
-        }
-        ram_size = backend_size;
-    }
-
-    if (!xen_enabled()) {
-        /* On 32-bit hosts, QEMU is limited by virtual address space */
-        if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
-            error_report("at most 2047 MB RAM can be simulated");
-            exit(1);
-        }
-    }
-
     loc_pop(&loc);
 }
 
@@ -3821,6 +3798,8 @@ void qemu_init(int argc, char **argv, char **envp)
     machine_class = select_machine();
     object_set_machine_compat_props(machine_class->compat_props);
 
+    set_memory_options(&ram_slots, &maxram_size, machine_class);
+
     os_daemonize();
 
     /*
@@ -4296,7 +4275,29 @@ void qemu_init(int argc, char **argv, char **envp)
         current_machine->cpu_type = parse_cpu_option(cpu_option);
     }
 
-    set_memory_options(&ram_slots, &maxram_size, machine_class);
+    if (!xen_enabled()) {
+        /* On 32-bit hosts, QEMU is limited by virtual address space */
+        if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {

softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 4290

Quoted 10 lines
softmmu/vl.c +10 -0
+            error_report("at most 2047 MB RAM can be simulated");
+            exit(1);
+        }
+    }
+
+    if (current_machine->ram_memdev_id) {
+        Object *backend;
+        ram_addr_t backend_size;
+
+        backend =

object_resolve_path_type(current_machine->ram_memdev_id,

softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 4292

Quoted 2 lines
softmmu/vl.c +2 -0
+                                           TYPE_MEMORY_BACKEND, NULL);
+        backend_size = object_property_get_uint(backend, "size",

&error_abort);

softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 4294

Quoted 2 lines
softmmu/vl.c +2 -0
+        if (backend_size != ram_size) {
+                error_report("Size specified by -m option must match

size of "

softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 4295

Quoted 1 line
softmmu/vl.c +1 -0
+                             "explicitly specified 'memory-backend'

property");

softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 4303

Quoted 8 lines
softmmu/vl.c +5 -0
+                exit(EXIT_FAILURE);
+        }
+        ram_size = backend_size;
+    }
+
     current_machine->ram_size = ram_size;
     current_machine->maxram_size = maxram_size;
     current_machine->ram_slots = ram_slots;

--
Alex Bennée

Signature · 1 line
Niek Linnenbank
#3 lore raw
In reply to Igor Mammedov
Quoted 19 lines · Igor Mammedov

Commit a1b18df9a4 moved -m option parsing after configure_accelerators() that broke TCG accelerator initialization which accesses global ram_size from size_code_gen_buffer() which is equal to 0 at that moment.

Partially revert a1b18df9a4, by returning set_memory_options() to its original location and only keep 32-bit host VA check and 'memory-backend' size check introduced by fe64d06afc at current place.

---

PS:
This should take care of regression and give more time to think about how to remove size_code_gen_buffer() dependency on ram_size

softmmu/vl.c +3 -0
+    if (current_machine->ram_memdev_id) {
+        Object *backend;
+        ram_addr_t backend_size;

softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 4298

Quoted 10 lines
softmmu/vl.c +10 -0
+
+        backend = object_resolve_path_type(current_machine->ram_memdev_id,
+                                           TYPE_MEMORY_BACKEND, NULL);
+        backend_size = object_property_get_uint(backend, "size",  &error_abort);
+        if (backend_size != ram_size) {
+                error_report("Size specified by -m option must match size of "
+                             "explicitly specified 'memory-backend' property");
+                exit(EXIT_FAILURE);
+        }
+        ram_size = backend_size;

Why do we do this assignment? We've just checked that backend_size == ram_size so the assignment won't do anything, will it?

In the version of this check in set_memory_options() the assignment was useful because the error check only happened if mem_str is not NULL, ie there was an explicitly specified 'size' option somewhere. It looks like now we require the backend size to match even if the size is not explicitly specified by the user but comes from some default somewhere?

thanks
-- PMM

#4 lore raw
Quoted 35 lines · On Thu, 27 Feb 2020 09:15:00 +0000 Peter Maydell <[email protected]>…
Quoted 19 lines · Igor Mammedov

Commit a1b18df9a4 moved -m option parsing after configure_accelerators() that broke TCG accelerator initialization which accesses global ram_size from size_code_gen_buffer() which is equal to 0 at that moment.

Partially revert a1b18df9a4, by returning set_memory_options() to its original location and only keep 32-bit host VA check and 'memory-backend' size check introduced by fe64d06afc at current place.

---

PS:
This should take care of regression and give more time to think about how to remove size_code_gen_buffer() dependency on ram_size

softmmu/vl.c +3 -0
+    if (current_machine->ram_memdev_id) {
+        Object *backend;
+        ram_addr_t backend_size;

softmmu/vl.c void qemu_init(int argc, char **argv, char **envp) · line 4298

Quoted 10 lines
softmmu/vl.c +10 -0
+
+        backend = object_resolve_path_type(current_machine->ram_memdev_id,
+                                           TYPE_MEMORY_BACKEND, NULL);
+        backend_size = object_property_get_uint(backend, "size",  &error_abort);
+        if (backend_size != ram_size) {
+                error_report("Size specified by -m option must match size of "
+                             "explicitly specified 'memory-backend' property");
+                exit(EXIT_FAILURE);
+        }
+        ram_size = backend_size;  

Why do we do this assignment? We've just checked that backend_size == ram_size so the assignment won't do anything, will it?

Quoted 7 lines

In the version of this check in set_memory_options() the assignment was useful because the error check only happened if mem_str is not NULL, ie there was an explicitly specified 'size' option somewhere. It looks like now we require the backend size to match even if the size is not explicitly specified by the user but comes from some default somewhere?

Size might come from default and in that case mem_str was skipping the check and updating ram_size with backend's value.
So this patch is not correct, as it is breaking the case where no "-m" was specified and explicit backend was provided.

Quoted 4 lines

thanks
-- PMM