From nobody Mon Feb 9 10:30:32 2026 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=1622450204; cv=none; d=zohomail.com; s=zohoarc; b=a2BEdKGIWu0Zl1iS5EzjdiV8Jg0oVYV6s5XuVm24LhIZ1W3eeM8tu9n8x9UQzHEHHyfo725yJVarm5EOTlyys2A5f68EVDTsjhA850X5wivNpIDvuDhu2AZOOyBpGLhqKPd4vHK7E9fkCLuqb6W4Wjq65+BG/O6U0kaSSyDu3cA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622450204; 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=VxH+qo58TKpOK6Ygx0BKQGFESeNIbGgYBaiMGjlWW1I=; b=O8KAIKgbPM6Y1JRE4hHI0fLppxDnV/0xDkncA6t+6LfkNbihpymAQRnbRH1MgNanW67gGMITWpWJIqHcjTADrbp0e/CAkMhCDACg+YHNvWaFZHDL8OODZQlyUT2WZc4E+Pd5RKbdaE2i1rohvCt0gVIb5xMpdk8pqQ0cNp3ZB8Y= 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 1622450204093286.6240998878867; Mon, 31 May 2021 01:36:44 -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-190-uHIm2WGKNfe4TjEji36nbg-1; Mon, 31 May 2021 04:36:40 -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 60A00107ACF4; Mon, 31 May 2021 08:36:36 +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 C33E55B686; Mon, 31 May 2021 08:36:35 +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 85B7F57DE5; Mon, 31 May 2021 08:36:35 +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 14V8aRmM007487 for ; Mon, 31 May 2021 04:36:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 215C1687EE; Mon, 31 May 2021 08:36:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.219]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8615F76E33 for ; Mon, 31 May 2021 08:36:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622450203; 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=VxH+qo58TKpOK6Ygx0BKQGFESeNIbGgYBaiMGjlWW1I=; b=Rwzsgf/lRaE0kYya4igG7IqcoUrMEVlck/afUGZjC+KKWNHsi2pq51QA3PbCeYt0yIA923 2FXg2Acsx64HjvjC/hh/2Zstb4oA/ad1C8SVhU1GXelL/HdhHhZ5b/Jy3+u0rtn7WIoYBR GCOcgdPrX33mn+ccAMvHT64PoJ6Ip/k= X-MC-Unique: uHIm2WGKNfe4TjEji36nbg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 05/10] numa_conf: Expose virNumaCache formatter Date: Mon, 31 May 2021 10:36:06 +0200 Message-Id: <079e498fe953d0c4015261dd0a2054efb6c1bae0.1622449288.git.mprivozn@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 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" Expose virNumaCache XML formatter so that it can be re-used by other parts of the code. Signed-off-by: Michal Privoznik --- src/conf/numa_conf.c | 81 +++++++++++++++++++++------------------- src/conf/numa_conf.h | 13 +++++++ src/libvirt_private.syms | 1 + 3 files changed, 56 insertions(+), 39 deletions(-) diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index 2a32b4ca06..c4f2ef10c1 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -82,8 +82,6 @@ VIR_ENUM_IMPL(virDomainMemoryLatency, "write" ); =20 -typedef struct _virNumaCache virNumaCache; - typedef struct _virDomainNumaInterconnect virDomainNumaInterconnect; =20 typedef struct _virDomainNumaNode virDomainNumaNode; @@ -107,13 +105,7 @@ struct _virDomainNuma { virNumaDistance *distances; /* remote node distances */ size_t ndistances; =20 - struct _virNumaCache { - unsigned int level; /* cache level */ - unsigned int size; /* cache size */ - unsigned int line; /* line size, !!! in bytes !!! */ - virNumaCacheAssociativity associativity; /* cache associativit= y */ - virNumaCachePolicy policy; /* cache policy */ - } *caches; + virNumaCache *caches; size_t ncaches; } *mem_nodes; /* guest node configuration */ size_t nmem_nodes; @@ -1102,7 +1094,6 @@ virDomainNumaDefFormatXML(virBuffer *buf, virBitmap *cpumask =3D virDomainNumaGetNodeCpumask(def, i); g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); - size_t j; =20 memAccess =3D virDomainNumaGetNodeMemoryAccessMode(def, i); discard =3D virDomainNumaGetNodeDiscard(def, i); @@ -1131,35 +1122,9 @@ virDomainNumaDefFormatXML(virBuffer *buf, def->mem_nodes[i].distances, def->mem_nodes[i].ndistances); =20 - for (j =3D 0; j < def->mem_nodes[i].ncaches; j++) { - virNumaCache *cache =3D &def->mem_nodes[i].caches[j]; - - virBufferAsprintf(&childBuf, "lev= el); - if (cache->associativity) { - virBufferAsprintf(&childBuf, " associativity=3D'%s'", - virNumaCacheAssociativityTypeToString(ca= che->associativity)); - } - - if (cache->policy) { - virBufferAsprintf(&childBuf, " policy=3D'%s'", - virNumaCachePolicyTypeToString(cache->po= licy)); - } - virBufferAddLit(&childBuf, ">\n"); - - virBufferAdjustIndent(&childBuf, 2); - virBufferAsprintf(&childBuf, - "\n", - cache->size); - - if (cache->line) { - virBufferAsprintf(&childBuf, - "\n", - cache->line); - } - - virBufferAdjustIndent(&childBuf, -2); - virBufferAddLit(&childBuf, "\n"); - } + virNumaCacheFormat(&childBuf, + def->mem_nodes[i].caches, + def->mem_nodes[i].ncaches); =20 virXMLFormatElement(buf, "cell", &attrBuf, &childBuf); } @@ -1839,3 +1804,41 @@ virNumaDistanceFormat(virBuffer *buf, =20 virXMLFormatElement(buf, "distances", NULL, &childBuf); } + + +void +virNumaCacheFormat(virBuffer *buf, + const virNumaCache *caches, + size_t ncaches) +{ + size_t i; + + for (i =3D 0; i < ncaches; i++) { + const virNumaCache *cache =3D &caches[i]; + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + + virBufferAsprintf(&attrBuf, " level=3D'%u'", cache->level); + if (cache->associativity) { + virBufferAsprintf(&attrBuf, " associativity=3D'%s'", + virNumaCacheAssociativityTypeToString(cache-= >associativity)); + } + + if (cache->policy) { + virBufferAsprintf(&attrBuf, " policy=3D'%s'", + virNumaCachePolicyTypeToString(cache->policy= )); + } + + virBufferAsprintf(&childBuf, + "\n", + cache->size); + + if (cache->line) { + virBufferAsprintf(&childBuf, + "\n", + cache->line); + } + + virXMLFormatElement(buf, "cache", &attrBuf, &childBuf); + } +} diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h index 1ef6455fb5..9dee4f3a40 100644 --- a/src/conf/numa_conf.h +++ b/src/conf/numa_conf.h @@ -259,3 +259,16 @@ struct _virNumaDistance { void virNumaDistanceFormat(virBuffer *buf, const virNumaDistance *distances, size_t ndistances); + +typedef struct _virNumaCache virNumaCache; +struct _virNumaCache { + unsigned int level; /* cache level */ + unsigned int size; /* cache size */ + unsigned int line; /* line size, !!! in bytes !!! */ + virNumaCacheAssociativity associativity; /* cache associativity */ + virNumaCachePolicy policy; /* cache policy */ +}; + +void virNumaCacheFormat(virBuffer *buf, + const virNumaCache *caches, + size_t ncaches); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9e9171a6d9..abe4525163 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -911,6 +911,7 @@ virDomainNumatuneSet; virDomainNumatuneSpecifiedMaxNode; virNumaCacheAssociativityTypeFromString; virNumaCacheAssociativityTypeToString; +virNumaCacheFormat; virNumaCachePolicyTypeFromString; virNumaCachePolicyTypeToString; virNumaDistanceFormat; --=20 2.31.1