All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>, ehabkost@redhat.com
Subject: [PATCH v6 76/79] hostmem: introduce "prealloc-threads" property
Date: Wed, 19 Feb 2020 11:09:50 -0500	[thread overview]
Message-ID: <20200219160953.13771-77-imammedo@redhat.com> (raw)
In-Reply-To: <20200219160953.13771-1-imammedo@redhat.com>

the property will allow user to specify number of threads to use
in pre-allocation stage. It also will allow to reduce implicit
hostmem dependency on current_machine.
On object creation it will default to 1, but via machine
compat property it will be updated to MachineState::smp::cpus
to keep current behavior for hostmem and main RAM (which is
now also hostmem based).

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v3:
  - use object_register_sugar_prop() instead of directly hacking
    compat_props (Paolo Bonzini <pbonzini@redhat.com>)
  - fix TODO description

CC: pbonzini@redhat.com
CC: ehabkost@redhat.com
---
 include/sysemu/hostmem.h |  2 ++
 backends/hostmem.c       | 43 ++++++++++++++++++++++++++++++++++++----
 vl.c                     | 14 +++++++++----
 3 files changed, 51 insertions(+), 8 deletions(-)

diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h
index 5db0d668ec..bdf86665ab 100644
--- a/include/sysemu/hostmem.h
+++ b/include/sysemu/hostmem.h
@@ -61,6 +61,7 @@ struct HostMemoryBackendClass {
  * @parent: opaque parent object container
  * @size: amount of memory backend provides
  * @mr: MemoryRegion representing host memory belonging to backend
+ * @prealloc_threads: number of threads to be used for preallocatining RAM
  */
 struct HostMemoryBackend {
     /* private */
@@ -70,6 +71,7 @@ struct HostMemoryBackend {
     uint64_t size;
     bool merge, dump, use_canonical_path;
     bool prealloc, force_prealloc, is_mapped, share;
+    uint32_t prealloc_threads;
     DECLARE_BITMAP(host_nodes, MAX_NODES + 1);
     HostMemPolicy policy;
 
diff --git a/backends/hostmem.c b/backends/hostmem.c
index e773bdfa6e..0988986016 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -223,7 +223,6 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
 {
     Error *local_err = NULL;
     HostMemoryBackend *backend = MEMORY_BACKEND(obj);
-    MachineState *ms = MACHINE(qdev_get_machine());
 
     if (backend->force_prealloc) {
         if (value) {
@@ -243,7 +242,7 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
         void *ptr = memory_region_get_ram_ptr(&backend->mr);
         uint64_t sz = memory_region_size(&backend->mr);
 
-        os_mem_prealloc(fd, ptr, sz, ms->smp.cpus, &local_err);
+        os_mem_prealloc(fd, ptr, sz, backend->prealloc_threads, &local_err);
         if (local_err) {
             error_propagate(errp, local_err);
             return;
@@ -252,14 +251,45 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
     }
 }
 
+static void host_memory_backend_get_prealloc_threads(Object *obj, Visitor *v,
+    const char *name, void *opaque, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+    visit_type_uint32(v, name, &backend->prealloc_threads, errp);
+}
+
+static void host_memory_backend_set_prealloc_threads(Object *obj, Visitor *v,
+    const char *name, void *opaque, Error **errp)
+{
+    HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+    Error *local_err = NULL;
+    uint32_t value;
+
+    visit_type_uint32(v, name, &value, &local_err);
+    if (local_err) {
+        goto out;
+    }
+    if (value <= 0) {
+        error_setg(&local_err,
+                   "property '%s' of %s doesn't take value '%d'",
+                   name, object_get_typename(obj), value);
+        goto out;
+    }
+    backend->prealloc_threads = value;
+out:
+    error_propagate(errp, local_err);
+}
+
 static void host_memory_backend_init(Object *obj)
 {
     HostMemoryBackend *backend = MEMORY_BACKEND(obj);
     MachineState *machine = MACHINE(qdev_get_machine());
 
+    /* TODO: convert access to globals to compat properties */
     backend->merge = machine_mem_merge(machine);
     backend->dump = machine_dump_guest_core(machine);
     backend->prealloc = mem_prealloc;
+    backend->prealloc_threads = 1;
 }
 
 static void host_memory_backend_post_init(Object *obj)
@@ -313,7 +343,6 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
 {
     HostMemoryBackend *backend = MEMORY_BACKEND(uc);
     HostMemoryBackendClass *bc = MEMORY_BACKEND_GET_CLASS(uc);
-    MachineState *ms = MACHINE(qdev_get_machine());
     Error *local_err = NULL;
     void *ptr;
     uint64_t sz;
@@ -378,7 +407,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
          */
         if (backend->prealloc) {
             os_mem_prealloc(memory_region_get_fd(&backend->mr), ptr, sz,
-                            ms->smp.cpus, &local_err);
+                            backend->prealloc_threads, &local_err);
             if (local_err) {
                 goto out;
             }
@@ -456,6 +485,12 @@ host_memory_backend_class_init(ObjectClass *oc, void *data)
         host_memory_backend_set_prealloc, &error_abort);
     object_class_property_set_description(oc, "prealloc",
         "Preallocate memory", &error_abort);
+    object_class_property_add(oc, "prealloc-threads", "int",
+        host_memory_backend_get_prealloc_threads,
+        host_memory_backend_set_prealloc_threads,
+        NULL, NULL, &error_abort);
+    object_class_property_set_description(oc, "prealloc-threads",
+        "Number of CPU threads to use for prealloc", &error_abort);
     object_class_property_add(oc, "size", "int",
         host_memory_backend_get_size,
         host_memory_backend_set_size,
diff --git a/vl.c b/vl.c
index 15cc5bd565..afc682e168 100644
--- a/vl.c
+++ b/vl.c
@@ -2828,8 +2828,7 @@ static void configure_accelerators(const char *progname)
     }
 }
 
-static void create_default_memdev(MachineState *ms, const char *path,
-                                  bool prealloc)
+static void create_default_memdev(MachineState *ms, const char *path)
 {
     Object *obj;
     MachineClass *mc = MACHINE_GET_CLASS(ms);
@@ -2838,7 +2837,6 @@ static void create_default_memdev(MachineState *ms, const char *path,
     if (path) {
         object_property_set_str(obj, path, "mem-path", &error_fatal);
     }
-    object_property_set_bool(obj, prealloc, "prealloc", &error_fatal);
     object_property_set_int(obj, ms->ram_size, "size", &error_fatal);
     object_property_add_child(object_get_objects_root(), mc->default_ram_id,
                               obj, &error_fatal);
@@ -3980,6 +3978,14 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    if (mem_prealloc) {
+        char *val;
+
+        val = g_strdup_printf("%d", current_machine->smp.cpus);
+        object_register_sugar_prop("memory-backend", "prealloc-threads", val);
+        g_free(val);
+    }
+
     /*
      * Get the default machine options from the machine if it is not already
      * specified either by the configuration file or by the command line.
@@ -4307,7 +4313,7 @@ int main(int argc, char **argv, char **envp)
 
     if (machine_class->default_ram_id && current_machine->ram_size &&
         numa_uses_legacy_mem() && !current_machine->ram_memdev_id) {
-        create_default_memdev(current_machine, mem_path, mem_prealloc);
+        create_default_memdev(current_machine, mem_path);
     }
     /* do monitor/qmp handling at preconfig state if requested */
     main_loop();
-- 
2.18.1



  parent reply	other threads:[~2020-02-19 16:32 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-19 16:08 [PATCH v6 00/79] refactor main RAM allocation to use hostmem backend Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 01/79] numa: remove deprecated -mem-path fallback to anonymous RAM Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 02/79] machine: introduce memory-backend property Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 03/79] machine: alias -mem-path and -mem-prealloc into memory-foo backend Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 04/79] machine: introduce convenience MachineState::ram Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 05/79] initialize MachineState::ram in NUMA case Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 06/79] vl.c: move -m parsing after memory backends has been processed Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 07/79] vl.c: ensure that ram_size matches size of machine.memory-backend Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 08/79] alpha/dp264: use memdev for RAM Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 09/79] arm/aspeed: actually check RAM size Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 10/79] arm/aspeed: use memdev for RAM Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 11/79] arm/collie: " Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 12/79] arm/cubieboard: " Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 13/79] arm/digic_boards: " Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 14/79] arm/highbank: " Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 15/79] arm/imx25_pdk: drop RAM size fixup Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 16/79] arm/imx25_pdk: use memdev for RAM Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 17/79] arm/integratorcp: " Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 18/79] arm/kzm: drop RAM size fixup Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 19/79] arm/kzm: use memdev for RAM Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 20/79] arm/mcimx6ul-evk: " Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 21/79] arm/mcimx7d-sabre: " Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 22/79] arm/mps2-tz: " Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 23/79] arm/mps2: " Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 24/79] arm/musicpal: " Igor Mammedov
