From patchwork Thu Apr 4 23:37:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 161816 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp2204265jan; Thu, 4 Apr 2019 16:38:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMZZnKEEWOKKW+5+tXxUXRG/qTkP/VvbUVgEgSttlYfQQkOOSXDEtWAh6EMHQqbNzOiW3Z X-Received: by 2002:a0c:f903:: with SMTP id v3mr7632482qvn.152.1554421087818; Thu, 04 Apr 2019 16:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554421087; cv=none; d=google.com; s=arc-20160816; b=Suv3sQ7rjW6GJFJiD9rQjbf79ChN2B+LBQVvtWn712s0/N3sl2bwuyW5pRvhOnRsGK O4jOcvHdZ2b/4KlU4nG8YtCAKKZKtkKe8AAAxuPE7ucUObgibUx3APhf68L4kXfYrGcW 4LkuBM1cgCxp2+22ZF6uiIHVtZ6CtOhMGRyzt/sEWKKkqjlQJenD8m3dpfmAdiQai/Pd 7QX9aDJD8/jKGc3qyvBCiSdrJxFuIcLvowRd22n6NVECS0JOyJy0acrlDCifAVfb5D/+ 9vJmEUms1sZvizFIm857r1UqNOVkVpE1JqY9aGuTBrI3pZo+NzAYwWk5hd1vilLvsjuC btvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :delivered-to; bh=ar4bmjAKuFJgiElDs9OtuHScXD3AHhAUOn4QSM16ihc=; b=ETXDoZ8UyX7hbgnIaURNJnKEnsSv19tBtmpYonlOiiVcJZ/W//OAHiYoEioWxHkrYi +bsgsH+IOehEW2Bf6Gbn6w5KirWUmI2/Z0mFrhxZ07uxubBnx5nQZrVOeMGSBs7bvT5R J3zXbm9jSy1KxQ7PG1Q+TRFAsMKjtuyLqKfGM+Th2N7CCqWENuVp/P9hxlmbbARGs1q9 Z/qiAK96FGHUsz5mSB1kNlunHoCfH9Ak9vRJtl8YRQiRrKRaF43BCZUcD8QZK3Suy6aj 2iRlT1o52LBskVyxyZb6cUNteh6mCkWnBgDH5K980tiKwfGylyaU8SVJafW1dNFFzzN/ WT7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id h19si129631qto.168.2019.04.04.16.38.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Apr 2019 16:38:07 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BBF53086223; Thu, 4 Apr 2019 23:38:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F88E1001E99; Thu, 4 Apr 2019 23:38:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7EC973FB13; Thu, 4 Apr 2019 23:38:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x34NbgKT011037 for ; Thu, 4 Apr 2019 19:37:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 62F0260919; Thu, 4 Apr 2019 23:37:42 +0000 (UTC) Delivered-To: libvirt-list@redhat.com Received: from worklaptop.redhat.com (ovpn-124-22.rdu2.redhat.com [10.10.124.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id A362A608E5; Thu, 4 Apr 2019 23:37:41 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Thu, 4 Apr 2019 19:37:24 -0400 Message-Id: <980d16e0dd03fdebba118fc2ab8a3a0b5dc08b76.1554419814.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/7] qemu: conf: Cache domCaps in qemuCaps X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Thu, 04 Apr 2019 23:38:06 +0000 (UTC) qemuCaps is tied to a binary on disk. domCaps is tied to a combo of binary+machine+arch+virttype values. For the qemu driver this almost entirely translates to a permutation of qemuCaps though Upcoming patches want to use the domCaps data store at XML validate time, but we need to cache the data so we aren't repeatedly regenerating it. Add a domCapsCache hash table to qemuCaps. This ensures that the domCaps cache is blown away whenever qemuCaps needs to be regenerated. Adjust virQEMUDriverGetDomainCapabilities to search the cache and add to it if we don't find a hit. Signed-off-by: Cole Robinson --- src/qemu/qemu_capabilities.c | 11 +++++++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_conf.c | 59 +++++++++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 7 deletions(-) -- 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list Reviewed-by: Daniel Henrique Barboza diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 46ba5e30b5..a3c1348157 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -582,6 +582,7 @@ struct _virQEMUCaps { virArch arch; + virHashTablePtr domCapsCache; virDomainCapsCPUModelsPtr kvmCPUModels; virDomainCapsCPUModelsPtr tcgCPUModels; @@ -1476,6 +1477,9 @@ virQEMUCapsNew(void) if (!(qemuCaps->flags = virBitmapNew(QEMU_CAPS_LAST))) goto error; + if (!(qemuCaps->domCapsCache = virHashCreate(5, virObjectFreeHashData))) + goto error; + return qemuCaps; error: @@ -1628,6 +1632,7 @@ void virQEMUCapsDispose(void *obj) } VIR_FREE(qemuCaps->machineTypes); + virHashFree(qemuCaps->domCapsCache); virObjectUnref(qemuCaps->kvmCPUModels); virObjectUnref(qemuCaps->tcgCPUModels); @@ -1790,6 +1795,12 @@ const char *virQEMUCapsGetPackage(virQEMUCapsPtr qemuCaps) } +virHashTablePtr virQEMUCapsGetDomainCapsCache(virQEMUCapsPtr qemuCaps) +{ + return qemuCaps->domCapsCache; +} + + int virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps, virDomainVirtType type, diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index c6f6980684..2a37f0c2ff 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -538,6 +538,7 @@ const char *virQEMUCapsGetBinary(virQEMUCapsPtr qemuCaps); virArch virQEMUCapsGetArch(virQEMUCapsPtr qemuCaps); unsigned int virQEMUCapsGetVersion(virQEMUCapsPtr qemuCaps); const char *virQEMUCapsGetPackage(virQEMUCapsPtr qemuCaps); +virHashTablePtr virQEMUCapsGetDomainCapsCache(virQEMUCapsPtr qemuCaps); unsigned int virQEMUCapsGetKVMVersion(virQEMUCapsPtr qemuCaps); int virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps, virDomainVirtType type, diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 635fdcc5a4..6a7c183075 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1358,10 +1358,39 @@ virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver, } +struct virQEMUDriverSearchDomcapsData { + const char *path; + const char *machine; + virArch arch; + virDomainVirtType virttype; +}; + + +static int +virQEMUDriverSearchDomcaps(const void *payload, + const void *name ATTRIBUTE_UNUSED, + const void *opaque) +{ + virDomainCapsPtr domCaps = (virDomainCapsPtr) payload; + struct virQEMUDriverSearchDomcapsData *data = (struct virQEMUDriverSearchDomcapsData *) opaque; + + if (STREQ_NULLABLE(data->path, domCaps->path) && + STREQ_NULLABLE(data->machine, domCaps->machine) && + data->arch == domCaps->arch && + data->virttype == domCaps->virttype) + return 1; + + return 0; +} + /** * virQEMUDriverGetDomainCapabilities: * - * Build a virDomainCapsPtr instance for the passed data. + * Get a reference to the virDomainCapsPtr instance from the virQEMUCapsPtr + * domCapsCache. If there's no domcaps in the cache, create a new instance, + * add it to the cache, and return a reference. + * + * The caller must release the reference with virObjetUnref * * Returns: a reference to a virDomainCapsPtr instance or NULL */ @@ -1375,18 +1404,34 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver, virDomainCapsPtr ret = NULL, domCaps = NULL; virCapsPtr caps = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + virHashTablePtr domCapsCache = virQEMUCapsGetDomainCapsCache(qemuCaps); + struct virQEMUDriverSearchDomcapsData data = { + .path = virQEMUCapsGetBinary(qemuCaps), + .machine = machine, + .arch = arch, + .virttype = virttype, + }; if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (!(domCaps = virDomainCapsNew(virQEMUCapsGetBinary(qemuCaps), machine, - arch, virttype))) - goto cleanup; + domCaps = virHashSearch(domCapsCache, + virQEMUDriverSearchDomcaps, &data, NULL); + if (!domCaps) { + /* hash miss, build new domcaps */ + if (!(domCaps = virDomainCapsNew(data.path, data.machine, + data.arch, data.virttype))) + goto cleanup; - if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps, - cfg->firmwares, cfg->nfirmwares) < 0) - goto cleanup; + if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps, + cfg->firmwares, cfg->nfirmwares) < 0) + goto cleanup; + + if (virHashAddEntry(domCapsCache, machine, domCaps) < 0) + goto cleanup; + } + virObjectRef(domCaps); VIR_STEAL_PTR(ret, domCaps); cleanup: virObjectUnref(domCaps);