From nobody Thu May 15 03:10:05 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 1517391741832661.5041109189665; Wed, 31 Jan 2018 01:42:21 -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 04A06780F7; Wed, 31 Jan 2018 09:42:20 +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 C5BE160CAB; Wed, 31 Jan 2018 09:42:19 +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 7EC2018033DE; Wed, 31 Jan 2018 09:42:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0V9fwZP025420 for ; Wed, 31 Jan 2018 04:41:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id B6BB85C26A; Wed, 31 Jan 2018 09:41:58 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5732618029 for ; Wed, 31 Jan 2018 09:41:51 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 8A6E8120480 for ; Wed, 31 Jan 2018 10:41:50 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Wed, 31 Jan 2018 10:41:41 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/8] 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.27]); Wed, 31 Jan 2018 09:42:20 +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 --- 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 2bdca5455783..14a3c459ffd3 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1255,22 +1255,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 @@ -1278,16 +1262,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; @@ -1295,6 +1282,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; @@ -1386,17 +1374,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 @@ -1502,7 +1489,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.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list