A bit of struct drm_sched_job cleanup
Subsystems (4)
cover A bit of struct drm_sched_job cleanup
At one point I thought I wanted to add a member to struct drm_sched_job. As I noticed there is a hole in the struct, I went to re-order some members to get rid of it (the hole), at which point I was greeted by a subtle bug cause by the frequent pattern of:
job = to_drm_sched_job(spsc_queue_peek|pop(...))
Because to_drm_sched_job is a container of, it implies a lot of the scheduler (and amdgpu) assumes job->queue_node is the first struct element. Dare to change that, code will compile but weird things will happen at runtime.
So I thought lets clean that up and remove that hardcoded sneaky assumption and that is what this series does.
1) Adds a helper so amdgpu can touch the scheduler internals a little bit less.
2) Removes the assumption job->queue_node must be the first element.
3) And finally removes the hole from struct drm_sched_job, fixing one instance of type confusion in passing too.
Tvrtko Ursulin (4):
drm/sched: Add job popping API
drm/amdgpu: Use the new low level job popping helper drm/sched: Remove to_drm_sched_job internal helper drm/sched: Make the type of drm_sched_job->last_dependency consistent
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 5 +- drivers/gpu/drm/scheduler/sched_entity.c | 20 ++++---- drivers/gpu/drm/scheduler/sched_main.c | 10 ++-- include/drm/gpu_scheduler.h | 59 ++++++++++++++++-------- 4 files changed, 57 insertions(+), 37 deletions(-)
Signature · 1 line
2.47.1
PATCH 1/4 drm/sched: Add job popping API
Idea is to add a helper for popping jobs from the entity with the goal of making amdgpu use it in the next patch. That way amdgpu will decouple itself a tiny bit more from scheduler implementation details.
--- drivers/gpu/drm/scheduler/sched_entity.c | 2 +- include/drm/gpu_scheduler.h | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_entity.c +1 -1
@@ -255,7 +255,7 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity)/* The entity is guaranteed to not be used by the scheduler */ prev =rcu_dereference_check (entity->last_scheduled, true);dma_fence_get (prev); -while ((job =to_drm_sched_job (spsc_queue_pop (&entity->job_queue)))) { +while ((job =__drm_sched_entity_pop_job (entity))) {struct drm_sched_fence *s_fence = job->s_fence;dma_fence_get (&s_fence->finished);
include/drm/gpu_scheduler.h +21 -0
@@ -611,6 +611,27 @@ void drm_sched_entity_set_priority(struct drm_sched_entity *entity,bool drm_sched_entity_is_ready (struct drm_sched_entity *entity);int drm_sched_entity_error (struct drm_sched_entity *entity); +/** +* __drm_sched_entity_pop_job - Low level helper for popping queued jobs +* +* @entity: scheduler entity +* +* Low level helper for popping queued jobs. Drivers should not use it. +* +* Returns the job dequeued or NULL. +*/ +static inline struct drm_sched_job * +__drm_sched_entity_pop_job (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); +} +struct drm_sched_fence *drm_sched_fence_alloc (struct drm_sched_entity *s_entity,void *owner); void drm_sched_fence_init(struct drm_sched_fence *fence,
Signature · 1 line
2.47.1
Danilo Krummrich
maintainerRe: [PATCH 1/4] drm/sched: Add job popping API
Quoted 3 lines · Tvrtko Ursulin
Idea is to add a helper for popping jobs from the entity with the goal of making amdgpu use it in the next patch. That way amdgpu will decouple itself a tiny bit more from scheduler implementation details.
I object to adding this function if it's *only* used for something that looks like an abuse of the API by amdgpu. Let's not make that more convenient.
Quoted 59 lines
Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>--- drivers/gpu/drm/scheduler/sched_entity.c | 2 +- include/drm/gpu_scheduler.h | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_entity.c +1
-1@@ -255,7 +255,7 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity)/* The entity is guaranteed to not be used by the scheduler */ prev =rcu_dereference_check (entity->last_scheduled, true);dma_fence_get (prev); -while ((job =to_drm_sched_job (spsc_queue_pop (&entity->job_queue)))) { +while ((job =__drm_sched_entity_pop_job (entity))) {struct drm_sched_fence *s_fence = job->s_fence;dma_fence_get (&s_fence->finished);include/drm/gpu_scheduler.h +21
-0@@ -611,6 +611,27 @@ void drm_sched_entity_set_priority(struct drm_sched_entity *entity,bool drm_sched_entity_is_ready (struct drm_sched_entity *entity);int drm_sched_entity_error (struct drm_sched_entity *entity); +/** +* __drm_sched_entity_pop_job - Low level helper for popping queued jobs +* +* @entity: scheduler entity +* +* Low level helper for popping queued jobs. Drivers should not use it. +* +* Returns the job dequeued or NULL. +*/ +static inline struct drm_sched_job * +__drm_sched_entity_pop_job (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); +} +struct drm_sched_fence *drm_sched_fence_alloc (struct drm_sched_entity *s_entity,void *owner); void drm_sched_fence_init(struct drm_sched_fence *fence,Signature · 1 line
2.47.1
Christian König
maintainerRe: [PATCH 1/4] drm/sched: Add job popping API
Am 20.01.25 um 18:13 schrieb Danilo Krummrich:
Quoted 6 lines · Tvrtko Ursulin
Quoted 3 lines
Idea is to add a helper for popping jobs from the entity with the goal of making amdgpu use it in the next patch. That way amdgpu will decouple itself a tiny bit more from scheduler implementation details.
I object to adding this function if it's *only* used for something that looks like an abuse of the API by amdgpu. Let's not make that more convenient.
Completely agree. Since when do we have that?
I don't remember agreeing to anything which messes so badly with scheduler internals.
Regards,
Christian.
Quoted 59 lines
Quoted 59 lines
Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>--- drivers/gpu/drm/scheduler/sched_entity.c | 2 +- include/drm/gpu_scheduler.h | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_entity.c +1
-1@@ -255,7 +255,7 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity)/* The entity is guaranteed to not be used by the scheduler */ prev =rcu_dereference_check (entity->last_scheduled, true);dma_fence_get (prev); -while ((job =to_drm_sched_job (spsc_queue_pop (&entity->job_queue)))) { +while ((job =__drm_sched_entity_pop_job (entity))) {struct drm_sched_fence *s_fence = job->s_fence;dma_fence_get (&s_fence->finished);include/drm/gpu_scheduler.h +21
-0@@ -611,6 +611,27 @@ void drm_sched_entity_set_priority(struct drm_sched_entity *entity,bool drm_sched_entity_is_ready (struct drm_sched_entity *entity);int drm_sched_entity_error (struct drm_sched_entity *entity); +/** +* __drm_sched_entity_pop_job - Low level helper for popping queued jobs +* +* @entity: scheduler entity +* +* Low level helper for popping queued jobs. Drivers should not use it. +* +* Returns the job dequeued or NULL. +*/ +static inline struct drm_sched_job * +__drm_sched_entity_pop_job (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); +} +struct drm_sched_fence *drm_sched_fence_alloc (struct drm_sched_entity *s_entity,void *owner); void drm_sched_fence_init(struct drm_sched_fence *fence,Signature · 1 line
2.47.1
Re: [PATCH 1/4] drm/sched: Add job popping API
Quoted 11 lines · Christian König
Am 20.01.25 um 18:13 schrieb Danilo Krummrich:
Quoted 6 lines · Tvrtko Ursulin
Quoted 3 lines
Idea is to add a helper for popping jobs from the entity with the goal of making amdgpu use it in the next patch. That way amdgpu will decouple itself a tiny bit more from scheduler implementation details.
I object to adding this function if it's *only* used for something that looks like an abuse of the API by amdgpu. Let's not make that more convenient.
Completely agree. Since when do we have that?
I don't remember agreeing to anything which messes so badly with scheduler internals.
Since 7c6e68c777f1 ("drm/amdgpu: Avoid HW GPU reset for RAS."). Where it looks to be implementing a permanently wedged state - drops everything submitted so far and claims to be blocking any future submission.
Remove that part instead and let the unsubmitted jobs be cleaned up when userspace clients exit? Would need specific hardware to test so it would need to be done on the AMD side.
Regards,
Tvrtko
Quoted 61 lines
Quoted 60 lines
Quoted 60 lines
Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>---
drivers/gpu/drm/scheduler/sched_entity.c| 2 +- include/drm/gpu_scheduler.h | 21 +++++++++++++++++++++2 files changed, 22 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_entity.c +1
-1@@ -255,7 +255,7 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity) /* The entity is guaranteed to not be used by the scheduler */ prev = rcu_dereference_check(entity->last_scheduled, true); dma_fence_get(prev); - while ((job = to_drm_sched_job(spsc_queue_pop(&entity->job_queue)))) { + while ((job = __drm_sched_entity_pop_job(entity))) { struct drm_sched_fence *s_fence = job->s_fence;
dma_fence_get(&s_fence->finished);include/drm/gpu_scheduler.h +2
-0@@ -611,6 +611,27 @@ void drm_sched_entity_set_priority(structdrm_sched_entity *entity, bool drm_sched_entity_is_ready(struct drm_sched_entity *entity); int drm_sched_entity_error(struct drm_sched_entity *entity); +/** +* __drm_sched_entity_pop_job - Low level helper for popping queued jobs
+ *
+ * @entity: scheduler entity
+ *
+ * Low level helper for popping queued jobs. Drivers should not use it.
+ *
+ * Returns the job dequeued or NULL.
+ */include/drm/gpu_scheduler.h +12
-0+static inline struct drm_sched_job * +__drm_sched_entity_pop_job (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); +} +struct
drm_sched_fence*drm_sched_fence_alloc( structdrm_sched_entity*s_entity, void *owner); void drm_sched_fence_init(structdrm_sched_fence*fence,Signature · 1 line
2.47.1
PATCH 2/4 drm/amdgpu: Use the new low level job popping helper
In reply to Tvrtko UrsulinAmdgpu is the only driver which peeks into scheduler internals in this way so lets make it use the previously added helper. This allows removing the local copy of the to_drm_sched_job macro.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +1 -4
@@ -411,9 +411,6 @@ static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job)return fence; } -#define to_drm_sched_job (sched_job) \ - container_of((sched_job), struct drm_sched_job, queue_node) -void amdgpu_job_stop_all_jobs_on_sched (struct drm_gpu_scheduler *sched) {struct drm_sched_job *s_job;
@@ -425,7 +422,7 @@ void amdgpu_job_stop_all_jobs_on_sched(struct drm_gpu_scheduler *sched)struct drm_sched_rq *rq = sched->sched_rq[i];spin_lock (&rq->lock);list_for_each_entry (s_entity, &rq->entities, list) { -while ((s_job =to_drm_sched_job (spsc_queue_pop (&s_entity->job_queue)))) { +while ((s_job =__drm_sched_entity_pop_job (s_entity))) {struct drm_sched_fence *s_fence = s_job->s_fence;dma_fence_signal (&s_fence->scheduled);
Signature · 1 line
2.47.1
PATCH 3/4 drm/sched: Remove to_drm_sched_job internal helper
In reply to Tvrtko UrsulinThe code assumes queue node is the first element in struct drm_sched_job. Since this is not documented it can be very fragile so lets just remove the internal helper and explicitly check for "nothing dequeued", before converting the node to a sched job.
--- drivers/gpu/drm/scheduler/sched_entity.c | 18 +++++++++--------- drivers/gpu/drm/scheduler/sched_main.c | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +9 -9
@@ -30,9 +30,6 @@#include "gpu_scheduler_trace.h" -#define to_drm_sched_job (sched_job) \ - container_of((sched_job), struct drm_sched_job, queue_node) -/** * drm_sched_entity_init - Init a context entity used by scheduler when * submit to HW ring.
@@ -476,11 +473,14 @@ drm_sched_job_dependency(struct drm_sched_job *job,struct drm_sched_job *drm_sched_entity_pop_job (struct drm_sched_entity *entity) {struct drm_sched_job *sched_job; +struct spsc_node *node; - sched_job =to_drm_sched_job (spsc_queue_peek (&entity->job_queue)); -if (!sched_job) + node =spsc_queue_peek (&entity->job_queue); +if (!node)return NULL ; + sched_job =container_of (node,typeof (*sched_job), queue_node); +while ((entity->dependency =drm_sched_job_dependency (sched_job, entity))) {trace_drm_sched_job_wait_dep (sched_job, entity->dependency);
@@ -511,10 +511,10 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)* the timestamp of the next job, if any. */ if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) { -struct drm_sched_job *next; - - next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue)); -if (next) { + node =spsc_queue_peek (&entity->job_queue); +if (node) { +struct drm_sched_job *next = +container_of (node,typeof (*next), queue_node);struct drm_sched_rq *rq;spin_lock (&entity->lock);
drivers/gpu/drm/scheduler/sched_main.c +5 -5
@@ -87,9 +87,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 ;/**
@@ -122,11 +119,14 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched, struct drm_sched_entity *entity) {struct drm_sched_job *s_job; +struct spsc_node *node; - s_job =to_drm_sched_job (spsc_queue_peek (&entity->job_queue)); -if (!s_job) + node =spsc_queue_peek (&entity->job_queue); +if (!node)return false; + s_job =container_of (node,typeof (*s_job), queue_node); +/* If a job exceeds the credit limit, truncate it to the credit limit * itself to guarantee forward progress. */
Signature · 1 line
2.47.1
Danilo Krummrich
maintainerRe: [PATCH 3/4] drm/sched: Remove to_drm_sched_job internal helper
Quoted 2 lines · Tvrtko Ursulin
The code assumes queue node is the first element in struct
drm_sched_job.
I'd add that this assumption lies in doing the NULL check after the container_of(). Without saying that, it might not be that obvious.
Quoted 31 lines
Since this is not documented it can be very fragile so lets just remove the internal helper and explicitly check for "nothing dequeued", before converting the node to a sched job.
Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>--- drivers/gpu/drm/scheduler/sched_entity.c | 18 +++++++++--------- drivers/gpu/drm/scheduler/sched_main.c | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +0
-3@@ -30,9 +30,6 @@#include "gpu_scheduler_trace.h" -#define to_drm_sched_job (sched_job) \ - container_of((sched_job), struct drm_sched_job, queue_node) -/** * drm_sched_entity_init - Init a context entity used by scheduler when * submit to HW ring. @@ -476,11 +473,14 @@ drm_sched_job_dependency(struct drm_sched_job *job,struct drm_sched_job *drm_sched_entity_pop_job (struct drm_sched_entity *entity) {
drivers/gpu/drm/scheduler/sched_entity.c drm_sched_job_dependency(struct drm_sched_job *job, · line 482
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_entity.c +4
-2struct drm_sched_job *sched_job; +struct spsc_node *node; - sched_job =to_drm_sched_job (spsc_queue_peek (&entity->job_queue)); -if (!sched_job) + node =spsc_queue_peek (&entity->job_queue); +if (!node)return NULL ; + sched_job =container_of (node,typeof (*sched_job), queue_node);
So, here you have this pattern for a valid used case and even twice. I think you should add drm_sched_entity_peek_job() instead and document what the preconditions are to be allowed to peek given it's an spsc queue.
Quoted 53 lines
drivers/gpu/drm/scheduler/sched_entity.c +5
-4+while ((entity->dependency =drm_sched_job_dependency (sched_job, entity))) {trace_drm_sched_job_wait_dep (sched_job, entity->dependency);@@ -511,10 +511,10 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)* the timestamp of the next job, if any. */ if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) { -struct drm_sched_job *next; - - next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue)); -if (next) { + node =spsc_queue_peek (&entity->job_queue); +if (node) { +struct drm_sched_job *next = +container_of (node,typeof (*next), queue_node);struct drm_sched_rq *rq;spin_lock (&entity->lock);drivers/gpu/drm/scheduler/sched_main.c +5
-5@@ -87,9 +87,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 ;/** @@ -122,11 +119,14 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched, struct drm_sched_entity *entity) {struct drm_sched_job *s_job; +struct spsc_node *node; - s_job =to_drm_sched_job (spsc_queue_peek (&entity->job_queue)); -if (!s_job) + node =spsc_queue_peek (&entity->job_queue); +if (!node)return false; + s_job =container_of (node,typeof (*s_job), queue_node); +/* If a job exceeds the credit limit, truncate it to the credit limit * itself to guarantee forward progress. */ Signature · 1 line
2.47.1
Re: [PATCH 3/4] drm/sched: Remove to_drm_sched_job internal helper
Quoted 6 lines · Danilo Krummrich
Quoted 2 lines · Tvrtko Ursulin
The code assumes queue node is the first element in struct
drm_sched_job.I'd add that this assumption lies in doing the NULL check after the
container_of(). Without saying that, it might not be that obvious.
Good point, I only put the full explanation in the cover letter.
Quoted 40 lines
Quoted 40 lines
Since this is not documented it can be very fragile so lets just remove the internal helper and explicitly check for "nothing dequeued", before converting the node to a sched job.
Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>--- drivers/gpu/drm/scheduler/sched_entity.c | 18 +++++++++--------- drivers/gpu/drm/scheduler/sched_main.c | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +3
-5@@ -30,9 +30,6 @@#include "gpu_scheduler_trace.h" -#define to_drm_sched_job (sched_job) \ - container_of((sched_job), struct drm_sched_job, queue_node) -/** * drm_sched_entity_init - Init a context entity used by scheduler when * submit to HW ring. @@ -476,11 +473,14 @@ drm_sched_job_dependency(struct drm_sched_job *job,struct drm_sched_job *drm_sched_entity_pop_job (struct drm_sched_entity *entity) {struct drm_sched_job *sched_job; +struct spsc_node *node; - sched_job =to_drm_sched_job (spsc_queue_peek (&entity->job_queue)); -if (!sched_job) + node =spsc_queue_peek (&entity->job_queue); +if (!node)return NULL ;
Quoted 5 lines
drivers/gpu/drm/scheduler/sched_entity.c drm_sched_job_dependency(struct drm_sched_job *job, · line 482
Quoted 1 line
drivers/gpu/drm/scheduler/sched_entity.c +1
-0+ sched_job =container_of (node,typeof (*sched_job), queue_node);So, here you have this pattern for a valid used case and even twice. I think you should add
drm_sched_entity_peek_job()instead and document what the preconditions are to be allowed to peek given it's an spsc queue.
I thought about it but would have to put the declaration into gpu_scheduler.h so I thought it would be a bit better like this. Since gpu_scheduler.h in the ideal world should contain as little as possible things which individual drivers should not use. And I see from your comment on 1/4 that you think the same (just that one was in effect documenting the current state of things).
What if I add a new header file local to driver/gpu/drm/scheduler for internal API?
Regards,
Tvrtko
Quoted 53 lines
Quoted 53 lines
drivers/gpu/drm/scheduler/sched_entity.c +5
-4+while ((entity->dependency =drm_sched_job_dependency (sched_job, entity))) {trace_drm_sched_job_wait_dep (sched_job, entity->dependency);@@ -511,10 +511,10 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)* the timestamp of the next job, if any. */ if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) { -struct drm_sched_job *next; - - next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue)); -if (next) { + node =spsc_queue_peek (&entity->job_queue); +if (node) { +struct drm_sched_job *next = +container_of (node,typeof (*next), queue_node);struct drm_sched_rq *rq;spin_lock (&entity->lock);drivers/gpu/drm/scheduler/sched_main.c +5
-5@@ -87,9 +87,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 ;/** @@ -122,11 +119,14 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched, struct drm_sched_entity *entity) {struct drm_sched_job *s_job; +struct spsc_node *node; - s_job =to_drm_sched_job (spsc_queue_peek (&entity->job_queue)); -if (!s_job) + node =spsc_queue_peek (&entity->job_queue); +if (!node)return false; + s_job =container_of (node,typeof (*s_job), queue_node); +/* If a job exceeds the credit limit, truncate it to the credit limit * itself to guarantee forward progress. */ Signature · 1 line
2.47.1
PATCH 4/4 drm/sched: Make the type of drm_sched_job->last_dependency consistent
In reply to Tvrtko UrsulinDependency tracking via xarray uses xa_limit_32b so there is not need for the struct member to be unsigned long.
At the same time re-order some struct members and take u32 credits outside of the pointer sandwich and avoid a hole.
Pahole report before:
/* size: 160, cachelines: 3, members: 14 */
/* sum members: 156, holes: 1, sum holes: 4 */
/* last cacheline: 32 bytes */And after:
/* size: 152, cachelines: 3, members: 14 */
/* last cacheline: 24 bytes */--- include/drm/gpu_scheduler.h | 38 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-)
include/drm/gpu_scheduler.h +20 -18
@@ -338,8 +338,14 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);* to schedule the job. */ struct drm_sched_job { -struct spsc_node queue_node; -struct list_head list; +u64 id; + +/** +* @submit_ts: +* +* When the job was pushed into the entity queue. +*/ +ktime_t submit_ts;/** * @sched:
@@ -349,24 +355,30 @@ struct drm_sched_job {* has finished. */ struct drm_gpu_scheduler *sched; +struct drm_sched_fence *s_fence; +struct drm_sched_entity *entity; +enum drm_sched_priority s_priority;u32 credits; +/** @last_dependency: tracks @dependencies as they signal */ +unsigned int last_dependency; +atomic_t karma; + +struct spsc_node queue_node; +struct list_head list;/* * work is used only after finish_cb has been used and will not be * accessed anymore. */ union { -struct dma_fence_cb finish_cb; -struct work_struct work; +struct dma_fence_cb finish_cb; +struct work_struct work; }; -uint64_t id; -atomic_t karma; -enum drm_sched_priority s_priority; -struct drm_sched_entity *entity;struct dma_fence_cb cb; +/** * @dependencies: *
@@ -375,16 +387,6 @@ struct drm_sched_job {* drm_sched_job_add_implicit_dependencies(). */ struct xarray dependencies; - -/** @last_dependency: tracks @dependencies as they signal */ -unsigned long last_dependency; - -/** -* @submit_ts: -* -* When the job was pushed into the entity queue. -*/ -ktime_t submit_ts; }; static inline bool drm_sched_invalidate_job(struct drm_sched_job *s_job,
Signature · 1 line
2.47.1