From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796290726; b=L0jkbu7Vkh8r2MeLHYd4IKdgMNpkVZqmVye0ToQ37IAIXbl96oyQotTm7Ip12pDnmPWe pazu4ZVq/L2NrcOvnp5Jc5zyflxZ31/BqcZaZc2BJ0me6VJ4l8/JflJ2XiNtsQdi16ahk 2GMRUq6/xD4TeWc2XW3q4A2lojknmGKhXdQKUYAK5uyw17GaosGPg2bhdVimH39PqZzLb 1ZdsZhexc2QlBgf41UOOtudN+8GAJGgYw40boJFEWqUU9mnFLDuLhlNBoMAQF2+4BjR+J DQrD9S0qLWrks8aMKdiAYMrDROfbdEyahhbQFUdPQeLjz/T3mQtGDITRCdjwAtJpM0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796290726; h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject: Message-ID:In-Reply-To:References:Organization:X-Mailer:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=k/fNn2AAd3luM/t3NIeWkvHUecXqU6CSVVc1TzUyj/M=; b=jrM7lyUIGGe6Th/CgLTO2w7VDnBQNo/BbbXL2j945wr5Xsp/O46NHs/tFEXUUMU2IzGL jmtK9f21lcDHrxzGRu+B8BWtcI8oeFNWH3x1HQPAsr+auFCll10e4U9KERzR2mNSUwjtS R+jX/+Til65piia2yLoKQ1+slivmSXQG/NLubw8GIUYq2V/KgTr751wEDs1taVP0Lx8nF Cp9R+1zSjcHiaonbierLhbp7kc3BV/uWwxcE9pfVp6aB9bQLKE6wq10MSX1BM0rafI38L qY2Dc19bkGn+8UB5ugleMvDgJzwvgP0zU51SOTlRuC0j87CdbFapHf32kA+Ne35aL5A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=BJfJEgFr; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BCFB606A339; Thu, 3 Dec 2026 09:38:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9BCFB606A339 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=BJfJEgFr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1796290718; bh=YpjF4o5BVO7eZwE1FS1/rXKH3pKA2q7v/Qz3oNrOCVU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BJfJEgFr1dyW2GMN9GnfgCSfrYJSkVSPfQKZf4XAh5YFYNbdnbTPuEpsbMXuawzjw xLfK+k1hA+S1tTr+SmtUlBi7TJKmOV6ln8TRMunt+m06Ex7RRJtLVP4JsnFnPiMRgP wHjclKAN414m3OXet7dZGtyqoFYHBUYWFUCs/7/8qwgEJWMYmhZykvdJBkiaMq8ZMI IM2i9iLqeUQAGKJ2PFzmy6kTwt87l9bMETDCoWS1qmuIewbyGF2cLrsbSJTbyaR7lA DXFq902Smbva8kbfl2NONmlpmPJHqd/Wc5CduNeBaXHZlQ8RqIeX5Ewaeeevjb6xbT dQBHpqNTFPfDg== Received: from fedora1.home (unknown [100.64.0.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by bali.collaboradmins.com (Postfix) with ESMTPSA id 14BFE17E0192; Thu, 03 Dec 2026 10:38:37 +0100 (CET) Date: Thu, 3 Dec 2026 10:38:33 +0100 From: Boris Brezillon To: Tvrtko Ursulin Cc: Steven Price , Liviu Dudau , Akash Goel , Karunika Choo , Lukas Zapolskas , Chris Diamand , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Sumit Semwal , Christian =?UTF-8?B?S8O2bmln?= , Philipp Stanner , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, Xianzhong Li Subject: Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time Message-ID: <20261203103833.0f99048a@fedora1.home> In-Reply-To: <287283e4-261b-4ebb-92a5-14d5d2a2b443@ursulin.net> References: <20261202-panhtor-dep-skip-v4-0-f84482d7a49c@collabora.com> <20261202-panhtor-dep-skip-v4-1-f84482d7a49c@collabora.com> <287283e4-261b-4ebb-92a5-14d5d2a2b443@ursulin.net> Organization: Collabora X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-redhat-linux-gnu) X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hi Tvrtko, On Wed, 2 Dec 2026 16:52:10 +0000 Tvrtko Ursulin wrote: > On 02/12/2026 11:34, Boris Brezillon wrote: > > All dependencies get added through drm_sched_job_add_dependency() or > > variants that call drm_sched_job_add_dependency() internally. At this > > point, the job is already attached an entity, and we can do the > > same-entity check there, so we don't insert the fence in the XArray in > > the first place. > > > > Note that we keep the elimination logic in > > drm_sched_entity_add_dependency_cb() too, because dependencies returned > > by ::prepare_job() could also potentially be coming from the same > > entity. > > > > Signed-off-by: Boris Brezillon > > --- > > drivers/gpu/drm/scheduler/sched_entity.c | 8 +------- > > drivers/gpu/drm/scheduler/sched_internal.h | 20 ++++++++++++++++++++ > > drivers/gpu/drm/scheduler/sched_main.c | 5 +++++ > > 3 files changed, 26 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c > > index 03e68b4102d5..39419b3ac552 100644 > > --- a/drivers/gpu/drm/scheduler/sched_entity.c > > +++ b/drivers/gpu/drm/scheduler/sched_entity.c > > @@ -473,13 +473,7 @@ static bool drm_sched_entity_add_dependency_cb(struct drm_sched_entity *entity, > > struct dma_fence *fence = entity->dependency; > > struct drm_sched_fence *s_fence; > > > > - if (fence->context == entity->fence_context || > > - fence->context == entity->fence_context + 1) { > > - /* > > - * Fence is a scheduled/finished fence from a job > > - * which belongs to the same entity, we can ignore > > - * fences from ourself > > - */ > > + if (drm_sched_entity_can_skip_dependency(entity, fence)) { > > dma_fence_put(entity->dependency); > > return false; > > } > > diff --git a/drivers/gpu/drm/scheduler/sched_internal.h b/drivers/gpu/drm/scheduler/sched_internal.h > > index 32d3ddb820be..b7afed36b915 100644 > > --- a/drivers/gpu/drm/scheduler/sched_internal.h > > +++ b/drivers/gpu/drm/scheduler/sched_internal.h > > @@ -122,6 +122,26 @@ drm_sched_entity_is_ready(struct drm_sched_entity *entity) > > return true; > > } > > > > +/** > > + * drm_sched_entity_can_skip_dependency() - Check if a dependency can be skipped. > > + * @entity: entity the dependency will be waited on > > + * @fence: fence representing the dependency > > + * > > + * Returns true if the dependency can be skipped, false if it can't. > > + */ > > +static inline bool > > +drm_sched_entity_can_skip_dependency(struct drm_sched_entity *entity, > > + struct dma_fence *fence) > > +{ > > + /* > > + * Fence is a scheduled/finished fence from a job > > + * which belongs to the same entity, we can ignore > > + * fences from ourself > > + */ > > + return fence->context == entity->fence_context || > > + fence->context == entity->fence_context + 1; > > +} > > + > > void drm_sched_entity_stats_release(struct kref *kref); > > > > /** > > diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c > > index 85a49e219837..5f123a5e39ff 100644 > > --- a/drivers/gpu/drm/scheduler/sched_main.c > > +++ b/drivers/gpu/drm/scheduler/sched_main.c > > @@ -678,6 +678,11 @@ int drm_sched_job_add_dependency(struct drm_sched_job *job, > > if (!fence) > > return 0; > > > > + if (drm_sched_entity_can_skip_dependency(job->entity, fence)) { > > + dma_fence_put(fence); > > + return 0; > > + } > > I did some testing today and I can confirm that this is the part which > can eliminate most dependencies. More on why later. > > What I still cannot 100% remember if at some point in the past I tried > it and something wasn't quite safe, but at least in my today's testing > it looked okay. > > I am also unsure of and I think needs discussing is whether it makes > sense to allow drivers to choose whether to unwrap or not, or we should > follow the same approach for everyone. > > In my testing I captured stats from one second duration of the Cyberpunk > 2077 benchmark on the Steam Deck. That's around 700 submitted jobs > across all GPU engines. Give or take, because I wasn't super precise > with capture start end. > > I looked at these numbers: > > * How many unwrapped fences per add dep on average? > * How many we can squash with strict same context but earlier? > * How many we can squash with the same scheduled+finished fence check? > * How many XArray dependecies per job on average we end up with all of > the above scenarios. > > I think the most interesting data point is actually the last one. > > With the stock kernel I saw around ~0.9 XArray dep entries per job. > > Squashing with this patch gets that down to ~0.3 deps per job. > > Unwrapping everything and applying the new and existing filtering on top > is pretty much the same average deps per job. Which is I think the most > interesting number since it directly sets the limit to the reduction of > theoretical run_job<->pop_job round-trips before job can actually get > submitted. > > (Talking about round-trips, I am slightly unclear how on panthor this > ends up a firmware cycle? Not a workqueue cycle?) It's not so much that it adds a FW cycle to signal (that one exists anyway), it's just that it potentially delays the execution of the job because of the time it takes the CPU to service the GPU interrupt and signal the fence FW queueX CPU queue(job0) job0(signal=fence0) [IRQ processing latency here] queue(job1) job1(wait=fence0,signal=fence1) instead of FW queueX CPU queue(job0) queue(job1) job0(signal=fence0) job1(wait=fence0,signal=fence1) > > Anway.. back to the main story - why unwrapping changes the picture so > little? This is because ~80% of submissions are a single dep which > unwraps to a single fence. Which means vast majority of those get > eliminated. It might be true for Vulkan, since VkTimelineSemaphores are probably less common than VkFence/Semaphore. But the implicit sync emulation we have in our gallium driver manages an internal timeline for all accesses to private BOs bound to the GPU VM. Most, if not all of the fences bound to this timeline are coming from the same queue, meaning the unwrapping of this timeline object likely leads to no dep being added. According to Xianzhong that's a ~7% improvement overall on glmark2, which is not negligible. I've also added traces to see how often we end up with jobs with absolutely no dep, and there are scenes where it's actually happening a lot (desktop is one of those, which explains the 30%+ improvement reported on this particular scene and kinda validate my theory). > > And even though when I unwrapped everything I saw around ~1800 real > fences, those ~20% of submissions with multiple deps still only resolve > to one dependency, never to zero like single dep submission almost > always do. > > So there we have it. It seems unwrapping does not buy us much. Perhaps > on the signaling side, given we can always resolve to a single fence > (which I find interesting on its own), we can say it's better to unwrap > to a single dma-fence than suffer the potentially inefficient signalling > side of dma-fence-array or dma-fence-chain? I doubt this is where the overhead comes from given how thin a layer chain/array fences are. My initial investigation really points towards it being related to the fact the job can start executing sooner when self-waits are eliminated, because the job is already queued to the ring buffer, whereas, if you force dma_fence waits before queuing, the "IRQ processing + work scheduling + job queuing + FW wake up" delays add up, and the HW gets to see the job later than it would have if it was queued ahead of time (while the GPU was still executing the previous job on the same queue). Note that this also has an impact when there are external deps involved, depending on the order of signaling: if the external deps appear to be signaled earlier than the self-deps, the array/chain is still considered not signaled, but if you explode those, the individual self-deps would be eliminated and the job would be queued before the GPU is done executing the previous jobs on the same queue, which implies better pipelining. > > I guess I need to come up with a different benchmark and look at > different metrics. Like (soft)irq/s, power, not sure. Well, the thing is, it probably varies between drivers and depends on different factors: 1. how HW -> CPU signaling works, and how long it takes to process the IRQ, schedule the work and push a job to the FW ring buffer 2. how deep the ring buffer is 3. how likely we are to have queueX -> queueX deps with no other deps (you seem to prove that this almost never happens on the amdgpu stack, but I'm sure that's true on panfrost/panthor), or even how external/internal deps are ordered in the chain/array 4. what the UMD does (internal timeline_syncobj, export/import SYNC_FD dances, ...) I'm certainly not saying we should force the unwrapping on every driver, and that's the very reason I was skeptical about forcing it at the drm_sched_job_add_dependency() level. TL;DR I really think we should start with an opt-in solution. This can take the form of a helper, like I proposed in v2, or it can be drivers open-coding the loop, or even an option at the entity level to change drm_sched_job_add_dependency()'s behavior. The key here is to let each driver decide whether it's good for them to unwrap containers. If at some point we end up with all drivers transitioning to this model we can consider making it the default. Thanks for all the effort you've put into gathering those numbers on a different HW BTW, that's really appreciated. Regards, Boris