From nobody Thu May 15 03:53:15 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517405838440689.9780651985233; Wed, 31 Jan 2018 05:37:18 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B3C75414C; Wed, 31 Jan 2018 13:37:16 +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 4CBF560CAE; Wed, 31 Jan 2018 13:37:16 +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 097B34ED36; Wed, 31 Jan 2018 13:37:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0VDb95E006675 for ; Wed, 31 Jan 2018 08:37:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4F21F5D973; Wed, 31 Jan 2018 13:37:09 +0000 (UTC) Received: from wheatley.localdomain (unknown [10.34.244.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B43D5D72B for ; Wed, 31 Jan 2018 13:37:03 +0000 (UTC) Received: from wheatley.brq.redhat.com (wheatley.usersys.redhat.com [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id 8D4F47E0080 for ; Wed, 31 Jan 2018 14:37:02 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 14:36:58 +0100 Message-Id: <02a0b74c0490b9e9a42925381937c6454e2fc619.1517405747.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/6] util: Don't overwrite mask in virResctrlAllocFindUnused 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 31 Jan 2018 13:37:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Due to confusing naming the pointer to the mask got copied which must not happen, so use UpdateMask instead of SetMask. That also means we can get completely rid of SetMask. Also don't clear the free bits since it is not used again (leftover from previous versions). Signed-off-by: Martin Kletzander Reviewed-by: Pavel Hrdina --- src/util/virresctrl.c | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index a0ea2748713e..fdd1ded6f76f 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1253,22 +1253,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl A= TTRIBUTE_UNUSED) =20 #endif /* ! __linux__ */ =20 -static int -virResctrlAllocSetMask(virResctrlAllocPerTypePtr a_type, - unsigned int cache, - virBitmapPtr mask) -{ - if (a_type->nmasks <=3D cache && - VIR_EXPAND_N(a_type->masks, a_type->nmasks, - cache - a_type->nmasks + 1) < 0) - return -1; - - virBitmapFree(a_type->masks[cache]); - a_type->masks[cache] =3D mask; - - return 0; -} - =20 /* * Given the information about requested allocation type `a_type`, the host @@ -1276,16 +1260,19 @@ virResctrlAllocSetMask(virResctrlAllocPerTypePtr a_= type, * this function tries to find the smallest free space in which the alloca= tion * for cache id `cache` would fit. We're looking for the smallest place in * order to minimize fragmentation and maximize the possibility of succeed= ing. + * + * Per-cache allocation for the @level, @type and @cache must already be + * allocated for @alloc (does not have to exist though). */ static int -virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type, +virResctrlAllocFindUnused(virResctrlAllocPtr alloc, virResctrlInfoPerTypePtr i_type, virResctrlAllocPerTypePtr f_type, unsigned int level, unsigned int type, unsigned int cache) { - unsigned long long *size =3D a_type->sizes[cache]; + unsigned long long *size =3D alloc->levels[level]->types[type]->sizes[= cache]; virBitmapPtr a_mask =3D NULL; virBitmapPtr f_mask =3D NULL; unsigned long long need_bits; @@ -1293,6 +1280,7 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a= _type, ssize_t pos =3D -1; ssize_t last_bits =3D 0; ssize_t last_pos =3D -1; + int ret =3D -1; =20 if (!size) return 0; @@ -1384,17 +1372,16 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr= a_type, if (!a_mask) return -1; =20 - for (i =3D last_pos; i < last_pos + need_bits; i++) { + for (i =3D last_pos; i < last_pos + need_bits; i++) ignore_value(virBitmapSetBit(a_mask, i)); - ignore_value(virBitmapClearBit(f_mask, i)); - } =20 - if (virResctrlAllocSetMask(a_type, cache, a_mask) < 0) { - virBitmapFree(a_mask); - return -1; - } + if (virResctrlAllocUpdateMask(alloc, level, type, cache, a_mask) < 0) + goto cleanup; =20 - return 0; + ret =3D 0; + cleanup: + virBitmapFree(a_mask); + return ret; } =20 =20 @@ -1500,7 +1487,7 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl, virResctrlInfoPerLevelPtr i_level =3D resctrl->levels[leve= l]; virResctrlInfoPerTypePtr i_type =3D i_level->types[type]; =20 - if (virResctrlAllocFindUnused(a_type, i_type, f_type, leve= l, type, cache) < 0) + if (virResctrlAllocFindUnused(alloc, i_type, f_type, level= , type, cache) < 0) goto cleanup; } } --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list