From nobody Fri Dec 19 06:19:50 2025 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=1678274118; cv=none; d=zohomail.com; s=zohoarc; b=lXLRoPuT5VM3IkZUUD8TRd9t0qrl2HZpros2GZ3kRCY0rCwWuQNMz8A/k5r7dIBkB+SOQr7EyQfnzsKKZ5tCDgL77S52DgsSTPjH9ZmJlnk4J+4piOwsyN8iiZ6bKQIptFXiYauG+K86z82Jj43zkVXka+zAJ7PI6n5Lp/RrCDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678274118; 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=oS2HNWwPMbvB/R6wn4qbOQ430T2va7xkr65YbIAXwGw=; b=lVG7xIQzmt6GTfpuHxAj0+4R+TUaMalgJ1JuouEbpWKueHA5xu+lLaAP3NcYXa3OqdUXFWiTwtPEcI5nXZSPpHt2UHY3QoB+wkxEGNDNz02LsWZPp/OgXJbP9/UlftcANWx4+KUwu1bhio1SBShNWUoioOK/iW3QZ4QkK6AP0q4= 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) 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 167827411829413.88123718885879; Wed, 8 Mar 2023 03:15:18 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-270-UIxjAoXlMrWnDwDtZE2S_Q-1; Wed, 08 Mar 2023 06:15:06 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E6DE385D06E; Wed, 8 Mar 2023 11:15:03 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3A65400DB36; Wed, 8 Mar 2023 11:15:03 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BC49719465B5; Wed, 8 Mar 2023 11:15:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A9A8419465B1 for ; Wed, 8 Mar 2023 11:14:44 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 809F1112132D; Wed, 8 Mar 2023 11:14:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22F2B1121314 for ; Wed, 8 Mar 2023 11:14:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678274117; 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=oS2HNWwPMbvB/R6wn4qbOQ430T2va7xkr65YbIAXwGw=; b=AR10o0T9ee9zcqZVkJ8VzMDl7c6BQkh3z0wIyG2Of/S0zuJmMXUVElZSvR2BjMWOIUJAwW 2Wb17B9uVEuxu2PiNPo+dy0/SDhLYE1MbRuXknnkMApI736YAjkUKEJiWjauLyM6uWNnJ9 4ADc5hnuRLE/2gF3jWK3T2DCXmRylNM= X-MC-Unique: UIxjAoXlMrWnDwDtZE2S_Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 02/14] virnuma: Introduce virNumaCPUSetToNodeset() Date: Wed, 8 Mar 2023 12:14:29 +0100 Message-Id: <0102038c19ca2d1ff95a9d0015552026a96f61bf.1678274036.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678274120178100001 Content-Type: text/plain; charset="utf-8"; x-default="true" So far, we have a function that expands given list of NUMA nodes into list of CPUs. But soon, we are going to need the inverse - expand list of CPUs into list of NUMA nodes. Introduce virNumaCPUSetToNodeset() for that. Signed-off-by: Michal Privoznik Reviewed-by: Kristina Hanicova --- src/libvirt_private.syms | 2 ++ src/util/virnuma.c | 59 ++++++++++++++++++++++++++++++++++++++++ src/util/virnuma.h | 3 ++ 3 files changed, 64 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d5b1b9cb72..3ae97e62de 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2975,6 +2975,7 @@ virNodeSuspendGetTargetMask; =20 =20 # util/virnuma.h +virNumaCPUSetToNodeset; virNumaGetAutoPlacementAdvice; virNumaGetDistances; virNumaGetHostMemoryNodeset; @@ -2982,6 +2983,7 @@ virNumaGetMaxCPUs; virNumaGetMaxNode; virNumaGetNodeCPUs; virNumaGetNodeMemory; +virNumaGetNodeOfCPU; virNumaGetPageInfo; virNumaGetPages; virNumaIsAvailable; diff --git a/src/util/virnuma.c b/src/util/virnuma.c index dae0827c65..5f484a16f5 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -311,6 +311,22 @@ virNumaGetNodeCPUs(int node, # undef MASK_CPU_ISSET # undef n_bits =20 + +/** + * virNumaGetNodeOfCPU: + * @cpu: CPU ID + * + * For given @cpu, return NUMA node which it belongs to. + * + * Returns: NUMA node # on success, + * -1 on failure (with errno set). + */ +int +virNumaGetNodeOfCPU(int cpu) +{ + return numa_node_of_cpu(cpu); +} + #else /* !WITH_NUMACTL */ =20 int @@ -366,6 +382,14 @@ virNumaGetNodeCPUs(int node G_GNUC_UNUSED, return -1; } =20 +int +virNumaGetNodeOfCPU(int cpu G_GNUC_UNUSED) +{ + errno =3D ENOSYS; + return -1; +} + + #endif /* !WITH_NUMACTL */ =20 /** @@ -990,6 +1014,41 @@ virNumaGetHostMemoryNodeset(void) } =20 =20 +/** + * virNumaNodesetToCPUset: + * @nodeset: returned bitmap containing a set of NUMA nodes + * @cpuset: bitmap containing a set of CPUs + * + * Convert a set of CPUs to set of NUMA nodes that contain the CPUs. + * + * Returns: 0 on success, + * -1 on failure (with error reported) + */ +int +virNumaCPUSetToNodeset(virBitmap **nodeset, + virBitmap *cpuset) +{ + g_autoptr(virBitmap) nodes =3D virBitmapNew(0); + ssize_t pos =3D -1; + + while ((pos =3D virBitmapNextSetBit(cpuset, pos)) >=3D 0) { + int node =3D virNumaGetNodeOfCPU(pos); + + if (node < 0) { + virReportSystemError(errno, + _("Unable to get NUMA node of cpu %zd"), + pos); + return -1; + } + + virBitmapSetBitExpand(nodes, node); + } + + *nodeset =3D g_steal_pointer(&nodes); + return 0; +} + + /** * virNumaNodesetToCPUset: * @nodeset: bitmap containing a set of NUMA nodes diff --git a/src/util/virnuma.h b/src/util/virnuma.h index c35acd47cb..67e699f2cf 100644 --- a/src/util/virnuma.h +++ b/src/util/virnuma.h @@ -45,7 +45,10 @@ int virNumaGetNodeMemory(int node, =20 unsigned int virNumaGetMaxCPUs(void) G_NO_INLINE; =20 +int virNumaGetNodeOfCPU(int cpu); int virNumaGetNodeCPUs(int node, virBitmap **cpus) G_NO_INLINE; +int virNumaCPUSetToNodeset(virBitmap **nodeset, + virBitmap *cpuset); int virNumaNodesetToCPUset(virBitmap *nodeset, virBitmap **cpuset); =20 --=20 2.39.2