From: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>,
phasta@mailbox.org, dri-devel@lists.freedesktop.org,
dakr@kernel.org, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 1/2] drm/sched: add drm_sched_prealloc_dependency_slots
Date: Tue, 18 Mar 2025 13:03:59 +0000 [thread overview]
Message-ID: <c394b28e-0cb1-4e91-a6cb-e53f6f2b8cc0@igalia.com> (raw)
In-Reply-To: <20250318120313.19099-2-christian.koenig@amd.com>
On 18/03/2025 12:03, Christian König wrote:
> The problem is that drivers sometimes need to add dependencies without
> allocating any memory.
>
> Add a function which preallocates slots by inserting signaled stub fences
> into the dependency array.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/scheduler/sched_main.c | 41 ++++++++++++++++++++++++--
> include/drm/gpu_scheduler.h | 2 ++
> 2 files changed, 40 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index 4d4219fbe49d..2085eea89513 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -852,6 +852,38 @@ void drm_sched_job_arm(struct drm_sched_job *job)
> }
> EXPORT_SYMBOL(drm_sched_job_arm);
>
> +/**
> + * drm_sched_job_prealloc_dependency_slots - avoid ENOMEM on adding dependencies
> + * @job: scheduler job where dependencies will be added
> + * @num_deps: number of dependencies to preallocate slots for
> + *
> + * Preallocate memory so that no ENOMEM can come later while adding
> + * dependencies.
> + *
> + * Return:
> + * 0 on success, or an error on failing to expand the array.
> + */
> +int drm_sched_job_prealloc_dependency_slots(struct drm_sched_job *job,
> + unsigned int num_deps)
> +{
> + struct dma_fence *fence;
> + u32 id = 0;
> + int ret;
> +
> + while (num_deps--) {
> + fence = dma_fence_get_stub();
> + ret = xa_alloc(&job->dependencies, &id, fence, xa_limit_32b,
> + GFP_KERNEL);
> + if (ret != 0) {
> + dma_fence_put(fence);
> + return ret;
> + }
> + }
> +
> + return 0;
> +}
> +EXPORT_SYMBOL(drm_sched_job_prealloc_dependency_slots);
> +
> /**
> * drm_sched_job_add_dependency - adds the fence as a job dependency
> * @job: scheduler job to add the dependencies to
> @@ -878,10 +910,12 @@ int drm_sched_job_add_dependency(struct drm_sched_job *job,
> * engines involved, rather than the number of BOs.
> */
> xa_for_each(&job->dependencies, index, entry) {
> - if (entry->context != fence->context)
> + bool signaled = dma_fence_is_signaled(entry);
I so dislike dma_fence_is_signaled() due it leaking the fence signaling
annotations to unsuspecting callers. I hope it doesn't mark someone's
lock/mutex as the critical signalling path..
Regards,
Tvrtko
> +
> + if (!signaled && entry->context != fence->context)
> continue;
>
> - if (dma_fence_is_later(fence, entry)) {
> + if (signaled || dma_fence_is_later(fence, entry)) {
> dma_fence_put(entry);
> xa_store(&job->dependencies, index, fence, GFP_KERNEL);
> } else {
> @@ -890,7 +924,8 @@ int drm_sched_job_add_dependency(struct drm_sched_job *job,
> return 0;
> }
>
> - ret = xa_alloc(&job->dependencies, &id, fence, xa_limit_32b, GFP_KERNEL);
> + ret = xa_alloc(&job->dependencies, &id, fence, xa_limit_32b,
> + GFP_KERNEL);
> if (ret != 0)
> dma_fence_put(fence);
>
> diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
> index 1a7e377d4cbb..916e820b27ff 100644
> --- a/include/drm/gpu_scheduler.h
> +++ b/include/drm/gpu_scheduler.h
> @@ -632,6 +632,8 @@ int drm_sched_job_init(struct drm_sched_job *job,
> u32 credits, void *owner);
> void drm_sched_job_arm(struct drm_sched_job *job);
> void drm_sched_entity_push_job(struct drm_sched_job *sched_job);
> +int drm_sched_job_prealloc_dependency_slots(struct drm_sched_job *job,
> + unsigned int num_deps);
> int drm_sched_job_add_dependency(struct drm_sched_job *job,
> struct dma_fence *fence);
> int drm_sched_job_add_syncobj_dependency(struct drm_sched_job *job,
next prev parent reply other threads:[~2025-03-18 13:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-18 12:03 Try to fix amdgpu's error handling Christian König
2025-03-18 12:03 ` [PATCH 1/2] drm/sched: add drm_sched_prealloc_dependency_slots Christian König
2025-03-18 12:39 ` Danilo Krummrich
2025-03-19 11:14 ` Christian König
2025-03-18 12:39 ` Philipp Stanner
2025-03-19 11:23 ` Christian König
2025-03-20 11:49 ` Tvrtko Ursulin
2025-03-21 8:20 ` Philipp Stanner
2025-03-21 13:25 ` Christian König
2025-03-18 13:03 ` Tvrtko Ursulin [this message]
2025-03-18 12:03 ` [PATCH 2/2] drm/amdgpu: fix gang submission error handling Christian König
2025-03-18 12:55 ` Tvrtko Ursulin
2025-03-18 12:36 ` Try to fix amdgpu's " Danilo Krummrich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c394b28e-0cb1-4e91-a6cb-e53f6f2b8cc0@igalia.com \
--to=tvrtko.ursulin@igalia.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=ckoenig.leichtzumerken@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=phasta@mailbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox