drm/scheduler: only kill entity if last user is killed v2
Subsystems (3)
Christian König
reviewerPATCH 1/2 drm/scheduler: only kill entity if last user is killed v2
Note which task is using the entity and only kill it if the last user of the entity is killed. This should prevent problems when entities are leaked to child processes.
v2: add missing kernel doc
--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 6 +++++- include/drm/gpu_scheduler.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +5 -1
@@ -275,6 +275,7 @@ static void drm_sched_entity_kill_jobs_cb(struct dma_fence *f,long drm_sched_entity_flush (struct drm_sched_entity *entity,long timeout) {struct drm_gpu_scheduler *sched; +struct task_struct *last_user;long ret = timeout; sched = entity->rq->sched;
@@ -295,7 +296,9 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)/* For killed process disable any more IBs enqueue right now */ -if ((current->flags &PF_EXITING ) && (current->exit_code ==SIGKILL )) + last_user =cmpxchg (&entity->last_user, current->group_leader,NULL ); +if ((!last_user || last_user == current->group_leader) && + (current->flags &PF_EXITING ) && (current->exit_code ==SIGKILL ))drm_sched_entity_set_rq (entity,NULL );return ret;
@@ -541,6 +544,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,trace_drm_sched_job (sched_job, entity); +WRITE_ONCE (entity->last_user, current->group_leader); first =spsc_queue_push (&entity->job_queue, &sched_job->queue_node);/* first job wakes up scheduler */
include/drm/gpu_scheduler.h +2 -0
@@ -66,6 +66,7 @@ enum drm_sched_priority {* @guilty: points to ctx's guilty. * @fini_status: contains the exit status in case the process was signalled. * @last_scheduled: points to the finished fence of the last scheduled job. +* @last_user: last group leader pushing a job into the entity. * * Entities will emit jobs in order to their corresponding hardware * ring, and the scheduler will alternate between entities based on
@@ -85,6 +86,7 @@ struct drm_sched_entity {struct dma_fence_cb cb;atomic_t *guilty;struct dma_fence *last_scheduled; +struct task_struct *last_user; };/**
Signature · 6 lines
2.14.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
reviewerPATCH 2/2 drm/scheduler: stop setting rq to NULL
We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup.
Just remove the entity from the scheduling list instead.
--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 +++++++------------------------ 1 file changed, 8 insertions(+), 27 deletions(-)
drivers/gpu/drm/scheduler/gpu_scheduler.c +8 -27
@@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, }EXPORT_SYMBOL (drm_sched_entity_init); -/** -* drm_sched_entity_is_initialized - Query if entity is initialized -* -* @sched: Pointer to scheduler instance -* @entity: The pointer to a valid scheduler entity -* -* return true if entity is initialized, false otherwise -*/ -static bool drm_sched_entity_is_initialized (struct drm_gpu_scheduler *sched, -struct drm_sched_entity *entity) -{ -return entity->rq !=NULL && - entity->rq->sched == sched; -} -/** * drm_sched_entity_is_idle - Check if entity is idle *
@@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) {rmb (); -if (!entity->rq ||spsc_queue_peek (&entity->job_queue) ==NULL ) +if (list_empty (&entity->list) || +spsc_queue_peek (&entity->job_queue) ==NULL )return true;return false;
@@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)long ret = timeout; sched = entity->rq->sched; -if (!drm_sched_entity_is_initialized (sched, entity)) -return ret;/** * The client will not queue more IBs during this fini, consume existing * queued IBs or discard them on SIGKILL
@@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) last_user =cmpxchg (&entity->last_user, current->group_leader,NULL );if ((!last_user || last_user == current->group_leader) && (current->flags &PF_EXITING ) && (current->exit_code ==SIGKILL )) -drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);return ret; }
@@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity)struct drm_gpu_scheduler *sched; sched = entity->rq->sched; -drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);/* Consumption of existing IBs wasn't completed. Forcefully * remove them here.
@@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct drm_sched_entity *entity,if (entity->rq == rq)return ; -spin_lock (&entity->rq_lock); - -if (entity->rq) -drm_sched_rq_remove_entity (entity->rq, entity); +BUG_ON (!rq); +spin_lock (&entity->rq_lock); +drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq; -if (rq) -drm_sched_rq_add_entity (rq, entity); - +drm_sched_rq_add_entity (rq, entity);spin_unlock (&entity->rq_lock); }EXPORT_SYMBOL (drm_sched_entity_set_rq);
Signature · 6 lines
2.14.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Quoted 8 lines · Christian König
We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup.
Just remove the entity from the scheduling list instead.
Signed-off-by Christian König <[email protected]>
Good catch.
Quoted 99 lines
--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 +++++++------------------------ 1 file changed, 8 insertions(+), 27 deletions(-)drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-15@@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, }EXPORT_SYMBOL (drm_sched_entity_init); -/** -* drm_sched_entity_is_initialized - Query if entity is initialized -* -* @sched: Pointer to scheduler instance -* @entity: The pointer to a valid scheduler entity -* -* return true if entity is initialized, false otherwise -*/ -static bool drm_sched_entity_is_initialized (struct drm_gpu_scheduler *sched, -struct drm_sched_entity *entity) -{ -return entity->rq !=NULL && - entity->rq->sched == sched; -} -/**
*drm_sched_entity_is_idle- Check if entity is idle *drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-1@@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) {rmb (); -if (!entity->rq ||spsc_queue_peek (&entity->job_queue) ==NULL ) +if (list_empty (&entity->list) || +spsc_queue_peek (&entity->job_queue) ==NULL )return true;return false;drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-2@@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)long ret = timeout; sched = entity->rq->sched; -if (!drm_sched_entity_is_initialized (sched, entity)) -return ret;/** * The client will not queue more IBs during this fini, consume existing
* queued IBs or discard them on SIGKILLdrivers/gpu/drm/scheduler/gpu_scheduler.c +1
-1@@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) last_user =cmpxchg (&entity->last_user, current->group_leader,NULL );if ((!last_user || last_user == current->group_leader) && (current->flags &PF_EXITING ) && (current->exit_code ==SIGKILL )) -drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);return ret;}
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-1@@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity)struct drm_gpu_scheduler *sched; sched = entity->rq->sched; -drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);/* Consumption of existing IBs wasn't completed. Forcefully * remove them here.
drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-7@@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct drm_sched_entity *entity, if (entity->rq == rq) return; -spin_lock (&entity->rq_lock); - -if (entity->rq) -drm_sched_rq_remove_entity (entity->rq, entity); +BUG_ON (!rq); +spin_lock (&entity->rq_lock); +drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq; -if (rq) -drm_sched_rq_add_entity (rq, entity); - +drm_sched_rq_add_entity (rq, entity);spin_unlock (&entity->rq_lock); }
Quoted 5 lines
EXPORT_SYMBOL(drm_sched_entity_set_rq);
--
2.14.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Quoted 63 lines · Nayan Deshmukh
On Mon, Jul 30, 2018 at 4:33 PM Christian König <[email protected] <mailto:[email protected]>> wrote:
We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup.
Just remove the entity from the scheduling list instead.
Signed-off-by Christian König <[email protected]<mailto:[email protected]>>
Good catch.
Acked-by Nayan Deshmukh <[email protected] <mailto:[email protected]>>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 +++++++------------------------ 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c index f563e4fbb4b6..1b733229201e 100644 --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c @@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, } EXPORT_SYMBOL(drm_sched_entity_init); -/** - * drm_sched_entity_is_initialized - Query if entity is initialized - * - * @sched: Pointer to scheduler instance - * @entity: The pointer to a valid scheduler entity - * - * return true if entity is initialized, false otherwise -*/ -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler *sched, - struct drm_sched_entity *entity) -{ - return entity->rq != NULL && - entity->rq->sched == sched; -} - /** * drm_sched_entity_is_idle - Check if entity is idle * @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) { rmb(); - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) + if (list_empty(&entity->list) || + spsc_queue_peek(&entity->job_queue) == NULL) return true;
Quoted 9 lines
return false;
@@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct
drm_sched_entity *entity, long timeout)
long ret = timeout;
sched = entity->rq->sched;
- if (!drm_sched_entity_is_initialized(sched, entity))
- return ret;Just to be clear, you remove this function because it's redundant to call it?
Andrey
Quoted 52 lines
/**
* The client will not queue more IBs during this fini,
consume existing
* queued IBs or discard them on SIGKILL
@@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct
drm_sched_entity *entity, long timeout)
last_user = cmpxchg(&entity->last_user,
current->group_leader, NULL);
if ((!last_user || last_user == current->group_leader) &&
(current->flags & PF_EXITING) && (current->exit_code
== SIGKILL))
- drm_sched_entity_set_rq(entity, NULL);
+ drm_sched_rq_remove_entity(entity->rq, entity);
return ret;
}
@@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct
drm_sched_entity *entity)
struct drm_gpu_scheduler *sched;
sched = entity->rq->sched;
- drm_sched_entity_set_rq(entity, NULL);
+ drm_sched_rq_remove_entity(entity->rq, entity);
/* Consumption of existing IBs wasn't completed. Forcefully
* remove them here.
@@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct
drm_sched_entity *entity,
if (entity->rq == rq)
return;
- spin_lock(&entity->rq_lock);
-
- if (entity->rq)
- drm_sched_rq_remove_entity(entity->rq, entity);
+ BUG_ON(!rq);
+ spin_lock(&entity->rq_lock);
+ drm_sched_rq_remove_entity(entity->rq, entity);
entity->rq = rq;
- if (rq)
- drm_sched_rq_add_entity(rq, entity);
-
+ drm_sched_rq_add_entity(rq, entity);
spin_unlock(&entity->rq_lock);
}
EXPORT_SYMBOL(drm_sched_entity_set_rq);
--
2.14.1Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
reviewerRe: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Am 30.07.2018 um 22:51 schrieb Andrey Grodzovsky:
Quoted 72 lines · Nayan Deshmukh
Quoted 68 lines · On Mon, Jul 30, 2018 at 4:33 PM Christian König…
We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup.
Just remove the entity from the scheduling list instead.
Signed-off-by Christian König <[email protected]<mailto:[email protected]>>
Good catch.
Acked-by Nayan Deshmukh <[email protected] <mailto:[email protected]>>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 +++++++------------------------ 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c index f563e4fbb4b6..1b733229201e 100644 --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c @@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, } EXPORT_SYMBOL(drm_sched_entity_init); -/** - * drm_sched_entity_is_initialized - Query if entity is initialized - * - * @sched: Pointer to scheduler instance - * @entity: The pointer to a valid scheduler entity - * - * return true if entity is initialized, false otherwise -*/ -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler *sched, - struct drm_sched_entity *entity) -{ - return entity->rq != NULL && - entity->rq->sched == sched; -} - /** * drm_sched_entity_is_idle - Check if entity is idle * @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) { rmb(); - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) + if (list_empty(&entity->list) || + spsc_queue_peek(&entity->job_queue) == NULL) return true; return false; @@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) long ret = timeout;
Quoted 6 lines
Quoted 4 lines
sched = entity->rq->sched; - if (!drm_sched_entity_is_initialized(sched, entity)) - return ret;Just to be clear, you remove this function because it's redundant to call it?
Yes, exactly.
Christian.
Quoted 60 lines
Andrey
Quoted 56 lines
/** * The client will not queue more IBs during this fini, consume existing * queued IBs or discard them on SIGKILL @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) last_user = cmpxchg(&entity->last_user, current->group_leader, NULL); if ((!last_user || last_user == current->group_leader) && (current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) - drm_sched_entity_set_rq(entity, NULL); + drm_sched_rq_remove_entity(entity->rq, entity); return ret; } @@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity) struct drm_gpu_scheduler *sched; sched = entity->rq->sched; - drm_sched_entity_set_rq(entity, NULL); + drm_sched_rq_remove_entity(entity->rq, entity); /* Consumption of existing IBs wasn't completed. Forcefully * remove them here. @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct drm_sched_entity *entity, if (entity->rq == rq) return; - spin_lock(&entity->rq_lock); - - if (entity->rq) - drm_sched_rq_remove_entity(entity->rq, entity); + BUG_ON(!rq); + spin_lock(&entity->rq_lock); + drm_sched_rq_remove_entity(entity->rq, entity); entity->rq = rq; - if (rq) - drm_sched_rq_add_entity(rq, entity); - + drm_sched_rq_add_entity(rq, entity); spin_unlock(&entity->rq_lock); } EXPORT_SYMBOL(drm_sched_entity_set_rq); -- 2.14.1_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Change is Reviewed-by: Andrey Grodzovsky <[email protected]>
Andrey
Quoted 78 lines · Christian König
Am 30.07.2018 um 22:51 schrieb Andrey Grodzovsky:
Quoted 77 lines · Nayan Deshmukh
Quoted 72 lines · On Mon, Jul 30, 2018 at 4:33 PM Christian König…
We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup.
Just remove the entity from the scheduling list instead.
Signed-off-by Christian König <[email protected]<mailto:[email protected]>>
Good catch.
Acked-by Nayan Deshmukh <[email protected] <mailto:[email protected]>>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 +++++++------------------------ 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c index f563e4fbb4b6..1b733229201e 100644 --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c @@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, } EXPORT_SYMBOL(drm_sched_entity_init); -/** - * drm_sched_entity_is_initialized - Query if entity is initialized - * - * @sched: Pointer to scheduler instance - * @entity: The pointer to a valid scheduler entity - * - * return true if entity is initialized, false otherwise -*/ -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler *sched, - struct drm_sched_entity *entity) -{ - return entity->rq != NULL && - entity->rq->sched == sched; -} - /** * drm_sched_entity_is_idle - Check if entity is idle * @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) { rmb(); - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) + if (list_empty(&entity->list) || + spsc_queue_peek(&entity->job_queue) == NULL) return true; return false; @@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) long ret = timeout; sched = entity->rq->sched; - if (!drm_sched_entity_is_initialized(sched, entity)) - return ret;
Quoted 67 lines
Quoted 1 line
Just to be clear, you remove this function because it's redundant to call it?
Yes, exactly.
Christian.
Quoted 60 lines
Andrey
Quoted 56 lines
/** * The client will not queue more IBs during this fini, consume existing * queued IBs or discard them on SIGKILL @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) last_user = cmpxchg(&entity->last_user, current->group_leader, NULL); if ((!last_user || last_user == current->group_leader) && (current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) - drm_sched_entity_set_rq(entity, NULL); + drm_sched_rq_remove_entity(entity->rq, entity); return ret; } @@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity) struct drm_gpu_scheduler *sched; sched = entity->rq->sched; - drm_sched_entity_set_rq(entity, NULL); + drm_sched_rq_remove_entity(entity->rq, entity); /* Consumption of existing IBs wasn't completed. Forcefully * remove them here. @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct drm_sched_entity *entity, if (entity->rq == rq) return; - spin_lock(&entity->rq_lock); - - if (entity->rq) - drm_sched_rq_remove_entity(entity->rq, entity); + BUG_ON(!rq); + spin_lock(&entity->rq_lock); + drm_sched_rq_remove_entity(entity->rq, entity); entity->rq = rq; - if (rq) - drm_sched_rq_add_entity(rq, entity); - + drm_sched_rq_add_entity(rq, entity); spin_unlock(&entity->rq_lock); } EXPORT_SYMBOL(drm_sched_entity_set_rq); -- 2.14.1_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
In reply to Christian KönigThinking again about this change and 53d5f1e drm/scheduler: move idle entities to scheduler with less load v2
Looks to me like use case for which fc9a539 drm/scheduler: add NULL pointer check for run queue (v2) was done
will not work anymore.
First of all in drm_sched_entity_push_job, 'if (!entity->rq)' will never be true any more since we stopped entity->rq to NULL in
drm_sched_entity_flush.
Second of all, even after we removed the entity from rq in drm_sched_entity_flush to terminate any subsequent submissions
to the queue the other thread doing push job can just acquire again a run queue
from drm_sched_entity_get_free_sched and continue submission so you can't substitute ' if (!entity->rq)' to 'if (list_empty(&entity->list))'.
What about adding a 'stopped' flag to drm_sched_entity to be set in drm_sched_entity_flush and in
drm_sched_entity_push_job check for 'if (!entity->stopped)' instead of ' if (!entity->rq)' ?
Andrey
Quoted 84 lines · Christian König
We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup.
Just remove the entity from the scheduling list instead.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 +++++++------------------------ 1 file changed, 8 insertions(+), 27 deletions(-)drivers/gpu/drm/scheduler/gpu_scheduler.c +5
-24@@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, }EXPORT_SYMBOL (drm_sched_entity_init); -/** -* drm_sched_entity_is_initialized - Query if entity is initialized -* -* @sched: Pointer to scheduler instance -* @entity: The pointer to a valid scheduler entity -* -* return true if entity is initialized, false otherwise -*/ -static bool drm_sched_entity_is_initialized (struct drm_gpu_scheduler *sched, -struct drm_sched_entity *entity) -{ -return entity->rq !=NULL && - entity->rq->sched == sched; -} -/** * drm_sched_entity_is_idle - Check if entity is idle * @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) {rmb (); -if (!entity->rq ||spsc_queue_peek (&entity->job_queue) ==NULL ) +if (list_empty (&entity->list) || +spsc_queue_peek (&entity->job_queue) ==NULL )return true;return false;@@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)long ret = timeout; sched = entity->rq->sched; -if (!drm_sched_entity_is_initialized (sched, entity)) -return ret;/** * The client will not queue more IBs during this fini, consume existing * queued IBs or discard them on SIGKILL @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) last_user =cmpxchg (&entity->last_user, current->group_leader,NULL );if ((!last_user || last_user == current->group_leader) && (current->flags &PF_EXITING ) && (current->exit_code ==SIGKILL )) -drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);return ret; }@@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity)struct drm_gpu_scheduler *sched; sched = entity->rq->sched; -drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);/* Consumption of existing IBs wasn't completed. Forcefully * remove them here. @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct drm_sched_entity *entity,if (entity->rq == rq)return ; -spin_lock (&entity->rq_lock); - -if (entity->rq) -drm_sched_rq_remove_entity (entity->rq, entity); +BUG_ON (!rq);
drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_set_rq(struct drm_sched_entity *entity, · line 411
Quoted 10 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +3
-3+spin_lock (&entity->rq_lock); +drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq; -if (rq) -drm_sched_rq_add_entity (rq, entity); - +drm_sched_rq_add_entity (rq, entity);spin_unlock (&entity->rq_lock); }EXPORT_SYMBOL (drm_sched_entity_set_rq);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
reviewerRe: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Am 02.08.2018 um 00:25 schrieb Andrey Grodzovsky:
Quoted 9 lines
Thinking again about this change and 53d5f1e drm/scheduler: move idle entities to scheduler with less load v2
Looks to me like use case for which fc9a539 drm/scheduler: add NULL pointer check for run queue (v2) was done
will not work anymore.
First of all in
drm_sched_entity_push_job, 'if (!entity->rq)' will never be true any more since we stoppedentity->rqto NULL in
drm_sched_entity_flush.
Good point, going to remove that.
Quoted 6 lines
Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just acquire again a run queue
from
drm_sched_entity_get_free_schedand continue submission
That is actually desired.
When another process is now using the entity to submit jobs adding it back to the rq is actually the right thing to do cause the entity is still in use.
Christian.
Quoted 95 lines
so you can't substitute ' if (!entity->rq)' to 'if (
list_empty(&entity->list))'.What about adding a 'stopped' flag to
drm_sched_entityto be set indrm_sched_entity_flushand in
drm_sched_entity_push_jobcheck for 'if (!entity->stopped)' instead of ' if (!entity->rq)' ?Andrey
Quoted 85 lines · Christian König
We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup.
Just remove the entity from the scheduling list instead.
Signed-off-by Christian König <[email protected]>---
drivers/gpu/drm/scheduler/gpu_scheduler.c| 35
+++++++------------------------1 file changed, 8 insertions(+), 27 deletions(-)drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0@@ -198,21 +198,6 @@ int drm_sched_entity_init(structdrm_sched_entity *entity, } EXPORT_SYMBOL(drm_sched_entity_init);-/**
- *drm_sched_entity_is_initialized- Query if entity is initialized
- *
- * @sched: Pointer to scheduler instance
- * @entity: The pointer to a valid scheduler entity
- *
- * return true if entity is initialized, false otherwisedrivers/gpu/drm/scheduler/gpu_scheduler.c +0
-2-*/ -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler*sched,
- structdrm_sched_entity*entity)drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-5-{ - return entity->rq != NULL && - entity->rq->sched == sched; -} -/**
*drm_sched_entity_is_idle- Check if entity is idle *drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-2@@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) { rmb(); - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) + if (list_empty(&entity->list) || + spsc_queue_peek(&entity->job_queue) == NULL) return true; return false;@@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) long ret = timeout; sched = entity->rq->sched; - if (!drm_sched_entity_is_initialized(sched, entity)) - return ret; /*** The client will not queue more IBs during this fini, consume existing * queued IBs or discard them on SIGKILL @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) last_user = cmpxchg(&entity->last_user, current->group_leader, NULL);if ((!last_user ||
last_user==current->group_leader) && (current->flags&PF_EXITING) && (current->exit_code== SIGKILL)) -drm_sched_entity_set_rq(entity, NULL);
+drm_sched_rq_remove_entity(entity->rq, entity);
return ret;
}drivers/gpu/drm/scheduler/gpu_scheduler.c +3
-4@@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity) struct drm_gpu_scheduler *sched; sched = entity->rq->sched; - drm_sched_entity_set_rq(entity, NULL); + drm_sched_rq_remove_entity(entity->rq, entity); /* Consumption of existing IBs wasn't completed. Forcefully* remove them here. @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct drm_sched_entity *entity, if (entity->rq == rq) return; - spin_lock(&entity->rq_lock); - - if (entity->rq) - drm_sched_rq_remove_entity(entity->rq, entity); + BUG_ON(!rq); + spin_lock(&entity->rq_lock); + drm_sched_rq_remove_entity(entity->rq, entity);
Quoted 9 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_set_rq(struct drm_sched_entity *entity, · line 411
Quoted 8 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-3entity->rq = rq; - if (rq) - drm_sched_rq_add_entity(rq, entity); - + drm_sched_rq_add_entity(rq, entity); spin_unlock(&entity->rq_lock); } EXPORT_SYMBOL(drm_sched_entity_set_rq);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Quoted 25 lines · Christian König
Am 02.08.2018 um 00:25 schrieb Andrey Grodzovsky:
Quoted 6 lines
Thinking again about this change and 53d5f1e drm/scheduler: move idle entities to scheduler with less load v2
Looks to me like use case for which fc9a539 drm/scheduler: add NULL pointer check for run queue (v2) was done
Quoted 6 lines
will not work anymore.
First of all in
drm_sched_entity_push_job, 'if (!entity->rq)' will never be true any more since we stoppedentity->rqto NULL in
drm_sched_entity_flush.Good point, going to remove that.
Quoted 8 lines
Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just acquire again a run queue
from
drm_sched_entity_get_free_schedand continue submission
Quoted 8 lines
Hi Christian
That is actually desired.
When another process is now using the entity to submit jobs adding it back to the rq is actually the right thing to do cause the entity is still in use.
I am not aware of the usecase so I might just be rambling. but if the thread/process that created the entity has called drm_sched_entity_flush then we shouldn't allow other processes to push jobs to that entity.
Nayan
Quoted 116 lines
Christian.
Quoted 111 lines
so you can't substitute ' if (!entity->rq)' to 'if (
list_empty(&entity->list))'.What about adding a 'stopped' flag to
drm_sched_entityto be set indrm_sched_entity_flushand in
drm_sched_entity_push_jobcheck for 'if (!entity->stopped)' instead of ' if (!entity->rq)' ?Andrey
Quoted 97 lines · Christian König
We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup.
Just remove the entity from the scheduling list instead.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 +++++++------------------------ 1 file changed, 8 insertions(+), 27 deletions(-)drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-16@@ -198,21 +198,6 @@ int drm_sched_entity_init(structdrm_sched_entity *entity, }EXPORT_SYMBOL (drm_sched_entity_init ); -/** -* drm_sched_entity_is_initialized - Query if entity is initialized -* -* @sched: Pointer to scheduler instance -* @entity: The pointer to a valid scheduler entity -* -* return true if entity is initialized, false otherwise -*/ -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler*sched, -struct drm_sched_entity *entity) -{ -return entity->rq !=NULL && - entity->rq->sched == sched; -} -/** * drm_sched_entity_is_idle - Check if entity is idle * @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) {rmb (); - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) +if (list_empty (&entity->list) || +spsc_queue_peek (&entity->job_queue) ==NULL )return true;return false;@@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) long ret = timeout; sched = entity->rq->sched; -if (!drm_sched_entity_is_initialized (sched, entity)) -return ret;/** * The client will not queue more IBs during this fini, consume existing
* queued IBs or discard them on SIGKILLdrivers/gpu/drm/scheduler/gpu_scheduler.c +1
-1@@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) last_user =cmpxchg (&entity->last_user, current->group_leader,NULL );if ((!last_user || last_user == current->group_leader) && (current->flags &PF_EXITING ) && (current->exit_code ==SIGKILL )) -drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);return ret;}
drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-7@@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity)struct drm_gpu_scheduler *sched; sched = entity->rq->sched; -drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);/* Consumption of existing IBs wasn't completed. Forcefully * remove them here. @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct drm_sched_entity *entity, if (entity->rq == rq) return; -spin_lock (&entity->rq_lock); - -if (entity->rq) -drm_sched_rq_remove_entity (entity->rq, entity); +BUG_ON (!rq); +spin_lock (&entity->rq_lock); +drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq; -if (rq) -drm_sched_rq_add_entity (rq, entity); - +drm_sched_rq_add_entity (rq, entity);spin_unlock (&entity->rq_lock); }EXPORT_SYMBOL (drm_sched_entity_set_rq);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
reviewerRe: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Am 02.08.2018 um 08:47 schrieb Nayan Deshmukh:
Quoted 33 lines · On Thu, Aug 2, 2018 at 12:12 PM Christian König…
Am 02.08.2018 um 00:25 schrieb Andrey Grodzovsky:
> Thinking again about this change and 53d5f1e drm/scheduler: move idle
> entities to scheduler with less load v2
>
> Looks to me like use case for which fc9a539 drm/scheduler: add NULL > pointer check for run queue (v2) was done
>
> will not work anymore.
>
> First of all indrm_sched_entity_push_job, 'if (!entity->rq)' will > never be true any more since we stoppedentity->rqto NULL in >
>drm_sched_entity_flush.Good point, going to remove that.
>
> Second of all, even after we removed the entity from rq in >drm_sched_entity_flushto terminate any subsequent submissions >
> to the queue the other thread doing push job can just acquire again a
> run queue
>
> fromdrm_sched_entity_get_free_schedand continue submissionHi Christian
Quoted 7 lines
That is actually desired.
When another process is now using the entity to submit jobs adding it back to the rq is actually the right thing to do cause the entity is still in use.
I am not aware of the usecase so I might just be rambling. but if the thread/process that created the entity has called
drm_sched_entity_flushthen we shouldn't allow other processes to push jobs to that entity.
Why not?
Calling flush() only means that we should wait for all waiting jobs to be send to the hardware. It doesn't mean that we need to stop accepting new jobs.
It is perfectly possible that a child process has inherited a file descriptor from it's parent and calls flush because it exits, while the parent is still using the file descriptor.
The only tricky part is how to handle it when a process is killed, but I think we came to good conclusion there as well.
We remove the entity from the scheduling when the last process which submitted jobs is killed or if there is no such process any more and the current flushing process is killed.
Christian.
Quoted 127 lines
Nayan
Christian. > so you can't substitute ' if (!entity->rq)' to 'if > (list_empty(&entity->list))'. > > What about adding a 'stopped' flag to drm_sched_entity to be set in > drm_sched_entity_flush and in > > drm_sched_entity_push_job check for 'if (!entity->stopped)' instead > of ' if (!entity->rq)' ? > > Andrey > > > On 07/30/2018 07:03 AM, Christian König wrote: >> We removed the redundancy of having an extra scheduler field, so we >> can't set the rq to NULL any more or otherwise won't know which >> scheduler to use for the cleanup. >> >> Just remove the entity from the scheduling list instead. >> >> Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> >> --- >> drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 >> +++++++------------------------ >> 1 file changed, 8 insertions(+), 27 deletions(-) >> >> diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c >> b/drivers/gpu/drm/scheduler/gpu_scheduler.c >> index f563e4fbb4b6..1b733229201e 100644 >> --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c >> +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c >> @@ -198,21 +198,6 @@ int drm_sched_entity_init(struct >> drm_sched_entity *entity, >> } >> EXPORT_SYMBOL(drm_sched_entity_init); >> -/** >> - * drm_sched_entity_is_initialized - Query if entity is initialized >> - * >> - * @sched: Pointer to scheduler instance >> - * @entity: The pointer to a valid scheduler entity >> - * >> - * return true if entity is initialized, false otherwise >> -*/ >> -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler >> *sched, >> - struct drm_sched_entity *entity) >> -{ >> - return entity->rq != NULL && >> - entity->rq->sched == sched; >> -} >> - >> /** >> * drm_sched_entity_is_idle - Check if entity is idle >> * >> @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct >> drm_sched_entity *entity) >> { >> rmb(); >> - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) >> + if (list_empty(&entity->list) || >> + spsc_queue_peek(&entity->job_queue) == NULL) >> return true; >> return false; >> @@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct >> drm_sched_entity *entity, long timeout) >> long ret = timeout; >> sched = entity->rq->sched; >> - if (!drm_sched_entity_is_initialized(sched, entity)) >> - return ret; >> /** >> * The client will not queue more IBs during this fini, consume >> existing >> * queued IBs or discard them on SIGKILL >> @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct >> drm_sched_entity *entity, long timeout) >> last_user = cmpxchg(&entity->last_user, current->group_leader, >> NULL); >> if ((!last_user || last_user == current->group_leader) && >> (current->flags & PF_EXITING) && (current->exit_code == >> SIGKILL)) >> - drm_sched_entity_set_rq(entity, NULL); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> return ret; >> } >> @@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct >> drm_sched_entity *entity) >> struct drm_gpu_scheduler *sched; >> sched = entity->rq->sched; >> - drm_sched_entity_set_rq(entity, NULL); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> /* Consumption of existing IBs wasn't completed. Forcefully >> * remove them here. >> @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct >> drm_sched_entity *entity, >> if (entity->rq == rq) >> return; >> - spin_lock(&entity->rq_lock); >> - >> - if (entity->rq) >> - drm_sched_rq_remove_entity(entity->rq, entity); >> + BUG_ON(!rq); >> + spin_lock(&entity->rq_lock); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> entity->rq = rq; >> - if (rq) >> - drm_sched_rq_add_entity(rq, entity); >> - >> + drm_sched_rq_add_entity(rq, entity); >> spin_unlock(&entity->rq_lock); >> } >> EXPORT_SYMBOL(drm_sched_entity_set_rq); >
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
In reply to Nayan DeshmukhQuoted 4 lines · Nayan Deshmukh
On Thu, Aug 2, 2018 at 12:12 PM Christian König <[email protected] <mailto:[email protected]>> wrote:
Quoted 17 lines
Am 02.08.2018 um 00:25 schrieb Andrey Grodzovsky:
> Thinking again about this change and 53d5f1e drm/scheduler: move
idle
> entities to scheduler with less load v2
>
> Looks to me like use case for which fc9a539 drm/scheduler: add NULL
> pointer check for run queue (v2) was done
>
> will not work anymore.
>
> First of all in drm_sched_entity_push_job, 'if (!entity->rq)' will
> never be true any more since we stopped entity->rq to NULL in
>
> drm_sched_entity_flush.
Good point, going to remove that.So basically we don't need that if (...){ return; } in drm_sched_entity_push_job any more ?
Quoted 11 lines
Quoted 6 lines
Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just acquire
again a
> run queue
>
> fromdrm_sched_entity_get_free_schedand continue submission
Quoted 8 lines
Hi Christian
That is actually desired.
When another process is now using the entity to submit jobs adding it back to the rq is actually the right thing to do cause the entity is still in use.
Yes, no problem if it's another process. But what about another thread from same process ? Is it a possible use case that 2 threads from same process submit to same entity concurrently ? If so and we specifically kill one, the other will not stop event if we want him to because current code makes him just require a rq for him self.
Quoted 7 lines
I am not aware of the usecase so I might just be rambling. but if the thread/process that created the entity has called
drm_sched_entity_flushthen we shouldn't allow other processes to push jobs to that entity.Nayan
Christian.
We don't really know who created the entity, the creation could be by X itself and then it's passed to other process for use. Check 'drm/scheduler: only kill entity if last user is killed v2', the idea is that if by the time you want to kill this entity another process (not another thread from your process - i.e. current->group_leader != last_user in drm_sched_entity_flush) already started to use this entity just let it be.
Andrey
Quoted 112 lines
Quoted 9 lines
so you can't substitute ' if (!entity->rq)' to 'if (
list_empty(&entity->list))'.What about adding a 'stopped' flag to
drm_sched_entityto be set indrm_sched_entity_flushand in
drm_sched_entity_push_jobcheck for 'if (!entity->stopped)'instead > of ' if (!entity->rq)' ? > > Andrey > > > On 07/30/2018 07:03 AM, Christian König wrote: >> We removed the redundancy of having an extra scheduler field, so we >> can't set the rq to NULL any more or otherwise won't know which >> scheduler to use for the cleanup. >> >> Just remove the entity from the scheduling list instead. >> >> Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> >> --- >> drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 >> +++++++------------------------ >> 1 file changed, 8 insertions(+), 27 deletions(-) >> >> diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c >> b/drivers/gpu/drm/scheduler/gpu_scheduler.c >> index f563e4fbb4b6..1b733229201e 100644 >> --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c >> +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c >> @@ -198,21 +198,6 @@ int drm_sched_entity_init(struct >> drm_sched_entity *entity, >> } >> EXPORT_SYMBOL(drm_sched_entity_init); >> -/** >> - * drm_sched_entity_is_initialized - Query if entity is initialized >> - * >> - * @sched: Pointer to scheduler instance >> - * @entity: The pointer to a valid scheduler entity >> - * >> - * return true if entity is initialized, false otherwise >> -*/ >> -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler >> *sched, >> - struct drm_sched_entity *entity) >> -{ >> - return entity->rq != NULL && >> - entity->rq->sched == sched; >> -} >> - >> /** >> * drm_sched_entity_is_idle - Check if entity is idle >> * >> @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct >> drm_sched_entity *entity) >> { >> rmb(); >> - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) >> + if (list_empty(&entity->list) || >> + spsc_queue_peek(&entity->job_queue) == NULL) >> return true; >> return false; >> @@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct >> drm_sched_entity *entity, long timeout) >> long ret = timeout; >> sched = entity->rq->sched; >> - if (!drm_sched_entity_is_initialized(sched, entity)) >> - return ret; >> /** >> * The client will not queue more IBs during this fini, consume >> existing >> * queued IBs or discard them on SIGKILL >> @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct >> drm_sched_entity *entity, long timeout) >> last_user = cmpxchg(&entity->last_user, current->group_leader, >> NULL); >> if ((!last_user || last_user == current->group_leader) && >> (current->flags & PF_EXITING) && (current->exit_code == >> SIGKILL)) >> - drm_sched_entity_set_rq(entity, NULL); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> return ret; >> } >> @@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct >> drm_sched_entity *entity) >> struct drm_gpu_scheduler *sched; >> sched = entity->rq->sched; >> - drm_sched_entity_set_rq(entity, NULL); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> /* Consumption of existing IBs wasn't completed. Forcefully >> * remove them here. >> @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct >> drm_sched_entity *entity, >> if (entity->rq == rq) >> return; >> - spin_lock(&entity->rq_lock); >> - >> - if (entity->rq) >> - drm_sched_rq_remove_entity(entity->rq, entity); >> + BUG_ON(!rq); >> + spin_lock(&entity->rq_lock); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> entity->rq = rq;
Quoted 9 lines
>> - if (rq)
>> - drm_sched_rq_add_entity(rq, entity);
>> -
>> + drm_sched_rq_add_entity(rq, entity);
>> spin_unlock(&entity->rq_lock);
>> }
>> EXPORT_SYMBOL(drm_sched_entity_set_rq);
>_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Am 02.08.2018 um 16:11 schrieb Andrey Grodzovsky:
Quoted 22 lines · Nayan Deshmukh
Quoted 18 lines · On Thu, Aug 2, 2018 at 12:12 PM Christian König…
Am 02.08.2018 um 00:25 schrieb Andrey Grodzovsky: > Thinking again about this change and 53d5f1e drm/scheduler: move idle > entities to scheduler with less load v2 > > Looks to me like use case for which fc9a539 drm/scheduler: add NULL > pointer check for run queue (v2) was done > > will not work anymore. > > First of all in drm_sched_entity_push_job, 'if (!entity->rq)' will > never be true any more since we stopped entity->rq to NULL in >
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
drm_sched_entity_flush.Good point, going to remove that.
So basically we don't need that if (...){ return; } in
drm_sched_entity_push_jobany more ?
Yes, exactly.
Quoted 16 lines
Quoted 16 lines
Quoted 7 lines
Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just acquire
again a
> run queue
>
> fromdrm_sched_entity_get_free_schedand continue submissionHi Christian
That is actually desired.
Quoted 7 lines
Quoted 5 lines
When another process is now using the entity to submit jobs adding it
back to the rq is actually the right thing to do cause the entity is still in use.Yes, no problem if it's another process. But what about another thread from same process ? Is it a possible use case that 2 threads from same process submit to same entity concurrently ? If so and we specifically kill one, the other will not stop event if we want him to because current code makes him just require a rq for him self.
Well you can't kill a single thread of a process (you can only interrupt it), a SIGKILL will always kill the whole process.
Quoted 6 lines
Quoted 6 lines
I am not aware of the usecase so I might just be rambling. but if the thread/process that created the entity has called
drm_sched_entity_flushthen we shouldn't allow other processes to push jobs to that entity.Nayan
Quoted 6 lines
Quoted 2 lines
Christian.
We don't really know who created the entity, the creation could be by X itself and then it's passed to other process for use. Check 'drm/scheduler: only kill entity if last user is killed v2', the idea is that if by the time you want to kill this entity another process (not another thread from your process
- i.e.current->group_leader!=last_userindrm_sched_entity_flush)
already started to use this entity just let it be.
Yes, exactly that's the idea.
Christian.
Quoted 127 lines
Andrey
Quoted 124 lines
Quoted 6 lines
so you can't substitute ' if (!entity->rq)' to 'if (
list_empty(&entity->list))'.What about adding a 'stopped' flag to
drm_sched_entityto beset in > drm_sched_entity_flush and in > > drm_sched_entity_push_job check for 'if (!entity->stopped)' instead > of ' if (!entity->rq)' ? > > Andrey > > > On 07/30/2018 07:03 AM, Christian König wrote: >> We removed the redundancy of having an extra scheduler field, so we >> can't set the rq to NULL any more or otherwise won't know which >> scheduler to use for the cleanup. >> >> Just remove the entity from the scheduling list instead. >> >> Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> >> --- >> drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 >> +++++++------------------------ >> 1 file changed, 8 insertions(+), 27 deletions(-) >> >> diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c >> b/drivers/gpu/drm/scheduler/gpu_scheduler.c >> index f563e4fbb4b6..1b733229201e 100644 >> --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c >> +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c >> @@ -198,21 +198,6 @@ int drm_sched_entity_init(struct >> drm_sched_entity *entity, >> } >> EXPORT_SYMBOL(drm_sched_entity_init); >> -/** >> - * drm_sched_entity_is_initialized - Query if entity is initialized >> - * >> - * @sched: Pointer to scheduler instance >> - * @entity: The pointer to a valid scheduler entity >> - * >> - * return true if entity is initialized, false otherwise >> -*/ >> -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler >> *sched, >> - struct drm_sched_entity *entity) >> -{ >> - return entity->rq != NULL && >> - entity->rq->sched == sched; >> -} >> - >> /** >> * drm_sched_entity_is_idle - Check if entity is idle >> * >> @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct >> drm_sched_entity *entity) >> { >> rmb(); >> - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) >> + if (list_empty(&entity->list) || >> + spsc_queue_peek(&entity->job_queue) == NULL) >> return true; >> return false; >> @@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct >> drm_sched_entity *entity, long timeout) >> long ret = timeout; >> sched = entity->rq->sched; >> - if (!drm_sched_entity_is_initialized(sched, entity)) >> - return ret; >> /** >> * The client will not queue more IBs during this fini, consume >> existing >> * queued IBs or discard them on SIGKILL >> @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct >> drm_sched_entity *entity, long timeout) >> last_user = cmpxchg(&entity->last_user, current->group_leader, >> NULL); >> if ((!last_user || last_user == current->group_leader) && >> (current->flags & PF_EXITING) && (current->exit_code == >> SIGKILL)) >> - drm_sched_entity_set_rq(entity, NULL); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> return ret; >> } >> @@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct >> drm_sched_entity *entity) >> struct drm_gpu_scheduler *sched; >> sched = entity->rq->sched; >> - drm_sched_entity_set_rq(entity, NULL); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> /* Consumption of existing IBs wasn't completed. Forcefully >> * remove them here. >> @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct >> drm_sched_entity *entity, >> if (entity->rq == rq) >> return; >> - spin_lock(&entity->rq_lock); >> - >> - if (entity->rq) >> - drm_sched_rq_remove_entity(entity->rq, entity); >> + BUG_ON(!rq); >> + spin_lock(&entity->rq_lock); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> entity->rq = rq; >> - if (rq) >> - drm_sched_rq_add_entity(rq, entity); >> - >> + drm_sched_rq_add_entity(rq, entity); >> spin_unlock(&entity->rq_lock); >> } >> EXPORT_SYMBOL(drm_sched_entity_set_rq); >
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Quoted 56 lines · Christian König
Am 02.08.2018 um 16:11 schrieb Andrey Grodzovsky:
Quoted 23 lines · Nayan Deshmukh
Quoted 19 lines · On Thu, Aug 2, 2018 at 12:12 PM Christian König…
Am 02.08.2018 um 00:25 schrieb Andrey Grodzovsky: > Thinking again about this change and 53d5f1e drm/scheduler: move idle > entities to scheduler with less load v2 > > Looks to me like use case for which fc9a539 drm/scheduler: add NULL > pointer check for run queue (v2) was done > > will not work anymore. > > First of all in drm_sched_entity_push_job, 'if (!entity->rq)' will > never be true any more since we stopped entity->rq to NULL in >Quoted 6 lines
Quoted 4 lines
Quoted 1 line
drm_sched_entity_flush.Good point, going to remove that.
So basically we don't need that if (...){ return; } in
drm_sched_entity_push_jobany more ?Yes, exactly.
Quoted 23 lines
Quoted 22 lines
Quoted 7 lines
Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just acquire
again a
> run queue
>
> fromdrm_sched_entity_get_free_schedand continue submissionHi Christian
That is actually desired.
When another process is now using the entity to submit jobs adding it
back to the rq is actually the right thing to do cause the entity is
still in use.
Quoted 3 lines
Quoted 1 line
Yes, no problem if it's another process. But what about another thread from same process ? Is it a possible use case that 2 threads from same process submit to same entity concurrently ? If so and we specifically kill one, the other will not stop event if we want him to because current code makes him just require a rq for him self.
Well you can't kill a single thread of a process (you can only interrupt it), a SIGKILL will always kill the whole process.
Is the following scenario possible and acceptable ?
2 threads from same process working on same queue where thread A currently in drm_sched_entity_flush->wait_event_timeout (the process getting shut down because of SIGKILL sent by user)
while thread B still inside drm_sched_entity_push_job before 'if (reschedule)'. 'A' stopped waiting because queue became empty and then removes the entity queue from scheduler's run queue while
B goes inside 'reschedule' because it evaluates to true ('first' is true and all the rest of the conditions), acquires new rq, and later adds it back to scheduler (different one maybe) and keeps submitting jobs as much as he likes and then can be stack for up to 'timeout' time in his drm_sched_entity_flush waiting for them.
My understanding was that introduction of entity->last is to force immediate termination job submissions by any thread from the terminating process.
Andrey
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
I am not aware of the usecase so I might just be rambling. but if the thread/process that created the entity has called
drm_sched_entity_flushthen we shouldn't allow other processes to push jobs to that entity.Nayan
Quoted 138 lines
Quoted 4 lines
Quoted 2 lines
Christian.
We don't really know who created the entity, the creation could be by X itself and then it's passed to other process for use. Check 'drm/scheduler: only kill entity if last user is killed v2', the idea is that if by the time you want to kill this entity another process (not another thread from your process - i.e.
current->group_leader!=last_userindrm_sched_entity_flush) already started to use this entity just let it be.Yes, exactly that's the idea.
Christian.
Quoted 128 lines
Andrey
Quoted 125 lines
Quoted 6 lines
so you can't substitute ' if (!entity->rq)' to 'if (
list_empty(&entity->list))'.What about adding a 'stopped' flag to
drm_sched_entityto beset in > drm_sched_entity_flush and in > > drm_sched_entity_push_job check for 'if (!entity->stopped)' instead > of ' if (!entity->rq)' ? > > Andrey > > > On 07/30/2018 07:03 AM, Christian König wrote: >> We removed the redundancy of having an extra scheduler field, so we >> can't set the rq to NULL any more or otherwise won't know which >> scheduler to use for the cleanup. >> >> Just remove the entity from the scheduling list instead. >> >> Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> >> --- >> drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 >> +++++++------------------------ >> 1 file changed, 8 insertions(+), 27 deletions(-) >> >> diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c >> b/drivers/gpu/drm/scheduler/gpu_scheduler.c >> index f563e4fbb4b6..1b733229201e 100644 >> --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c >> +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c >> @@ -198,21 +198,6 @@ int drm_sched_entity_init(struct >> drm_sched_entity *entity, >> } >> EXPORT_SYMBOL(drm_sched_entity_init); >> -/** >> - * drm_sched_entity_is_initialized - Query if entity is initialized >> - * >> - * @sched: Pointer to scheduler instance >> - * @entity: The pointer to a valid scheduler entity >> - * >> - * return true if entity is initialized, false otherwise >> -*/ >> -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler >> *sched, >> - struct drm_sched_entity *entity) >> -{ >> - return entity->rq != NULL && >> - entity->rq->sched == sched; >> -} >> - >> /** >> * drm_sched_entity_is_idle - Check if entity is idle >> * >> @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct >> drm_sched_entity *entity) >> { >> rmb(); >> - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) >> + if (list_empty(&entity->list) || >> + spsc_queue_peek(&entity->job_queue) == NULL) >> return true; >> return false; >> @@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct >> drm_sched_entity *entity, long timeout) >> long ret = timeout; >> sched = entity->rq->sched; >> - if (!drm_sched_entity_is_initialized(sched, entity)) >> - return ret; >> /** >> * The client will not queue more IBs during this fini, consume >> existing >> * queued IBs or discard them on SIGKILL >> @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct >> drm_sched_entity *entity, long timeout) >> last_user = cmpxchg(&entity->last_user, current->group_leader, >> NULL); >> if ((!last_user || last_user == current->group_leader) && >> (current->flags & PF_EXITING) && (current->exit_code == >> SIGKILL)) >> - drm_sched_entity_set_rq(entity, NULL); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> return ret; >> } >> @@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct >> drm_sched_entity *entity) >> struct drm_gpu_scheduler *sched; >> sched = entity->rq->sched; >> - drm_sched_entity_set_rq(entity, NULL); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> /* Consumption of existing IBs wasn't completed. Forcefully >> * remove them here. >> @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct >> drm_sched_entity *entity, >> if (entity->rq == rq) >> return; >> - spin_lock(&entity->rq_lock); >> - >> - if (entity->rq) >> - drm_sched_rq_remove_entity(entity->rq, entity); >> + BUG_ON(!rq); >> + spin_lock(&entity->rq_lock); >> + drm_sched_rq_remove_entity(entity->rq, entity); >> entity->rq = rq; >> - if (rq) >> - drm_sched_rq_add_entity(rq, entity); >> - >> + drm_sched_rq_add_entity(rq, entity); >> spin_unlock(&entity->rq_lock); >> } >> EXPORT_SYMBOL(drm_sched_entity_set_rq); >
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Am 03.08.2018 um 16:54 schrieb Andrey Grodzovsky:
Quoted 26 lines
[SNIP]
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 7 lines
Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just acquire
again a
> run queue
>
> fromdrm_sched_entity_get_free_schedand continue submissionHi Christian
That is actually desired.
When another process is now using the entity to submit jobs adding it
back to the rq is actually the right thing to do cause the entity is
still in use.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Yes, no problem if it's another process. But what about another thread from same process ? Is it a possible use case that 2 threads from same process submit to same entity concurrently ? If so and we specifically kill one, the other will not stop event if we want him to because current code makes him just require a rq for him self.
Well you can't kill a single thread of a process (you can only interrupt it), a SIGKILL will always kill the whole process.
Is the following scenario possible and acceptable ?
2 threads from same process working on same queue where thread A currently indrm_sched_entity_flush->wait_event_timeout(the process getting shut down because of SIGKILL sent by user)
while thread B still insidedrm_sched_entity_push_jobbefore 'if (reschedule)'. 'A' stopped waiting because queue became empty and then removes the entity queue from scheduler's run queue while
B goes inside 'reschedule' because it evaluates to true ('first' is true and all the rest of the conditions), acquires new rq, and later adds it back to scheduler (different one maybe) and keeps submitting jobs as much as he likes and then can be stack for up to 'timeout' time in hisdrm_sched_entity_flushwaiting for them.
I'm not 100% sure but I don't think that can happen.
See flushing the fd is done while dropping the fd, which happens only after all threads of the process in question are killed.
Otherwise the flushing wouldn't make to much sense. In other words imagine an application where a thread does a write() on a fd which is killed.
The idea of the flush is to preserve the data and that won't work if that isn't correctly ordered.
Quoted 1 line
My understanding was that introduction of
entity->lastis to force immediate termination job submissions by any thread from the terminating process.
We could consider reordering that once more. Going to play out all scenarios in my head over the weekend :)
Christian.
Quoted 2 lines
Andrey
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Quoted 31 lines · Christian König
Am 03.08.2018 um 16:54 schrieb Andrey Grodzovsky:
Quoted 30 lines
[SNIP]
Quoted 26 lines
Quoted 16 lines
Quoted 16 lines
Quoted 7 lines
Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just
acquire again a
> run queue
>
> fromdrm_sched_entity_get_free_schedand continue submissionHi Christian
That is actually desired.
Quoted 8 lines
Quoted 6 lines
When another process is now using the entity to submit jobs adding it
back to the rq is actually the right thing to do cause the entity is
still in use.Yes, no problem if it's another process. But what about another thread from same process ? Is it a possible use case that 2 threads from same process submit to same entity concurrently ? If so and we specifically kill one, the other will not stop event if we want him to because current code makes him just require a rq for him self.
Well you can't kill a single thread of a process (you can only interrupt it), a SIGKILL will always kill the whole process.
Quoted 8 lines
Quoted 4 lines
Is the following scenario possible and acceptable ?
2 threads from same process working on same queue where thread A currently indrm_sched_entity_flush->wait_event_timeout(the process getting shut down because of SIGKILL sent by user)
while thread B still insidedrm_sched_entity_push_jobbefore 'if (reschedule)'. 'A' stopped waiting because queue became empty and then removes the entity queue from scheduler's run queue while
B goes inside 'reschedule' because it evaluates to true ('first' is true and all the rest of the conditions), acquires new rq, and later adds it back to scheduler (different one maybe) and keeps submitting jobs as much as he likes and then can be stack for up to 'timeout' time in hisdrm_sched_entity_flushwaiting for them.I'm not 100% sure but I don't think that can happen.
See flushing the fd is done while dropping the fd, which happens only after all threads of the process in question are killed.
Yea, this FDs handling is indeed a lot of gray area for me but as far as I remember flushing is done per each thread when exits (possibly due to a signal). Now signals interception and processing (as a result of which .flush will get called if SIGKILL received) is done in some points amongst which is when returning from IOCTL. So if first thread was at the very end of the CS ioctl when SIGKILL was received while the other one at the beginning then I think we might see something like the scenario above.
Andrey
Quoted 14 lines
Otherwise the flushing wouldn't make to much sense. In other words imagine an application where a thread does a
write()on a fd which is killed.The idea of the flush is to preserve the data and that won't work if that isn't correctly ordered.
Quoted 1 line
My understanding was that introduction of
entity->lastis to force immediate termination job submissions by any thread from the terminating process.We could consider reordering that once more. Going to play out all scenarios in my head over the weekend :)
Christian.
Quoted 2 lines
Andrey
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
reviewerRe: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Am 03.08.2018 um 20:41 schrieb Andrey Grodzovsky:
Quoted 40 lines · Christian König
Quoted 36 lines
Am 03.08.2018 um 16:54 schrieb Andrey Grodzovsky:
Quoted 34 lines
[SNIP]
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 7 lines
Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just
acquire again a
> run queue
>
> fromdrm_sched_entity_get_free_schedand continue submissionHi Christian
That is actually desired.
When another process is now using the entity to submit jobs adding it
back to the rq is actually the right thing to do cause the entity is
still in use.Quoted 3 lines
Quoted 1 line
Yes, no problem if it's another process. But what about another thread from same process ? Is it a possible use case that 2 threads from same process submit to same entity concurrently ? If so and we specifically kill one, the other will not stop event if we want him to because current code makes him just require a rq for him self.
Well you can't kill a single thread of a process (you can only interrupt it), a SIGKILL will always kill the whole process.
Is the following scenario possible and acceptable ?
2 threads from same process working on same queue where thread A currently indrm_sched_entity_flush->wait_event_timeout(the process getting shut down because of SIGKILL sent by user)
while thread B still insidedrm_sched_entity_push_jobbefore 'if (reschedule)'. 'A' stopped waiting because queue became empty and then removes the entity queue from scheduler's run queue while
B goes inside 'reschedule' because it evaluates to true ('first' is true and all the rest of the conditions), acquires new rq, and later adds it back to scheduler (different one maybe) and keeps submitting jobs as much as he likes and then can be stack for up to 'timeout' time in hisdrm_sched_entity_flushwaiting for them.
Quoted 7 lines
Quoted 3 lines
I'm not 100% sure but I don't think that can happen.
See flushing the fd is done while dropping the fd, which happens only after all threads of the process in question are killed.
Yea, this FDs handling is indeed a lot of gray area for me but as far as I remember flushing is done per each thread when exits (possibly due to a signal). Now signals interception and processing (as a result of which .flush will get called if SIGKILL received) is done in some points amongst which is when returning from IOCTL. So if first thread was at the very end of the CS ioctl when SIGKILL was received while the other one at the beginning then I think we might see something like the scenario above.
SIGKILL isn't processed as long as any thread of the application is still inside the kernel. That's why we have wait_event_killable().
So I don't think that the scenario above is possible, but I'm really not 100% sure either.
Christian.
Quoted 20 lines
Andrey
Quoted 14 lines
Otherwise the flushing wouldn't make to much sense. In other words imagine an application where a thread does a
write()on a fd which is killed.The idea of the flush is to preserve the data and that won't work if that isn't correctly ordered.
Quoted 1 line
My understanding was that introduction of
entity->lastis to force immediate termination job submissions by any thread from the terminating process.We could consider reordering that once more. Going to play out all scenarios in my head over the weekend :)
Christian.
Quoted 2 lines
Andrey
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Quoted 43 lines · Christian König
Am 03.08.2018 um 20:41 schrieb Andrey Grodzovsky:
Quoted 42 lines · Christian König
Quoted 38 lines
Am 03.08.2018 um 16:54 schrieb Andrey Grodzovsky:
Quoted 26 lines
[SNIP]
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 7 lines
Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just
acquire again a
> run queue
>
> fromdrm_sched_entity_get_free_schedand continue submissionHi Christian
That is actually desired.
When another process is now using the entity to submit jobs adding it
back to the rq is actually the right thing to do cause the entity is
still in use.Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Yes, no problem if it's another process. But what about another thread from same process ? Is it a possible use case that 2 threads from same process submit to same entity concurrently ? If so and we specifically kill one, the other will not stop event if we want him to because current code makes him just require a rq for him self.
Well you can't kill a single thread of a process (you can only interrupt it), a SIGKILL will always kill the whole process.
Is the following scenario possible and acceptable ?
2 threads from same process working on same queue where thread A currently indrm_sched_entity_flush->wait_event_timeout(the process getting shut down because of SIGKILL sent by user)
while thread B still insidedrm_sched_entity_push_jobbefore 'if (reschedule)'. 'A' stopped waiting because queue became empty and then removes the entity queue from scheduler's run queue while
B goes inside 'reschedule' because it evaluates to true ('first' is true and all the rest of the conditions), acquires new rq, and later adds it back to scheduler (different one maybe) and keeps submitting jobs as much as he likes and then can be stack for up to 'timeout' time in hisdrm_sched_entity_flushwaiting for them.I'm not 100% sure but I don't think that can happen.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
See flushing the fd is done while dropping the fd, which happens only after all threads of the process in question are killed.
Yea, this FDs handling is indeed a lot of gray area for me but as far as I remember flushing is done per each thread when exits (possibly due to a signal). Now signals interception and processing (as a result of which .flush will get called if SIGKILL received) is done in some points amongst which is when returning from IOCTL. So if first thread was at the very end of the CS ioctl when SIGKILL was received while the other one at the beginning then I think we might see something like the scenario above.
SIGKILL isn't processed as long as any thread of the application is still inside the kernel. That's why we have
wait_event_killable().
Can you tell me where is this happening ? What i see is in the code is thatdo_group_exit calls zap_other_threads which just adds SIGKILL to signal sets of other threads in group and sends a wake up.
Then do_exit will close all FDs for current thread and so .flush will be called, when last thread drops it's refcount for the FD .release will be called.
Andrey
Quoted 30 lines
So I don't think that the scenario above is possible, but I'm really not 100% sure either.
Christian.
Quoted 24 lines
Andrey
Quoted 14 lines
Otherwise the flushing wouldn't make to much sense. In other words imagine an application where a thread does a
write()on a fd which is killed.The idea of the flush is to preserve the data and that won't work if that isn't correctly ordered.
Quoted 1 line
My understanding was that introduction of
entity->lastis to force immediate termination job submissions by any thread from the terminating process.We could consider reordering that once more. Going to play out all scenarios in my head over the weekend :)
Christian.
Quoted 2 lines
Andrey
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
reviewerRe: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Am 09.08.2018 um 19:39 schrieb Andrey Grodzovsky:
Quoted 6 lines
[SNIP]
Quoted 1 line
SIGKILL isn't processed as long as any thread of the application is still inside the kernel. That's why we have
wait_event_killable().Can you tell me where is this happening ? What i see is in the code is that
do_group_exitcallszap_other_threadswhich just adds SIGKILL to signal sets of other threads in group and sends a wake up.
Thendo_exitwill close all FDs for current thread and so .flush will be called, when last thread drops it's refcount for the FD .release will be called.
Good question, I have not the slightest idea.
Killed processes certainly doesn't die until all threads return from kernel space, but I'm not 100% sure if that happens before or after the flush.
Christian.
Quoted 2 lines
Andrey
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
In reply to Andrey GrodzovskyHi Andrey,
Good catch. I guess since both Christian and I were working on it parallelly we didn't catch this problem.
If it is only causing a problem in push_job then we can handle it something like this:
----------------------------------------------------------------------------------------------------------------------------
(quoted diff) +0 -0
b/drivers/gpu/drm/scheduler/gpu_scheduler.c
index 05dc6ecd4003..f344ce32f128 100644
drivers/gpu/drm/scheduler/gpu_scheduler.c +0 -0
@@ -563,6 +563,11 @@ void drm_sched_entity_push_job(struct drm_sched_job
*sched_job,
first = spsc_queue_count(&entity->job_queue) == 0;
reschedule = idle && first && (entity->num_rq_list > 1);+ if (first && list_empty(&entity->list)) {
+ DRM_ERROR("Trying to push to a killed entity\n");
+ return;
+ }
+
if (reschedule) {
rq = drm_sched_entity_get_free_sched(entity);
spin_lock(&entity->rq_lock);
@@ -580,11 +585,6 @@ void drm_sched_entity_push_job(struct drm_sched_job
*sched_job,
if (first) {
/* Add the entity to the run queue */
spin_lock(&entity->rq_lock);
- if (!entity->rq) {
- DRM_ERROR("Trying to push to a killed entity\n");
- spin_unlock(&entity->rq_lock);
- return;
- }
drm_sched_rq_add_entity(entity->rq, entity);
spin_unlock(&entity->rq_lock);
drm_sched_wakeup(entity->rq->sched);-----------------------------------------------------------------------------------------------------------------------------
Quoted 19 lines · Andrey Grodzovsky
Thinking again about this change and 53d5f1e drm/scheduler: move idle entities to scheduler with less load v2
Looks to me like use case for which fc9a539 drm/scheduler: add NULL pointer check for run queue (v2) was done
will not work anymore.
First of all in
drm_sched_entity_push_job, 'if (!entity->rq)' will never be true any more since we stoppedentity->rqto NULL in
drm_sched_entity_flush.Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just acquire again a run queue
Quoted 7 lines
from
drm_sched_entity_get_free_schedand continue submission so you can't substitute ' if (!entity->rq)' to 'if (list_empty(&entity->list))'.What about adding a 'stopped' flag to
drm_sched_entityto be set indrm_sched_entity_flushand inBut it might be worth adding a stopped flag field if it is required at
other places as well.
Thanks,
Nayan
Quoted 104 lines
drm_sched_entity_push_jobcheck for 'if (!entity->stopped)' instead of ' if (!entity->rq)' ?Andrey
Quoted 9 lines · Christian König
We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup.
Just remove the entity from the scheduling list instead.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 35+++++++------------------------
Review
Quoted 3 lines
1 file changed, 8 insertions(+), 27 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/scheduler/gpu_scheduler.cdrivers/gpu/drm/scheduler/gpu_scheduler.c int drm_sched_entity_init(struct drm_sched_entity
Quoted 4 lines
index
f563e4fbb4b6..1b733229201e100644drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0@@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity*entity,
drivers/gpu/drm/scheduler/gpu_scheduler.c int drm_sched_entity_init(struct drm_sched_entity · line 209
Quoted 12 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-9}EXPORT_SYMBOL (drm_sched_entity_init); -/** -* drm_sched_entity_is_initialized - Query if entity is initialized -* -* @sched: Pointer to scheduler instance -* @entity: The pointer to a valid scheduler entity -* -* return true if entity is initialized, false otherwise -*/ -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler*sched,
drivers/gpu/drm/scheduler/gpu_scheduler.c int drm_sched_entity_init(struct drm_sched_entity · line 210
Quoted 1 line
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-1-struct drm_sched_entity *entity)
drivers/gpu/drm/scheduler/gpu_scheduler.c static bool drm_sched_entity_is_idle(struct
Quoted 9 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-5-{ -return entity->rq !=NULL && - entity->rq->sched == sched; -} -/** * drm_sched_entity_is_idle - Check if entity is idle * @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct
drm_sched_entity*entity)drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct drm_sched_entity
Quoted 10 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-1{rmb (); -if (!entity->rq ||spsc_queue_peek (&entity->job_queue) ==NULL ) +if (list_empty (&entity->list) || +spsc_queue_peek (&entity->job_queue) ==NULL )return true;return false;@@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity*entity, long timeout)
drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct drm_sched_entity · line 269
Quoted 7 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-2long ret = timeout; sched = entity->rq->sched; -if (!drm_sched_entity_is_initialized (sched, entity)) -return ret;/** * The client will not queue more IBs during this fini, consume existing
drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct drm_sched_entity
Quoted 2 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0* queued IBs or discard them on SIGKILL @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity*entity, long timeout)
drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct drm_sched_entity · line 283
Quoted 1 line
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0last_user = cmpxchg(&entity->last_user, current->group_leader,NULL);
drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct drm_sched_entity · line 285
Quoted 2 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0if ((!last_user || last_user == current->group_leader) && (current->flags & PF_EXITING) && (current->exit_code ==SIGKILL))
drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_fini(struct drm_sched_entity
Quoted 6 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-1-drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);return ret; }@@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity*entity)
drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_set_rq(struct
Quoted 9 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-1struct drm_gpu_scheduler *sched; sched = entity->rq->sched; -drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);/* Consumption of existing IBs wasn't completed. Forcefully * remove them here. @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct
drm_sched_entity*entity,Quoted 9 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-4if (entity->rq == rq)return ; -spin_lock (&entity->rq_lock); - -if (entity->rq) -drm_sched_rq_remove_entity (entity->rq, entity); +BUG_ON (!rq);
Quoted 12 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_set_rq(struct · line 411
Quoted 10 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +3
-3+spin_lock (&entity->rq_lock); +drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq; -if (rq) -drm_sched_rq_add_entity (rq, entity); - +drm_sched_rq_add_entity (rq, entity);spin_unlock (&entity->rq_lock); }EXPORT_SYMBOL (drm_sched_entity_set_rq);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Quoted 12 lines · Nayan Deshmukh
Hi Andrey,
Good catch. I guess since both Christian and I were working on it parallelly we didn't catch this problem.
If it is only causing a problem in
push_jobthen we can handle it something like this:----------------------------------------------------------------------------------------------------------------------------
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0
drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_push_job(struct · line 567
Quoted 5 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-0@@ -563,6 +563,11 @@ void drm_sched_entity_push_job(structdrm_sched_job *sched_job, first = spsc_queue_count(&entity->job_queue) == 0; reschedule = idle && first && (entity->num_rq_list > 1); + if (first && list_empty(&entity->list)) {
first might be false if the other process interrupted by SIGKILL in middle of wait_event_killable in drm_sched_entity_flush when there were still item in queue. I don't see a good way besides adding a 'stopped' flag to drm_sched_enitity.
Andrey
Quoted 166 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0+ DRM_ERROR("Trying to push to a killed entity\n"); + return; + } + if (reschedule) { rq = drm_sched_entity_get_free_sched(entity);
spin_lock(&entity->rq_lock);drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-5@@ -580,11 +585,6 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job, if (first) { /* Add the entity to the run queue */ spin_lock(&entity->rq_lock); - if (!entity->rq) { - DRM_ERROR("Trying to push to a killed entity\n"); - spin_unlock(&entity->rq_lock); - return; - } drm_sched_rq_add_entity(entity->rq, entity); spin_unlock(&entity->rq_lock);
drm_sched_wakeup(entity->rq->sched);
-----------------------------------------------------------------------------------------------------------------------------On Thu, Aug 2, 2018 at 3:55 AM Andrey Grodzovsky <[email protected] <mailto:[email protected]>> wrote:
Thinking again about this change and 53d5f1e drm/scheduler: move idle entities to scheduler with less load v2
Looks to me like use case for which fc9a539 drm/scheduler: add NULL pointer check for run queue (v2) was done
will not work anymore.
First of all in
drm_sched_entity_push_job, 'if (!entity->rq)' will never
be true any more since we stoppedentity->rqto NULL in
drm_sched_entity_flush.Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just acquire again a run queue
from
drm_sched_entity_get_free_schedand continue submission so you can't substitute ' if (!entity->rq)' to 'if (list_empty(&entity->list))'.What about adding a 'stopped' flag to
drm_sched_entityto be set indrm_sched_entity_flushand inBut it might be worth adding a stopped flag field if it is required at other places as well.
Thanks,
Nayandrm_sched_entity_push_job check for 'if (!entity->stopped)' instead of ' if (!entity->rq)' ? Andrey On 07/30/2018 07:03 AM, Christian König wrote: > We removed the redundancy of having an extra scheduler field, so we > can't set the rq to NULL any more or otherwise won't know which > scheduler to use for the cleanup. > > Just remove the entity from the scheduling list instead. > > Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> > --- > drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 +++++++------------------------ > 1 file changed, 8 insertions(+), 27 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c > index f563e4fbb4b6..1b733229201e 100644 > --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c > +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c > @@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, > } > EXPORT_SYMBOL(drm_sched_entity_init); > > -/** > - * drm_sched_entity_is_initialized - Query if entity is initialized > - * > - * @sched: Pointer to scheduler instance > - * @entity: The pointer to a valid scheduler entity > - * > - * return true if entity is initialized, false otherwise > -*/ > -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler *sched, > - struct drm_sched_entity *entity) > -{ > - return entity->rq != NULL && > - entity->rq->sched == sched; > -} > - > /** > * drm_sched_entity_is_idle - Check if entity is idle > * > @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) > { > rmb(); > > - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) > + if (list_empty(&entity->list) || > + spsc_queue_peek(&entity->job_queue) == NULL) > return true; > > return false; > @@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) > long ret = timeout; > > sched = entity->rq->sched; > - if (!drm_sched_entity_is_initialized(sched, entity)) > - return ret; > /** > * The client will not queue more IBs during this fini, consume existing > * queued IBs or discard them on SIGKILL > @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) > last_user = cmpxchg(&entity->last_user, current->group_leader, NULL); > if ((!last_user || last_user == current->group_leader) && > (current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) > - drm_sched_entity_set_rq(entity, NULL); > + drm_sched_rq_remove_entity(entity->rq, entity); > > return ret; > } > @@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity) > struct drm_gpu_scheduler *sched; > > sched = entity->rq->sched; > - drm_sched_entity_set_rq(entity, NULL); > + drm_sched_rq_remove_entity(entity->rq, entity); > > /* Consumption of existing IBs wasn't completed. Forcefully > * remove them here. > @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct drm_sched_entity *entity, > if (entity->rq == rq) > return; > > - spin_lock(&entity->rq_lock); > - > - if (entity->rq) > - drm_sched_rq_remove_entity(entity->rq, entity); > + BUG_ON(!rq); > > + spin_lock(&entity->rq_lock); > + drm_sched_rq_remove_entity(entity->rq, entity);
Quoted 9 lines
> entity->rq = rq;
> - if (rq)
> - drm_sched_rq_add_entity(rq, entity);
> -
> + drm_sched_rq_add_entity(rq, entity);
> spin_unlock(&entity->rq_lock);
> }
> EXPORT_SYMBOL(drm_sched_entity_set_rq);_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Quoted 27 lines · Andrey Grodzovsky
On 08/02/2018 02:43 AM, Nayan Deshmukh wrote:
Hi Andrey,
Good catch. I guess since both Christian and I were working on it parallelly we didn't catch this problem.
If it is only causing a problem in
push_jobthen we can handle it something like this:----------------------------------------------------------------------------------------------------------------------------
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-0@@ -563,6 +563,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job, first =spsc_queue_count (&entity->job_queue) ==0 ; reschedule = idle && first && (entity->num_rq_list >1 ); +if (first &&list_empty (&entity->list)) {
Quoted 6 lines
first might be false if the other process interrupted by SIGKILL in middle of
wait_event_killableindrm_sched_entity_flushwhen there were still item in queue.
I don't see a good way besides adding a 'stopped' flag todrm_sched_enitity.
Sorry I missed this mail. This case might happen but this was also not being handled previously.
Nayan
Quoted 52 lines
Andrey
drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-5+DRM_ERROR ("Trying to push to a killed entity\n" ); +return ; + } +if (reschedule) { rq =drm_sched_entity_get_free_sched (entity);spin_lock (&entity->rq_lock);@@ -580,11 +585,6 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job, if (first) {/* Add the entity to the run queue */ spin_lock (&entity->rq_lock); -if (!entity->rq) { -DRM_ERROR ("Trying to push to a killed entity\n" ); -spin_unlock (&entity->rq_lock); -return ; - }drm_sched_rq_add_entity (entity->rq, entity);spin_unlock (&entity->rq_lock);drm_sched_wakeup(entity->rq->sched);-----------------------------------------------------------------------------------------------------------------------------
Quoted 22 lines · Andrey Grodzovsky
Thinking again about this change and 53d5f1e drm/scheduler: move idle entities to scheduler with less load v2
Looks to me like use case for which fc9a539 drm/scheduler: add NULL pointer check for run queue (v2) was done
will not work anymore.
First of all in
drm_sched_entity_push_job, 'if (!entity->rq)' will never be true any more since we stoppedentity->rqto NULL in
drm_sched_entity_flush.Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just acquire again a run queue
from
drm_sched_entity_get_free_schedand continue submission so you can't substitute ' if (!entity->rq)' to 'if (list_empty(&entity->list))'.
Quoted 126 lines
Quoted 4 lines
What about adding a 'stopped' flag to
drm_sched_entityto be set indrm_sched_entity_flushand inBut it might be worth adding a stopped flag field if it is required at
other places as well.
Thanks,
NayanQuoted 116 lines
drm_sched_entity_push_jobcheck for 'if (!entity->stopped)' instead of ' if (!entity->rq)' ?Andrey
Quoted 9 lines · Christian König
We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup.
Just remove the entity from the scheduling list instead.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 35+++++++------------------------
Review
Quoted 3 lines
1 file changed, 8 insertions(+), 27 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/scheduler/gpu_scheduler.cdrivers/gpu/drm/scheduler/gpu_scheduler.c int drm_sched_entity_init(struct drm_sched_entity
Quoted 4 lines
index
f563e4fbb4b6..1b733229201e100644drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0@@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity*entity,
drivers/gpu/drm/scheduler/gpu_scheduler.c int drm_sched_entity_init(struct drm_sched_entity · line 209
Quoted 12 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-9}EXPORT_SYMBOL (drm_sched_entity_init); -/** -* drm_sched_entity_is_initialized - Query if entity is initialized -* -* @sched: Pointer to scheduler instance -* @entity: The pointer to a valid scheduler entity -* -* return true if entity is initialized, false otherwise -*/ -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler*sched,
drivers/gpu/drm/scheduler/gpu_scheduler.c int drm_sched_entity_init(struct drm_sched_entity · line 210
Quoted 1 line
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-1-struct drm_sched_entity *entity)
drivers/gpu/drm/scheduler/gpu_scheduler.c static bool drm_sched_entity_is_idle(struct
Quoted 9 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-5-{ -return entity->rq !=NULL && - entity->rq->sched == sched; -} -/** * drm_sched_entity_is_idle - Check if entity is idle * @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct
drm_sched_entity*entity)drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct drm_sched_entity
Quoted 10 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-1{rmb (); -if (!entity->rq ||spsc_queue_peek (&entity->job_queue) ==NULL ) +if (list_empty (&entity->list) || +spsc_queue_peek (&entity->job_queue) ==NULL )return true;return false;@@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity*entity, long timeout)
drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct drm_sched_entity · line 269
Quoted 7 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-2long ret = timeout; sched = entity->rq->sched; -if (!drm_sched_entity_is_initialized (sched, entity)) -return ret;/** * The client will not queue more IBs during this fini, consume existing
drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct drm_sched_entity
Quoted 2 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0* queued IBs or discard them on SIGKILL @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity*entity, long timeout)
drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct drm_sched_entity · line 283
Quoted 1 line
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0last_user = cmpxchg(&entity->last_user, current->group_leader,NULL);
drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct drm_sched_entity · line 285
Quoted 2 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0if ((!last_user || last_user == current->group_leader) && (current->flags & PF_EXITING) && (current->exit_code ==SIGKILL))
drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_fini(struct drm_sched_entity
Quoted 6 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-1-drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);return ret; }@@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity*entity)
drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_set_rq(struct
Quoted 9 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-1struct drm_gpu_scheduler *sched; sched = entity->rq->sched; -drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);/* Consumption of existing IBs wasn't completed. Forcefully * remove them here. @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct
drm_sched_entity*entity,Quoted 19 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-7if (entity->rq == rq)return ; -spin_lock (&entity->rq_lock); - -if (entity->rq) -drm_sched_rq_remove_entity (entity->rq, entity); +BUG_ON (!rq); +spin_lock (&entity->rq_lock); +drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq; -if (rq) -drm_sched_rq_add_entity (rq, entity); - +drm_sched_rq_add_entity (rq, entity);spin_unlock (&entity->rq_lock); }EXPORT_SYMBOL (drm_sched_entity_set_rq);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Quoted 34 lines · Nayan Deshmukh
On Thu, Aug 2, 2018, 8:09 PM Andrey Grodzovsky <[email protected] <mailto:[email protected]>> wrote:
On 08/02/2018 02:43 AM, Nayan Deshmukh wrote:Quoted 12 lines
Hi Andrey, Good catch. I guess since both Christian and I were working on it parallelly we didn't catch this problem. If it is only causing a problem in push_job then we can handle it something like this: ---------------------------------------------------------------------------------------------------------------------------- diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c index 05dc6ecd4003..f344ce32f128 100644Quoted 8 lines
--- a/drivers/gpu/drm/scheduler/gpu_scheduler.c +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c @@ -563,6 +563,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job, first = spsc_queue_count(&entity->job_queue) == 0; reschedule = idle && first && (entity->num_rq_list > 1); + if (first && list_empty(&entity->list)) {first might be false if the other process interrupted by SIGKILL in middle of
wait_event_killableindrm_sched_entity_flushwhen there were still item in queue.
I don't see a good way besides adding a 'stopped' flag todrm_sched_enitity.
Quoted 3 lines
Sorry I missed this mail. This case might happen but this was also not being handled previously.
Nayan
The original code before 'drm/scheduler: stop setting rq to NULL' was , because you didn't use the queue's emptiness as a criteria for aborting your next push to queue but rather checking for entity->rq != NULL.
Andrey
Quoted 189 lines
Andrey
Quoted 185 lines
+ DRM_ERROR("Trying to push to a killed entity\n"); + return; + } + if (reschedule) { rq = drm_sched_entity_get_free_sched(entity); spin_lock(&entity->rq_lock); @@ -580,11 +585,6 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job, if (first) { /* Add the entity to the run queue */ spin_lock(&entity->rq_lock); - if (!entity->rq) { - DRM_ERROR("Trying to push to a killed entity\n"); - spin_unlock(&entity->rq_lock); - return; - } drm_sched_rq_add_entity(entity->rq, entity); spin_unlock(&entity->rq_lock); drm_sched_wakeup(entity->rq->sched); ----------------------------------------------------------------------------------------------------------------------------- On Thu, Aug 2, 2018 at 3:55 AM Andrey Grodzovsky <[email protected] <mailto:[email protected]>> wrote: Thinking again about this change and 53d5f1e drm/scheduler: move idle entities to scheduler with less load v2 Looks to me like use case for which fc9a539 drm/scheduler: add NULL pointer check for run queue (v2) was done will not work anymore. First of all in drm_sched_entity_push_job, 'if (!entity->rq)' will never be true any more since we stopped entity->rq to NULL in drm_sched_entity_flush. Second of all, even after we removed the entity from rq in drm_sched_entity_flush to terminate any subsequent submissions to the queue the other thread doing push job can just acquire again a run queue from drm_sched_entity_get_free_sched and continue submission so you can't substitute ' if (!entity->rq)' to 'if (list_empty(&entity->list))'. What about adding a 'stopped' flag to drm_sched_entity to be set in drm_sched_entity_flush and in But it might be worth adding a stopped flag field if it is required at other places as well. Thanks, Nayan drm_sched_entity_push_job check for 'if (!entity->stopped)' instead of ' if (!entity->rq)' ? Andrey On 07/30/2018 07:03 AM, Christian König wrote: > We removed the redundancy of having an extra scheduler field, so we > can't set the rq to NULL any more or otherwise won't know which > scheduler to use for the cleanup. > > Just remove the entity from the scheduling list instead. > > Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> > --- > drivers/gpu/drm/scheduler/gpu_scheduler.c | 35 +++++++------------------------ > 1 file changed, 8 insertions(+), 27 deletions(-) > > diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c > index f563e4fbb4b6..1b733229201e 100644 > --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c > +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c > @@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, > } > EXPORT_SYMBOL(drm_sched_entity_init); > > -/** > - * drm_sched_entity_is_initialized - Query if entity is initialized > - * > - * @sched: Pointer to scheduler instance > - * @entity: The pointer to a valid scheduler entity > - * > - * return true if entity is initialized, false otherwise > -*/ > -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler *sched, > - struct drm_sched_entity *entity) > -{ > - return entity->rq != NULL && > - entity->rq->sched == sched; > -} > - > /** > * drm_sched_entity_is_idle - Check if entity is idle > * > @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) > { > rmb(); > > - if (!entity->rq || spsc_queue_peek(&entity->job_queue) == NULL) > + if (list_empty(&entity->list) || > + spsc_queue_peek(&entity->job_queue) == NULL) > return true; > > return false; > @@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) > long ret = timeout; > > sched = entity->rq->sched; > - if (!drm_sched_entity_is_initialized(sched, entity)) > - return ret; > /** > * The client will not queue more IBs during this fini, consume existing > * queued IBs or discard them on SIGKILL > @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) > last_user = cmpxchg(&entity->last_user, current->group_leader, NULL); > if ((!last_user || last_user == current->group_leader) && > (current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) > - drm_sched_entity_set_rq(entity, NULL); > + drm_sched_rq_remove_entity(entity->rq, entity); > > return ret; > } > @@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity *entity) > struct drm_gpu_scheduler *sched; > > sched = entity->rq->sched; > - drm_sched_entity_set_rq(entity, NULL); > + drm_sched_rq_remove_entity(entity->rq, entity); > > /* Consumption of existing IBs wasn't completed. Forcefully > * remove them here. > @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct drm_sched_entity *entity, > if (entity->rq == rq) > return; > > - spin_lock(&entity->rq_lock); > - > - if (entity->rq) > - drm_sched_rq_remove_entity(entity->rq, entity); > + BUG_ON(!rq); > > + spin_lock(&entity->rq_lock); > + drm_sched_rq_remove_entity(entity->rq, entity); > entity->rq = rq; > - if (rq) > - drm_sched_rq_add_entity(rq, entity); > - > + drm_sched_rq_add_entity(rq, entity); > spin_unlock(&entity->rq_lock); > } > EXPORT_SYMBOL(drm_sched_entity_set_rq);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/2] drm/scheduler: stop setting rq to NULL
Quoted 45 lines · Andrey Grodzovsky
On 08/03/2018 08:12 AM, Nayan Deshmukh wrote:
Quoted 27 lines · Andrey Grodzovsky
On 08/02/2018 02:43 AM, Nayan Deshmukh wrote:
Hi Andrey,
Good catch. I guess since both Christian and I were working on it parallelly we didn't catch this problem.
If it is only causing a problem in
push_jobthen we can handle it something like this:----------------------------------------------------------------------------------------------------------------------------
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-0@@ -563,6 +563,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job, first =spsc_queue_count (&entity->job_queue) ==0 ; reschedule = idle && first && (entity->num_rq_list >1 ); +if (first &&list_empty (&entity->list)) {Quoted 6 lines
first might be false if the other process interrupted by SIGKILL in middle of
wait_event_killableindrm_sched_entity_flushwhen there were still item in queue.
I don't see a good way besides adding a 'stopped' flag todrm_sched_enitity.Sorry I missed this mail. This case might happen but this was also not being handled previously.
Quoted 8 lines
Nayan
The original code before 'drm/scheduler: stop setting rq to NULL' was , because you didn't use the queue's emptiness as a criteria for aborting your next push to queue but rather
checking forentity->rq!= NULL.
But (entity->rq != NULL) check was inside the body of if (first) so it was also dependent on the queue's emptiness earlier. Well in any case it doesn't matter now as with Christian's patch we can remove the if condition altogether.
Nayan
Quoted 182 lines
Andrey
Quoted 177 lines
Andrey
drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-5+DRM_ERROR ("Trying to push to a killed entity\n" ); +return ; + } +if (reschedule) { rq =drm_sched_entity_get_free_sched (entity);spin_lock (&entity->rq_lock);@@ -580,11 +585,6 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job, if (first) {/* Add the entity to the run queue */ spin_lock (&entity->rq_lock); -if (!entity->rq) { -DRM_ERROR ("Trying to push to a killed entity\n" ); -spin_unlock (&entity->rq_lock); -return ; - }drm_sched_rq_add_entity (entity->rq, entity);spin_unlock (&entity->rq_lock);drm_sched_wakeup(entity->rq->sched);-----------------------------------------------------------------------------------------------------------------------------
Quoted 19 lines · Andrey Grodzovsky
Thinking again about this change and 53d5f1e drm/scheduler: move idle entities to scheduler with less load v2
Looks to me like use case for which fc9a539 drm/scheduler: add NULL pointer check for run queue (v2) was done
will not work anymore.
First of all in
drm_sched_entity_push_job, 'if (!entity->rq)' will never be true any more since we stoppedentity->rqto NULL in
drm_sched_entity_flush.Second of all, even after we removed the entity from rq in
drm_sched_entity_flushto terminate any subsequent submissionsto the queue the other thread doing push job can just acquire again a run queue
Quoted 7 lines
from
drm_sched_entity_get_free_schedand continue submission so you can't substitute ' if (!entity->rq)' to 'if (list_empty(&entity->list))'.What about adding a 'stopped' flag to
drm_sched_entityto be set indrm_sched_entity_flushand inBut it might be worth adding a stopped flag field if it is required at
other places as well.
Thanks,
NayanQuoted 116 lines
drm_sched_entity_push_jobcheck for 'if (!entity->stopped)' instead of ' if (!entity->rq)' ?Andrey
Quoted 9 lines · Christian König
We removed the redundancy of having an extra scheduler field, so we can't set the rq to NULL any more or otherwise won't know which scheduler to use for the cleanup.
Just remove the entity from the scheduling list instead.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 35+++++++------------------------
Review
Quoted 3 lines
1 file changed, 8 insertions(+), 27 deletions(-)(quoted diff) +0
-0
b/drivers/gpu/drm/scheduler/gpu_scheduler.cdrivers/gpu/drm/scheduler/gpu_scheduler.c int drm_sched_entity_init(struct drm_sched_entity
Quoted 4 lines
index
f563e4fbb4b6..1b733229201e100644drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0@@ -198,21 +198,6 @@ int drm_sched_entity_init(struct drm_sched_entity*entity,
drivers/gpu/drm/scheduler/gpu_scheduler.c int drm_sched_entity_init(struct drm_sched_entity · line 209
Quoted 12 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-9}EXPORT_SYMBOL (drm_sched_entity_init); -/** -* drm_sched_entity_is_initialized - Query if entity is initialized -* -* @sched: Pointer to scheduler instance -* @entity: The pointer to a valid scheduler entity -* -* return true if entity is initialized, false otherwise -*/ -static bool drm_sched_entity_is_initialized(struct drm_gpu_scheduler*sched,
drivers/gpu/drm/scheduler/gpu_scheduler.c int drm_sched_entity_init(struct drm_sched_entity · line 210
Quoted 1 line
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-1-struct drm_sched_entity *entity)
drivers/gpu/drm/scheduler/gpu_scheduler.c static bool drm_sched_entity_is_idle(struct
Quoted 9 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-5-{ -return entity->rq !=NULL && - entity->rq->sched == sched; -} -/** * drm_sched_entity_is_idle - Check if entity is idle * @@ -224,7 +209,8 @@ static bool drm_sched_entity_is_idle(struct
drm_sched_entity*entity)drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct
Quoted 10 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-1{rmb (); -if (!entity->rq ||spsc_queue_peek (&entity->job_queue) ==NULL ) +if (list_empty (&entity->list) || +spsc_queue_peek (&entity->job_queue) ==NULL )return true;return false;@@ -279,8 +265,6 @@ long drm_sched_entity_flush(struct
drm_sched_entity*entity, long timeout)drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct · line 269
Quoted 7 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-2long ret = timeout; sched = entity->rq->sched; -if (!drm_sched_entity_is_initialized (sched, entity)) -return ret;/** * The client will not queue more IBs during this fini, consume existing
drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct
Quoted 2 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0* queued IBs or discard them on SIGKILL @@ -299,7 +283,7 @@ long drm_sched_entity_flush(struct
drm_sched_entity*entity, long timeout)drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct · line 283
Quoted 1 line
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0last_user = cmpxchg(&entity->last_user, current->group_leader,NULL);
drivers/gpu/drm/scheduler/gpu_scheduler.c long drm_sched_entity_flush(struct · line 285
Quoted 2 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +0
-0if ((!last_user || last_user == current->group_leader) && (current->flags & PF_EXITING) && (current->exit_code ==SIGKILL))
drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_fini(struct drm_sched_entity
Quoted 6 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-1-drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);return ret; }@@ -320,7 +304,7 @@ void drm_sched_entity_fini(struct drm_sched_entity*entity)
drivers/gpu/drm/scheduler/gpu_scheduler.c void drm_sched_entity_set_rq(struct
Quoted 9 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-1struct drm_gpu_scheduler *sched; sched = entity->rq->sched; -drm_sched_entity_set_rq (entity,NULL ); +drm_sched_rq_remove_entity (entity->rq, entity);/* Consumption of existing IBs wasn't completed. Forcefully * remove them here. @@ -416,15 +400,12 @@ void drm_sched_entity_set_rq(struct
drm_sched_entity*entity,Quoted 19 lines
drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-7if (entity->rq == rq)return ; -spin_lock (&entity->rq_lock); - -if (entity->rq) -drm_sched_rq_remove_entity (entity->rq, entity); +BUG_ON (!rq); +spin_lock (&entity->rq_lock); +drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq; -if (rq) -drm_sched_rq_add_entity (rq, entity); - +drm_sched_rq_add_entity (rq, entity);spin_unlock (&entity->rq_lock); }EXPORT_SYMBOL (drm_sched_entity_set_rq);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Christian,
The code looks good to me. But I was just wondering what will happen when the last user is killed and some other user tries to push to the entity.
Regards,
Nayan Deshmukh
Quoted 75 lines · Christian König
Note which task is using the entity and only kill it if the last user of the entity is killed. This should prevent problems when entities are leaked to
child processes.v2: add missing kernel doc
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 6 +++++- include/drm/gpu_scheduler.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-0@@ -275,6 +275,7 @@ static void drm_sched_entity_kill_jobs_cb(structdma_fence *f, long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) { struct drm_gpu_scheduler *sched; +struct task_struct *last_user;long ret = timeout;sched = entity->rq->sched;drivers/gpu/drm/scheduler/gpu_scheduler.c +3
-1@@ -295,7 +296,9 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)/* For killed process disable any more IBs enqueue right now */ -if ((current->flags &PF_EXITING ) && (current->exit_code == SIGKILL)) + last_user =cmpxchg (&entity->last_user, current->group_leader,NULL ); + if ((!last_user || last_user == current->group_leader) && + (current->flags & PF_EXITING) && (current->exit_code ==SIGKILL))
drm_sched_entity_set_rq(entity, NULL); return ret;drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-0@@ -541,6 +544,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,trace_drm_sched_job (sched_job, entity); +WRITE_ONCE (entity->last_user, current->group_leader); first =spsc_queue_push (&entity->job_queue, &sched_job->queue_node);/* first job wakes up scheduler */include/drm/gpu_scheduler.h +0
-0@@ -66,6 +66,7 @@ enum drm_sched_priority {* @guilty: points to ctx's guilty. * @fini_status: contains the exit status in case the process was signalled.
* @last_scheduled: points to the finished fence of the last scheduled
job.
+ * @last_user: last group leader pushing a job into the entity. *
* Entities will emit jobs in order to their corresponding hardware
* ring, and the scheduler will alternate between entities based oninclude/drm/gpu_scheduler.h +1
-1@@ -85,6 +86,7 @@ struct drm_sched_entity {struct dma_fence_cb cb;atomic_t *guilty;struct dma_fence *last_scheduled; +struct task_struct *last_user; };/** --
Quoted 3 lines
2.14.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
I believe that in this case
if (!entity->rq) {
DRM_ERROR...
return;
}
clause will take place.
P.S I remember we planned to actually propagate the error back to the caller so i guess we should take care of this sooner or later.
The change is Reviewed-by: Andrey Grodzovsky <[email protected]>
Andrey
Quoted 92 lines · Nayan Deshmukh
Hi Christian,
The code looks good to me. But I was just wondering what will happen when the last user is killed and some other user tries to push to the entity.
Regards,
Nayan DeshmukhOn Mon, Jul 30, 2018 at 4:33 PM Christian König <[email protected] <mailto:[email protected]>> wrote:
Note which task is using the entity and only kill it if the last user of the entity is killed. This should prevent problems when entities are leaked to child processes. v2: add missing kernel doc Signed-off-by: Christian König <[email protected] <mailto:[email protected]>> --- drivers/gpu/drm/scheduler/gpu_scheduler.c | 6 +++++- include/drm/gpu_scheduler.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/scheduler/gpu_scheduler.c b/drivers/gpu/drm/scheduler/gpu_scheduler.c index 3f2fc5e8242a..f563e4fbb4b6 100644 --- a/drivers/gpu/drm/scheduler/gpu_scheduler.c +++ b/drivers/gpu/drm/scheduler/gpu_scheduler.c @@ -275,6 +275,7 @@ static void drm_sched_entity_kill_jobs_cb(struct dma_fence *f, long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) { struct drm_gpu_scheduler *sched; + struct task_struct *last_user; long ret = timeout; sched = entity->rq->sched; @@ -295,7 +296,9 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) /* For killed process disable any more IBs enqueue right now */ - if ((current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) + last_user = cmpxchg(&entity->last_user, current->group_leader, NULL); + if ((!last_user || last_user == current->group_leader) && + (current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) drm_sched_entity_set_rq(entity, NULL); return ret; @@ -541,6 +544,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job, trace_drm_sched_job(sched_job, entity); + WRITE_ONCE(entity->last_user, current->group_leader); first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node); /* first job wakes up scheduler */ diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h index 091b9afcd184..21c648b0b2a1 100644 --- a/include/drm/gpu_scheduler.h +++ b/include/drm/gpu_scheduler.h @@ -66,6 +66,7 @@ enum drm_sched_priority { * @guilty: points to ctx's guilty. * @fini_status: contains the exit status in case the process was signalled. * @last_scheduled: points to the finished fence of the last scheduled job. + * @last_user: last group leader pushing a job into the entity. * * Entities will emit jobs in order to their corresponding hardware * ring, and the scheduler will alternate between entities based on @@ -85,6 +86,7 @@ struct drm_sched_entity { struct dma_fence_cb cb; atomic_t *guilty; struct dma_fence *last_scheduled; + struct task_struct *last_user; }; /** -- 2.14.1
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
That makes sense. The change is Acked-by: Nayan Deshmukh < [email protected]>
Quoted 107 lines · Andrey Grodzovsky
I believe that in this case
if (!entity->rq) {
DRM_ERROR... return;}
clause will take place.
P.SI remember we planned to actually propagate the error back to the caller so i guess we should take care of this sooner or later.The change is Reviewed-by: Andrey Grodzovsky <[email protected]> <[email protected]>
Andrey
On 07/30/2018 09:34 AM, Nayan Deshmukh wrote:
Hi Christian,
The code looks good to me. But I was just wondering what will happen when the last user is killed and some other user tries to push to the entity.
Regards,
Nayan DeshmukhQuoted 74 lines · Christian König
Note which task is using the entity and only kill it if the last user of the entity is killed. This should prevent problems when entities are leaked to
child processes.v2: add missing kernel doc
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/scheduler/gpu_scheduler.c | 6 +++++- include/drm/gpu_scheduler.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-0@@ -275,6 +275,7 @@ static void drm_sched_entity_kill_jobs_cb(structdma_fence *f, long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) { struct drm_gpu_scheduler *sched; +struct task_struct *last_user;long ret = timeout;sched = entity->rq->sched;drivers/gpu/drm/scheduler/gpu_scheduler.c +3
-1@@ -295,7 +296,9 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)/* For killed process disable any more IBs enqueue right now */ -if ((current->flags &PF_EXITING ) && (current->exit_code == SIGKILL)) + last_user =cmpxchg (&entity->last_user, current->group_leader,NULL ); + if ((!last_user || last_user == current->group_leader) && + (current->flags & PF_EXITING) && (current->exit_code ==SIGKILL))
drm_sched_entity_set_rq(entity, NULL); return ret;drivers/gpu/drm/scheduler/gpu_scheduler.c +1
-0@@ -541,6 +544,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job,trace_drm_sched_job (sched_job, entity); +WRITE_ONCE (entity->last_user, current->group_leader); first =spsc_queue_push (&entity->job_queue, &sched_job->queue_node);/* first job wakes up scheduler */include/drm/gpu_scheduler.h +0
-0@@ -66,6 +66,7 @@ enum drm_sched_priority {* @guilty: points to ctx's guilty. * @fini_status: contains the exit status in case the process was signalled.
* @last_scheduled: points to the finished fence of the last scheduled
job.
+ * @last_user: last group leader pushing a job into the entity. *
* Entities will emit jobs in order to their corresponding hardware
* ring, and the scheduler will alternate between entities based oninclude/drm/gpu_scheduler.h +1
-0@@ -85,6 +86,7 @@ struct drm_sched_entity {struct dma_fence_cb cb;atomic_t *guilty;struct dma_fence *last_scheduled; +struct task_struct *last_user; };
Quoted 11 lines
Quoted 5 lines
include/drm/gpu_scheduler.h +0
-1/** -- 2.14.1
_______________________________________________
dri-devel mailing [email protected]://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel