From nobody Tue May 14 08:04:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620825833; cv=none; d=zohomail.com; s=zohoarc; b=mu03BJou90uEwZgrW8tQfF0uaFu1TJdSYs5M1moO5kKIEp/Zg9GmNHodV58aZzmp5tuYf6/TozDnuABytdmhp2FJCJbFz+3VXN6isagyqMCW6RMlXikpX2846hFywvJXz9CVZlQ99rYK/sft7sUrqz8R+wtAtD56tkilDkub5VU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620825833; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5FnAEpE/xvjMDAvzn2xLHQWmc5Ht0f4bhc3E7hpY5/s=; b=ewbz7NUN/tzCIKFMnqPMo+TEwLS9/tvUly0RcQnTHOvR+kdgISmmoh5u9nPZVoydAAHj2hubXf0hI8LEJHPv8+adVJ0MOuMWfh9+bXc8A3lYTBG0C6dUt5HqthZNCFCZZ3r4CLFs4MrpNY38iKxJQ6N9+NEfiBXRXfxNmcTo0+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620825833505625.1990144205645; Wed, 12 May 2021 06:23:53 -0700 (PDT) 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-376-M8aWoLmOObOwHvDG2wtNCw-1; Wed, 12 May 2021 09:23:50 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F0EC101371B; Wed, 12 May 2021 13:23:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D193F6249C; Wed, 12 May 2021 13:23:44 +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 C046D180B464; Wed, 12 May 2021 13:23:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14CDNdrB030413 for ; Wed, 12 May 2021 09:23:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id D9C20E715; Wed, 12 May 2021 13:23:39 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B8FBE150 for ; Wed, 12 May 2021 13:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620825832; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5FnAEpE/xvjMDAvzn2xLHQWmc5Ht0f4bhc3E7hpY5/s=; b=Xh/nlwaWRmqESVZWYFCQ7dYLR50U/rwQ7YCdFSgHZCCPZYbqvYKJGoQ8llYcJ2pEz89Etm U0CIJaOAqjB1axWOiy4XMw9iHn3goOs07gn/b+Bo72viAuiXCvrpzcz3OQKJyOF2s8LxB7 fJC2Szmq25b5CpKHbGQwexE7vsOHn58= X-MC-Unique: M8aWoLmOObOwHvDG2wtNCw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/3] libxl: Break down an if() in libxlCapsInitNuma() Date: Wed, 12 May 2021 15:23:29 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There's an if-else statement in libxlCapsInitNuma() that can really be just two standalone if()-s. Writing it as such helps with code readability. Signed-off-by: Michal Privoznik Reviewed-by: Jim Fehlig --- src/libxl/libxl_capabilities.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index ea4f370a6d..a64a9266c4 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -260,13 +260,13 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCaps *caps) virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("libxl_get_numainfo failed")); goto cleanup; - } else { - cpu_topo =3D libxl_get_cpu_topology(ctx, &nr_cpus); - if (cpu_topo =3D=3D NULL || nr_cpus =3D=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("libxl_get_cpu_topology failed")); - goto cleanup; - } + } + + cpu_topo =3D libxl_get_cpu_topology(ctx, &nr_cpus); + if (cpu_topo =3D=3D NULL || nr_cpus =3D=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("libxl_get_cpu_topology failed")); + goto cleanup; } =20 cpus =3D g_new0(virCapsHostNUMACellCPU *, nr_nodes); --=20 2.26.3 From nobody Tue May 14 08:04:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620825837; cv=none; d=zohomail.com; s=zohoarc; b=n1FQIAhKILG2NWgjnCW2vKy7IhuAPlfbJS7MJa/Jfsmfp3a3B51iLh8AA8HCmWE90hvJv32M0acwL8WLI8Ndrpeb6jk1idRvNAVd6uBdrJJnP8v8GfVrkiHMOkLzdPxiQBQgtmENENUu0qdYD6JFi1bQBppd74NHuLC+qQD91WY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620825837; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vx49S4+hdKInWgvF+A2wd+RbrvjcywNfxQO/NsS2oXs=; b=l+kAMrnYQbZI7CQh4v+r0hLW808cE2koqWaB1DWbVeim5Ovp1vlhNlTp6IXQUFolP1jiFyTjnYjPF8Pdj2oWOxj7RkfllS00O5sYdEohnIDcqSXfYwc38wxWPJ03UWoK6h3dK0Ygs7OQRwpPnBV7OCJUnbugX88bRlAbyNuEs5A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1620825837789183.17730295790648; Wed, 12 May 2021 06:23:57 -0700 (PDT) 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-105--lqU1T8eNp2UNzr3t2sk9A-1; Wed, 12 May 2021 09:23:52 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F7DEC73B0; Wed, 12 May 2021 13:23:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B874F3A3; Wed, 12 May 2021 13:23:44 +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 623A7180B463; Wed, 12 May 2021 13:23:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14CDNeie030423 for ; Wed, 12 May 2021 09:23:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id B69B5E715; Wed, 12 May 2021 13:23:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 376A0E150 for ; Wed, 12 May 2021 13:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620825836; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=vx49S4+hdKInWgvF+A2wd+RbrvjcywNfxQO/NsS2oXs=; b=NFc90aW2rzPBkg/C1twbn91CrkkzBn6mYiI+gPUAPg/BNrevteS+Nhx1mUIe7YE+qJ2XMO wBShDjO/Eh4oQoVSXg8hHdNdo17Xy75JVedIyuMoO4P29JipJJFuj3avi3ne8pLJsXkRuQ f0K76bGXgIiGV8uxKoIA0o2d/FOYdS4= X-MC-Unique: -lqU1T8eNp2UNzr3t2sk9A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/3] capabilities: Turn @cpus in _virCapsHostNUMACell into GArray Date: Wed, 12 May 2021 15:23:30 +0200 Message-Id: <865bcfc96b33bcbd252067f9493d573a9f0a9e98.1620824567.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Currently, we are storing the list of CPUs belonging to a NUMA cell as a regular C array of virCapsHostNUMACellCPU structs. The length of the array is stored separately, next to the array. This works, except for one case - freeing the array. Since the array length is stored separately we can't use automatic cleanup/free. The solution is to rework how the array is stored -> switch to GAarray which stores the length among with the array items and allows us to define a clear function which is called over each individual item in the array upon its release. For many places this has no direct effect on how the array is constructed, except for libxl. A multidimensional array is constructed there and honestly, I did not want to touch it. Therefore, instead of constructing CPU list directly into GArray I'm just copying over the values after the multidimensional array is created. Signed-off-by: Michal Privoznik --- src/conf/capabilities.c | 129 ++++++++++++++++++--------------- src/conf/capabilities.h | 11 +-- src/libvirt_private.syms | 2 +- src/libxl/libxl_capabilities.c | 20 +++-- src/test/test_driver.c | 12 +-- tests/testutils.c | 23 +++--- 6 files changed, 108 insertions(+), 89 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 1dae6d38cc..4c50f5d52a 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -95,30 +95,41 @@ virCapabilitiesNew(virArch hostarch, return caps; } =20 -void -virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPU *cpus, - size_t ncpus) + +static void +virCapsHostNUMACellCPUClear(void *data) { - size_t i; + virCapsHostNUMACellCPU *cpu =3D data; + + virBitmapFree(cpu->siblings); + memset(cpu, 0, sizeof(*cpu)); +} =20 - if (!cpus) - return; =20 - for (i =3D 0; i < ncpus; i++) { - virBitmapFree(cpus[i].siblings); - cpus[i].siblings =3D NULL; - } +/** + * virCapsHostNUMACellCPUNew: + * @prealloc: number of items to allocate + * + * Creates a new array of host CPUs. + */ +GArray * +virCapsHostNUMACellCPUNew(size_t prealloc) +{ + GArray *ret; + + ret =3D g_array_sized_new(FALSE, FALSE, sizeof(virCapsHostNUMACellCPU)= , prealloc); + g_array_set_clear_func(ret, virCapsHostNUMACellCPUClear); + return ret; } =20 + static void virCapabilitiesFreeHostNUMACell(virCapsHostNUMACell *cell) { if (cell =3D=3D NULL) return; =20 - virCapabilitiesClearHostNUMACellCPUTopology(cell->cpus, cell->ncpus); - - g_free(cell->cpus); + g_array_unref(cell->cpus); g_free(cell->siblings); g_free(cell->pageinfo); g_free(cell); @@ -329,7 +340,6 @@ virCapabilitiesSetNetPrefix(virCaps *caps, * @caps: capabilities to extend * @num: ID number of NUMA cell * @mem: Total size of memory in the NUMA node (in KiB) - * @ncpus: number of CPUs in cell * @cpus: array of CPU definition structures * @nsiblings: number of sibling NUMA nodes * @siblings: info on sibling NUMA nodes @@ -346,8 +356,7 @@ void virCapabilitiesHostNUMAAddCell(virCapsHostNUMA *caps, int num, unsigned long long mem, - int ncpus, - virCapsHostNUMACellCPU **cpus, + GArray **cpus, int nsiblings, virCapsHostNUMACellSiblingInfo **siblings, int npageinfo, @@ -357,9 +366,10 @@ virCapabilitiesHostNUMAAddCell(virCapsHostNUMA *caps, =20 cell->num =3D num; cell->mem =3D mem; - if (cpus) { - cell->ncpus =3D ncpus; + if (cpus && *cpus) { cell->cpus =3D g_steal_pointer(cpus); + } else { + cell->cpus =3D virCapsHostNUMACellCPUNew(0); } if (siblings) { cell->nsiblings =3D nsiblings; @@ -845,20 +855,22 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf, virBufferAddLit(buf, "\n"); } =20 - virBufferAsprintf(buf, "\n", cell->ncpus); + virBufferAsprintf(buf, "\n", cell->cpus->len); virBufferAdjustIndent(buf, 2); - for (j =3D 0; j < cell->ncpus; j++) { - virBufferAsprintf(buf, "cpus[j].id); + for (j =3D 0; j < cell->cpus->len; j++) { + virCapsHostNUMACellCPU *cpu =3D &g_array_index(cell->cpus, vi= rCapsHostNUMACellCPU, j); =20 - if (cell->cpus[j].siblings) { - if (!(siblings =3D virBitmapFormat(cell->cpus[j].siblings)= )) + virBufferAsprintf(buf, "id); + + if (cpu->siblings) { + if (!(siblings =3D virBitmapFormat(cpu->siblings))) return -1; =20 virBufferAsprintf(buf, " socket_id=3D'%d' die_id=3D'%d' core_id= =3D'%d' siblings=3D'%s'", - cell->cpus[j].socket_id, - cell->cpus[j].die_id, - cell->cpus[j].core_id, + cpu->socket_id, + cpu->die_id, + cpu->core_id, siblings); VIR_FREE(siblings); } @@ -1341,14 +1353,16 @@ virCapabilitiesHostNUMAGetMaxcpu(virCapsHostNUMA *c= aps) { unsigned int maxcpu =3D 0; size_t node; - size_t cpu; =20 for (node =3D 0; node < caps->cells->len; node++) { virCapsHostNUMACell *cell =3D g_ptr_array_index(caps->cells, node); + size_t j; =20 - for (cpu =3D 0; cpu < cell->ncpus; cpu++) { - if (cell->cpus[cpu].id > maxcpu) - maxcpu =3D cell->cpus[cpu].id; + for (j =3D 0; j < cell->cpus->len; j++) { + virCapsHostNUMACellCPU *cpu =3D &g_array_index(cell->cpus, vi= rCapsHostNUMACellCPU, j); + + if (cpu->id > maxcpu) + maxcpu =3D cpu->id; } } =20 @@ -1362,7 +1376,6 @@ virCapabilitiesHostNUMAGetCellCpus(virCapsHostNUMA *c= aps, virBitmap *cpumask) { virCapsHostNUMACell *cell =3D NULL; - size_t cpu; size_t i; /* The numa node numbers can be non-contiguous. Ex: 0,1,16,17. */ for (i =3D 0; i < caps->cells->len; i++) { @@ -1372,12 +1385,14 @@ virCapabilitiesHostNUMAGetCellCpus(virCapsHostNUMA = *caps, cell =3D NULL; } =20 - for (cpu =3D 0; cell && cpu < cell->ncpus; cpu++) { - if (virBitmapSetBit(cpumask, cell->cpus[cpu].id) < 0) { + for (i =3D 0; cell && i < cell->cpus->len; i++) { + virCapsHostNUMACellCPU *cpu =3D &g_array_index(cell->cpus, virCap= sHostNUMACellCPU, i); + + if (virBitmapSetBit(cpumask, cpu->id) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cpu '%u' in node '%zu' is out of range " + _("CPU '%u' in node '%zu' is out of range " "of the provided bitmap"), - cell->cpus[cpu].id, node); + cpu->id, node); return -1; } } @@ -1532,10 +1547,9 @@ static int virCapabilitiesHostNUMAInitFake(virCapsHostNUMA *caps) { virNodeInfo nodeinfo; - virCapsHostNUMACellCPU *cpus; int ncpus; int n, s, c, t; - int id, cid; + int id; int onlinecpus G_GNUC_UNUSED; bool tmp; =20 @@ -1547,10 +1561,10 @@ virCapabilitiesHostNUMAInitFake(virCapsHostNUMA *ca= ps) =20 id =3D 0; for (n =3D 0; n < nodeinfo.nodes; n++) { + g_autoptr(GArray) cpus =3D NULL; int nodecpus =3D nodeinfo.sockets * nodeinfo.cores * nodeinfo.thre= ads; - cid =3D 0; =20 - cpus =3D g_new0(virCapsHostNUMACellCPU, nodecpus); + cpus =3D virCapsHostNUMACellCPUNew(nodecpus); =20 for (s =3D 0; s < nodeinfo.sockets; s++) { for (c =3D 0; c < nodeinfo.cores; c++) { @@ -1559,15 +1573,17 @@ virCapabilitiesHostNUMAInitFake(virCapsHostNUMA *ca= ps) ignore_value(virBitmapSetBit(siblings, id + t)); =20 for (t =3D 0; t < nodeinfo.threads; t++) { + virCapsHostNUMACellCPU cpu =3D { 0 }; + if (virHostCPUGetOnline(id, &tmp) < 0) goto error; if (tmp) { - cpus[cid].id =3D id; - cpus[cid].die_id =3D 0; - cpus[cid].socket_id =3D s; - cpus[cid].core_id =3D c; - cpus[cid].siblings =3D virBitmapNewCopy(siblings); - cid++; + cpu.id =3D id; + cpu.die_id =3D 0; + cpu.socket_id =3D s; + cpu.core_id =3D c; + cpu.siblings =3D virBitmapNewCopy(siblings); + g_array_append_val(cpus, cpu); } =20 id++; @@ -1577,7 +1593,7 @@ virCapabilitiesHostNUMAInitFake(virCapsHostNUMA *caps) =20 virCapabilitiesHostNUMAAddCell(caps, 0, nodeinfo.memory, - cid, &cpus, + &cpus, 0, NULL, 0, NULL); } @@ -1585,9 +1601,6 @@ virCapabilitiesHostNUMAInitFake(virCapsHostNUMA *caps) return 0; =20 error: - for (; cid >=3D 0; cid--) - virBitmapFree(cpus[cid].siblings); - VIR_FREE(cpus); return -1; } =20 @@ -1596,9 +1609,7 @@ static int virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps) { int n; - virCapsHostNUMACellCPU *cpus =3D NULL; int ret =3D -1; - int ncpus =3D 0; int max_node; =20 if ((max_node =3D virNumaGetMaxNode()) < 0) @@ -1606,12 +1617,13 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *ca= ps) =20 for (n =3D 0; n <=3D max_node; n++) { g_autoptr(virBitmap) cpumap =3D NULL; + int ncpus; + g_autoptr(GArray) cpus =3D NULL; g_autofree virCapsHostNUMACellSiblingInfo *siblings =3D NULL; int nsiblings =3D 0; g_autofree virCapsHostNUMACellPageInfo *pageinfo =3D NULL; int npageinfo; unsigned long long memory; - int cpu; size_t i; =20 if ((ncpus =3D virNumaGetNodeCPUs(n, &cpumap)) < 0) { @@ -1621,13 +1633,16 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *ca= ps) goto cleanup; } =20 - cpus =3D g_new0(virCapsHostNUMACellCPU, ncpus); - cpu =3D 0; + cpus =3D virCapsHostNUMACellCPUNew(ncpus); =20 for (i =3D 0; i < virBitmapSize(cpumap); i++) { if (virBitmapIsBitSet(cpumap, i)) { - if (virCapabilitiesFillCPUInfo(i, cpus + cpu++) < 0) + virCapsHostNUMACellCPU cpu =3D { 0 }; + + if (virCapabilitiesFillCPUInfo(i, &cpu) < 0) goto cleanup; + + g_array_append_val(cpus, cpu); } } =20 @@ -1642,7 +1657,7 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps) memory >>=3D 10; =20 virCapabilitiesHostNUMAAddCell(caps, n, memory, - ncpus, &cpus, + &cpus, nsiblings, &siblings, npageinfo, &pageinfo); } @@ -1650,8 +1665,6 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps) ret =3D 0; =20 cleanup: - virCapabilitiesClearHostNUMACellCPUTopology(cpus, ncpus); - VIR_FREE(cpus); return ret; } =20 diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index ba863447c0..f1b4a8e800 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -106,9 +106,8 @@ struct _virCapsHostNUMACellPageInfo { =20 struct _virCapsHostNUMACell { int num; - int ncpus; unsigned long long mem; /* in kibibytes */ - virCapsHostNUMACellCPU *cpus; + GArray *cpus; /* virCapsHostNUMACellCPU */ int nsiblings; virCapsHostNUMACellSiblingInfo *siblings; int npageinfo; @@ -253,8 +252,7 @@ void virCapabilitiesHostNUMAAddCell(virCapsHostNUMA *caps, int num, unsigned long long mem, - int ncpus, - virCapsHostNUMACellCPU **cpus, + GArray **cpus, int nsiblings, virCapsHostNUMACellSiblingInfo **siblings, int npageinfo, @@ -320,9 +318,8 @@ virCapabilitiesDomainSupported(virCaps *caps, int domaintype); =20 =20 -void -virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPU *cpu, - size_t ncpus); +GArray * +virCapsHostNUMACellCPUNew(size_t prealloc); =20 char * virCapabilitiesFormatXML(virCaps *caps); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1b12c49018..036c890f32 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -59,7 +59,6 @@ virCapabilitiesAddHostFeature; virCapabilitiesAddHostMigrateTransport; virCapabilitiesAddStoragePool; virCapabilitiesAllocMachines; -virCapabilitiesClearHostNUMACellCPUTopology; virCapabilitiesDomainDataLookup; virCapabilitiesDomainSupported; virCapabilitiesFormatXML; @@ -78,6 +77,7 @@ virCapabilitiesInitCaches; virCapabilitiesInitPages; virCapabilitiesNew; virCapabilitiesSetNetPrefix; +virCapsHostNUMACellCPUNew; =20 =20 # conf/checkpoint_conf.h diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index a64a9266c4..96edecf4b3 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -313,13 +313,20 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCaps *caps) =20 caps->host.numa =3D virCapabilitiesHostNUMANew(); for (i =3D 0; i < nr_nodes; i++) { + g_autoptr(GArray) gcpus =3D NULL; + size_t j; + if (numa_info[i].size =3D=3D LIBXL_NUMAINFO_INVALID_ENTRY) continue; =20 + gcpus =3D virCapsHostNUMACellCPUNew(nr_cpus_node[i]); + + for (j =3D 0; j < nr_cpus_node[i]; j++) { + g_array_append_val(gcpus, cpus[i][j]); + } + nr_siblings =3D numa_info[i].num_dists; if (nr_siblings) { - size_t j; - siblings =3D g_new0(virCapsHostNUMACellSiblingInfo, nr_sibling= s); =20 for (j =3D 0; j < nr_siblings; j++) { @@ -330,20 +337,15 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCaps *caps) =20 virCapabilitiesHostNUMAAddCell(caps->host.numa, i, numa_info[i].size / 1024, - nr_cpus_node[i], &cpus[i], + &gcpus, nr_siblings, &siblings, 0, NULL); - - /* This is safe, as the CPU list is now stored in the NUMA cell */ - cpus[i] =3D NULL; } =20 ret =3D 0; =20 cleanup: if (ret !=3D 0) { - for (i =3D 0; cpus && i < nr_nodes; i++) - VIR_FREE(cpus[i]); if (caps->host.numa) { virCapabilitiesHostNUMAUnref(caps->host.numa); caps->host.numa =3D NULL; @@ -351,6 +353,8 @@ libxlCapsInitNuma(libxl_ctx *ctx, virCaps *caps) VIR_FREE(siblings); } =20 + for (i =3D 0; cpus && i < nr_nodes; i++) + VIR_FREE(cpus[i]); VIR_FREE(cpus); VIR_FREE(nr_cpus_node); libxl_cputopology_list_free(cpu_topo, nr_cpus); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ea5a5005e7..fb82eeb2a4 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -307,15 +307,17 @@ testBuildCapabilities(virConnectPtr conn) =20 caps->host.numa =3D virCapabilitiesHostNUMANew(); for (i =3D 0; i < privconn->numCells; i++) { - virCapsHostNUMACellCPU *cpu_cells; + g_autoptr(GArray) cpus =3D NULL; virCapsHostNUMACellPageInfo *pages; size_t nPages =3D caps->host.nPagesSize - 1; =20 - cpu_cells =3D g_new0(virCapsHostNUMACellCPU, privconn->cells[i].nu= mCpus); + cpus =3D virCapsHostNUMACellCPUNew(privconn->cells[i].numCpus); + pages =3D g_new0(virCapsHostNUMACellPageInfo, nPages); =20 - memcpy(cpu_cells, privconn->cells[i].cpus, - sizeof(*cpu_cells) * privconn->cells[i].numCpus); + for (j =3D 0; j < privconn->cells[i].numCpus; j++) { + g_array_append_val(cpus, privconn->cells[i].cpus[j]); + } =20 if (i =3D=3D 1) pages[0].size =3D caps->host.pagesSize[1]; @@ -329,7 +331,7 @@ testBuildCapabilities(virConnectPtr conn) =20 virCapabilitiesHostNUMAAddCell(caps->host.numa, i, privconn->cells[i].mem, - privconn->cells[i].numCpus, &cpu_ce= lls, + &cpus, 0, NULL, nPages, &pages); } diff --git a/tests/testutils.c b/tests/testutils.c index d6b7c2a580..89c4ed464d 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -916,30 +916,33 @@ virCapsHostNUMA * virTestCapsBuildNUMATopology(int seq) { g_autoptr(virCapsHostNUMA) caps =3D virCapabilitiesHostNUMANew(); - virCapsHostNUMACellCPU *cell_cpus =3D NULL; int core_id, cell_id; int id; =20 id =3D 0; for (cell_id =3D 0; cell_id < MAX_CELLS; cell_id++) { - cell_cpus =3D g_new0(virCapsHostNUMACellCPU, MAX_CPUS_IN_CELL); + g_autoptr(GArray) cpus =3D NULL; + + cpus =3D virCapsHostNUMACellCPUNew(MAX_CPUS_IN_CELL); =20 for (core_id =3D 0; core_id < MAX_CPUS_IN_CELL; core_id++) { - cell_cpus[core_id].id =3D id + core_id; - cell_cpus[core_id].socket_id =3D cell_id + seq; - cell_cpus[core_id].core_id =3D id + core_id; - cell_cpus[core_id].siblings =3D virBitmapNew(MAX_CPUS_IN_CELL); - ignore_value(virBitmapSetBit(cell_cpus[core_id].siblings, id)); + virCapsHostNUMACellCPU cpu =3D { 0 }; + + cpu.id =3D id + core_id; + cpu.socket_id =3D cell_id + seq; + cpu.core_id =3D id + core_id; + cpu.siblings =3D virBitmapNew(MAX_CPUS_IN_CELL); + ignore_value(virBitmapSetBit(cpu.siblings, id)); + + g_array_append_val(cpus, cpu); } id++; =20 virCapabilitiesHostNUMAAddCell(caps, cell_id + seq, MAX_MEM_IN_CELL, - MAX_CPUS_IN_CELL, &cell_cpus, + &cpus, 0, NULL, 0, NULL); - - cell_cpus =3D NULL; } =20 return g_steal_pointer(&caps); --=20 2.26.3 From nobody Tue May 14 08:04:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620825853; cv=none; d=zohomail.com; s=zohoarc; b=T6wAMpVHO+IMTVoKkWRV1ptQ3Y95Ta1YWaoGv74eNBz/l23rZzwe7nChaPc27USKsfxdq8IAGxZ+kddA7bm03YG80F7FWwzyiQRBJN8qFiw64vZxh1JvoXZ4shqdv+iebRYS/xV/fBERfp/dI3eR3nsjKbcHB60Ux++aqomnQiw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620825853; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IYsPjjuygz7bu54Zgvw5XHN5IMu9NH9MQTVJHKHw8MY=; b=VoyyDZPfzxeSRGBzRLAoMJ8Gn7yyyBMvoPPlXvak0r1skwbRPJsCrU+Jddwts31YK5WtdEvIwrd5hxxiLpugBymeM5CcUnxb4Xlfw3Zge3h3vRXfqC4ewk91WxVKOd4N3FPZjQjvieZ6h5LnvLK6kJ5OtcMc+rBBj435vlwompw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1620825853724155.66589030504576; Wed, 12 May 2021 06:24:13 -0700 (PDT) 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-473-IJg_ODFiPR6Ig_JyYB-5pA-1; Wed, 12 May 2021 09:24:09 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB911107ACC7; Wed, 12 May 2021 13:24:03 +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 8D3F560657; Wed, 12 May 2021 13:24:03 +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 4A40555342; Wed, 12 May 2021 13:24:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14CDNfXW030428 for ; Wed, 12 May 2021 09:23:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 91E9E3A3; Wed, 12 May 2021 13:23:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13A15E715 for ; Wed, 12 May 2021 13:23:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620825852; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=IYsPjjuygz7bu54Zgvw5XHN5IMu9NH9MQTVJHKHw8MY=; b=Ddi8Goj+4WsWCAZmVcSr79dz6J+uwf2/YRN3gcFL0CmtDBXiEg5jGg0DbwO+uNct7pCQU7 9doovFoqpljVGYAd3YsHlHbQxUr+/TXYi21rsdok2OzJDnNs7DjZNe/4je+GbuNZrm7ErY WZiQ8GtlTsuP07FG0WxKTBwkApv7+jQ= X-MC-Unique: IJg_ODFiPR6Ig_JyYB-5pA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/3] virCapabilitiesHostNUMAInitReal: Drop cleanup label Date: Wed, 12 May 2021 15:23:31 +0200 Message-Id: <8a2e36209b83bcdf78123c83f7e93c16b0c54935.1620824567.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This label is no longer needed after previous cleanup. Signed-off-by: Michal Privoznik --- src/conf/capabilities.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 4c50f5d52a..e6caac9eff 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1609,11 +1609,10 @@ static int virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps) { int n; - int ret =3D -1; int max_node; =20 if ((max_node =3D virNumaGetMaxNode()) < 0) - goto cleanup; + return -1; =20 for (n =3D 0; n <=3D max_node; n++) { g_autoptr(virBitmap) cpumap =3D NULL; @@ -1630,7 +1629,7 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps) if (ncpus =3D=3D -2) continue; =20 - goto cleanup; + return -1; } =20 cpus =3D virCapsHostNUMACellCPUNew(ncpus); @@ -1640,17 +1639,17 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *ca= ps) virCapsHostNUMACellCPU cpu =3D { 0 }; =20 if (virCapabilitiesFillCPUInfo(i, &cpu) < 0) - goto cleanup; + return -1; =20 g_array_append_val(cpus, cpu); } } =20 if (virCapabilitiesGetNUMASiblingInfo(n, &siblings, &nsiblings) < = 0) - goto cleanup; + return -1; =20 if (virCapabilitiesGetNUMAPagesInfo(n, &pageinfo, &npageinfo) < 0) - goto cleanup; + return -1; =20 /* Detect the amount of memory in the numa cell in KiB */ virNumaGetNodeMemory(n, &memory, NULL); @@ -1662,10 +1661,7 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *cap= s) npageinfo, &pageinfo); } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 --=20 2.26.3