Small DRM scheduler improvements
Subsystems (3)
cover Small DRM scheduler improvements
From: Tvrtko Ursulin <[email protected]>
Leftovers from the earlier "DRM scheduler fixes and improvements" series.
It looks the fixes have now propagated back to drm-misc-next so this should now be mergeable.
It also needed a small rebase to account for one revert and one spelling fix which landed in the meantime.
As a reminder, what remains are kerneldoc improvements, struct layout tweaks for clarity, one trivial cleanup for the FIFO mode, and most importantly two spin lock-unlock cycles are removed from the push job path by pulling taking of the locks one level up.
I smoke tested it on the Steam Deck and lockdep seems happy.
Tvrtko Ursulin (5):
drm/sched: Optimise drm_sched_entity_push_job drm/sched: Stop setting current entity in FIFO mode drm/sched: Re-order struct drm_sched_rq members for clarity drm/sched: Re-group and rename the entity run-queue lock drm/sched: Further optimise drm_sched_entity_push_job
drivers/gpu/drm/scheduler/sched_entity.c | 42 +++++++++++++++--------- drivers/gpu/drm/scheduler/sched_main.c | 32 +++++++++--------- include/drm/gpu_scheduler.h | 28 +++++++++------- 3 files changed, 58 insertions(+), 44 deletions(-)
Signature · 1 line
2.46.0
PATCH 1/5 drm/sched: Optimise drm_sched_entity_push_job
From: Tvrtko Ursulin <[email protected]>
In FIFO mode We can avoid dropping the lock only to immediately re-acquire by adding a new drm_sched_rq_update_fifo_locked() helper.
v2:
* Remove drm_sched_rq_update_fifo() altogether. (Christian)
--- drivers/gpu/drm/scheduler/sched_entity.c | 13 +++++++++---- drivers/gpu/drm/scheduler/sched_main.c | 6 +++--- include/drm/gpu_scheduler.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +9 -4
@@ -514,8 +514,12 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)struct drm_sched_job *next; next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue)); -if (next) -drm_sched_rq_update_fifo (entity, next->submit_ts); +if (next) { +spin_lock (&entity->rq_lock); +drm_sched_rq_update_fifo_locked (entity, + next->submit_ts); +spin_unlock (&entity->rq_lock); + } }/* Jobs and entities might have different lifecycles. Since we're
@@ -613,10 +617,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) sched = rq->sched;drm_sched_rq_add_entity (rq, entity); -spin_unlock (&entity->rq_lock);if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) -drm_sched_rq_update_fifo (entity, submit_ts); +drm_sched_rq_update_fifo_locked (entity, submit_ts); + +spin_unlock (&entity->rq_lock);drm_sched_wakeup (sched); }
drivers/gpu/drm/scheduler/sched_main.c +3 -3
@@ -169,14 +169,15 @@ static inline void drm_sched_rq_remove_fifo_locked(struct drm_sched_entity *enti } } -void drm_sched_rq_update_fifo (struct drm_sched_entity *entity,ktime_t ts) +void drm_sched_rq_update_fifo_locked (struct drm_sched_entity *entity,ktime_t ts) {/* * Both locks need to be grabbed, one to protect from entity->rq change * for entity from within concurrent drm_sched_entity_select_rq and the * other to update the rb tree structure. */ -spin_lock (&entity->rq_lock); +lockdep_assert_held (&entity->rq_lock); +spin_lock (&entity->rq->lock);drm_sched_rq_remove_fifo_locked (entity);
@@ -187,7 +188,6 @@ void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts) drm_sched_entity_compare_before);spin_unlock (&entity->rq->lock); -spin_unlock (&entity->rq_lock); }/**
include/drm/gpu_scheduler.h +1 -1
@@ -593,7 +593,7 @@ void drm_sched_rq_add_entity(struct drm_sched_rq *rq,void drm_sched_rq_remove_entity (struct drm_sched_rq *rq,struct drm_sched_entity *entity); -void drm_sched_rq_update_fifo (struct drm_sched_entity *entity,ktime_t ts); +void drm_sched_rq_update_fifo_locked (struct drm_sched_entity *entity,ktime_t ts); int drm_sched_entity_init(struct drm_sched_entity *entity, enum drm_sched_priority priority,
Signature · 1 line
2.46.0
Re: [PATCH 1/5] drm/sched: Optimise drm_sched_entity_push_job
Hi,
Quoted 6 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
In FIFO mode We can avoid dropping the lock only to immediately re- acquire
by adding a newdrm_sched_rq_update_fifo_locked()helper.
Please write detailed commit messages, as described here [1].
1. Describe the problem: current state and why it's bad.
2. Then, describe in imperative (present tense) form what the commit does about the problem.
Optionally, in between can be information about why it's solved this way and not another etc.
Applies to the other patches, too.
[1] https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
Quoted 58 lines
v2:
* Removedrm_sched_rq_update_fifo()altogether. (Christian)Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Cc Alex Deucher <[email protected]>Cc Luben Tuikov <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Reviewed-by Christian König <[email protected]>---
drivers/gpu/drm/scheduler/sched_entity.c | 13 +++++++++---- drivers/gpu/drm/scheduler/sched_main.c | 6 +++--- include/drm/gpu_scheduler.h | 2 +-3 files changed, 13 insertions(+), 8 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -514,8 +514,12 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity) struct drm_sched_job *next;
next = to_drm_sched_job(spsc_queue_peek(&entity->job_queue));
- if (next)
-drm_sched_rq_update_fifo(entity, next->submit_ts);
+ if (next) {
+spin_lock(&entity->rq_lock);
+ drm_sched_rq_update_fifo_locked(entity,
+next->submit_ts);
+spin_unlock(&entity->rq_lock);
+ }
}
/* Jobs and entities might have different lifecycles. Since we'redrivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -613,10 +617,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) sched = rq->sched;
drm_sched_rq_add_entity(rq, entity);
-spin_unlock(&entity->rq_lock);
if (drm_sched_policy==DRM_SCHED_POLICY_FIFO)
-drm_sched_rq_update_fifo(entity, submit_ts);
+drm_sched_rq_update_fifo_locked(entity, submit_ts); +
+spin_unlock(&entity->rq_lock);
drm_sched_wakeup(sched);
}drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -169,14 +169,15 @@ static inline void
Quoted 8 lines
drm_sched_rq_remove_fifo_locked(struct
drm_sched_entity*enti }
}
-voiddrm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts)
+voiddrm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts)
Since you touch function name / signature already, would you mind writing a small doc string that also mentions the locking requirements or lack of the same?
Quoted 8 lines
{
/*
* Both locks need to be grabbed, one to protect fromentity->rqchange
* for entity from within concurrentdrm_sched_entity_select_rqand the
* other to update the rb tree structure.
*/
It seems to me that the comment above is now out of date, no?
Thx for your efforts,
P.
Quoted 32 lines
-
spin_lock(&entity->rq_lock);
+lockdep_assert_held(&entity->rq_lock);
+
spin_lock(&entity->rq->lock);
drm_sched_rq_remove_fifo_locked(entity);drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -187,7 +188,6 @@ void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts) drm_sched_entity_compare_before);
spin_unlock(&entity->rq->lock);
-spin_unlock(&entity->rq_lock);
}
/**include/drm/gpu_scheduler.h +0
-0@@ -593,7 +593,7 @@ void drm_sched_rq_add_entity(struct drm_sched_rq *rq, void drm_sched_rq_remove_entity(struct drm_sched_rq *rq, struct drm_sched_entity *entity);
-voiddrm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts);
+voiddrm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts);
int drm_sched_entity_init(structdrm_sched_entity*entity, enumdrm_sched_prioritypriority,
Re: [PATCH 1/5] drm/sched: Optimise drm_sched_entity_push_job
Quoted 10 lines · Philipp Stanner
Hi,
Quoted 6 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
In FIFO mode We can avoid dropping the lock only to immediately re- acquire
by adding a newdrm_sched_rq_update_fifo_locked()helper.
Quoted 4 lines
Please write detailed commit messages, as described here [1].
1. Describe the problem: current state and why it's bad.
2. Then, describe in imperative (present tense) form what the commit does about the problem.
Both pieces of info are already there:
1. Drops the lock to immediately re-acquire it.
2. We avoid that by by adding a locked helper.
Quoted 7 lines
Optionally, in between can be information about why it's solved this way and not another etc.
Applies to the other patches, too.
[1] https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
Thanks I am new here and did not know this.
Seriosuly, lets not be too blindly strict about this because it can get IMO ridiculous.
One example when I previously accomodated your request is patch 3/5 from this series:
"""
Current kerneldoc for struct drm_sched_rq incompletely documents what fields are protected by the lock.
This is not good because it is misleading.
Lets fix it by listing all the elements which are protected by the lock. """
While this was the original commit text you weren't happy with:
"""
drm/sched: Re-order struct drm_sched_rq members for clarity
Lets re-order the members to make it clear which are protected by the lock
and at the same time document it via kerneldoc.
"""
I maintain the original text was passable.
On top, this was just a respin to accomodate the merge process. All approvals were done and dusted couple weeks or so ago so asking for yet another respin for such trivial objections is not great.
Regards,
Tvrtko
Quoted 119 lines
Quoted 62 lines
v2:
* Removedrm_sched_rq_update_fifo()altogether. (Christian)Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Cc Alex Deucher <[email protected]>Cc Luben Tuikov <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Reviewed-by Christian König <[email protected]>--- drivers/gpu/drm/scheduler/sched_entity.c | 13 +++++++++---- drivers/gpu/drm/scheduler/sched_main.c | 6 +++--- include/drm/gpu_scheduler.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +6
-2@@ -514,8 +514,12 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity) struct drm_sched_job *next; next = to_drm_sched_job(spsc_queue_peek(&entity->job_queue)); -if (next) -drm_sched_rq_update_fifo (entity, next->submit_ts); +if (next) { +spin_lock (&entity->rq_lock); +drm_sched_rq_update_fifo_locked (entity, + next->submit_ts); +spin_unlock (&entity->rq_lock); + } }/* Jobs and entities might have different lifecycles. Since we're
drivers/gpu/drm/scheduler/sched_entity.c +3
-2@@ -613,10 +617,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) sched = rq->sched; drm_sched_rq_add_entity(rq, entity); -spin_unlock (&entity->rq_lock); if (drm_sched_policy == DRM_SCHED_POLICY_FIFO) -drm_sched_rq_update_fifo (entity, submit_ts); +drm_sched_rq_update_fifo_locked (entity, submit_ts); + +spin_unlock (&entity->rq_lock); drm_sched_wakeup(sched);}
drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -169,14 +169,15 @@ static inline voiddrm_sched_rq_remove_fifo_locked(struct
drm_sched_entity*enti
}
}Quoted 4 lines
-void
drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts)
+voiddrm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts)Since you touch function name / signature already, would you mind writing a small doc string that also mentions the locking requirements or lack of the same?
Quoted 8 lines
{
/*
* Both locks need to be grabbed, one to protect fromentity->rq
change
* for entity from within concurrentdrm_sched_entity_select_rqand
the
* other to update the rb tree structure.
*/It seems to me that the comment above is now out of date, no?
Thx for your efforts,
P.Quoted 32 lines
-
spin_lock(&entity->rq_lock);
+lockdep_assert_held(&entity->rq_lock);drivers/gpu/drm/scheduler/sched_main.c +1
-1+ spin_lock(&entity->rq->lock); drm_sched_rq_remove_fifo_locked(entity);@@ -187,7 +188,6 @@ void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts) drm_sched_entity_compare_before); spin_unlock(&entity->rq->lock); -spin_unlock (&entity->rq_lock); }/**
include/drm/gpu_scheduler.h +1
-1@@ -593,7 +593,7 @@ void drm_sched_rq_add_entity(struct drm_sched_rq *rq, void drm_sched_rq_remove_entity(struct drm_sched_rq *rq, struct drm_sched_entity *entity); -void drm_sched_rq_update_fifo (struct drm_sched_entity *entity, ktime_t ts); +void drm_sched_rq_update_fifo_locked (struct drm_sched_entity *entity,ktime_t ts);int drm_sched_entity_init(struct
drm_sched_entity*entity, enumdrm_sched_prioritypriority,
Re: [PATCH 1/5] drm/sched: Optimise drm_sched_entity_push_job
Quoted 63 lines · Tvrtko Ursulin
Quoted 11 lines · Philipp Stanner
Hi,
Quoted 7 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
In FIFO mode We can avoid dropping the lock only to immediately re-
acquire
by adding a newdrm_sched_rq_update_fifo_locked()helper.Quoted 5 lines
Please write detailed commit messages, as described here [1].
1. Describe the problem: current state and why it's bad.
2. Then, describe in imperative (present tense) form what the commit
does about the problem.Both pieces of info are already there:
1. Drops the lock to immediately re-acquire it.
2. We avoid that by by adding a locked helper.Quoted 9 lines
Optionally, in between can be information about why it's solved this
way and not another etc.Applies to the other patches, too.
[1]
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changesThanks I am new here and did not know this.
Seriosuly, lets not be too blindly strict about this because it can get
IMO ridiculous.One example when I previously accomodated your request is patch 3/5 from
this series:"""
Current kerneldoc for structdrm_sched_rqincompletely documents what fields are protected by the lock.This is not good because it is misleading.
Lets fix it by listing all the elements which are protected by the lock.
"""While this was the original commit text you weren't happy with:
"""
drm/sched: Re-order structdrm_sched_rqmembers for clarityLets re-order the members to make it clear which are protected by the lock
and at the same time document it via kerneldoc.
"""
Quoted 6 lines
I maintain the original text was passable.
On top, this was just a respin to accomodate the merge process. All approvals were done and dusted couple weeks or so ago so asking for yet
another respin for such trivial objections is not great.
I understand that you're unhappy, but please understand the position I'm coming from. As you know, since you sent these patches within a different series (and, thus, since I reviewed them), I was trusted with co-maintaining this piece of shared infrastructure.
And since you've worked on it a bit now, I suppose you also know that the GPU Scheduler is arguably in quite a bad shape, has far too little documentation, has leaks, maybe race conditions, parts *where the locking rules are unclear* and is probably only fully understood by a small hand full of people. I also argue that this is a *very* complicated piece of software.
So I might be or appear to be a bit pedantic, but I'm not doing that to terrorize you, but because I want this thing to become well documented, understandable, and bisectable. Working towards a canonical, idiot- proof commit style is one measure that will help with that.
I want to offer you the following: I can be more relaxed with things universally recognized as trivial (comment changes, struct member reordering) – but when something like a lock is touched in any way, we shall document that in the commit message as canonically as possible, so someone who's less experienced and just bisected the commit immediately understands what has been done (or rather: was supposed to be done).
Greetings
P.
Quoted 130 lines
Regards,
Tvrtko
Quoted 124 lines
Quoted 59 lines
v2:
* Removedrm_sched_rq_update_fifo()altogether. (Christian)Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Cc Alex Deucher <[email protected]>Cc Luben Tuikov <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Reviewed-by Christian König <[email protected]>---
drivers/gpu/drm/scheduler/sched_entity.c | 13 +++++++++---- drivers/gpu/drm/scheduler/sched_main.c | 6 +++--- include/drm/gpu_scheduler.h | 2 +-3 files changed, 13 insertions(+), 8 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -514,8 +514,12 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity) struct drm_sched_job *next;
next = to_drm_sched_job(spsc_queue_peek(&entity->job_queue));
- if (next)
-drm_sched_rq_update_fifo(entity, next->submit_ts);
+ if (next) {
+spin_lock(&entity->rq_lock);
+ drm_sched_rq_update_fifo_locked(entity,
+next->submit_ts);
+spin_unlock(&entity->rq_lock);
+ }
}
/* Jobs and entities might have different lifecycles. Since we'redrivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -613,10 +617,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) sched = rq->sched;
drm_sched_rq_add_entity(rq, entity);
-spin_unlock(&entity->rq_lock);
if (drm_sched_policy==DRM_SCHED_POLICY_FIFO)
-drm_sched_rq_update_fifo(entity, submit_ts);
+drm_sched_rq_update_fifo_locked(entity, submit_ts); +
+spin_unlock(&entity->rq_lock);
drm_sched_wakeup(sched);
}drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -169,14 +169,15 @@ static inline voidQuoted 8 lines
drm_sched_rq_remove_fifo_locked(struct
drm_sched_entity*enti }
}
-voiddrm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts)
+voiddrm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts)Since you touch function name / signature already, would you mind writing a small doc string that also mentions the locking requirements
or lack of the same?Quoted 10 lines
{
/*
* Both locks need to be grabbed, one to protect from entity-Quoted 1 line
rq
change
* for entity from within concurrentdrm_sched_entity_select_rqand
the
* other to update the rb tree structure.
*/It seems to me that the comment above is now out of date, no?
Thx for your efforts,
P.Quoted 33 lines
-
spin_lock(&entity->rq_lock);
+lockdep_assert_held(&entity->rq_lock);
+
spin_lock(&entity->rq->lock);
drm_sched_rq_remove_fifo_locked(entity);drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -187,7 +188,6 @@ void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts) drm_sched_entity_compare_before);
spin_unlock(&entity->rq->lock);
-spin_unlock(&entity->rq_lock);
}
/**include/drm/gpu_scheduler.h +0
-0@@ -593,7 +593,7 @@ void drm_sched_rq_add_entity(struct
drm_sched_rq
*rq,
voiddrm_sched_rq_remove_entity(struct drm_sched_rq *rq, struct drm_sched_entity *entity);
-voiddrm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts);
+voiddrm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts);
int drm_sched_entity_init(structdrm_sched_entity*entity, enumdrm_sched_prioritypriority,
Re: [PATCH 1/5] drm/sched: Optimise drm_sched_entity_push_job
Quoted 76 lines · Philipp Stanner
Quoted 63 lines · Tvrtko Ursulin
Quoted 11 lines · Philipp Stanner
Hi,
Quoted 7 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
In FIFO mode We can avoid dropping the lock only to immediately re-
acquire
by adding a newdrm_sched_rq_update_fifo_locked()helper.Quoted 5 lines
Please write detailed commit messages, as described here [1].
1. Describe the problem: current state and why it's bad.
2. Then, describe in imperative (present tense) form what the
commit
does about the problem.Both pieces of info are already there:
1. Drops the lock to immediately re-acquire it.
2. We avoid that by by adding a locked helper.Quoted 9 lines
Optionally, in between can be information about why it's solved this
way and not another etc.Applies to the other patches, too.
[1]
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changesThanks I am new here and did not know this.
Seriosuly, lets not be too blindly strict about this because it can get
IMO ridiculous.One example when I previously accomodated your request is patch 3/5 from
this series:"""
Current kerneldoc for structdrm_sched_rqincompletely documents what fields are protected by the lock.This is not good because it is misleading.
Lets fix it by listing all the elements which are protected by the lock.
"""While this was the original commit text you weren't happy with:
"""
drm/sched: Re-order structdrm_sched_rqmembers for clarityLets re-order the members to make it clear which are protected by the lock
and at the same time document it via kerneldoc.
"""Quoted 6 lines
I maintain the original text was passable.
On top, this was just a respin to accomodate the merge process. All approvals were done and dusted couple weeks or so ago so asking for yet
another respin for such trivial objections is not great.I understand that you're unhappy, but please understand the position I'm coming from. As you know, since you sent these patches within a different series (and, thus, since I reviewed them), I was trusted with co-maintaining this piece of shared infrastructure.
Quoted 6 lines
And since you've worked on it a bit now, I suppose you also know that the GPU Scheduler is arguably in quite a bad shape, has far too little documentation, has leaks, maybe race conditions, parts *where the locking rules are unclear* and is probably only fully understood by a small hand full of people. I also argue that this is a *very* complicated piece of software.
We already went over that and agreed. Not least I agreed the base is shaky since few years ago. :)
Btw if things align, I hope you will at some point see a follow up series from me which makes some significant simplifications and improvements at the same time.
Quoted 5 lines
So I might be or appear to be a bit pedantic, but I'm not doing that to terrorize you, but because I want this thing to become well documented, understandable, and bisectable. Working towards a canonical, idiot- proof commit style is one measure that will help with that.
Quoted 7 lines
I want to offer you the following: I can be more relaxed with things universally recognized as trivial (comment changes, struct member reordering) – but when something like a lock is touched in any way, we shall document that in the commit message as canonically as possible, so someone who's less experienced and just bisected the commit immediately understands what has been done (or rather: was supposed to be done).
So how would you suggest to expand this commit text so it doesn't read too self-repeating?
Regards,
Tvrtko
Re: [PATCH 1/5] drm/sched: Optimise drm_sched_entity_push_job
Quoted 99 lines · Tvrtko Ursulin
Quoted 87 lines · Philipp Stanner
Quoted 70 lines · Tvrtko Ursulin
Quoted 12 lines · Philipp Stanner
Hi,
Quoted 8 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
In FIFO mode We can avoid dropping the lock only to immediately
re-
acquire
by adding a newdrm_sched_rq_update_fifo_locked()helper.Quoted 6 lines
Please write detailed commit messages, as described here [1].
1. Describe the problem: current state and why it's bad.
2. Then, describe in imperative (present tense) form what the
commit
does about the problem.Both pieces of info are already there:
1. Drops the lock to immediately re-acquire it.
2. We avoid that by by adding a locked helper.Quoted 9 lines
Optionally, in between can be information about why it's solved this
way and not another etc.Applies to the other patches, too.
[1]
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changesThanks I am new here and did not know this.
Seriosuly, lets not be too blindly strict about this because it can
get
IMO ridiculous.One example when I previously accomodated your request is patch 3/5
from
this series:"""
Current kerneldoc for structdrm_sched_rqincompletely documents what
fields are protected by the lock.This is not good because it is misleading.
Lets fix it by listing all the elements which are protected by the
lock.
"""While this was the original commit text you weren't happy with:
"""
drm/sched: Re-order structdrm_sched_rqmembers for clarityLets re-order the members to make it clear which are protected by the
lock
and at the same time document it via kerneldoc.
"""Quoted 8 lines
I maintain the original text was passable.
On top, this was just a respin to accomodate the merge process. All
approvals were done and dusted couple weeks or so ago so asking for
yet
another respin for such trivial objections is not great.I understand that you're unhappy, but please understand the position
I'm coming from. As you know, since you sent these patches within a different series (and, thus, since I reviewed them), I was trusted with
co-maintaining this piece of shared infrastructure.Quoted 9 lines
And since you've worked on it a bit now, I suppose you also know that
the GPU Scheduler is arguably in quite a bad shape, has far too little
documentation, has leaks, maybe race conditions, parts *where the locking rules are unclear* and is probably only fully understood by a
small hand full of people. I also argue that this is a *very* complicated piece of software.
Quoted 6 lines
We already went over that and agreed. Not least I agreed the base is shaky since few years ago. :)
Btw if things align, I hope you will at some point see a follow up series from me which makes some significant simplifications and improvements at the same time.
Cool, good to hear!
(Would be even cooler if simplifications and improvements can be delivered through separate patch series to be easier to review etc.)
Quoted 19 lines
Quoted 7 lines
So I might be or appear to be a bit pedantic, but I'm not doing that to
terrorize you, but because I want this thing to become well documented,
understandable, and bisectable. Working towards a canonical, idiot- proof commit style is one measure that will help with that.Quoted 11 lines
I want to offer you the following: I can be more relaxed with things
universally recognized as trivial (comment changes, struct member reordering) – but when something like a lock is touched in any way, we
shall document that in the commit message as canonically as possible,
so someone who's less experienced and just bisected the commit immediately understands what has been done (or rather: was supposed to
be done).
Quoted 3 lines
So how would you suggest to expand this commit text so it doesn't read
too self-repeating?
My issue with this particular commit message is mainly that it doesn't make it obvious what the patch is supposed to do. So one can make it quicker and better to review by detailing it a bit more, so the reviewer then can compare commit message vs. what the code does. It seems to me for example that the actual optimization is being done in drm_sched_entity_push_job(), and drm_sched_entity_pop_job() had to be ported, too, for correctness
Another small thing that might be cool is something that makes it a bit more obvious that this is an optimization, not a fix.
So I would probably write:
"So far, drm_sched_rq_update_fifo() automatically takes drm_sched_entity.rq_lock. For DRM_SCHED_POLICY_FIFO, this is inefficient because that lock is then taken, released and retaken in drm_sched_entity_push_job().
Improve performance by moving the locking out ofdrm_sched_rq_update_fifo()."
Not that much longer but makes it far more obvious what shall be achieved where :]
(Let me read through the other patches briefly. Then we should be good with v2 of this series.. or would it be v3 then?)
Thanks,
P.
Quoted 5 lines
Regards,
Tvrtko
Re: [PATCH 1/5] drm/sched: Optimise drm_sched_entity_push_job
Quoted 103 lines · Philipp Stanner
Quoted 102 lines · Tvrtko Ursulin
Quoted 87 lines · Philipp Stanner
Quoted 70 lines · Tvrtko Ursulin
Quoted 12 lines · Philipp Stanner
Hi,
Quoted 8 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
In FIFO mode We can avoid dropping the lock only to immediately
re-
acquire
by adding a newdrm_sched_rq_update_fifo_locked()helper.Quoted 6 lines
Please write detailed commit messages, as described here [1].
1. Describe the problem: current state and why it's bad.
2. Then, describe in imperative (present tense) form what
the
commit
does about the problem.Both pieces of info are already there:
1. Drops the lock to immediately re-acquire it.
2. We avoid that by by adding a locked helper.Quoted 9 lines
Optionally, in between can be information about why it's solved this
way and not another etc.Applies to the other patches, too.
[1]
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changesThanks I am new here and did not know this.
Seriosuly, lets not be too blindly strict about this because it can
get
IMO ridiculous.One example when I previously accomodated your request is patch 3/5
from
this series:"""
Current kerneldoc for structdrm_sched_rqincompletely documents what
fields are protected by the lock.This is not good because it is misleading.
Lets fix it by listing all the elements which are protected by the
lock.
"""While this was the original commit text you weren't happy with:
"""
drm/sched: Re-order structdrm_sched_rqmembers for clarityLets re-order the members to make it clear which are protected by the
lock
and at the same time document it via kerneldoc.
"""Quoted 8 lines
I maintain the original text was passable.
On top, this was just a respin to accomodate the merge process. All
approvals were done and dusted couple weeks or so ago so asking for
yet
another respin for such trivial objections is not great.I understand that you're unhappy, but please understand the position
I'm coming from. As you know, since you sent these patches within a different series (and, thus, since I reviewed them), I was trusted with
co-maintaining this piece of shared infrastructure.Quoted 9 lines
And since you've worked on it a bit now, I suppose you also know that
the GPU Scheduler is arguably in quite a bad shape, has far too little
documentation, has leaks, maybe race conditions, parts *where the locking rules are unclear* and is probably only fully understood by a
small hand full of people. I also argue that this is a *very* complicated piece of software.We already went over that and agreed. Not least I agreed the base is shaky since few years ago. :)
Quoted 7 lines
Quoted 3 lines
Btw if things align, I hope you will at some point see a follow up series from me which makes some significant simplifications and improvements at the same time.
Cool, good to hear!
(Would be even cooler if simplifications and improvements can be delivered through separate patch series to be easier to review etc.)
Yes, when I spot something I pull it ahead and/or standalone when it makes sense. But it is early days and a big job.
Quoted 23 lines
Quoted 19 lines
Quoted 7 lines
So I might be or appear to be a bit pedantic, but I'm not doing that to
terrorize you, but because I want this thing to become well documented,
understandable, and bisectable. Working towards a canonical, idiot- proof commit style is one measure that will help with that.Quoted 11 lines
I want to offer you the following: I can be more relaxed with things
universally recognized as trivial (comment changes, struct member reordering) – but when something like a lock is touched in any way, we
shall document that in the commit message as canonically as possible,
so someone who's less experienced and just bisected the commit immediately understands what has been done (or rather: was supposed to
be done).Quoted 3 lines
So how would you suggest to expand this commit text so it doesn't read
too self-repeating?
Quoted 7 lines
My issue with this particular commit message is mainly that it doesn't make it obvious what the patch is supposed to do. So one can make it quicker and better to review by detailing it a bit more, so the reviewer then can compare commit message vs. what the code does. It seems to me for example that the actual optimization is being done in
drm_sched_entity_push_job(), anddrm_sched_entity_pop_job()had to be ported, too, for correctness
"It seems" aka the commit title says so. ;)
Quoted 10 lines
Another small thing that might be cool is something that makes it a bit more obvious that this is an optimization, not a fix.
So I would probably write:
"So far,
drm_sched_rq_update_fifo()automatically takes drm_sched_entity.rq_lock. ForDRM_SCHED_POLICY_FIFO, this is inefficient because that lock is then taken, released and retaken indrm_sched_entity_push_job().
Quoted 5 lines
Improve performance by moving the locking out of
drm_sched_rq_update_fifo()."Not that much longer but makes it far more obvious what shall be achieved where :]
How about this:
"""
In FIFO mode (which is the default), both drm_sched_entity_push_job() and drm_sched_rq_update_fifo(), where the latter calls the former, are currently taking and releasing the same entity->rq_lock.
We can avoid that design inelegance, and also have a miniscule efficiency improvement on the idle submit path, by introducing a new drm_sched_rq_update_fifo_locked() helper and pulling up the lock taking to its callers. """
Quoted 2 lines
(Let me read through the other patches briefly. Then we should be good with v2 of this series.. or would it be v3 then?)
Depends how you count. By unique series titles or by fundamental content.
Regards,
Tvrtko
Re: [PATCH 1/5] drm/sched: Optimise drm_sched_entity_push_job
Quoted 203 lines · Tvrtko Ursulin
Quoted 126 lines · Philipp Stanner
Quoted 116 lines · Tvrtko Ursulin
Quoted 101 lines · Philipp Stanner
Quoted 82 lines · Tvrtko Ursulin
Quoted 12 lines · Philipp Stanner
Hi,
Quoted 8 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
In FIFO mode We can avoid dropping the lock only to immediately
re-
acquire
by adding a newdrm_sched_rq_update_fifo_locked()helper.Quoted 9 lines
Please write detailed commit messages, as described here [1].
1. Describe the problem: current state and why it's bad.
2. Then, describe in imperative (present tense) form what
the
commit
does about the problem.Both pieces of info are already there:
1. Drops the lock to immediately re-acquire it.
2. We avoid that by by adding a locked helper.Quoted 10 lines
Optionally, in between can be information about why it's solved
this
way and not another etc.Applies to the other patches, too.
[1]
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changesThanks I am new here and did not know this.
Seriosuly, lets not be too blindly strict about this because it
can
get
IMO ridiculous.One example when I previously accomodated your request is patch
3/5
from
this series:"""
Current kerneldoc for structdrm_sched_rqincompletely documents
what
fields are protected by the lock.This is not good because it is misleading.
Lets fix it by listing all the elements which are protected by
the
lock.
"""While this was the original commit text you weren't happy with:
"""
drm/sched: Re-order structdrm_sched_rqmembers for clarityLets re-order the members to make it clear which are protected by
the
lock
and at the same time document it via kerneldoc. """I maintain the original text was passable.
Quoted 8 lines
On top, this was just a respin to accomodate the merge process.
All
approvals were done and dusted couple weeks or so ago so asking
for
yet
another respin for such trivial objections is not great.I understand that you're unhappy, but please understand the position
I'm coming from. As you know, since you sent these patches within a
different series (and, thus, since I reviewed them), I was trusted
with
co-maintaining this piece of shared infrastructure.Quoted 12 lines
And since you've worked on it a bit now, I suppose you also know
that
the GPU Scheduler is arguably in quite a bad shape, has far too little
documentation, has leaks, maybe race conditions, parts *where the
locking rules are unclear* and is probably only fully understood by
a
small hand full of people. I also argue that this is a *very* complicated piece of software.Quoted 8 lines
We already went over that and agreed. Not least I agreed the base is
shaky since few years ago. :)Btw if things align, I hope you will at some point see a follow up
series from me which makes some significant simplifications and improvements at the same time.Quoted 4 lines
Cool, good to hear!
(Would be even cooler if simplifications and improvements can be delivered through separate patch series to be easier to review etc.)Yes, when I spot something I pull it ahead and/or standalone when it makes sense. But it is early days and a big job.
Quoted 27 lines
Quoted 23 lines
Quoted 8 lines
So I might be or appear to be a bit pedantic, but I'm not doing that to
terrorize you, but because I want this thing to become well documented,
understandable, and bisectable. Working towards a canonical, idiot-
proof commit style is one measure that will help with that.Quoted 14 lines
I want to offer you the following: I can be more relaxed with things
universally recognized as trivial (comment changes, struct member
reordering) – but when something like a lock is touched in any way,
we
shall document that in the commit message as canonically as possible,
so someone who's less experienced and just bisected the commit immediately understands what has been done (or rather: was supposed
to
be done).Quoted 3 lines
So how would you suggest to expand this commit text so it doesn't read
too self-repeating?Quoted 11 lines
My issue with this particular commit message is mainly that it doesn't
make it obvious what the patch is supposed to do. So one can make it
quicker and better to review by detailing it a bit more, so the reviewer then can compare commit message vs. what the code does. It seems to me for example that the actual optimization is being done indrm_sched_entity_push_job(), anddrm_sched_entity_pop_job()had to be
ported, too, for correctness"It seems" aka the commit title says so. ;)
Quoted 12 lines
Another small thing that might be cool is something that makes it a bit
more obvious that this is an optimization, not a fix.So I would probably write:
"So far,
drm_sched_rq_update_fifo()automatically takes drm_sched_entity.rq_lock. ForDRM_SCHED_POLICY_FIFO, this is inefficient because that lock is then taken, released and retaken indrm_sched_entity_push_job().Quoted 5 lines
Improve performance by moving the locking out of
drm_sched_rq_update_fifo()."Not that much longer but makes it far more obvious what shall be achieved where :]
How about this:
"""
In FIFO mode (which is the default), bothdrm_sched_entity_push_job()anddrm_sched_rq_update_fifo(), where the latter calls the former, are
currently taking and releasing the sameentity->rq_lock.
Quoted 6 lines
We can avoid that design inelegance, and also have a miniscule efficiency improvement on the idle submit path, by introducing a new
drm_sched_rq_update_fifo_locked()helper and pulling up the lock taking
to its callers.
"""
That looks good to me
P.
Quoted 12 lines
Quoted 4 lines
(Let me read through the other patches briefly. Then we should be good
with v2 of this series.. or would it be v3 then?)Depends how you count. By unique series titles or by fundamental content.
Regards,
Tvrtko
Re: [PATCH 1/5] drm/sched: Optimise drm_sched_entity_push_job
Quoted 204 lines · Philipp Stanner
Quoted 203 lines · Tvrtko Ursulin
Quoted 126 lines · Philipp Stanner
Quoted 116 lines · Tvrtko Ursulin
Quoted 101 lines · Philipp Stanner
Quoted 82 lines · Tvrtko Ursulin
Quoted 12 lines · Philipp Stanner
Hi,
Quoted 8 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
In FIFO mode We can avoid dropping the lock only to immediately
re-
acquire
by adding a newdrm_sched_rq_update_fifo_locked()helper.Quoted 9 lines
Please write detailed commit messages, as described here [1].
1. Describe the problem: current state and why it's
bad.
2. Then, describe in imperative (present tense) form
what
the
commit
does about the problem.Both pieces of info are already there:
1. Drops the lock to immediately re-acquire it.
2. We avoid that by by adding a locked helper.Quoted 10 lines
Optionally, in between can be information about why it's solved
this
way and not another etc.Applies to the other patches, too.
[1]
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changesThanks I am new here and did not know this.
Seriosuly, lets not be too blindly strict about this because it
can
get
IMO ridiculous.One example when I previously accomodated your request is patch
3/5
from
this series:"""
Current kerneldoc for structdrm_sched_rqincompletely documents
what
fields are protected by the lock.This is not good because it is misleading.
Lets fix it by listing all the elements which are protected by
the
lock.
"""While this was the original commit text you weren't happy with:
"""
drm/sched: Re-order structdrm_sched_rqmembers for clarityLets re-order the members to make it clear which are protected by
the
lock
and at the same time document it via kerneldoc. """I maintain the original text was passable.
Quoted 8 lines
On top, this was just a respin to accomodate the merge process.
All
approvals were done and dusted couple weeks or so ago so asking
for
yet
another respin for such trivial objections is not great.I understand that you're unhappy, but please understand the position
I'm coming from. As you know, since you sent these patches within a
different series (and, thus, since I reviewed them), I was trusted
with
co-maintaining this piece of shared infrastructure.Quoted 12 lines
And since you've worked on it a bit now, I suppose you also know
that
the GPU Scheduler is arguably in quite a bad shape, has far too little
documentation, has leaks, maybe race conditions, parts *where the
locking rules are unclear* and is probably only fully understood by
a
small hand full of people. I also argue that this is a *very* complicated piece of software.Quoted 8 lines
We already went over that and agreed. Not least I agreed the base is
shaky since few years ago. :)Btw if things align, I hope you will at some point see a follow up
series from me which makes some significant simplifications and improvements at the same time.Quoted 4 lines
Cool, good to hear!
(Would be even cooler if simplifications and improvements can be delivered through separate patch series to be easier to review etc.)Yes, when I spot something I pull it ahead and/or standalone when it makes sense. But it is early days and a big job.
Quoted 27 lines
Quoted 23 lines
Quoted 8 lines
So I might be or appear to be a bit pedantic, but I'm not doing that to
terrorize you, but because I want this thing to become well documented,
understandable, and bisectable. Working towards a canonical, idiot-
proof commit style is one measure that will help with that.Quoted 14 lines
I want to offer you the following: I can be more relaxed with things
universally recognized as trivial (comment changes, struct member
reordering) – but when something like a lock is touched in any way,
we
shall document that in the commit message as canonically as possible,
so someone who's less experienced and just bisected the commit immediately understands what has been done (or rather: was supposed
to
be done).Quoted 3 lines
So how would you suggest to expand this commit text so it doesn't read
too self-repeating?Quoted 11 lines
My issue with this particular commit message is mainly that it doesn't
make it obvious what the patch is supposed to do. So one can make it
quicker and better to review by detailing it a bit more, so the reviewer then can compare commit message vs. what the code does. It seems to me for example that the actual optimization is being done indrm_sched_entity_push_job(), anddrm_sched_entity_pop_job()had to be
ported, too, for correctness"It seems" aka the commit title says so. ;)
Quoted 12 lines
Another small thing that might be cool is something that makes it a bit
more obvious that this is an optimization, not a fix.So I would probably write:
"So far,
drm_sched_rq_update_fifo()automatically takes drm_sched_entity.rq_lock. ForDRM_SCHED_POLICY_FIFO, this is inefficient because that lock is then taken, released and retaken indrm_sched_entity_push_job().Quoted 5 lines
Improve performance by moving the locking out of
drm_sched_rq_update_fifo()."Not that much longer but makes it far more obvious what shall be achieved where :]
How about this:
"""
In FIFO mode (which is the default), bothdrm_sched_entity_push_job()anddrm_sched_rq_update_fifo(), where the latter calls the former, are
currently taking and releasing the sameentity->rq_lock.
Quoted 8 lines
Quoted 6 lines
We can avoid that design inelegance, and also have a miniscule efficiency improvement on the idle submit path, by introducing a new
drm_sched_rq_update_fifo_locked()helper and pulling up the lock taking
to its callers.
"""That looks good to me
Cool. So this for 1/5, your text and some tweaks for 4/5, anything else or I can respin with that?
Regards,
Tvrtko
Quoted 17 lines
P.
Quoted 12 lines
Quoted 4 lines
(Let me read through the other patches briefly. Then we should be good
with v2 of this series.. or would it be v3 then?)Depends how you count. By unique series titles or by fundamental content.
Regards,
Tvrtko
Re: [PATCH 1/5] drm/sched: Optimise drm_sched_entity_push_job
Quoted 21 lines · Tvrtko Ursulin
Quoted 19 lines · Philipp Stanner
Quoted 18 lines
[...]
How about this:"""
In FIFO mode (which is the default), bothdrm_sched_entity_push_job()
anddrm_sched_rq_update_fifo(), where the latter calls the former,
are
currently taking and releasing the sameentity->rq_lock.We can avoid that design inelegance, and also have a miniscule efficiency improvement on the idle submit path, by introducing a new
drm_sched_rq_update_fifo_locked()helper and pulling up the lock taking
to its callers.
"""
Quoted 5 lines
Quoted 1 line
That looks good to me
Cool. So this for 1/5, your text and some tweaks for 4/5, anything else
or I can respin with that?
Just went through all of them and looks good to me, I think we can go with that.
Note that below your signature in the latest answer to patch 4 I mentioned a second position where the old name was forgotten; was not sure if you saw that.
Regards,
P.
Quoted 24 lines
Regards,
Tvrtko
Quoted 18 lines
P.
Quoted 13 lines
Quoted 5 lines
(Let me read through the other patches briefly. Then we should be
good
with v2 of this series.. or would it be v3 then?)Depends how you count. By unique series titles or by fundamental content.
Regards,
Tvrtko
PATCH 2/5 drm/sched: Stop setting current entity in FIFO mode
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
It does not seem there is a need to set the current entity in FIFO mode since ot only serves as being a "cursor" in round-robin mode. Even if scheduling mode is changed at runtime the change in behaviour is simply to restart from the first entity, instead of continuing in RR mode from where FIFO left it, and that sounds completely fine.
--- drivers/gpu/drm/scheduler/sched_main.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -1
@@ -355,7 +355,6 @@ drm_sched_rq_select_entity_fifo(struct drm_gpu_scheduler *sched,return ERR_PTR (-ENOSPC ); } - rq->current_entity = entity;reinit_completion (&entity->entity_idle);break ; }
Signature · 1 line
2.46.0
Re: [PATCH 2/5] drm/sched: Stop setting current entity in FIFO mode
Quoted 5 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
It does not seem there is a need to set the current entity in FIFO mode
since ot only serves as being a "cursor" in round-robin mode. Even if
s/ot/it
Quoted 5 lines
scheduling mode is changed at runtime the change in behaviour is simply
to restart from the first entity, instead of continuing in RR mode from
where FIFO left it, and that sounds completely fine.
Imperative sentence: "Remove setting the cursor from drm_sched_rq_select_entity_fifo()"
Thx
P.
Quoted 27 lines
Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Cc Alex Deucher <[email protected]>Cc Luben Tuikov <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Acked-by Christian König <[email protected]>Reviewed-by Philipp Stanner <[email protected]>---
drivers/gpu/drm/scheduler/sched_main.c | 1 -1 file changed, 1 deletion(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -355,7 +355,6 @@ drm_sched_rq_select_entity_fifo(struct drm_gpu_scheduler *sched, return ERR_PTR(-ENOSPC); }drivers/gpu/drm/scheduler/sched_main.c +0
-1- rq->current_entity = entity;
reinit_completion(&entity->entity_idle); break;
}
PATCH 3/5 drm/sched: Re-order struct drm_sched_rq members for clarity
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Current kerneldoc for struct drm_sched_rq incompletely documents what fields are protected by the lock.
This is not good because it is misleading.
Lets fix it by listing all the elements which are protected by the lock.
While at it, lets also re-order the members so all protected by the lock are in a single group.
v2:
* Refer variables by kerneldoc syntax, more verbose commit text. (Philipp)
--- include/drm/gpu_scheduler.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
include/drm/gpu_scheduler.h +6 -4
@@ -243,10 +243,10 @@ struct drm_sched_entity {/** * struct drm_sched_rq - queue of entities to be scheduled. * -* @lock: to modify the entities list. * @sched: the scheduler to which this rq belongs to. -* @entities: list of the entities to be scheduled. +* @lock: protects @entities, @rb_tree_root and @current_entity. * @current_entity: the entity which is to be scheduled. +* @entities: list of the entities to be scheduled. * @rb_tree_root: root of time based priority queue of entities for FIFO scheduling * * Run queue is a set of entities scheduling command submissions for
@@ -254,10 +254,12 @@ struct drm_sched_entity {* the next entity to emit commands from. */ struct drm_sched_rq { -spinlock_t lock;struct drm_gpu_scheduler *sched; -struct list_head entities; + +spinlock_t lock; +/* Following members are protected by the @lock: */ struct drm_sched_entity *current_entity; +struct list_head entities;struct rb_root_cached rb_tree_root; };
Signature · 1 line
2.46.0
PATCH 4/5 drm/sched: Re-group and rename the entity run-queue lock
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Christian suggested to rename the lock and improve the documentation of what it protects. And to also re-order the structure members so all protected by the lock are together in a block.
--- drivers/gpu/drm/scheduler/sched_entity.c | 28 ++++++++++++------------ drivers/gpu/drm/scheduler/sched_main.c | 2 +- include/drm/gpu_scheduler.h | 15 +++++++------ 3 files changed, 23 insertions(+), 22 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +14 -14
@@ -105,7 +105,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,/* We start in an idle state. */ complete_all (&entity->entity_idle); -spin_lock_init (&entity->rq_lock); +spin_lock_init (&entity->lock);spsc_queue_init (&entity->job_queue);atomic_set (&entity->fence_seq,0 );
@@ -133,10 +133,10 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity, {WARN_ON (!num_sched_list || !sched_list); -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); entity->sched_list = sched_list; entity->num_sched_list = num_sched_list; -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); }EXPORT_SYMBOL (drm_sched_entity_modify_sched);
@@ -244,10 +244,10 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity)if (!entity->rq)return ; -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); entity->stopped = true;drm_sched_rq_remove_entity (entity->rq, entity); -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);/* Make sure this entity is not used by the scheduler at the moment */ wait_for_completion (&entity->entity_idle);
@@ -396,9 +396,9 @@ static void drm_sched_entity_wakeup(struct dma_fence *f,void drm_sched_entity_set_priority (struct drm_sched_entity *entity,enum drm_sched_priority priority) { -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); entity->priority = priority; -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); }EXPORT_SYMBOL (drm_sched_entity_set_priority);
@@ -515,10 +515,10 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity) next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue));if (next) { -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);drm_sched_rq_update_fifo_locked (entity, next->submit_ts); -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); } }
@@ -559,14 +559,14 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)if (fence && !dma_fence_is_signaled (fence))return ; -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); sched =drm_sched_pick_best (entity->sched_list, entity->num_sched_list); rq = sched ? sched->sched_rq[entity->priority] :NULL ;if (rq != entity->rq) {drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq; } -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);if (entity->num_sched_list ==1 ) entity->sched_list =NULL ;
@@ -605,9 +605,9 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)struct drm_sched_rq *rq;/* Add the entity to the run queue */ -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);if (entity->stopped) { -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);DRM_ERROR ("Trying to push to a killed entity\n" );return ;
@@ -621,7 +621,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO )drm_sched_rq_update_fifo_locked (entity, submit_ts); -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);drm_sched_wakeup (sched); }
drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -176,7 +176,7 @@ void drm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts* for entity from within concurrent drm_sched_entity_select_rq and the * other to update the rb tree structure. */ -lockdep_assert_held (&entity->rq_lock); +lockdep_assert_held (&entity->lock);spin_lock (&entity->rq->lock);
include/drm/gpu_scheduler.h +8 -7
@@ -96,6 +96,14 @@ struct drm_sched_entity {*/ struct list_head list; +/** +* @lock: +* +* Lock protecting the run-queue (@rq) to which this entity belongs, +* @priority and the list of schedulers (@sched_list, @num_sched_list). +*/ +spinlock_t lock; +/** * @rq: *
@@ -140,13 +148,6 @@ struct drm_sched_entity {*/ enum drm_sched_priority priority; -/** -* @rq_lock: -* -* Lock to modify the runqueue to which this entity belongs. -*/ -spinlock_t rq_lock; -/** * @job_queue: the list of jobs of this entity. */
Signature · 1 line
2.46.0
Re: [PATCH 4/5] drm/sched: Re-group and rename the entity run-queue lock
Quoted 3 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
Christian suggested to rename the lock and improve the documentation
Let's move it to Annotators:
(Otherwise some time in the future a Christian Kaiser might start working on the scheduler on steal the praise ^^)
Quoted 2 lines
of
what it protects.
So without Christian's name here I'd phrase it as:
"When writing to a drm_sched_entity's run-queue, writers are protected through the lock drm_sched_entity.rq_lock. This naming, however, frequently collides with the separate internal lock of struct drm_sched_rq, resulting in uses like this:
spin_lock(&entity->rq_lock); spin_lock(&entity->rq->lock);
Rename drm_sched_entity.rq_lock to improve readability. While at it, re-order that struct's members to make it more obvious what the lock protects.
Quoted 160 lines
And to also re-order the structure members so all
protected by the lock are together in a block.Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Cc Alex Deucher <[email protected]>Cc Luben Tuikov <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Reviewed-by Christian König <[email protected]>---
drivers/gpu/drm/scheduler/sched_entity.c | 28 ++++++++++++---------- --
drivers/gpu/drm/scheduler/sched_main.c | 2 +- include/drm/gpu_scheduler.h | 15 +++++++------3 files changed, 23 insertions(+), 22 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -105,7 +105,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, /* We start in an idle state. */ complete_all(&entity->entity_idle);drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock_init (&entity->rq_lock); +spin_lock_init (&entity->lock);
spsc_queue_init(&entity->job_queue);
atomic_set(&entity->fence_seq, 0);drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -133,10 +133,10 @@ void drm_sched_entity_modify_sched(structdrm_sched_entity *entity, { WARN_ON(!num_sched_list || !sched_list);drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);
entity->sched_list=sched_list;
entity->num_sched_list=num_sched_list;drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);}
EXPORT_SYMBOL(drm_sched_entity_modify_sched);drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -244,10 +244,10 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity) if (!entity->rq) return;drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);
entity->stopped= true;drm_sched_rq_remove_entity(entity->rq, entity);drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);
/* Make sure this entity is not used by the scheduler at the moment */
wait_for_completion(&entity->entity_idle);drivers/gpu/drm/scheduler/sched_entity.c +2
-2@@ -396,9 +396,9 @@ static void drm_sched_entity_wakeup(structdma_fence *f, void drm_sched_entity_set_priority(struct drm_sched_entity *entity, enum drm_sched_priority priority) { - spin_lock(&entity->rq_lock); + spin_lock(&entity->lock); entity->priority = priority; -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); } EXPORT_SYMBOL(drm_sched_entity_set_priority);drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -515,10 +515,10 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)
next = to_drm_sched_job(spsc_queue_peek(&entity-Quoted 1 line
job_queue));if (next) {
drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);drm_sched_rq_update_fifo_locked(entity, next-
Quoted 1 line
submit_ts);drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);}
}drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -559,14 +559,14 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity) if (fence && !dma_fence_is_signaled(fence)) return;drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);sched = drm_sched_pick_best(entity->sched_list, entity-
Quoted 1 line
num_sched_list);rq = sched ? sched->sched_rq[entity->priority] : NULL; if (rq !=
entity->rq) {drm_sched_rq_remove_entity(entity->rq, entity);entity->rq= rq;
}drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);
if (entity->num_sched_list== 1)
entity->sched_list= NULL;drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -605,9 +605,9 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) struct drm_sched_rq *rq;
/* Add the entity to the run queue */drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);if (
entity->stopped) {drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);
DRM_ERROR("Trying to push to a killed entity\n");
return;drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -621,7 +621,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) if (drm_sched_policy == DRM_SCHED_POLICY_FIFO) drm_sched_rq_update_fifo_locked(entity, submit_ts);drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);
drm_sched_wakeup(sched);
}drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -176,7 +176,7 @@ void drm_sched_rq_update_fifo_locked(struct
drm_sched_entity*entity,ktime_tts
* for entity from within concurrentdrm_sched_entity_select_rqand the
* other to update the rb tree structure.
*/drivers/gpu/drm/scheduler/sched_main.c +1
-1-lockdep_assert_held (&entity->rq_lock); +lockdep_assert_held (&entity->lock);
spin_lock(&entity->rq->lock);include/drm/gpu_scheduler.h +0
-0@@ -96,6 +96,14 @@ struct drm_sched_entity {*/ struct list_head list;
Quoted 1 line
Uh, btw, while reviewing, I just saw that we still have that FIXME further up:
/** * @rq: * * Runqueue on which this entity is currently scheduled. * * FIXME: Locking is very unclear for this. Writers are protected by * @rq_lock, but readers are generally lockless and seem to just race * with not even a READ_ONCE. */ struct drm_sched_rq *rq;
At the very least, rq_lock should be renamed here, too. AFAICS the series doesn't solve the FIXME, so we keep it, agreed?
Quoted 14 lines
include/drm/gpu_scheduler.h +4
-0+/** +* @lock: +* +* Lock protecting the run-queue (@rq) to which this entity belongs,
include/drm/gpu_scheduler.h +1
-0+* @priority and the list of schedulers (@sched_list, @num_sched_list).
include/drm/gpu_scheduler.h +3
-0+*/ +spinlock_t lock; +/**
* @rq:
*
include/drm/gpu_scheduler.h struct drm_sched_entity { · line 148
Quoted 1 line
include/drm/gpu_scheduler.h +0
-0@@ -140,13 +148,6 @@ struct drm_sched_entity {*/
I think this comment here above also uses the term "rq_lock". While you're fixing it, maybe also do a quick grep for "rq_lock" in case I overlooked it somewhere else. I stopped drinking coffee today, so...
Thx,
P.
Quoted 12 lines
include/drm/gpu_scheduler.h +0
-0enum drm_sched_priority priority;include/drm/gpu_scheduler.h +0
-7-/** -* @rq_lock: -* -* Lock to modify the runqueue to which this entity belongs. -*/ -spinlock_t rq_lock; -/**
* @job_queue: the list of jobs of this entity. */
Re: [PATCH 4/5] drm/sched: Re-group and rename the entity run-queue lock
Quoted 7 lines · Philipp Stanner
Quoted 3 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
Christian suggested to rename the lock and improve the documentation
Let's move it to Annotators:
Suggested-by Christian König <[email protected]>
Ack.
Quoted 12 lines
(Otherwise some time in the future a Christian Kaiser might start working on the scheduler on steal the praise ^^)
Quoted 2 lines
of
what it protects.So without Christian's name here I'd phrase it as:
"When writing to a drm_sched_entity's run-queue, writers are protected through the lock drm_sched_entity.rq_lock. This naming, however, frequently collides with the separate internal lock of structdrm_sched_rq, resulting in uses like this:
Quoted 6 lines
spin_lock(&entity->rq_lock); spin_lock(&entity->rq->lock);Rename drm_sched_entity.rq_lock to improve readability. While at it, re-order that struct's members to make it more obvious what the lock protects.
Will copy&paste - thanks for typing it out.
Quoted 176 lines
Quoted 158 lines
And to also re-order the structure members so all
protected by the lock are together in a block.Signed-off-by Tvrtko Ursulin <[email protected]>Cc Christian König <[email protected]>Cc Alex Deucher <[email protected]>Cc Luben Tuikov <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Reviewed-by Christian König <[email protected]>--- drivers/gpu/drm/scheduler/sched_entity.c | 28 ++++++++++++---------- -- drivers/gpu/drm/scheduler/sched_main.c | 2 +- include/drm/gpu_scheduler.h | 15 +++++++------ 3 files changed, 23 insertions(+), 22 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +1
-1@@ -105,7 +105,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, /* We start in an idle state. */ complete_all(&entity->entity_idle); -spin_lock_init (&entity->rq_lock); +spin_lock_init (&entity->lock); spsc_queue_init(&entity->job_queue);
atomic_set(&entity->fence_seq, 0);drivers/gpu/drm/scheduler/sched_entity.c +4
-4@@ -133,10 +133,10 @@ void drm_sched_entity_modify_sched(structdrm_sched_entity *entity, { WARN_ON(!num_sched_list || !sched_list); -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); entity->sched_list = sched_list; entity->num_sched_list = num_sched_list; -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); } EXPORT_SYMBOL(drm_sched_entity_modify_sched);@@ -244,10 +244,10 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity) if (!entity->rq) return; -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); entity->stopped = true; drm_sched_rq_remove_entity(entity->rq, entity); -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); /* Make sure this entity is not used by the scheduler at themoment */
wait_for_completion(&entity->entity_idle);drivers/gpu/drm/scheduler/sched_entity.c +4
-4@@ -396,9 +396,9 @@ static void drm_sched_entity_wakeup(structdma_fence *f, void drm_sched_entity_set_priority(struct drm_sched_entity *entity, enum drm_sched_priority priority) { - spin_lock(&entity->rq_lock); + spin_lock(&entity->lock); entity->priority = priority; -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); } EXPORT_SYMBOL(drm_sched_entity_set_priority);@@ -515,10 +515,10 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity) next = to_drm_sched_job(spsc_queue_peek(&entity- > job_queue)); if (next) { -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); drm_sched_rq_update_fifo_locked(entity, next- > submit_ts); -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);}
}drivers/gpu/drm/scheduler/sched_entity.c +2
-2@@ -559,14 +559,14 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity) if (fence && !dma_fence_is_signaled(fence)) return; -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); sched = drm_sched_pick_best(entity->sched_list, entity- > num_sched_list); rq = sched ? sched->sched_rq[entity->priority] : NULL; if (rq != entity->rq) { drm_sched_rq_remove_entity(entity->rq, entity); entity->rq = rq; } -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);if (
entity->num_sched_list== 1)
entity->sched_list= NULL;drivers/gpu/drm/scheduler/sched_entity.c +2
-2@@ -605,9 +605,9 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) struct drm_sched_rq *rq; /* Add the entity to the run queue */ -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); if (entity->stopped) { -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); DRM_ERROR("Trying to push to a killedentity\n");
return;drivers/gpu/drm/scheduler/sched_entity.c +1
-1@@ -621,7 +621,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) if (drm_sched_policy == DRM_SCHED_POLICY_FIFO) drm_sched_rq_update_fifo_locked(entity, submit_ts); -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);
drm_sched_wakeup(sched);
}drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -176,7 +176,7 @@ void drm_sched_rq_update_fifo_locked(struct
drm_sched_entity*entity,ktime_tts
* for entity from within concurrentdrm_sched_entity_select_rqand the
* other to update the rb tree structure.
*/drivers/gpu/drm/scheduler/sched_main.c +1
-1-lockdep_assert_held (&entity->rq_lock); +lockdep_assert_held (&entity->lock); spin_lock(&entity->rq->lock);include/drm/gpu_scheduler.h +0
-0include/drm/gpu_scheduler.h struct drm_sched_entity { · line 98
Quoted 3 lines
include/drm/gpu_scheduler.h +0
-0@@ -96,6 +96,14 @@ struct drm_sched_entity {*/ struct list_head list;Uh, btw, while reviewing, I just saw that we still have that FIXME further up:
/** * @rq: * * Runqueue on which this entity is currently scheduled. * * FIXME: Locking is very unclear for this. Writers are protected by * @rq_lock, but readers are generally lockless and seem to just race * with not even a READ_ONCE. */ struct drm_sched_rq *rq;
Quoted 1 line
At the very least,
rq_lockshould be renamed here, too. AFAICS the
Good catch!
Quoted 1 line
series doesn't solve the FIXME, so we keep it, agreed?
Yep.
Regards,
Tvrtko
Quoted 37 lines
Quoted 14 lines
include/drm/gpu_scheduler.h +5
-0+/** +* @lock: +* +* Lock protecting the run-queue (@rq) to which this entity belongs, +* @priority and the list of schedulers (@sched_list, @num_sched_list).
include/drm/gpu_scheduler.h +3
-0+*/ +spinlock_t lock; + /*** @rq: * include/drm/gpu_scheduler.h struct drm_sched_entity { · line 148
Quoted 1 line
include/drm/gpu_scheduler.h +0
-0@@ -140,13 +148,6 @@ struct drm_sched_entity {*/ I think this comment here above also uses the term "
rq_lock". While you're fixing it, maybe also do a quick grep for "rq_lock" in case I overlooked it somewhere else. I stopped drinking coffee today, so...Thx,
P.Quoted 12 lines
include/drm/gpu_scheduler.h +0
-7enum drm_sched_priority priority; -/** -* @rq_lock: -* -* Lock to modify the runqueue to which this entity belongs. -*/ -spinlock_t rq_lock; - /*** @job_queue: the list of jobs of this entity. */
PATCH 5/5 drm/sched: Further optimise drm_sched_entity_push_job
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Having removed one re-lock cycle on the entity->lock in a patch titled "drm/sched: Optimise drm_sched_entity_push_job", with only a tiny bit larger refactoring we can do the same optimisation on the rq->lock. (Currently both drm_sched_rq_add_entity() and drm_sched_rq_update_fifo_locked() take and release the same lock.)
To achieve this we make drm_sched_rq_update_fifo_locked() and drm_sched_rq_add_entity() expect the rq->lock to be held.
We also align drm_sched_rq_update_fifo_locked(), drm_sched_rq_add_entity() and drm_sched_rq_remove_fifo_locked() function signatures, by adding rq as a parameter to the latter.
v2:
* Fix after rebase of the series.
* Avoid naming incosistency between drm_sched_rq_add/remove. (Christian)
--- drivers/gpu/drm/scheduler/sched_entity.c | 11 +++++++-- drivers/gpu/drm/scheduler/sched_main.c | 29 ++++++++++++------------ include/drm/gpu_scheduler.h | 3 ++- 3 files changed, 25 insertions(+), 18 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +9 -2
@@ -515,9 +515,14 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity) next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue));if (next) { +struct drm_sched_rq *rq; +spin_lock (&entity->lock); -drm_sched_rq_update_fifo_locked (entity, + rq = entity->rq; +spin_lock (&rq->lock); +drm_sched_rq_update_fifo_locked (entity, rq, next->submit_ts); +spin_unlock (&rq->lock);spin_unlock (&entity->lock); } }
@@ -616,11 +621,13 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) rq = entity->rq; sched = rq->sched; +spin_lock (&rq->lock);drm_sched_rq_add_entity (rq, entity);if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) -drm_sched_rq_update_fifo_locked (entity, submit_ts); +drm_sched_rq_update_fifo_locked (entity, rq, submit_ts); +spin_unlock (&rq->lock);spin_unlock (&entity->lock);drm_sched_wakeup (sched);
drivers/gpu/drm/scheduler/sched_main.c +14 -15
@@ -159,17 +159,18 @@ static __always_inline bool drm_sched_entity_compare_before(struct rb_node *a,return ktime_before (ent_a->oldest_job_waiting, ent_b->oldest_job_waiting); } -static inline void drm_sched_rq_remove_fifo_locked (struct drm_sched_entity *entity) +static void drm_sched_rq_remove_fifo_locked (struct drm_sched_entity *entity, +struct drm_sched_rq *rq) { -struct drm_sched_rq *rq = entity->rq; -if (!RB_EMPTY_NODE (&entity->rb_tree_node)) {rb_erase_cached (&entity->rb_tree_node, &rq->rb_tree_root);RB_CLEAR_NODE (&entity->rb_tree_node); } } -void drm_sched_rq_update_fifo_locked (struct drm_sched_entity *entity,ktime_t ts) +void drm_sched_rq_update_fifo_locked (struct drm_sched_entity *entity, +struct drm_sched_rq *rq, +ktime_t ts) {/* * Both locks need to be grabbed, one to protect from entity->rq change
@@ -177,17 +178,14 @@ void drm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts* other to update the rb tree structure. */ lockdep_assert_held (&entity->lock); +lockdep_assert_held (&rq->lock); -spin_lock (&entity->rq->lock); - -drm_sched_rq_remove_fifo_locked (entity); +drm_sched_rq_remove_fifo_locked (entity, rq); entity->oldest_job_waiting = ts; -rb_add_cached (&entity->rb_tree_node, &entity->rq->rb_tree_root, +rb_add_cached (&entity->rb_tree_node, &rq->rb_tree_root, drm_sched_entity_compare_before); - -spin_unlock (&entity->rq->lock); }/**
@@ -219,15 +217,14 @@ static void drm_sched_rq_init(struct drm_gpu_scheduler *sched,void drm_sched_rq_add_entity (struct drm_sched_rq *rq,struct drm_sched_entity *entity) { +lockdep_assert_held (&entity->lock); +lockdep_assert_held (&rq->lock); +if (!list_empty (&entity->list))return ; -spin_lock (&rq->lock); -atomic_inc (rq->sched->score);list_add_tail (&entity->list, &rq->entities); - -spin_unlock (&rq->lock); }/**
@@ -241,6 +238,8 @@ void drm_sched_rq_add_entity(struct drm_sched_rq *rq,void drm_sched_rq_remove_entity (struct drm_sched_rq *rq,struct drm_sched_entity *entity) { +lockdep_assert_held (&entity->lock); +if (list_empty (&entity->list))return ;
@@ -253,7 +252,7 @@ void drm_sched_rq_remove_entity(struct drm_sched_rq *rq, rq->current_entity =NULL ;if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) -drm_sched_rq_remove_fifo_locked (entity); +drm_sched_rq_remove_fifo_locked (entity, rq);spin_unlock (&rq->lock); }
include/drm/gpu_scheduler.h +2 -1
@@ -596,7 +596,8 @@ void drm_sched_rq_add_entity(struct drm_sched_rq *rq,void drm_sched_rq_remove_entity (struct drm_sched_rq *rq,struct drm_sched_entity *entity); -void drm_sched_rq_update_fifo_locked (struct drm_sched_entity *entity,ktime_t ts); +void drm_sched_rq_update_fifo_locked (struct drm_sched_entity *entity, +struct drm_sched_rq *rq,ktime_t ts); int drm_sched_entity_init(struct drm_sched_entity *entity, enum drm_sched_priority priority,
Signature · 1 line
2.46.0