From nobody Mon Feb 9 09:24:08 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=1688672703; cv=none; d=zohomail.com; s=zohoarc; b=CrfHi/5LAU+2lazTIRYakidHaWGuZspcVD5O3KLMmNIWj2dl0QQeVCScjT01Wml7K1K2HxguOCCTuLA04OcKPM7NfNePCBq7UrKV/NOHtVfe8rWPIv2MYB9fQryeQgdJ7m2RxBCZz+MbcKXlaRS2+yfMHBjCHUwQ4o1aMTqL9A8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688672703; h=Content-Type:Content-Transfer-Encoding:Cc: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=3nrCTuVu0CUmEi2tpCCelfbr/zQtC9XfBGzYtadbpnA=; b=jT7aFSvDMXKHWcOviOYgkbxK1zsFn15ahu6bq8Wtcy2RFLkQC1nVw5PrtvmCcjmW9hmOVy54cq7awoU13aWashWvN1F1DKZrNDLQPOAyTbsSLQYSCgnXe3ntmcw4s74AHQ6EQxUOPSC7+1DWQIkzhJmNjJg7QLqvtomCo8M6/ME= 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 1688672703971963.9377732636632; Thu, 6 Jul 2023 12:45:03 -0700 (PDT) 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-35-Hap-40mOMECnLD5a6bI4OA-1; Thu, 06 Jul 2023 15:44:23 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 49ABF1044595; Thu, 6 Jul 2023 19:44:21 +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 30B2A2166B25; Thu, 6 Jul 2023 19:44:21 +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 32FC11946A50; Thu, 6 Jul 2023 19:44:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0DA2B194658F for ; Thu, 6 Jul 2023 19:44:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EFB7B40C206F; Thu, 6 Jul 2023 19:44:18 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.32.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4B5540C2063; Thu, 6 Jul 2023 19:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688672703; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=3nrCTuVu0CUmEi2tpCCelfbr/zQtC9XfBGzYtadbpnA=; b=h+1DgboLAmIpfWTm1Skh31CLUTb9SRv/gf2HgkJi5B4ZBMgDiQFa/qccF/s1QTWzX99O8V Fx/YDcqkkDlE8oH7dNsKHkWtgXQqINJMtCxdhvxgRm+vKTQc7KfULNzeq6DbgxoynomyQE RIZKnHH3AadeDUN+vwUvtdXNyDUxW3Q= X-MC-Unique: Hap-40mOMECnLD5a6bI4OA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 1/2] nodedev: refactor mdevctl thread functions Date: Thu, 6 Jul 2023 14:44:16 -0500 Message-ID: <20230706194417.1639816-2-jjongsma@redhat.com> In-Reply-To: <20230706194417.1639816-1-jjongsma@redhat.com> References: <18e27cd1-554c-1cd9-d0dc-3ff73ddf9bfd@redhat.com> <20230706194417.1639816-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: , Cc: fiuczy@linux.ibm.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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: 1688672704670100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Factor out a new scheduleMdevctlUpdate() function so that we can re-use it from other places. Now that other events can make it necessary to re-query mdevctl for mdev updates, this function will be useful for coalescing multiple updates in quick succession into a single mdevctl query. Also rename a couple functions. The names weren't very descriptive of their behavior. For example, the old scheduleMdevctlHandler() function didn't actually schedule anything, it just started a thread. So rename it to free up the 'schedule' name for the above refactored function. Signed-off-by: Jonathon Jongsma Reviewed-by: Boris Fiuczynski --- src/node_device/node_device_udev.c | 37 ++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index fce4212728..9ba550dbc1 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2075,7 +2075,7 @@ udevPCITranslateInit(bool privileged G_GNUC_UNUSED) =20 =20 static void -mdevctlHandlerThread(void *opaque G_GNUC_UNUSED) +mdevctlUpdateThreadFunc(void *opaque G_GNUC_UNUSED) { udevEventData *priv =3D driver->privateData; VIR_LOCK_GUARD lock =3D virLockGuardLock(&priv->mdevctlLock); @@ -2085,8 +2085,9 @@ mdevctlHandlerThread(void *opaque G_GNUC_UNUSED) } =20 =20 + static void -scheduleMdevctlHandler(int timer G_GNUC_UNUSED, void *opaque) +launchMdevctlUpdateThread(int timer G_GNUC_UNUSED, void *opaque) { udevEventData *priv =3D opaque; virThread thread; @@ -2096,7 +2097,7 @@ scheduleMdevctlHandler(int timer G_GNUC_UNUSED, void = *opaque) priv->mdevctlTimeout =3D -1; } =20 - if (virThreadCreateFull(&thread, false, mdevctlHandlerThread, + if (virThreadCreateFull(&thread, false, mdevctlUpdateThreadFunc, "mdevctl-thread", false, NULL) < 0) { virReportSystemError(errno, "%s", _("failed to create mdevctl thread")); @@ -2192,6 +2193,26 @@ mdevctlEnableMonitor(udevEventData *priv) } =20 =20 +/* Schedules an mdevctl update for 100ms in the future, canceling any exis= ting + * timeout that may have been set. In this way, multiple update requests in + * quick succession can be collapsed into a single update. if @force is tr= ue, + * an update thread will be spawned immediately. */ +static void +scheduleMdevctlUpdate(udevEventData *data, + bool force) +{ + if (!force) { + if (data->mdevctlTimeout > 0) + virEventRemoveTimeout(data->mdevctlTimeout); + data->mdevctlTimeout =3D virEventAddTimeout(100, launchMdevctlUpda= teThread, + data, NULL); + return; + } + + launchMdevctlUpdateThread(-1, data); +} + + static void mdevctlEventHandleCallback(GFileMonitor *monitor G_GNUC_UNUSED, GFile *file, @@ -2222,15 +2243,7 @@ mdevctlEventHandleCallback(GFileMonitor *monitor G_G= NUC_UNUSED, * configuration change, try to coalesce these changes by waiting for = the * CHANGES_DONE_HINT event. As a fallback, add a timeout to trigger t= he * signal if that event never comes */ - if (event_type !=3D G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) { - if (priv->mdevctlTimeout > 0) - virEventRemoveTimeout(priv->mdevctlTimeout); - priv->mdevctlTimeout =3D virEventAddTimeout(100, scheduleMdevctlHa= ndler, - priv, NULL); - return; - } - - scheduleMdevctlHandler(-1, priv); + scheduleMdevctlUpdate(priv, (event_type =3D=3D G_FILE_MONITOR_EVENT_CH= ANGES_DONE_HINT)); } =20 =20 --=20 2.41.0 From nobody Mon Feb 9 09:24:08 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=1688672713; cv=none; d=zohomail.com; s=zohoarc; b=Ab46fIldtv7jNnrl1c8dgVpSH5wmQCXjNwo+O6Df94jwDaT1wI57tkDtiRtHuFv6tY6YTAjCmXoqkHx2qwSv8LpV4DJDxTWG0xaw0NmEGhavfIYzz62keb6+PAVDnOIGI21Ify6P9fZZpL8teQzKDo8Q4to7Xb3DrwnI2iAMvDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688672713; h=Content-Type:Content-Transfer-Encoding:Cc: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=cpJuaGXHGwnfuYNDiW0Ynkw51s9wlIpzW4AbeDMcGNw=; b=GHlhnPYNzPfRFYTQ2BAGenAKruW7mdc5RhfqBU2qce6sL8qG5At2RCawYUERZbdKMqSPISaWk8vJrM2iM9vh6uAdc1fjuZdlIrrNq9zTkLiRVGvOXMTWGtFqbciaBNEBlG+CTVXiFxgO6pPNF+G+JX41An6iLgQTCahOGshQOXE= 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 1688672713369546.287882588487; Thu, 6 Jul 2023 12:45:13 -0700 (PDT) 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-608-mwSdWqz2N_iGIK6DxhTAbQ-1; Thu, 06 Jul 2023 15:44:28 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E5315830DB7; Thu, 6 Jul 2023 19:44:21 +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 C6B2CC575E0; Thu, 6 Jul 2023 19:44:21 +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 6B4E01946A69; Thu, 6 Jul 2023 19:44:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5624C1946589 for ; Thu, 6 Jul 2023 19:44:19 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3A89940C2070; Thu, 6 Jul 2023 19:44:19 +0000 (UTC) Received: from himantopus.redhat.com (unknown [10.22.32.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F33940C2063; Thu, 6 Jul 2023 19:44:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688672711; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=cpJuaGXHGwnfuYNDiW0Ynkw51s9wlIpzW4AbeDMcGNw=; b=TPEAJbEV2W7p169rECr2K6tZgs9gotxc7tk2alIa8jLTAZy/n4FwpQ3uX8XujM0R9z+Z17 AkS77UvlKjpKfENqOLBFZgP3FjL8LnNY74KigGDmB8pXmvMfC1HSL/evFWO4f+VJdsBSWI eVrxfOcYpVN5Yz89ftW4yAfDOj0vsak= X-MC-Unique: mwSdWqz2N_iGIK6DxhTAbQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] nodedev: update mdevs from the mdevctl thread Date: Thu, 6 Jul 2023 14:44:17 -0500 Message-ID: <20230706194417.1639816-3-jjongsma@redhat.com> In-Reply-To: <20230706194417.1639816-1-jjongsma@redhat.com> References: <18e27cd1-554c-1cd9-d0dc-3ff73ddf9bfd@redhat.com> <20230706194417.1639816-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: , Cc: fiuczy@linux.ibm.com Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 1688672714846100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Rather than directly executing mdevctl from the udev event thread when we determine that we need to re-query, schedule the mdevctl thread to run. This also helps to coalesce multiple back-to-back updates into a single one when there are multiple updates in a row or at startup when a host has a very large number of mdevs. Signed-off-by: Jonathon Jongsma Reviewed-by: Boris Fiuczynski --- src/node_device/node_device_udev.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 9ba550dbc1..da63d326a1 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1443,6 +1443,9 @@ udevGetDeviceDetails(struct udev_device *device, } =20 =20 +static void scheduleMdevctlUpdate(udevEventData *data, bool force); + + static int udevRemoveOneDeviceSysPath(const char *path) { @@ -1475,8 +1478,7 @@ udevRemoveOneDeviceSysPath(const char *path) virNodeDeviceObjEndAPI(&obj); =20 /* cannot check for mdev_types since they have already been removed */ - if (nodeDeviceUpdateMediatedDevices() < 0) - VIR_WARN("mdevctl failed to update mediated devices"); + scheduleMdevctlUpdate(driver->privateData, false); =20 virObjectEventStateQueue(driver->nodeDeviceEventState, event); return 0; @@ -1604,8 +1606,8 @@ udevAddOneDevice(struct udev_device *device) has_mdev_types =3D virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_MDEV_T= YPES); virNodeDeviceObjEndAPI(&obj); =20 - if (has_mdev_types && nodeDeviceUpdateMediatedDevices() < 0) - VIR_WARN("mdevctl failed to update mediated devices"); + if (has_mdev_types) + scheduleMdevctlUpdate(driver->privateData, false); =20 ret =3D 0; =20 @@ -1767,8 +1769,7 @@ udevHandleOneDevice(struct udev_device *device) if (ret =3D=3D 0 && udevGetDeviceType(device, &dev_cap_type) =3D=3D 0 && dev_cap_type =3D=3D VIR_NODE_DEV_CAP_MDEV) - if (nodeDeviceUpdateMediatedDevices() < 0) - VIR_WARN("mdevctl failed to update mediated devices"); + scheduleMdevctlUpdate(driver->privateData, false); return ret; } =20 --=20 2.41.0