From: Danilo Krummrich <dakr@kernel.org>
To: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: amd-gfx@lists.freedesktop.org, kernel-dev@igalia.com,
"Christian König" <christian.koenig@amd.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Philipp Stanner" <phasta@kernel.org>
Subject: Re: [PATCH 1/3] drm/sched: Add internal job peek/pop API
Date: Thu, 6 Feb 2025 17:54:14 +0100 [thread overview]
Message-ID: <Z6TpNo_MgnXcNSsH@cassiopeiae> (raw)
In-Reply-To: <20250206164031.43413-2-tvrtko.ursulin@igalia.com>
On Thu, Feb 06, 2025 at 04:40:29PM +0000, Tvrtko Ursulin wrote:
> Idea is to add helpers for peeking and popping jobs from entities with
> the goal of decoupling the hidden assumption in the code that queue_node
> is the first element in struct drm_sched_job.
>
> That assumption usually comes in the form of:
>
> while ((job = to_drm_sched_job(spsc_queue_pop(&entity->job_queue))))
>
> Which breaks if the queue_node is re-positioned due to_drm_sched_job
> being implemented with a container_of.
>
> This also allows us to remove duplicate definitions of to_drm_sched_job.
>
> 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_entity.c | 11 +++---
> drivers/gpu/drm/scheduler/sched_internal.h | 43 ++++++++++++++++++++++
> drivers/gpu/drm/scheduler/sched_main.c | 7 ++--
> 3 files changed, 51 insertions(+), 10 deletions(-)
> create mode 100644 drivers/gpu/drm/scheduler/sched_internal.h
>
> diff --git a/drivers/gpu/drm/scheduler/sched_internal.h b/drivers/gpu/drm/scheduler/sched_internal.h
> new file mode 100644
> index 000000000000..565c83e32371
> --- /dev/null
> +++ b/drivers/gpu/drm/scheduler/sched_internal.h
> @@ -0,0 +1,43 @@
> +
> +
> +/**
> + * __drm_sched_entity_queue_pop - Low level helper for popping queued jobs
Why the '__' prefix?
Could also use this to replace spsc_queue_pop() in drm_sched_entity_pop_job().
> + *
> + * @entity: scheduler entity
> + *
> + * Low level helper for popping queued jobs.
> + *
> + * Returns the job dequeued or NULL.
> + */
> +static inline struct drm_sched_job *
> +__drm_sched_entity_queue_pop(struct drm_sched_entity *entity)
> +{
> + struct spsc_node *node;
> +
> + node = spsc_queue_pop(&entity->job_queue);
> + if (!node)
> + return NULL;
> +
> + return container_of(node, struct drm_sched_job, queue_node);
> +}
> +
> +/**
> + * __drm_sched_entity_queue_peek - Low level helper for peeking at the job queue
Same here.
Could also use this for drm_sched_entity_is_ready().
> + *
> + * @entity: scheduler entity
> + *
> + * Low level helper for peeking at the job queue
> + *
> + * Returns the job at the head of the queue or NULL.
> + */
> +static inline struct drm_sched_job *
> +__drm_sched_entity_queue_peek(struct drm_sched_entity *entity)
> +{
> + struct spsc_node *node;
> +
> + node = spsc_queue_peek(&entity->job_queue);
> + if (!node)
> + return NULL;
> +
> + return container_of(node, struct drm_sched_job, queue_node);
> +}
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index a48be16ab84f..43ca98e8db5f 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -78,6 +78,8 @@
> #include <drm/gpu_scheduler.h>
> #include <drm/spsc_queue.h>
>
> +#include "sched_internal.h"
> +
> #define CREATE_TRACE_POINTS
> #include "gpu_scheduler_trace.h"
>
> @@ -87,9 +89,6 @@ static struct lockdep_map drm_sched_lockdep_map = {
> };
> #endif
>
> -#define to_drm_sched_job(sched_job) \
> - container_of((sched_job), struct drm_sched_job, queue_node)
> -
> int drm_sched_policy = DRM_SCHED_POLICY_FIFO;
>
> /**
> @@ -123,7 +122,7 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched,
> {
> struct drm_sched_job *s_job;
>
> - s_job = to_drm_sched_job(spsc_queue_peek(&entity->job_queue));
> + s_job = __drm_sched_entity_queue_peek(entity);
> if (!s_job)
> return false;
>
> --
> 2.48.0
>
next prev parent reply other threads:[~2025-02-06 16:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 16:40 [PATCH v3 0/3] drm/sched: Job queue peek/pop helpers and struct job re-order Tvrtko Ursulin
2025-02-06 16:40 ` [PATCH 1/3] drm/sched: Add internal job peek/pop API Tvrtko Ursulin
2025-02-06 16:54 ` Danilo Krummrich [this message]
2025-02-07 8:41 ` Tvrtko Ursulin
2025-02-06 16:40 ` [PATCH 2/3] drm/amdgpu: Pop jobs from the queue more robustly Tvrtko Ursulin
2025-02-11 8:22 ` Christian König
2025-02-11 10:08 ` Philipp Stanner
2025-02-11 10:21 ` Christian König
2025-02-11 10:35 ` Tvrtko Ursulin
2025-02-14 10:21 ` Tvrtko Ursulin
2025-02-14 10:31 ` Christian König
2025-02-14 10:34 ` Tvrtko Ursulin
2025-02-14 10:39 ` Christian König
2025-02-06 16:40 ` [PATCH 3/3] drm/sched: Remove a hole from struct drm_sched_job Tvrtko Ursulin
2025-02-06 17:04 ` Danilo Krummrich
2025-02-11 8:28 ` Christian König
2025-02-06 16:58 ` [PATCH v3 0/3] drm/sched: Job queue peek/pop helpers and struct job re-order Danilo Krummrich
2025-02-07 10:13 ` Tvrtko Ursulin
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=Z6TpNo_MgnXcNSsH@cassiopeiae \
--to=dakr@kernel.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.