From nobody Mon Feb 9 16:52:53 2026 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=1622450209; cv=none; d=zohomail.com; s=zohoarc; b=iGDOhzbWjCMpbmLcpeHXrPkU2ygKu09i+G21/A/viUQhPZV2wt031R8iZDlzlJPA7bIhwvYZJIKAB/4ydaRw44mrOM8SXQfnBjOiigTQxsk8D/UtDVPi7iQBCLqyrJs8N9cBnz7NgQ7gbEWSLAC/BZWxCJChAe1XGLigHfWzqKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622450209; 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=F8Epz4/uhQPnxRalPCBNaJPUjHzVMMw1iwo3PFHJAYo=; b=foyfL7vy25ELjKUbmMvMIAquKO3I7Isakkg7lkhaZFqCbB45eyBMb6Obq82X76ovzGCQ/LJ51yf1r2lO18rOA1fe3VY4w/GmYQv/mFbGEOH5jxMOn/LYzw9bjwg8dVH309W+IZrH09/+PAvfA3waEA5j4huB9qvUIoZa6r7LQMM= 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 1622450209619822.0911570094064; Mon, 31 May 2021 01:36:49 -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-543-gomrmXT5MLW62oX6ty0sUA-1; Mon, 31 May 2021 04:36:45 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9F6A100B3B8; Mon, 31 May 2021 08:36:38 +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 ADD8A10246F1; Mon, 31 May 2021 08:36:38 +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 727911801263; Mon, 31 May 2021 08:36:38 +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 14V8aU8i007520 for ; Mon, 31 May 2021 04:36:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id EB689687EE; Mon, 31 May 2021 08:36:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.219]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DCAF76E33 for ; Mon, 31 May 2021 08:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622450208; 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=F8Epz4/uhQPnxRalPCBNaJPUjHzVMMw1iwo3PFHJAYo=; b=C9mtod0Du9K9NqD6YRl5zX4B5oDi++cgeXvhRx+POr3vR6ryxnNs0tziT7Jqx2fDCKngKV Rv4mgYKwRSg0jWH6flGAfQm+5nnfS8IN2ZN/SRNOabIyBz3LL1A2Kac4TRAdqGMFuPrXrT tkbtb6shMRKGu+6rbIOL+X09UKbnroc= X-MC-Unique: gomrmXT5MLW62oX6ty0sUA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 09/10] capabilities: Expose NUMA interconnects Date: Mon, 31 May 2021 10:36:10 +0200 Message-Id: <91ed16c38faf78215c0687a8ba0db79dba46b898.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.84 on 10.5.11.22 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" Links between NUMA nodes can have different latencies and bandwidths. This info is newly defined in ACPI 6.2 under Heterogeneous Memory Attribute Table (HMAT) table. Linux kernel learned how to report these values under sysfs and thus we can expose them in our capabilities XML. The sysfs interface is documented in kernel's Documentation/admin-guide/mm/numaperf.rst. Long story short, two nodes can be in initiator-target relationship. A node can be initiator if it has a CPU or a device that's capable of initiating memory transfer. Therefore a node that has just memory can only be target. An initiator-target link can then have any combination of {bandwidth, latency} - {access, read, write} attribute (6 in total). However, the standard says access is applicable iff read and write values are the same. Therefore, we really have just four combinations of attributes: bandwidth-read, bandwidth-write, latency-read, latency-write. This is the combination that kernel reports anyway. Then, under /sys/system/devices/node/nodeX/acccess0/initiators we find values for those 4 attributes and also symlinks named "nodeN" which then represent initiators to nodeX. For instance: /sys/system/node/node1/access0/initiators/node0 -> ../../node0 /sys/system/node/node1/access0/initiators/read_bandwidth /sys/system/node/node1/access0/initiators/read_latency /sys/system/node/node1/access0/initiators/write_bandwidth /sys/system/node/node1/access0/initiators/write_latency This means that node0 is initiator and node1 is target and values of the interconnect can be read. In theory, there can be separate links to memory side caches too (e.g. one link from node X to node Y's main memory, another from node X to node Y's L1 cache, another one to L2 cache and so on). But sysfs does not express this relationship just yet. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1786309 Signed-off-by: Michal Privoznik --- docs/schemas/capability.rng | 3 + src/conf/capabilities.c | 181 +++++++++++++++++++++++++++++++++++- src/conf/capabilities.h | 1 + 3 files changed, 184 insertions(+), 1 deletion(-) diff --git a/docs/schemas/capability.rng b/docs/schemas/capability.rng index 5c1fb3607c..66dba829a8 100644 --- a/docs/schemas/capability.rng +++ b/docs/schemas/capability.rng @@ -138,6 +138,9 @@ + + + =20 diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 7b60676070..8f2d7b75d7 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -191,7 +191,8 @@ virCapabilitiesHostNUMAUnref(virCapsHostNUMA *caps) =20 if (g_atomic_int_dec_and_test(&caps->refs)) { g_ptr_array_unref(caps->cells); - + if (caps->interconnects) + g_array_unref(caps->interconnects); g_free(caps); } } @@ -890,6 +891,13 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf, } virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); + + if (caps->interconnects) { + const virNumaInterconnect *interconnects; + interconnects =3D &g_array_index(caps->interconnects, virNumaInter= connect, 0); + virNumaInterconnectFormat(buf, interconnects, caps->interconnects-= >len); + } + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); return 0; @@ -1735,6 +1743,174 @@ virCapabilitiesHostNUMAInitFake(virCapsHostNUMA *ca= ps) } =20 =20 +static void +virCapabilitiesHostInsertHMAT(GArray *interconnects, + int initiator, + int target, + unsigned int read_bandwidth, + unsigned int write_bandwidth, + unsigned int read_latency, + unsigned int write_latency) +{ + virNumaInterconnect ni; + + ni =3D (virNumaInterconnect) { VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH, + initiator, target, 0, VIR_MEMORY_LATENCY_READ, read_bandwidth}; + g_array_append_val(interconnects, ni); + + ni =3D (virNumaInterconnect) { VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH, + initiator, target, 0, VIR_MEMORY_LATENCY_WRITE, write_bandwidth}; + g_array_append_val(interconnects, ni); + + ni =3D (virNumaInterconnect) { VIR_NUMA_INTERCONNECT_TYPE_LATENCY, + initiator, target, 0, VIR_MEMORY_LATENCY_READ, read_latency}; + g_array_append_val(interconnects, ni); + + ni =3D (virNumaInterconnect) { VIR_NUMA_INTERCONNECT_TYPE_LATENCY, + initiator, target, 0, VIR_MEMORY_LATENCY_WRITE, write_latency}; + g_array_append_val(interconnects, ni); +} + + +static int +virCapabilitiesHostNUMAInitInterconnectsNode(GArray *interconnects, + int node) +{ + g_autofree char *path =3D NULL; + g_autofree char *initPath =3D NULL; + g_autoptr(DIR) dir =3D NULL; + int direrr =3D 0; + struct dirent *entry; + unsigned int read_bandwidth; + unsigned int write_bandwidth; + unsigned int read_latency; + unsigned int write_latency; + + path =3D g_strdup_printf(SYSFS_SYSTEM_PATH "/node/node%d/access0", nod= e); + + if (!virFileExists(path)) + return 0; + + if (virCapabilitiesGetNodeCacheReadFile(path, "initiators", + "read_bandwidth", + &read_bandwidth) < 0) + return -1; + if (virCapabilitiesGetNodeCacheReadFile(path, "initiators", + "write_bandwidth", + &write_bandwidth) < 0) + return -1; + + /* Bandwidths are read in MiB but stored in KiB */ + read_bandwidth <<=3D 10; + write_bandwidth <<=3D 10; + + if (virCapabilitiesGetNodeCacheReadFile(path, "initiators", + "read_latency", + &read_latency) < 0) + return -1; + if (virCapabilitiesGetNodeCacheReadFile(path, "initiators", + "write_latency", + &write_latency) < 0) + return -1; + + initPath =3D g_strdup_printf("%s/initiators", path); + + if (virDirOpen(&dir, initPath) < 0) + return -1; + + while ((direrr =3D virDirRead(dir, &entry, path)) > 0) { + const char *dname =3D STRSKIP(entry->d_name, "node"); + int initNode; + + if (!dname) + continue; + + if (virStrToLong_i(dname, NULL, 10, &initNode) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to parse %s"), + entry->d_name); + return -1; + } + + virCapabilitiesHostInsertHMAT(interconnects, + initNode, node, + read_bandwidth, + write_bandwidth, + read_latency, + write_latency); + } + + return 0; +} + + +static int +virCapsHostNUMAInterconnectComparator(const void *a, + const void *b) +{ + const virNumaInterconnect *aa =3D a; + const virNumaInterconnect *bb =3D b; + + if (aa->type !=3D bb->type) + return aa->type - bb->type; + + if (aa->initiator !=3D bb->initiator) + return aa->initiator - bb->initiator; + + if (aa->target !=3D bb->target) + return aa->target - bb->target; + + if (aa->cache !=3D bb->cache) + return aa->cache - bb->cache; + + if (aa->accessType !=3D bb->accessType) + return aa->accessType - bb->accessType; + + return aa->value - bb->value; +} + + +static int +virCapabilitiesHostNUMAInitInterconnects(virCapsHostNUMA *caps) +{ + g_autoptr(DIR) dir =3D NULL; + int direrr =3D 0; + struct dirent *entry; + g_autofree char *path =3D NULL; + g_autoptr(GArray) interconnects =3D g_array_new(FALSE, FALSE, sizeof(v= irNumaInterconnect)); + + path =3D g_strdup_printf(SYSFS_SYSTEM_PATH "/node/"); + + if (virDirOpenIfExists(&dir, path) < 0) + return -1; + + while (dir && (direrr =3D virDirRead(dir, &entry, path)) > 0) { + const char *dname =3D STRSKIP(entry->d_name, "node"); + int node; + + if (!dname) + continue; + + if (virStrToLong_i(dname, NULL, 10, &node) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to parse %s"), + entry->d_name); + return -1; + } + + if (virCapabilitiesHostNUMAInitInterconnectsNode(interconnects, no= de) < 0) + return -1; + } + + if (interconnects->len > 0) { + g_array_sort(interconnects, virCapsHostNUMAInterconnectComparator); + caps->interconnects =3D g_steal_pointer(&interconnects); + } + + return 0; +} + + static int virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps) { @@ -1795,6 +1971,9 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMA *caps) &caches); } =20 + if (virCapabilitiesHostNUMAInitInterconnects(caps) < 0) + goto cleanup; + ret =3D 0; =20 cleanup: diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 334b361e7a..1b99202c9b 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -114,6 +114,7 @@ struct _virCapsHostNUMACell { struct _virCapsHostNUMA { gint refs; GPtrArray *cells; + GArray *interconnects; /* virNumaInterconnect */ }; =20 struct _virCapsHostSecModelLabel { --=20 2.31.1