From nobody Mon Feb 9 12:12:03 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=1678812790; cv=none; d=zohomail.com; s=zohoarc; b=Td8BcALZP6xiix6RTQNPJAs8AhJS5xdKnTRx7Nfss1UobV/97EouiaXp7lZ/Sh+1z5RMeGmiJB2M+2+lzN3Lsm5hFzQDQRSnSufqSOEC/nAYXfwuRxd5LHxW5gSF77+aRcMm1c/1ch8pv/6fe+jIXuxCrDK66Q/oWP5Vyj0OUhc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678812790; 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=oRjM/WdtRCl9O6HxPYy9zQ3ie64zOT21T3pPUpJ+lP4=; b=J6Gj2FkD12OFQipHxMb8npvVvwCuO+qiiETWMh2qOtTodRRwP9/Grt19ejNkZ9B6vFVbgppToCmuqNj/L+oEl0T+MKZwizh25FLCT7WMuOlOCG32myNPc++JPW0Ef2a9uNIW+5IdylijO6dXLvDyqY/LLwLyyQjFkzIl27PNUK4= 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 1678812790666522.930159711867; Tue, 14 Mar 2023 09:53:10 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-58-8JhzNgEgPqiO7jYEk4R9Pw-1; Tue, 14 Mar 2023 12:53:06 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BC31F3C11794; Tue, 14 Mar 2023 16:52:59 +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 2FD27140EBF4; Tue, 14 Mar 2023 16:52:59 +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 E521E1946A40; Tue, 14 Mar 2023 16:52:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A344019465A2 for ; Tue, 14 Mar 2023 16:52:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 92CA32166B2B; Tue, 14 Mar 2023 16:52:32 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38DC32166B26 for ; Tue, 14 Mar 2023 16:52:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678812789; 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=oRjM/WdtRCl9O6HxPYy9zQ3ie64zOT21T3pPUpJ+lP4=; b=PBtEOFnbkAicbgXlna4Sdl9pRtg0JbGTOPZZVBpk6xjx4OU4JbOD+7LLuPT+6KC+NjgMwH ZlOhbSvn4OHroYSsOA63xXQIlT7sWrLTwbh0Vd4QiUEA2yRJKwjHOrSgBj5Eu00GWKT12+ 8tOB8TXZS6rC6HtP1zE4Wk8crbkDvUQ= X-MC-Unique: 8JhzNgEgPqiO7jYEk4R9Pw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 02/15] virnuma: Introduce virNumaCPUSetToNodeset() Date: Tue, 14 Mar 2023 17:52:16 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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.7 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: 1678812791921100001 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 6f44788233..605522c9f6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2976,6 +2976,7 @@ virNodeSuspendGetTargetMask; =20 =20 # util/virnuma.h +virNumaCPUSetToNodeset; virNumaGetAutoPlacementAdvice; virNumaGetDistances; virNumaGetHostMemoryNodeset; @@ -2983,6 +2984,7 @@ virNumaGetMaxCPUs; virNumaGetMaxNode; virNumaGetNodeCPUs; virNumaGetNodeMemory; +virNumaGetNodeOfCPU; virNumaGetPageInfo; virNumaGetPages; virNumaIsAvailable; diff --git a/src/util/virnuma.c b/src/util/virnuma.c index dae0827c65..4a15bf32c8 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 +/** + * virNumaCPUSetToNodeset: + * @cpuset: bitmap containing a set of CPUs + * @nodeset: returned bitmap containing a set of NUMA nodes + * + * 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 *cpuset, + virBitmap **nodeset) +{ + 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..2c30ef4e31 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 *cpuset, + virBitmap **nodeset); int virNumaNodesetToCPUset(virBitmap *nodeset, virBitmap **cpuset); =20 --=20 2.39.2