From nobody Sat Apr 20 09:41:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559316176; cv=none; d=zoho.com; s=zohoarc; b=Ci/nWS/2Pg6jMQcPceQ7vUr4/IjOh1tcBUPeIMLz2Vfo6NuuSRiRFCJc8kfMNlA7PmF4e+QJfUP/LljWgdGCZrT2UxkGcbFooM2Mw7wNqBwf5mFGsyfp8JKjuuA+YT+fKxeNQ3dW1SUZYMlrswOtJXnD0ToWUzQdnAJQmPewD+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559316176; 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:ARC-Authentication-Results; bh=IwJoPss7LINCXmWxwIil6rcLZoLHqohjhNJLU5om2g4=; b=VnXtdduy8B2iBZ52GqAV2RcSgCJf2uoddhzdpQ9kfAJZfO723LaRHW+uxWo92gXRWI2UMsp9qPhGr/jZ8SOTcq/b1BWYvT7BTQ/cEg36v8lqe1LBFwhR8Vhm9DETTdp5XOxJQhuYIfK8giwWO5TJRWLMge4sQTA2n1qV3F68G1Q= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559316176964888.6544805128971; Fri, 31 May 2019 08:22:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3518D3078862; Fri, 31 May 2019 15:22:28 +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 C9CF658779; Fri, 31 May 2019 15:22:24 +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 A962A206D1; Fri, 31 May 2019 15:22:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4VFM7Yw019526 for ; Fri, 31 May 2019 11:22:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9A4751759D; Fri, 31 May 2019 15:22:07 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.73]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 19DF05D719 for ; Fri, 31 May 2019 15:22:06 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 31 May 2019 17:21:59 +0200 Message-Id: <20190531152202.2909-2-abologna@redhat.com> In-Reply-To: <20190531152202.2909-1-abologna@redhat.com> References: <20190531152202.2909-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] util: Introduce virBitmapUnion() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 31 May 2019 15:22:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Andrea Bolognani Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virbitmap.c | 26 ++++++++++++++++++++++++++ src/util/virbitmap.h | 4 ++++ tests/virbitmaptest.c | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 909975750c..678d0348a2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1517,6 +1517,7 @@ virBitmapSubtract; virBitmapToData; virBitmapToDataBuf; virBitmapToString; +virBitmapUnion; =20 =20 # util/virbuffer.h diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 91df4b8601..1f0db563ab 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -1260,6 +1260,32 @@ virBitmapIntersect(virBitmapPtr a, } =20 =20 +/** + * virBitmapUnion: + * @a: bitmap, modified to contain result + * @b: other bitmap + * + * Performs union of two bitmaps: a =3D union(a, b) + * + * Returns 0 on success, <0 on failure. + */ +int +virBitmapUnion(virBitmapPtr a, + virBitmapPtr b) +{ + size_t i; + + for (i =3D 0; i < b->nbits; i++) { + if (virBitmapIsBitSet(b, i)) { + if (virBitmapSetBitExpand(a, i) < 0) + return -1; + } + } + + return 0; +} + + /** * virBitmapSubtract: * @a: minuend/result diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 38dc06412a..49d9910fa7 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -149,6 +149,10 @@ bool virBitmapOverlaps(virBitmapPtr b1, void virBitmapIntersect(virBitmapPtr a, virBitmapPtr b) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 +int virBitmapUnion(virBitmapPtr a, + virBitmapPtr b) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + void virBitmapSubtract(virBitmapPtr a, virBitmapPtr b) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 2fbafc0a76..f9d3cfd995 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -740,6 +740,34 @@ test14(const void *opaque) return ret; } =20 +/* virBitmapUnion() */ +static int +test15(const void *opaque) +{ + const struct testBinaryOpData *data =3D opaque; + VIR_AUTOPTR(virBitmap) amap =3D NULL; + VIR_AUTOPTR(virBitmap) bmap =3D NULL; + VIR_AUTOPTR(virBitmap) resmap =3D NULL; + + if (!(amap =3D virBitmapParseUnlimited(data->a)) || + !(bmap =3D virBitmapParseUnlimited(data->b)) || + !(resmap =3D virBitmapParseUnlimited(data->res))) { + return -1; + } + + if (virBitmapUnion(amap, bmap) < 0) + return -1; + + if (!virBitmapEqual(amap, resmap)) { + fprintf(stderr, + "\n bitmap union failed: union('%s', '%s') !=3D '%s'\n", + data->a, data->b, data->res); + return -1; + } + + return 0; +} + =20 #define TESTBINARYOP(A, B, RES, FUNC) \ testBinaryOpData.a =3D A; \ @@ -798,6 +826,15 @@ mymain(void) TESTBINARYOP("0-3", "0,^0", "0-3", test14); TESTBINARYOP("0,2", "1,3", "0,2", test14); =20 + virTestCounterReset("test15-"); + TESTBINARYOP("0-1", "0-1", "0-1", test15); + TESTBINARYOP("0", "1", "0-1", test15); + TESTBINARYOP("0-1", "2-3", "0-3", test15); + TESTBINARYOP("0-3", "1-2", "0-3", test15); + TESTBINARYOP("0,^0", "12345", "12345", test15); + TESTBINARYOP("12345", "0,^0", "12345", test15); + TESTBINARYOP("0,^0", "0,^0", "0,^0", test15); + return ret; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 09:41:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559316213; cv=none; d=zoho.com; s=zohoarc; b=PtYR2py8Su9GM7I1Mw00RXoEFRqlfuB99HQwjblnViJNg815X7fbU/QE5EVj7mx7cScqF7ewO3Kg8C19DkAsX7O2/yVp0AGAeUQOdhzGXWiVpZRnOV8mSdfu9R1eSijOaq1Uu0Xkfy93AG5rp+yvBr3DY75H7ZgLgZ3UykVrRYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559316213; 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:ARC-Authentication-Results; bh=5UD6chwrwcQJoVGkq/TtbhOPbtySzo11UmapPqiY4Qo=; b=lO+RDG3ZzGzCsLAXWeZ/VH0ctFT0zcFoP91dcdhVYOMGeKAcLhTVx6GQjupDn0hLhGkTPCEIlaiTEu2ticZLv5D7L+hcUVCqrNXSg8rHVjQgoHMJzjaqJYhNetKH7o8UpSxPU3TUylrMeXmEp8i1hurIZT8+tACopMu7Ys+05OY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559316213004920.0665364063194; Fri, 31 May 2019 08:23:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C06D81DE3; Fri, 31 May 2019 15:23:25 +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 5D7572CE13; Fri, 31 May 2019 15:23:24 +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 0EC4D18363C3; Fri, 31 May 2019 15:23:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4VFM8SB019537 for ; Fri, 31 May 2019 11:22:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7A1201759D; Fri, 31 May 2019 15:22:08 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.73]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE1C25D719 for ; Fri, 31 May 2019 15:22:07 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 31 May 2019 17:22:00 +0200 Message-Id: <20190531152202.2909-3-abologna@redhat.com> In-Reply-To: <20190531152202.2909-1-abologna@redhat.com> References: <20190531152202.2909-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] fixup? util: Optimize virBitmapUnion() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 31 May 2019 15:23:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The original implementation is extremely straightforward but not too efficient, because it uses the public API instead of poking the innards directly. This second implementation does the latter, and as a consequence can afford to make @b const, which is nice even though most existing virBitmap APIs use non-const pointers even for read-only bitmaps. That said, I'm not entirely sure I got it quite right, so a review from someone who's well versed in the virBitmap internals (*cough* Peter *cough*) would be appreciated, and if my implementation passes muster or can be amended through review comments I'll gladly squash this commit into the previous one. Signed-off-by: Andrea Bolognani Reviewed-by: J=C3=A1n Tomko --- src/util/virbitmap.c | 18 ++++++++++++------ src/util/virbitmap.h | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 1f0db563ab..f2127c053d 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -1271,17 +1271,23 @@ virBitmapIntersect(virBitmapPtr a, */ int virBitmapUnion(virBitmapPtr a, - virBitmapPtr b) + const virBitmap *b) { size_t i; + size_t max; =20 - for (i =3D 0; i < b->nbits; i++) { - if (virBitmapIsBitSet(b, i)) { - if (virBitmapSetBitExpand(a, i) < 0) - return -1; - } + if (a->nbits < b->nbits && + virBitmapExpand(a, b->nbits) < 0) { + return -1; } =20 + max =3D a->map_len; + if (max > b->map_len) + max =3D b->map_len; + + for (i =3D 0; i < max; i++) + a->map[i] |=3D b->map[i]; + return 0; } =20 diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h index 49d9910fa7..8696214da8 100644 --- a/src/util/virbitmap.h +++ b/src/util/virbitmap.h @@ -150,7 +150,7 @@ void virBitmapIntersect(virBitmapPtr a, virBitmapPtr b) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 int virBitmapUnion(virBitmapPtr a, - virBitmapPtr b) + const virBitmap *b) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 void virBitmapSubtract(virBitmapPtr a, virBitmapPtr b) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 09:41:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559316214; cv=none; d=zoho.com; s=zohoarc; b=MT4X6gIuP53oBSFJ9yYzob9WqAK0M8Di1BZ68JZMZcZG9Tivt4go1t8Ll3pv9hg09VifXZvFIcxvRkeHn++zIUsBa+vUbrKuQ0o3N4Gd5tPc8LMDpt2C04Gr6uFjc5FscHcBlk6ea3VlMQ9CWrSuG5ngVOjZJ/NObkHt6soCMJw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559316214; 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:ARC-Authentication-Results; bh=T7BHdY2mQat2qkJE7kh89AGuRd2nB7Xn0tE/r2kZ3rc=; b=XeWv8qfYNnXwCtabhhPfV8ZEJERs4jK9W1SsqTqmTXMs0QkkaDma3GMAGQiVMESpNv6v7mcD21wsAILW+tP1IzWaZL0UGiU8HEeR8waynd+x47WGjcuHZJb1ps2JjVZ83EfwHlsrORbEBdwlB7phH7RwJYPX8jad5VZWf9LcNZk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559316214371957.6374146321256; Fri, 31 May 2019 08:23:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14908C0AD292; Fri, 31 May 2019 15:23:29 +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 D951C2E035; Fri, 31 May 2019 15:23:26 +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 94D9018363C4; Fri, 31 May 2019 15:23:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4VFM9pZ019552 for ; Fri, 31 May 2019 11:22:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5A8E25D719; Fri, 31 May 2019 15:22:09 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.73]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCA031759D for ; Fri, 31 May 2019 15:22:08 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 31 May 2019 17:22:01 +0200 Message-Id: <20190531152202.2909-4-abologna@redhat.com> In-Reply-To: <20190531152202.2909-1-abologna@redhat.com> References: <20190531152202.2909-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] util: Introduce virNumaNodesetToCPUset() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 31 May 2019 15:23:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This helper converts a set of NUMA node to the set of CPUs they contain. Signed-off-by: Andrea Bolognani Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virnuma.c | 55 ++++++++++++++++++++++++++++++++++++++++ src/util/virnuma.h | 2 ++ 3 files changed, 58 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 678d0348a2..3553545504 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2556,6 +2556,7 @@ virNumaGetPages; virNumaIsAvailable; virNumaNodeIsAvailable; virNumaNodesetIsAvailable; +virNumaNodesetToCPUset; virNumaSetPagePoolSize; virNumaSetupMemoryPolicy; =20 diff --git a/src/util/virnuma.c b/src/util/virnuma.c index dd3fb7519e..9f9f149f0a 100644 --- a/src/util/virnuma.c +++ b/src/util/virnuma.c @@ -297,6 +297,49 @@ virNumaGetNodeCPUs(int node, # undef MASK_CPU_ISSET # undef n_bits =20 +/** + * virNumaNodesetToCPUset: + * @nodeset: bitmap containing a set of NUMA nodes + * @cpuset: return location for a bitmap containing a set of CPUs + * + * Convert a set of NUMA node to the set of CPUs they contain. + * + * Returns 0 on success, <0 on failure. + */ +int +virNumaNodesetToCPUset(virBitmapPtr nodeset, + virBitmapPtr *cpuset) +{ + VIR_AUTOPTR(virBitmap) allNodesCPUs =3D NULL; + size_t nodesetSize; + size_t i; + + *cpuset =3D NULL; + + if (!nodeset) + return 0; + + allNodesCPUs =3D virBitmapNewEmpty(); + nodesetSize =3D virBitmapSize(nodeset); + + for (i =3D 0; i < nodesetSize; i++) { + VIR_AUTOPTR(virBitmap) nodeCPUs =3D NULL; + + if (!virBitmapIsBitSet(nodeset, i)) + continue; + + if (virNumaGetNodeCPUs(i, &nodeCPUs) < 0) + return -1; + + if (virBitmapUnion(allNodesCPUs, nodeCPUs) < 0) + return -1; + } + + VIR_STEAL_PTR(*cpuset, allNodesCPUs); + + return 0; +} + #else /* !WITH_NUMACTL */ =20 int @@ -351,6 +394,18 @@ virNumaGetNodeCPUs(int node ATTRIBUTE_UNUSED, _("NUMA isn't available on this host")); return -1; } + +int +virNumaNodesetToCPUset(virBitmapPtr nodeset, + virBitmapPtr *cpuset) +{ + *cpuset =3D NULL; + + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("NUMA isn't available on this host")); + return -1; +} + #endif /* !WITH_NUMACTL */ =20 /** diff --git a/src/util/virnuma.h b/src/util/virnuma.h index cd7a3ec11f..8e95011dfa 100644 --- a/src/util/virnuma.h +++ b/src/util/virnuma.h @@ -48,6 +48,8 @@ int virNumaGetNodeMemory(int node, unsigned int virNumaGetMaxCPUs(void); =20 int virNumaGetNodeCPUs(int node, virBitmapPtr *cpus) ATTRIBUTE_NOINLINE; +int virNumaNodesetToCPUset(virBitmapPtr nodeset, + virBitmapPtr *cpuset); =20 int virNumaGetPageInfo(int node, unsigned int page_size, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 09:41:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1559316167; cv=none; d=zoho.com; s=zohoarc; b=WyxHpLOprUclyuzpN9qOEL3TXykPPsdE82aWC32M5gq0t1jDUiCFIUj6WRy2eS2t2o7CSNUj4yD0HDsF/SE7XsgHlaU0wLj0a+Eg0450oukHjPO716loSLAHvwpNi/hcS1G0sulBHd5le0fxx0wFdQqdQ8gcaKVJN3aou10gGUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559316167; 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:ARC-Authentication-Results; bh=GCs3JT7JbCoQQAtJr7cPPFDFgKV3b+AwYPcTkAVaatI=; b=GlZCWKLBSYSsFF1USw9v9UbE6lZMst1VTCzYYiUSgjxPUkLq42lE/cMgy6qJ9gMvO2XY/L9PozieYGFYo6ax2U62RUiraGToshScPpMizmZFGiN94XCGtB54b4ivOYh5utnjeL0H8MP7SZy4OlfJ5GarQTeCmYlDPOsy3SwFOg4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1559316167552329.91294149416626; Fri, 31 May 2019 08:22:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 781A030C1B92; Fri, 31 May 2019 15:22:26 +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 1D64817A8C; Fri, 31 May 2019 15:22:23 +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 8599F18363C2; Fri, 31 May 2019 15:22:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4VFMA3p019558 for ; Fri, 31 May 2019 11:22:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 38DFB1759D; Fri, 31 May 2019 15:22:10 +0000 (UTC) Received: from kinshicho.brq.redhat.com (unknown [10.43.2.73]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC5665D719 for ; Fri, 31 May 2019 15:22:09 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 31 May 2019 17:22:02 +0200 Message-Id: <20190531152202.2909-5-abologna@redhat.com> In-Reply-To: <20190531152202.2909-1-abologna@redhat.com> References: <20190531152202.2909-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/4] qemu: Fix qemuProcessInitCpuAffinity() 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 31 May 2019 15:22:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Commit f136b83139c6 made some changes in the way we set CPU affinity for QEMU processes, and while doing so unfortunately also introduced a logic bug in that it tried to use a NUMA node map where a CPU map was expected. Because of that, guests using would suddenly fail to start: # virsh start guest error: Failed to start domain guest error: cannot set CPU affinity on process 40055: Invalid argument This was particularly easy to trigger on POWER 8 machines, where secondary threads always show up as offline in the host: having in the guest configuration, for example, would result in libvirt trying to set the process affinity so that it would prefer running on CPU 1, but since that's a secondary thread and thus shows up as offline, the operation would fail, and so would starting the guest. Use the newly introduced virNumaNodesetToCPUset() to convert the NUMA node map to a CPU map, which in the example above would be 8-15 with CPU 8 showing up as online in the guest. https://bugzilla.redhat.com/show_bug.cgi?id=3D1703661 Signed-off-by: Andrea Bolognani Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index fa5909e9be..295ad2e1ff 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2489,11 +2489,16 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm) if (virDomainNumaGetNodeCount(vm->def->numa) <=3D 1 && virDomainNumatuneGetMode(vm->def->numa, -1, &mem_mode) =3D=3D 0 && mem_mode =3D=3D VIR_DOMAIN_NUMATUNE_MEM_STRICT) { + virBitmapPtr nodeset =3D NULL; + if (virDomainNumatuneMaybeGetNodeset(vm->def->numa, priv->autoNodeset, - &cpumapToSet, + &nodeset, -1) < 0) goto cleanup; + + if (virNumaNodesetToCPUset(nodeset, &cpumapToSet) < 0) + goto cleanup; } else if (vm->def->cputune.emulatorpin) { cpumapToSet =3D vm->def->cputune.emulatorpin; } else { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list