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=1796206163; b=BiBxA/aFMtFsU5XT77/ajmeMkyemd2UR3aqQV2tlZAk0sAgED1qIeiyNcd/bZMSxS9Qe XY0R6IkY4iozYR2aidLwO/nphyUeNxeercHUfKIwIT6xisCwMttw5U0E060E/7uolOGEa cBpFOLTm4qjA+45wq7XOZVXJA6nIV7dIBE7G2zDc9FA1qi5pl7XLumHaDEXYS2paORUHa G6lyxmRyu0k2WpSEGoxEHWmA4cseuNECyjCBZqkcTjpqx0ZmKwiVDGYpSExpPO2lBavh8 TWxNnc35+ITnEj9ee5HMim8HmTb/fUuViIRafSYLIbxT1L2KQ+JLgiQgfEzxGxK8zmA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796206163; 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=UENOeCGf+r/xXXCuVNMt2aAV+YYyyGSO+z8aWpLaB7w=; b=4dCwbRQGZ4EhcV+glyDEvafNkDaQwNnaJ94XpCHl4+A5zX2XKgSilkpQyioOPWtUBTph LNIbO30iB6d2pfaYyuhtjh6PXZA2EyANQ7GmbEK1Uy3RcL4lkJQV2nkPK31z/5r4ZVlGt HpnSrQtSGSzcn+h1QEHowEjomJdix0U/G+Jb+20SDyyy3TiLRbaiDGV3mWnCHDtJS61UZ ttgOsVD6WNhBKYP1yzJ2V4yw0GpBDplzPiOA1sTchU6axPVQXWxXL4hYzbL2dTnFKwHFe vvI/rBzwvOTFaYlo774cJESB3KMcwP6RMve+Gw1VnXxHh3lZLMZFB7rDrxzJSa4dEOA== 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=SqhP4x3W; 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 959E2606A325; Wed, 2 Dec 2026 10:09:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 959E2606A325 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=SqhP4x3W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1796206160; bh=hVZX9fm/yd2oczP6XIeNol/sjxjkLse65C9FSyMQghg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SqhP4x3WmJHGLRKemfGKD1N21Zzz8Yw0ex0PLpqhAjta08XdF7VpIPvGVIEa4IFaR lHTdQPBJtYtKUsG3TLXjyw4RntBXO96qxF4EAegRaqRQtIV1DO3FWxJwwGTm6egZPu XpLto/4zHvAAGwfGZ4en3OKAYPTIs+Td1SG8f0GywZoA6wBNXlUtt8/ROuOjG/Zefj BD2iz/01jJrBZLQgQYc19maVl1arIK+D86u1knwaAqtDLOAqDAzIXFRYzI8x7HwL8z zzqf96zakWK6qqpPI9Oj+CNQ1zCzFQjQ1sGYmREiIrsht7DQgnBQOFjJbb6RwBPTQC DrcGKn3/fs1wQ== 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 AC1F617E054F; Wed, 02 Dec 2026 11:09:19 +0100 (CET) Date: Wed, 2 Dec 2026 11:09:14 +0100 From: Boris Brezillon To: Philipp Stanner Cc: phasta@kernel.org, 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?= , 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] drm/panthor: Skip job dependencies when we can Message-ID: <20261202110914.24479237@fedora1.home> In-Reply-To: References: <20261201-panhtor-dep-skip-v1-1-432f313dea0f@collabora.com> Organization: Collabora X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-redhat-linux-gnu) X-Mailing-List: linux-kernel@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=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, 01 Dec 2026 15:09:47 +0100 Philipp Stanner wrote: > On Tue, 2026-12-01 at 14:58 +0100, Boris Brezillon wrote: > > If a job is passed a dependency that's coming from the same queue the > > job is targeting, we can get rid of the dependency because of the > > implicit serialization provided by the queue. =20 >=20 > Shouldn't drm_sched be doing that already? See below. It does do that if the dependency added to the XArray is not a container fence. But the case we're having here is a fence_array (sync_fd export) or fence_chain (timeline syncobj) being added directly to the dependency list. >=20 > Am I understanding correctly that someone sets a dependency for > something on the same userspace context, not merely relying on FIFO > behavior? Most of the time userspace gets passed objects to wait on (Vk[Timeline]Semaphore/Fence) without knowing where they come from, so extracting info on whether this is the same queue or not is hard to figure out at this level. The KMD has full knowledge of this, which makes it the perfect place to do the NOP-dep eviction. >=20 > JobQueue currently is not deadlock-resistant against that because I > expected drivers to ignore such deps. Yep, it's not so much that we're running into a deadlock. This patch really is about optimizing stuff by letting drm_sched queue the job before its predecessor on the same queue are done. By doing that, we avoid an extra FW <-> CPU round-trip to signal the fence and wake up drm_sched to re-evaluate the current entity dependency and finally push the job to the ringbuf. >=20 > >=20 > > =20 >=20 > [=E2=80=A6] >=20 > > =C2=A0 > > +static bool can_skip_dep(const struct drm_sched_job *job, struct dma_f= ence *fence) > > +{ > > + if (!fence) > > + return true; > > + > > + /* This fence comes from our queue, and the serialization happening at > > + * the queue level makes it so we can skip the CPU wait. > > + */ > > + if (fence->context =3D=3D job->entity->fence_context || > > + =C2=A0=C2=A0=C2=A0 fence->context =3D=3D job->entity->fence_context += 1) > > + return true; > > + =20 >=20 > [=E2=80=A6] >=20 > > + if (can_skip_dep(job, fence)) { > > + dma_fence_put(fence); =20 >=20 > drm_sched does: >=20 > static bool drm_sched_entity_add_dependency_cb(struct drm_sched_entity *e= ntity, > struct drm_sched_job *sched_job) > { > struct drm_gpu_scheduler *sched =3D entity->rq->sched; > struct dma_fence *fence =3D entity->dependency; > struct drm_sched_fence *s_fence; >=20 > if (fence->context =3D=3D entity->fence_context || > fence->context =3D=3D 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 > */ > dma_fence_put(entity->dependency); > return false; > } >=20 >=20 >=20 > I seem to be missing something, because at first glance drm_sched > should ignore your added dependencies. The catch here is that it doesn't work with container fences. So, either we explode container fences at insertion time (when drm_sched_job_add_dependency() & co is called), or we do it in drm_sched_entity_add_dependency_cb() and try to see through the container. The former potentially means adding more entries in the Xarray, the latter implies reworking the entity dep tracking logic to save the position inside the container being considered (so basically an _unwrap() cursor stored somewhere). There's also the case where the GPU <-> CPU round-trip doesn't matter because the HW pipeline capabilities are too limited (if you have a queue of exactly one job, you'll have to wait for the previous job to signal its fence before pushing a new job anyway, so there's no point splitting container fences if it doesn't save you this round-trip). TL;DR yes drm_sched has this logic baked in, but it's highly dependent on how the driver adds its dependencies, and panthor was just ignoring this fact until now.