From nobody Tue Feb 10 04:13:23 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