From nobody Fri May 10 07:36:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1708650695314201.29179719489161; Thu, 22 Feb 2024 17:11:35 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4953517D3; Thu, 22 Feb 2024 20:11:34 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1FB7E1D6E; Thu, 22 Feb 2024 20:06:25 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9F23919D9; Thu, 22 Feb 2024 20:05:49 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 5C8F819EF for ; Thu, 22 Feb 2024 20:05:48 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-325-tXPhUOGlMTySydVFxZjATA-1; Thu, 22 Feb 2024 20:05:44 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6B93E1C04339; Fri, 23 Feb 2024 01:05:44 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.45.224.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D693D2166AEE; Fri, 23 Feb 2024 01:05:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: tXPhUOGlMTySydVFxZjATA-1 From: Andrea Bolognani To: devel@lists.libvirt.org Subject: [PATCH 1/3] util: Accept TIDs for virProcess{Get,Set}Affinity() on BSD Date: Fri, 23 Feb 2024 02:05:39 +0100 Message-ID: <20240223010541.211981-2-abologna@redhat.com> In-Reply-To: <20240223010541.211981-1-abologna@redhat.com> References: <20240223010541.211981-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: VGIJVC4MKMKOHETUJPM6VX46C327RCOP X-Message-ID-Hash: VGIJVC4MKMKOHETUJPM6VX46C327RCOP X-MailFrom: abologna@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Roman Bogorodskiy X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1708650697029100001 Depending on the situation, the IDs that we pass to these functions can be either referring to processes or threads. Linux doesn't have separate interfaces for one or the other, but FreeBSD does and we're explicitly telling it that the ID refers to a process. When it refers to a thread instead, the call will fail, and the VM will not be able to start. Luckily, another possible choice is CPU_WHICH_TIDPID, which makes things behave the same as Linux. Signed-off-by: Andrea Bolognani Reviewed-by: Martin Kletzander --- src/util/virprocess.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 047b0aa0cd..8384bd1378 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -551,7 +551,7 @@ int virProcessSetAffinity(pid_t pid, CPU_SET(i, &mask); } =20 - if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, + if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid, sizeof(mask), &mask) !=3D 0) { if (quiet) { VIR_DEBUG("cannot set CPU affinity on process %d: %s", @@ -574,7 +574,7 @@ virProcessGetAffinity(pid_t pid) virBitmap *ret =3D NULL; =20 CPU_ZERO(&mask); - if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, pid, + if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid, sizeof(mask), &mask) !=3D 0) { virReportSystemError(errno, _("cannot get CPU affinity of process %1$d"),= pid); --=20 2.43.2 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 10 07:36:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1708650621144178.2164014166333; Thu, 22 Feb 2024 17:10:21 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0438717FB; Thu, 22 Feb 2024 20:10:19 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B0DF01A5E; Thu, 22 Feb 2024 20:06:12 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8D48118FA; Thu, 22 Feb 2024 20:05:49 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 445D619D1 for ; Thu, 22 Feb 2024 20:05:47 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-96-im6JMTJEN32n_Fj3IrggFQ-1; Thu, 22 Feb 2024 20:05:45 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3ED04185A783; Fri, 23 Feb 2024 01:05:45 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.45.224.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AABBA2166AEE; Fri, 23 Feb 2024 01:05:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: im6JMTJEN32n_Fj3IrggFQ-1 From: Andrea Bolognani To: devel@lists.libvirt.org Subject: [PATCH 2/3] util: Prefer cpuset_{get,set}affinity() on BSD Date: Fri, 23 Feb 2024 02:05:40 +0100 Message-ID: <20240223010541.211981-3-abologna@redhat.com> In-Reply-To: <20240223010541.211981-1-abologna@redhat.com> References: <20240223010541.211981-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: M5Z3PGW45CSOOPPKA25J3JDSPQWCLSJY X-Message-ID-Hash: M5Z3PGW45CSOOPPKA25J3JDSPQWCLSJY X-MailFrom: abologna@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Roman Bogorodskiy X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1708650622889100001 FreeBSD 14 implements sched_{get,set}affinity() for compatibility with Linux, but we should still use the native syscalls instead. Signed-off-by: Andrea Bolognani Reviewed-by: Martin Kletzander --- src/util/virprocess.c | 110 +++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 8384bd1378..426d56c1ce 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -444,7 +444,61 @@ int virProcessKillPainfully(pid_t pid, bool force) return virProcessKillPainfullyDelay(pid, force, 0, false); } =20 -#if WITH_DECL_CPU_SET_T +#if defined(WITH_BSD_CPU_AFFINITY) + +int virProcessSetAffinity(pid_t pid, + virBitmap *map, + bool quiet) +{ + size_t i; + cpuset_t mask; + + CPU_ZERO(&mask); + for (i =3D 0; i < virBitmapSize(map); i++) { + if (virBitmapIsBitSet(map, i)) + CPU_SET(i, &mask); + } + + if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid, + sizeof(mask), &mask) !=3D 0) { + if (quiet) { + VIR_DEBUG("cannot set CPU affinity on process %d: %s", + pid, g_strerror(errno)); + } else { + virReportSystemError(errno, + _("cannot set CPU affinity on process %1$= d"), pid); + return -1; + } + } + + return 0; +} + +virBitmap * +virProcessGetAffinity(pid_t pid) +{ + size_t i; + cpuset_t mask; + virBitmap *ret =3D NULL; + + CPU_ZERO(&mask); + if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid, + sizeof(mask), &mask) !=3D 0) { + virReportSystemError(errno, + _("cannot get CPU affinity of process %1$d"),= pid); + return NULL; + } + + ret =3D virBitmapNew(sizeof(mask) * 8); + + for (i =3D 0; i < sizeof(mask) * 8; i++) + if (CPU_ISSET(i, &mask)) + ignore_value(virBitmapSetBit(ret, i)); + + return ret; +} + +#elif WITH_DECL_CPU_SET_T =20 int virProcessSetAffinity(pid_t pid, virBitmap *map, bool quiet) { @@ -536,60 +590,6 @@ virProcessGetAffinity(pid_t pid) return ret; } =20 -#elif defined(WITH_BSD_CPU_AFFINITY) - -int virProcessSetAffinity(pid_t pid, - virBitmap *map, - bool quiet) -{ - size_t i; - cpuset_t mask; - - CPU_ZERO(&mask); - for (i =3D 0; i < virBitmapSize(map); i++) { - if (virBitmapIsBitSet(map, i)) - CPU_SET(i, &mask); - } - - if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid, - sizeof(mask), &mask) !=3D 0) { - if (quiet) { - VIR_DEBUG("cannot set CPU affinity on process %d: %s", - pid, g_strerror(errno)); - } else { - virReportSystemError(errno, - _("cannot set CPU affinity on process %1$= d"), pid); - return -1; - } - } - - return 0; -} - -virBitmap * -virProcessGetAffinity(pid_t pid) -{ - size_t i; - cpuset_t mask; - virBitmap *ret =3D NULL; - - CPU_ZERO(&mask); - if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TIDPID, pid, - sizeof(mask), &mask) !=3D 0) { - virReportSystemError(errno, - _("cannot get CPU affinity of process %1$d"),= pid); - return NULL; - } - - ret =3D virBitmapNew(sizeof(mask) * 8); - - for (i =3D 0; i < sizeof(mask) * 8; i++) - if (CPU_ISSET(i, &mask)) - ignore_value(virBitmapSetBit(ret, i)); - - return ret; -} - #else /* WITH_DECL_CPU_SET_T */ =20 int virProcessSetAffinity(pid_t pid G_GNUC_UNUSED, --=20 2.43.2 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 10 07:36:02 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 170865052139687.41593049357584; Thu, 22 Feb 2024 17:08:41 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4B4E51D6F; Thu, 22 Feb 2024 20:08:40 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 473741BCF; Thu, 22 Feb 2024 20:05:58 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id CDC4019F4; Thu, 22 Feb 2024 20:05:48 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 2C6B718FA for ; Thu, 22 Feb 2024 20:05:48 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-315-uyb6zlQDPI691OpHahTXiA-1; Thu, 22 Feb 2024 20:05:46 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 137D883B827; Fri, 23 Feb 2024 01:05:46 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.45.224.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7EF7F2166AF1; Fri, 23 Feb 2024 01:05:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: uyb6zlQDPI691OpHahTXiA-1 From: Andrea Bolognani To: devel@lists.libvirt.org Subject: [PATCH 3/3] util: Add debug print missing from BSD Date: Fri, 23 Feb 2024 02:05:41 +0100 Message-ID: <20240223010541.211981-4-abologna@redhat.com> In-Reply-To: <20240223010541.211981-1-abologna@redhat.com> References: <20240223010541.211981-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 275DR6DYGYIW4YMBP2MHZF63HUYEFHAD X-Message-ID-Hash: 275DR6DYGYIW4YMBP2MHZF63HUYEFHAD X-MailFrom: abologna@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Roman Bogorodskiy X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1708650522558100001 Signed-off-by: Andrea Bolognani Reviewed-by: Martin Kletzander --- src/util/virprocess.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 426d56c1ce..647f687cb8 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -453,6 +453,8 @@ int virProcessSetAffinity(pid_t pid, size_t i; cpuset_t mask; =20 + VIR_DEBUG("Set process affinity on %lld", (long long)pid); + CPU_ZERO(&mask); for (i =3D 0; i < virBitmapSize(map); i++) { if (virBitmapIsBitSet(map, i)) --=20 2.43.2 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org