From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796230333; b=4Io/rJf/ZVLnn/IayzETzeLZVg39LkdodIbOCitMJoEW+Y/wbUs6LwWMVAfPDDqukPXG AfVdU2gRtAJi9kuh59ArqIO82px9igUnH/sF+mle1vpmIimN0lSfwpdYp32x94lKJfem4 6M3NySRkm9+qq1dQbFxQqyOfijVwXnE2Peq91BdYw3IK2jMTKY6Qg8VIbAWMceW4yLQ1h Geks8T273fva5bauHMtgSwqPSbwruCx1ZKMB6YoCsN1sauhXnoLRGoLAIM7L0uqRSxk1/ ZIAuHH0zTVMhGiLCO7fyMpIMsAdMp4bcS20TbbZAGnavE86csz985STaKqzIsaUWrVA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796230333; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=d6xR999wWAQLGDaBDs+4nqRrbeje489eJKxNumTh30Y=; b=TjAei4PNfzc/BkXYCeO7zRCWOS/MrewGEed+GEj+XL28VpzRrNVkHBkmvc/2bRxDkk9X CdB+tW2bOAHJ5SyG4Yfakq3V3k18f+mrQq2dVl2+koV6xQETYxWl5zQG51hv6h52LII2c G4Dvcau3H4w8sCof2Ow3O5welMGGgY+9A8ZuXJYsyYYWLI4CKfrCwiLRZMk8EpsfPi8+g tBVAs6qWEOthD72akVi8rkiCaAUkLWyvy6qsVSG9zx2zzf+41nX9i+t0R9L24diBeExyF +8OONr7dBRbBh2rjdvLD3t40aTGQf0Y546rKcSHB14CO3pfVwG0yblFqh2J3pG3XvjA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=ursulin.net; spf=pass smtp.mailfrom=ursulin.net; dkim=pass header.d=ursulin.net header.i=@ursulin.net header.a=rsa-sha256 header.s=google header.b=wukHxEmE; arc=none smtp.remote-ip=209.85.128.53 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E915E606A31A for ; Wed, 2 Dec 2026 16:52:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E915E606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ursulin.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ursulin.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=ursulin.net header.i=@ursulin.net header.a=rsa-sha256 header.s=google header.b=wukHxEmE Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4a35a60499eso103919325e9.0 for ; Wed, 02 Dec 2026 08:52:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin.net; s=google; t=1796230331; x=1796835131; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=d6xR999wWAQLGDaBDs+4nqRrbeje489eJKxNumTh30Y=; b=wukHxEmEY1HK0LMq0o0wZu2TKz2Hxw1t8tBDLl+/e4h+nNc654RwuRvapCXnpxy/aT G9+qdvZPppzWwKeM3UyOCNZk7td11BwXjiNB2Eay4MCsTeMHgzL4nmm1UQZVsDevtl2I Ok2XncY1KvX3Okmi4cC5gAqwnxHaOxBgbzdRcyRcCBNNC2AvZ+Ntsoe81JH/T6k/sXpO eO0LblTsJG94mpMtbum/TXQ3aEzxru7qH6B03XRSDOVz5R2fNzVM0Potc93Mks5vKFCy pnRgZrdKcNyLfDJgJ09vpCNU2VTEKG3NJJxcBvPazqIYuiVWl7CAneb6dtldwJUoy5Z0 nb9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796230331; x=1796835131; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=d6xR999wWAQLGDaBDs+4nqRrbeje489eJKxNumTh30Y=; b=DVam59lf5JWhqFl0NqfIBTBB648SQQMkb95/JI9Fajn4ngbz9/L/gkMRC+9Q/ApvxP iIDeRdnTz4vcYxGpE+pVEIBFRucq2mdnvQZIlIQNfwQkmXYqoBa1czvuBxHRqC2UFu0l flM8wc/mDV0DhwQbzzbYqJB24SK8YvDeCTy/OGnQUcsUlRHfTRo6r18igjOtapNuYHII U6CZ4bf48YLHxCV6bc67QQZgerZKjqdLR73E7Qy6kLzHD5dUzrjkzC33i+2LrvrXJn2u 9a7AR4HaBuEaQlyN9kQ9fSq8qIOk3unZ32jRjxrqOKa7a/mJ5YTqlxUL4DT+27g5spCA hDCw== X-Forwarded-Encrypted: i=1; AL+hErHU7aWUr2JQTq3tm5j0RmlUlkBTbOQJz/69oRPefcRitubMSCtxHDWxsBcvL76ptIFox2D5c7oOesVHI2A=@vger.kernel.org X-Gm-Message-State: APuU4Z/P0WjXOMkja+R4cJ5hVtD2YKi2Jr9CneAbYhWvshMJpElLhnmz e+RmB63kSWhTiQoZw0j7hBC6a/32DSfuLICexTfgQTi9gMVi4z4O8d6+6zjfSeXHtS4= X-Gm-Gg: AZFdTZdv3iblLX5tqb4BCA2BsuEFiKJtUjvni8XRtvpnRJm37IUtpV+Js52F1qmAFRH xSc9nVYX2VcttNb0wHJezWGIm1zm2RWAnluBJoXrOVYDX8nki8qL0lUSC1OKPgTQol+3thMFnWc h/YN8acQOKC6pIN8uzNGOYpMeoVGNWpsjZIWBikmL6OiEKrqXeXNLzjVN0m5wC/SnRsJoyTZWAY P9pOoApDqAIaj05/h2Kx3W3UdhdqGyuKi4I5EOZTShB1Sjxg4aQxLP7u1euejmSw/DdzR31d642 09t7Csqou1grihnrIedCL2ayIwtaCd2ljdqSJgrZ3VaESD4TiM1ROjwbaF3Br2nGlwc6Qk07sKC YaX2jY+8/okV9W11OJBk1c51WZXkJtaGVKq/sGMJqc48tfgJkkniTpw5No6Fq1mFOAfm+sy8/43 XruvVT4d8Uk0TkO5wCN8dltUBgh31n4RPOoY1iZvc/UhYLXDJDZoLYK/qyrxmevLxqBKGDNDf86 wHsu+xLI0ro0UREKZD4SoIdHPkZzWyABX3YxWoBjVjeVUqh2mKebacY5j0GKaG68SoiFNkRCQBg glpq/9BngTGTbol44VpxzPOXKD7VsalW7D3ipPUtnMnE8Q== X-Received: by 2002:a05:600c:a0d:b0:4a1:825a:56fd with SMTP id 5b1f17b1804b1-4bb88826c1fmr789387435e9.32.1796230330893; Wed, 02 Dec 2026 08:52:10 -0800 (PST) Received: from [192.168.0.116] ([81.79.79.1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853c9170sm1158101635e9.14.2026.12.02.08.52.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 08:52:10 -0800 (PST) Message-ID: <287283e4-261b-4ebb-92a5-14d5d2a2b443@ursulin.net> Date: Wed, 2 Dec 2026 16:52:10 +0000 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time To: Boris Brezillon , Steven Price , Liviu Dudau , Akash Goel , Karunika Choo , Lukas Zapolskas , Chris Diamand Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Sumit Semwal , =?UTF-8?Q?Christian_K=C3=B6nig?= , 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 References: <20261202-panhtor-dep-skip-v4-0-f84482d7a49c@collabora.com> <20261202-panhtor-dep-skip-v4-1-f84482d7a49c@collabora.com> Content-Language: en-GB From: Tvrtko Ursulin In-Reply-To: <20261202-panhtor-dep-skip-v4-1-f84482d7a49c@collabora.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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?) 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. 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 guess I need to come up with a different benchmark and look at different metrics. Like (soft)irq/s, power, not sure. Regards, Tvrtko P.S. For reference the full unwrap I tested with this patch: diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c index ba2a06e22707..ec50be7e44a4 100644 --- a/drivers/gpu/drm/scheduler/sched_main.c +++ b/drivers/gpu/drm/scheduler/sched_main.c @@ -71,6 +71,7 @@ #include #include #include +#include #include #include @@ -675,34 +676,52 @@ EXPORT_SYMBOL(drm_sched_job_arm); int drm_sched_job_add_dependency(struct drm_sched_job *job, struct dma_fence *fence) { + struct drm_sched_entity *entity = job->entity; + struct dma_fence_unwrap iter; struct dma_fence *entry; - unsigned long index; - u32 id = 0; - int ret; + int ret = 0; if (!fence) return 0; - /* Deduplicate if we already depend on a fence from the same context. - * This lets the size of the array of deps scale with the number of - * engines involved, rather than the number of BOs. - */ - xa_for_each(&job->dependencies, index, entry) { - if (entry->context != fence->context) + dma_fence_unwrap_for_each(entry, &iter, fence) { + struct dma_fence *dep; + unsigned long index; + bool found = false; + + if (entry->context == entity->fence_context || + entry->context == entity->fence_context + 1) continue; - if (dma_fence_is_later(fence, entry)) { - dma_fence_put(entry); - xa_store(&job->dependencies, index, fence, GFP_KERNEL); - } else { - dma_fence_put(fence); + xa_for_each(&job->dependencies, index, dep) { + if (entry->context != dep->context) + continue; + + found = true; + + if (dma_fence_is_later(entry, dep)) { + xa_store(&job->dependencies, index, + dma_fence_get(entry), GFP_KERNEL); + dma_fence_put(dep); + } + + break; + } + + if (!found) { + u32 id = 0; + + ret = xa_alloc(&job->dependencies, &id, + dma_fence_get(entry), + xa_limit_32b, GFP_KERNEL); + if (ret) { + dma_fence_put(entry); + break; + } } - return 0; } - ret = xa_alloc(&job->dependencies, &id, fence, xa_limit_32b, GFP_KERNEL); - if (ret != 0) - dma_fence_put(fence); + dma_fence_put(fence); return ret; } > + > /* Deduplicate if we already depend on a fence from the same context. > * This lets the size of the array of deps scale with the number of > * engines involved, rather than the number of BOs. >