From nobody Sun Feb 8 22:03:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1726152706345364.978275302607; Thu, 12 Sep 2024 07:51:46 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 47BD61736; Thu, 12 Sep 2024 10:51:45 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 557E41664; Thu, 12 Sep 2024 10:48:29 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C807A144E; Thu, 12 Sep 2024 10:48:13 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 12A001277 for ; Thu, 12 Sep 2024 10:48:13 -0400 (EDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-204-_hOUVHJLNHif8v-I-1V5qQ-1; Thu, 12 Sep 2024 10:48:11 -0400 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-374baf9f142so603383f8f.2 for ; Thu, 12 Sep 2024 07:48:11 -0700 (PDT) Received: from wheatley.localdomain (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378956d3743sm14728555f8f.79.2024.09.12.07.48.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Sep 2024 07:48:08 -0700 (PDT) Received: from wheatley.redhat.com (wheatley.k8r.cz [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id D9B892468101 for ; Thu, 12 Sep 2024 16:48:06 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726152492; h=from:from: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; bh=6OuttD45ahUYo+oYkJ3ODNPuWHQtCj9DXUXwoFa6bYQ=; b=Kfr7gi946sdhCbeQRDwZOq58KXW7G5ETJww2esbtwYfGmu1My8xQXq76H1aRpRnetWxrND qGdG/oBqOjsrNYWaBx07KlCJO2QlpFpqQtgnZJruo8cQdRnKbWAYnZyjNBgq0cQt+LCpsf VO9ONM3yhXaERmdXFXOt5q4oyuQHioY= X-MC-Unique: _hOUVHJLNHif8v-I-1V5qQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726152490; x=1726757290; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6OuttD45ahUYo+oYkJ3ODNPuWHQtCj9DXUXwoFa6bYQ=; b=w0FlDV3vksbzSIY8MCSmZfYPWnuOkZ9IBwafTnliSwO6vNSmRoVapl6SyJSJE5zP6j G459nln/MKVcexvZIa5y9fzbah57xA2OBS4LLtiiWljbtoMKepL+nF157yVpl7YUbeZv Jw8sNjKHzsacjru+Eauwhmtg6yToOCVR7bZHsqUIsUaqCKvsliOK2WkMp7t7bUQKIIJc VpmQ9+inTExBJohW+qUgiGb9blrbUJfvl5dBUtsvZksJgTfrlY2zP4MEoyZ+cr57KVK1 k1wxFtfXT1SccVYypDpeMMDz5CxmKck+SuZbjYSqI7vtvWuPC15IyaYvKlhSfj+TR7dh lBPQ== X-Gm-Message-State: AOJu0YwfK9gfu8H66I3LDsZfB54Z6UWHKM6IJaZcRIMLuzWU78A4FbcK je/lzGHx4w7v1maEbz13sb40WrN6RHKlT/bui57LklmXjgemJFuasoN7gCraj8PM34PJzMkRveT YwjNSjQKXMTtGAPwo9uvvipHC1BLjItICJCcfGFHUY1FEJiHZ1z3K3u4noe+tBk+upPITlr5aL9 qC9k9WfR/TlnmGD03H60XG0HI0Q0LQAiHIW6Yg8PA= X-Received: by 2002:a5d:4692:0:b0:374:b691:e9b8 with SMTP id ffacd0b85a97d-378c2d625d5mr1874029f8f.59.1726152489942; Thu, 12 Sep 2024 07:48:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaQtHF7AyN8C7YUCsZ0cxiuxl5VJu/2JXegsV/p4f9OMBTn95nCxek0CZJQtaGfSB0kVm0Ag== X-Received: by 2002:a5d:4692:0:b0:374:b691:e9b8 with SMTP id ffacd0b85a97d-378c2d625d5mr1874015f8f.59.1726152489422; Thu, 12 Sep 2024 07:48:09 -0700 (PDT) From: Martin Kletzander To: devel@lists.libvirt.org Subject: [PATCH 09/10] resctrl: Do not use max_id for Date: Thu, 12 Sep 2024 16:47:58 +0200 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: EY5QNRLRB2OSLTVCRHYMBVEE7BZHXJ4P X-Message-ID-Hash: EY5QNRLRB2OSLTVCRHYMBVEE7BZHXJ4P X-MailFrom: mkletzan@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1726152707692116600 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Martin Kletzander --- src/conf/capabilities.c | 5 ++- src/util/virresctrl.c | 77 ++++++++++++++++++++++++----------------- src/util/virresctrl.h | 3 ++ 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 1d3b7050b2e3..3d0602e1b6fe 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -2128,7 +2128,9 @@ virCapabilitiesInitResctrlMemory(virCaps *caps) node =3D g_new0(virCapsHostMemBWNode, 1); =20 if (virResctrlInfoGetMemoryBandwidth(caps->host.resctrl, - bank->level, &node->control) = > 0) { + bank->level, + bank->id, + &node->control) > 0) { node->id =3D bank->id; node->cpus =3D virBitmapNewCopy(bank->cpus); =20 @@ -2269,6 +2271,7 @@ virCapabilitiesInitCaches(virCaps *caps) if (i =3D=3D caps->host.cache.nbanks) { /* If it is a new cache, then update its resctrl informati= on. */ if (virResctrlInfoGetCache(caps->host.resctrl, + bank->id, bank->level, bank->size, &bank->ncontrols, diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index f3ec4d67059f..3acc1447ad56 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -121,6 +121,7 @@ struct _virResctrlInfoPerType { unsigned int bits; unsigned int max_cache_id; =20 + virBitmap *cache_ids; /* In order to be self-sufficient we need size information per cache. * Funnily enough, one of the outcomes of the resctrl design is that it * does not account for different sizes per cache on the same level. = So @@ -146,11 +147,8 @@ struct _virResctrlInfoMemBW { unsigned int max_allocation; /* level number of last level cache */ unsigned int last_level_cache; - /* max id of last level cache, this is used to track - * how many last level cache available in host system, - * the number of memory bandwidth allocation controller - * is identical with last level cache. */ - unsigned int max_id; + + virBitmap *cache_ids; }; =20 struct _virResctrlInfoMongrp { @@ -192,6 +190,7 @@ virResctrlInfoMemBWFree(virResctrlInfoMemBW *ptr) if (!ptr) return; =20 + virBitmapFree(ptr->cache_ids); g_free(ptr); } =20 @@ -203,6 +202,7 @@ virResctrlInfoPerTypeFree(virResctrlInfoPerType *ptr) if (!ptr) return; =20 + virBitmapFree(ptr->cache_ids); g_free(ptr); } =20 @@ -848,6 +848,7 @@ virResctrlInfoIsEmpty(virResctrlInfo *resctrl) int virResctrlInfoGetMemoryBandwidth(virResctrlInfo *resctrl, unsigned int level, + unsigned int id, virResctrlInfoMemBWPerNode *control) { virResctrlInfoMemBW *membw_info =3D resctrl->membw_info; @@ -858,6 +859,13 @@ virResctrlInfoGetMemoryBandwidth(virResctrlInfo *resct= rl, if (membw_info->last_level_cache !=3D level) return 0; =20 + /* This "should not happen", but resctrl code is constantly full of + * surprises. Warning might make us aware in the future. */ + if (!virBitmapIsBitSet(membw_info->cache_ids, id)) { + VIR_WARN("Memory bandwidth for cache id %u is not recorded in list= of cache IDs", + id); + } + control->granularity =3D membw_info->bandwidth_granularity; control->min =3D membw_info->min_bandwidth; control->max_allocation =3D membw_info->max_allocation; @@ -867,6 +875,7 @@ virResctrlInfoGetMemoryBandwidth(virResctrlInfo *resctr= l, =20 int virResctrlInfoGetCache(virResctrlInfo *resctrl, + unsigned int id, unsigned int level, unsigned long long size, size_t *ncontrols, @@ -885,12 +894,15 @@ virResctrlInfoGetCache(virResctrlInfo *resctrl, if (resctrl->membw_info) { virResctrlInfoMemBW *membw_info =3D resctrl->membw_info; =20 + if (!membw_info->cache_ids) + membw_info->cache_ids =3D virBitmapNew(0); + if (level > membw_info->last_level_cache) { membw_info->last_level_cache =3D level; - membw_info->max_id =3D 0; - } else if (membw_info->last_level_cache =3D=3D level) { - membw_info->max_id++; + virBitmapShrink(membw_info->cache_ids, 0); } + + virBitmapSetBitExpand(membw_info->cache_ids, id); } =20 if (level >=3D resctrl->nlevels) @@ -905,6 +917,11 @@ virResctrlInfoGetCache(virResctrlInfo *resctrl, if (!i_type) continue; =20 + if (!i_type->cache_ids) + i_type->cache_ids =3D virBitmapNew(id); + + virBitmapSetBitExpand(i_type->cache_ids, id); + /* Let's take the opportunity to update our internal information a= bout * the cache size */ if (!i_type->size) { @@ -919,7 +936,6 @@ virResctrlInfoGetCache(virResctrlInfo *resctrl, level, i_type->size, size); goto error; } - i_type->max_cache_id++; } =20 VIR_EXPAND_N(*controls, *ncontrols, 1); @@ -1418,8 +1434,7 @@ virResctrlAllocMemoryBandwidthFormat(virResctrlAlloc = *alloc, =20 =20 static int -virResctrlAllocParseProcessMemoryBandwidth(virResctrlInfo *resctrl, - virResctrlAlloc *alloc, +virResctrlAllocParseProcessMemoryBandwidth(virResctrlAlloc *alloc, char *mem_bw) { unsigned int bandwidth; @@ -1442,12 +1457,6 @@ virResctrlAllocParseProcessMemoryBandwidth(virResctr= lInfo *resctrl, _("Invalid bandwidth %1$u"), bandwidth); return -1; } - if (id > resctrl->membw_info->max_id) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing or inconsistent resctrl info for memory = bandwidth node '%1$u'"), - id); - return -1; - } if (alloc->mem_bw->nbandwidths <=3D id) { VIR_EXPAND_N(alloc->mem_bw->bandwidths, alloc->mem_bw->nbandwidths, id - alloc->mem_bw->nbandwidths + 1); @@ -1495,7 +1504,7 @@ virResctrlAllocParseMemoryBandwidthLine(virResctrlInf= o *resctrl, =20 mbs =3D g_strsplit(tmp, ";", 0); for (next =3D mbs; *next; next++) { - if (virResctrlAllocParseProcessMemoryBandwidth(resctrl, alloc, *ne= xt) < 0) + if (virResctrlAllocParseProcessMemoryBandwidth(alloc, *next) < 0) return -1; } =20 @@ -1597,7 +1606,8 @@ virResctrlAllocParseProcessCache(virResctrlInfo *resc= trl, if (!resctrl || level >=3D resctrl->nlevels || !resctrl->levels[level] || - !resctrl->levels[level]->types[type]) { + !resctrl->levels[level]->types[type] || + !virBitmapIsBitSet(resctrl->levels[level]->types[type]->cache_ids,= cache_id)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing or inconsistent resctrl info for level '= %1$u' type '%2$s'"), level, virCacheTypeToString(type)); @@ -1790,7 +1800,7 @@ virResctrlAllocNewFromInfo(virResctrlInfo *info) for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) { virResctrlInfoPerType *i_type =3D i_level->types[j]; g_autoptr(virBitmap) mask =3D NULL; - size_t k =3D 0; + ssize_t bit =3D -1; =20 if (!i_type) continue; @@ -1798,8 +1808,8 @@ virResctrlAllocNewFromInfo(virResctrlInfo *info) mask =3D virBitmapNew(i_type->bits); virBitmapSetAll(mask); =20 - for (k =3D 0; k <=3D i_type->max_cache_id; k++) { - if (virResctrlAllocUpdateMask(ret, i, j, k, mask) < 0) + while ((bit =3D virBitmapNextSetBit(i_type->cache_ids, bit)) >= =3D 0) { + if (virResctrlAllocUpdateMask(ret, i, j, bit, mask) < 0) return NULL; } } @@ -1830,10 +1840,21 @@ virResctrlAllocCopyMemBW(virResctrlAlloc *dst, src_bw->nbandwidths - dst_bw->nbandwidths); =20 for (i =3D 0; i < src_bw->nbandwidths; i++) { - if (dst_bw->bandwidths[i]) + if (!src_bw->bandwidths[i]) { + if (!dst_bw->bandwidths[i]) + continue; + + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("bandwidth controller id %1$zd does not exist= "), + i); + return -1; + } + + if (!dst_bw->bandwidths[i]) { + dst_bw->bandwidths[i] =3D g_new0(unsigned int, 1); + *dst_bw->bandwidths[i] =3D *src_bw->bandwidths[i]; continue; - dst_bw->bandwidths[i] =3D g_new0(unsigned int, 1); - *dst_bw->bandwidths[i] =3D *src_bw->bandwidths[i]; + } } =20 return 0; @@ -2065,12 +2086,6 @@ virResctrlAllocMemoryBandwidth(virResctrlInfo *resct= rl, mem_bw_info->min_bandwidth); return -1; } - if (i > mem_bw_info->max_id) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("bandwidth controller id %1$zd does not exist= , max controller id %2$u"), - i, mem_bw_info->max_id); - return -1; - } } return 0; } diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 0e4b535f9e52..c70b112864eb 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -47,6 +47,7 @@ VIR_ENUM_DECL(virResctrlMonitorPrefix); =20 typedef struct _virResctrlInfoPerCache virResctrlInfoPerCache; struct _virResctrlInfoPerCache { + unsigned int id; /* Smallest possible increase of the allocation size in bytes */ unsigned long long granularity; /* Minimal allocatable size in bytes (if different from granularity) */ @@ -96,6 +97,7 @@ virResctrlInfoNew(void); =20 int virResctrlInfoGetCache(virResctrlInfo *resctrl, + unsigned int id, unsigned int level, unsigned long long size, size_t *ncontrols, @@ -104,6 +106,7 @@ virResctrlInfoGetCache(virResctrlInfo *resctrl, int virResctrlInfoGetMemoryBandwidth(virResctrlInfo *resctrl, unsigned int level, + unsigned int id, virResctrlInfoMemBWPerNode *control); /* Alloc-related things */ typedef struct _virResctrlAlloc virResctrlAlloc; --=20 2.46.0