From: Philipp Stanner <phasta@mailbox.org>
To: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: kernel-dev@igalia.com,
"Christian König" <christian.koenig@amd.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Matthew Brost" <matthew.brost@intel.com>,
"Philipp Stanner" <phasta@kernel.org>
Subject: Re: [RFC v4 04/16] drm/sched: Avoid double re-lock on the job free path
Date: Mon, 12 May 2025 14:49:55 +0200 [thread overview]
Message-ID: <657c053d7cd443ff310dfff19d03ab11e0f17289.camel@mailbox.org> (raw)
In-Reply-To: <20250425102034.85133-5-tvrtko.ursulin@igalia.com>
On Fri, 2025-04-25 at 11:20 +0100, Tvrtko Ursulin wrote:
> Currently the job free work item will lock sched->job_list_lock first
> time
> to see if there are any jobs, free a single job, and then lock again
> to
> decide whether to re-queue itself if there are more finished jobs.
>
> Since drm_sched_get_finished_job() already looks at the second job in
> the
> queue we can simply add the signaled check and have it return the
> presence
> of more jobs to free to the caller. That way the work item does not
> have
> to lock the list again and repeat the signaled check.
Are you convinced that this is worth it?
I'm torn. It's rare that one returns a status through a boolean by
reference.
Independently from that, this is a candidate which certainly can be
branched out from this series, to make the series completely about the
new scheduling policy, not general other improvements.
P.
>
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: Philipp Stanner <phasta@kernel.org>
> ---
> drivers/gpu/drm/scheduler/sched_main.c | 39 +++++++++++-------------
> --
> 1 file changed, 16 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c
> b/drivers/gpu/drm/scheduler/sched_main.c
> index 86e40157b09b..a45b02fd2af3 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -365,22 +365,6 @@ static void __drm_sched_run_free_queue(struct
> drm_gpu_scheduler *sched)
> queue_work(sched->submit_wq, &sched->work_free_job);
> }
>
> -/**
> - * drm_sched_run_free_queue - enqueue free-job work if ready
> - * @sched: scheduler instance
> - */
> -static void drm_sched_run_free_queue(struct drm_gpu_scheduler
> *sched)
> -{
> - struct drm_sched_job *job;
> -
> - spin_lock(&sched->job_list_lock);
> - job = list_first_entry_or_null(&sched->pending_list,
> - struct drm_sched_job, list);
> - if (job && dma_fence_is_signaled(&job->s_fence->finished))
> - __drm_sched_run_free_queue(sched);
> - spin_unlock(&sched->job_list_lock);
> -}
> -
> /**
> * drm_sched_job_done - complete a job
> * @s_job: pointer to the job which is done
> @@ -1097,12 +1081,13 @@ drm_sched_select_entity(struct
> drm_gpu_scheduler *sched)
> * drm_sched_get_finished_job - fetch the next finished job to be
> destroyed
> *
> * @sched: scheduler instance
> + * @have_more: are there more finished jobs on the list
> *
> * Returns the next finished job from the pending list (if there is
> one)
> * ready for it to be destroyed.
> */
> static struct drm_sched_job *
> -drm_sched_get_finished_job(struct drm_gpu_scheduler *sched)
> +drm_sched_get_finished_job(struct drm_gpu_scheduler *sched, bool
> *have_more)
> {
> struct drm_sched_job *job, *next;
>
> @@ -1110,22 +1095,27 @@ drm_sched_get_finished_job(struct
> drm_gpu_scheduler *sched)
>
> job = list_first_entry_or_null(&sched->pending_list,
> struct drm_sched_job, list);
> -
> if (job && dma_fence_is_signaled(&job->s_fence->finished)) {
> /* remove job from pending_list */
> list_del_init(&job->list);
>
> /* cancel this job's TO timer */
> cancel_delayed_work(&sched->work_tdr);
> - /* make the scheduled timestamp more accurate */
> +
> + *have_more = false;
> next = list_first_entry_or_null(&sched-
> >pending_list,
> typeof(*next),
> list);
> -
> if (next) {
> + /* make the scheduled timestamp more
> accurate */
> if (test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT,
> &next->s_fence-
> >scheduled.flags))
> next->s_fence->scheduled.timestamp =
> dma_fence_timestamp(&job-
> >s_fence->finished);
> +
> + if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
> + &next->s_fence-
> >finished.flags))
> + *have_more = true;
> +
> /* start TO timer for next job */
> drm_sched_start_timeout(sched);
> }
> @@ -1184,12 +1174,15 @@ static void drm_sched_free_job_work(struct
> work_struct *w)
> struct drm_gpu_scheduler *sched =
> container_of(w, struct drm_gpu_scheduler,
> work_free_job);
> struct drm_sched_job *job;
> + bool have_more;
>
> - job = drm_sched_get_finished_job(sched);
> - if (job)
> + job = drm_sched_get_finished_job(sched, &have_more);
> + if (job) {
> sched->ops->free_job(job);
> + if (have_more)
> + __drm_sched_run_free_queue(sched);
> + }
>
> - drm_sched_run_free_queue(sched);
> drm_sched_run_job_queue(sched);
> }
>
next prev parent reply other threads:[~2025-05-12 12:50 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-25 10:20 [RFC v4 00/16] Fair DRM scheduler Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 01/16] drm/sched: Add some scheduling quality unit tests Tvrtko Ursulin
2025-04-29 15:03 ` Christian König
2025-04-29 15:45 ` Michel Dänzer
2025-04-29 15:52 ` Christian König
2025-04-25 10:20 ` [RFC v4 02/16] drm/sched: Add some more " Tvrtko Ursulin
2025-04-29 15:07 ` Christian König
2025-04-25 10:20 ` [RFC v4 03/16] drm/sched: De-clutter drm_sched_init Tvrtko Ursulin
2025-04-29 15:16 ` Christian König
2025-04-25 10:20 ` [RFC v4 04/16] drm/sched: Avoid double re-lock on the job free path Tvrtko Ursulin
2025-05-12 12:49 ` Philipp Stanner [this message]
2025-05-12 12:57 ` Matthew Brost
2025-05-14 8:54 ` Tvrtko Ursulin
2025-05-14 8:46 ` Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 05/16] drm/sched: Consolidate drm_sched_job_timedout Tvrtko Ursulin
2025-05-12 12:53 ` Philipp Stanner
2025-05-14 8:57 ` Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 06/16] drm/sched: Consolidate drm_sched_rq_select_entity_rr Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 07/16] drm/sched: Implement RR via FIFO Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 08/16] drm/sched: Consolidate entity run queue management Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 09/16] drm/sched: Move run queue related code into a separate file Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 10/16] drm/sched: Free all finished jobs at once Tvrtko Ursulin
2025-05-12 12:56 ` Philipp Stanner
2025-05-14 9:00 ` Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 11/16] drm/sched: Account entity GPU time Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 12/16] drm/sched: Remove idle entity from tree Tvrtko Ursulin
2025-05-12 13:03 ` Philipp Stanner
2025-05-14 9:22 ` Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 13/16] drm/sched: Add fair scheduling policy Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 14/16] drm/sched: Remove FIFO and RR and simplify to a single run queue Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 15/16] drm/sched: Queue all free credits in one worker invocation Tvrtko Ursulin
2025-04-25 10:20 ` [RFC v4 16/16] drm/sched: Embed run queue singleton into the scheduler Tvrtko Ursulin
2025-05-12 13:05 ` Philipp Stanner
2025-04-29 7:25 ` [RFC v4 00/16] Fair DRM scheduler Tvrtko Ursulin
2025-05-19 16:51 ` Pierre-Eric Pelloux-Prayer
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=657c053d7cd443ff310dfff19d03ab11e0f17289.camel@mailbox.org \
--to=phasta@mailbox.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=kernel-dev@igalia.com \
--cc=matthew.brost@intel.com \
--cc=phasta@kernel.org \
--cc=tvrtko.ursulin@igalia.com \
/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;
as well as URLs for NNTP newsgroup(s).