From patchwork Wed Feb 19 16:09:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 11391885 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1CABC109A for ; Wed, 19 Feb 2020 16:32:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E7AF424676 for ; Wed, 19 Feb 2020 16:32:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QKCEDECW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E7AF424676 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:55878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4SGm-0003iJ-1n for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Feb 2020 11:32:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37933) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j4Rwm-000598-7r for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:11:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j4Rwj-0001bs-64 for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:11:34 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:52742 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j4Rwe-0001Zi-AC for qemu-devel@nongnu.org; Wed, 19 Feb 2020 11:11:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582128687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QkmHNGF0kUn2HU7S3GOFvwkJsekL3iXycc+SpG5kyN8=; b=QKCEDECWldXsNE7LBmkAl4/x3Zn5AU//cyJhVq9g8zyyPwk/O9LMNPbMtXrXtnG5yHzbM2 +zKpqtp85n1+iZ3dVIwloFEfCVmtsgEW5aApwWRsCY9dKDgW94tW3mySwR4AqYwB6Ss8zt aPcswY59C4xekpZLjFPPxKYi4qVdJiI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-429-Lw4hENNRPuWSf4nC38PxzQ-1; Wed, 19 Feb 2020 11:11:26 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1BA1218C8C05 for ; Wed, 19 Feb 2020 16:11:25 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40B8B8ED00; Wed, 19 Feb 2020 16:11:24 +0000 (UTC) From: Igor Mammedov To: qemu-devel@nongnu.org Subject: [PATCH v6 76/79] hostmem: introduce "prealloc-threads" property Date: Wed, 19 Feb 2020 11:09:50 -0500 Message-Id: <20200219160953.13771-77-imammedo@redhat.com> In-Reply-To: <20200219160953.13771-1-imammedo@redhat.com> References: <20200219160953.13771-1-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: Lw4hENNRPuWSf4nC38PxzQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , ehabkost@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- v3: - use object_register_sugar_prop() instead of directly hacking compat_props (Paolo Bonzini ) - 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();