Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C7907E9B249 for ; Tue, 24 Feb 2026 10:32:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2B51489083; Tue, 24 Feb 2026 10:32:17 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=mailbox.org header.i=@mailbox.org header.b="l3gHVYZg"; dkim-atps=neutral Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9181C89083 for ; Tue, 24 Feb 2026 10:32:15 +0000 (UTC) Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4fKvDD2SSGz9vGx; Tue, 24 Feb 2026 11:32:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1771929132; h=from:from:reply-to: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; bh=3Q6QPkQGSNXa6+cmfsogIufuj+sWVtBm0OC1M1VOKTE=; b=l3gHVYZg+AeABjc7WUS/yWZfY5tunDMlnilPWOGvQB01eVQXQwbRAA9VAlJimsvT+WI9WR IUaNPiC0SrvsXhmFkpUj/bQ0B2ItNceX+2q2k9nhk1GRryD9KnO8xVl2U+OUj6+jFvvrKL MTmOqmBTYo+B2NgVaFeGK+vbMX7ZMcq/KRqs/Yx2RI4DKg1r9A2OEeADQjsf1km5l4HgVf l9I0hQNMyQsjZCHqhEzZdODNGDtrlSQ7PT4QDeueZeozOZLPU1L3X77vwYcQ0FuK8JaZI3 7LfLUkyyZvgSbL+0DWUKMmJmLFTFieF0s7g7InzgJw4fvQc9M77nyLGTQ+zhIw== Message-ID: Subject: Re: Opportunistic dma_fence polling From: Philipp Stanner To: Christian =?ISO-8859-1?Q?K=F6nig?= , phasta@kernel.org Cc: dri-devel@lists.freedesktop.org, Boris Brezillon , Danilo Krummrich Date: Tue, 24 Feb 2026 11:32:10 +0100 In-Reply-To: References: <91f84eccd59d593822dbb97c995ae9c52ba788d2.camel@mailbox.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MBO-RS-ID: e41dc6c7afb45d5f25e X-MBO-RS-META: bdrwh5stob78angmfco5bhehwdiyu5ud X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: phasta@kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Mon, 2026-02-23 at 12:42 +0100, Christian K=C3=B6nig wrote: > Hi Philip, >=20 > I only found this message by coincident, please make sure to always CC my= AMD work email address as well. You've been the direct recipent, in the To: header field :) >=20 > On 2/19/26 12:06, Philipp Stanner wrote: > > Yo Christian, > >=20 > > I'd like to discuss the dma_fence fast path optimization > > (ops.is_signaled) again. > >=20 > > As far as I understand by now, the use case is that some drivers will > > never signal fences; but the consumer of the fence actively polls > > whether a fence is signaled or not. > >=20 > > Right? >=20 > Close but not 100% right. The semantic is that enabled_signaling is only = called when somebody actively waits for the dma_fence to finish. >=20 > So as long as both userspace and kernel only poll for the fence status en= able_signaling is never called and only is_signaled is called. So you're telling me that enable_signaling enables interrupt-driven signaling, typically. IOW in some cases you can request that a specific fence gets signaled the expensive way (interrupt) while polling on the others. What is the hw->hw signaling that the documentation details? hw->sw signaling seems to refer to interrupts. >=20 > What drivers/fence implementations do with that is up to them. For exampl= e userqueues use it as preemption signaling, but most drivers simply try to= avoid waking up the system with IRQs. >=20 > > I have a bunch of questions regarding that: > >=20 > > =C2=A0=C2=A0 1. What does the party polling the fence typically look li= ke? I bet > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 it's not userspace, is it? Userspace I'd= expect to use poll() on > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 a FD, thus an underlying driver has to c= heck the fence somehow. >=20 > No no, that is indeed userspace. Userspace has no direct access to a fence. It's, ultimately a kernel ioctl through which userspace can check a fence. That's what I meant: it's kernel code implemented in the driver [but running in the user's process context] >=20 > As soon as the kernel starts to call dma_fence_wait() (for example) we ha= ve the normal guaranteed to signal semantics we always have. >=20 > > =C2=A0=C2=A0 2. What if that party checks the fence, determines it is u= nsignaled? > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Will it then again try later? >=20 > I have no idea, that depends on how the userspace component is implemente= d. >=20 > > =C2=A0=C2=A0 3. If it tries again later anyways, then what is the probl= em with > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 the fence-issuing driver itself checking= every 5, 10 or 50 > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 milliseconds what the counter in the GPU= ring buffer is, and then > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 signals all those fences? >=20 > That you need to wake up for that, this costs quite a lot of power. >=20 > See two different approach: >=20 > 1. Interrupt driven, e.g. somebody says signal me as soon as possible whe= n the work is done. >=20 > 2. Poll driven, e.g. userspace wakes up every N milliseconds anyway and i= t doesn't matter if the status changes a bit later. Makes sense, I guess. >=20 > > So it circles around the question why ops.is_signaled is supposedly > > unavoidable. >=20 > Additional to the interrupt/poll handling it is also a really important o= ptimization for multicore systems, e.g. it makes the signaling state visibl= e to other CPU cores even when the core handling the IRQ is still busy. What is the "signaling state"? A fence's signaled status is indicated through an atomic flag which becomes visible globally once someone, like said interrupt, has signaled the fence. P. >=20 > That is also really important for some use cases as far as I know. Keep i= n mind that this framework drivers everything from Android mobiles all the = way up to supercomputers. >=20 > I mean what we could potentially do is to fix the locking invariant of th= e is_signaled callback, but that is probably the only simplification possib= le without breaking tons of use cases. >=20 > Regards, > Christian. >=20 > >=20 > > Regards > > P. >=20