2020-02-19 16:08 ` [PATCH v6 25/79] arm/nseries: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 26/79] arm/omap_sx1: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 27/79] arm/palm: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 28/79] arm/sabrelite: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 29/79] arm/raspi: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 30/79] arm/sbsa-ref: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 31/79] arm/versatilepb: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 32/79] arm/vexpress: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 33/79] arm/virt: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 34/79] arm/xilinx_zynq: drop RAM size fixup Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 35/79] arm/xilinx_zynq: use memdev for RAM Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 36/79] arm/xlnx-versal-virt: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 37/79] arm/xlnx-zcu102: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 38/79] s390x/s390-virtio-ccw: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 39/79] null-machine: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 40/79] cris/axis_dev88: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 41/79] hppa: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 42/79] x86/microvm: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 43/79] x86/pc: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 44/79] lm32/lm32_boards: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 45/79] lm32/milkymist: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 46/79] m68k/an5206: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 47/79] m68k/q800: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 48/79] m68k/mcf5208: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 49/79] m68k/next-cube: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 50/79] mips/boston: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 51/79] mips/mips_fulong2e: drop RAM size fixup Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 52/79] mips/mips_fulong2e: use memdev for RAM Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 53/79] mips/mips_jazz: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 54/79] mips/mips_jazz: add max ram size check Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 55/79] mips/mips_malta: use memdev for RAM Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 56/79] mips/mips_mipssim: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 57/79] mips/mips_r4k: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 58/79] ppc/e500: drop RAM size fixup Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 59/79] ppc/e500: use memdev for RAM Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 60/79] ppc/mac_newworld: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 61/79] ppc/mac_oldworld: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 62/79] ppc/pnv: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 63/79] ppc/ppc405_boards: add RAM size checks Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 64/79] ppc/ppc405_boards: use memdev for RAM Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 65/79] ppc/{ppc440_bamboo, sam460ex}: drop RAM size fixup Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 66/79] ppc/{ppc440_bamboo, sam460ex}: use memdev for RAM Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 67/79] ppc/spapr: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 68/79] ppc/virtex_ml507: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 69/79] sparc/leon3: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 70/79] sparc/sun4m: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 71/79] sparc/niagara: " Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 72/79] remove no longer used memory_region_allocate_system_memory() Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 73/79] exec: cleanup qemu_minrampagesize()/qemu_maxrampagesize() Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 74/79] exec: drop bogus mem_path from qemu_ram_alloc_from_fd() Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 75/79] make mem_path local variable Igor Mammedov
2020-02-19 16:09 ` Igor Mammedov [this message]
2020-02-19 16:09 ` [PATCH v6 77/79] hostmem: fix strict bind policy Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 78/79] tests/numa-test: make top level args dynamic and g_autofree(cli) cleanups Igor Mammedov
2020-02-19 16:09 ` [PATCH v6 79/79] tests:numa-test: use explicit memdev to specify node RAM Igor Mammedov
2020-02-19 16:58 ` [PATCH v6 00/79] refactor main RAM allocation to use hostmem backend no-reply
2020-02-24  8:45 ` Philippe Mathieu-Daudé
2020-02-24 11:33   ` Igor Mammedov
2020-02-24 11:38     ` Philippe Mathieu-Daudé

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=20200219160953.13771-77-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.