drm/gpu-sched: fix force APP kill hang(v3)
Subsystems (4)
PATCH 1/1 drm/gpu-sched: fix force APP kill hang(v3)
issue:
there are VMC page fault occurred if force APP kill during 3dmark test, the cause is in entity_fini we manually signal all those jobs in entity's queue which confuse the sync/dep mechanism:
1)page fault occurred in sdma's clear job which operate on shadow buffer, and shadow buffer's Gart table is cleaned by ttm_bo_release since the fence in its reservation was fake signaled by entity_fini() under the case of SIGKILL received.
2)page fault occurred in gfx' job because during the lifetime of gfx job we manually fake signal all jobs from its entity in entity_fini(), thus the unmapping/clear PTE job depend on those result fence is satisfied and sdma start clearing the PTE and lead to GFX page fault.
fix:
1)should at least wait all jobs already scheduled complete in entity_fini() if SIGKILL is the case.
2)if a fence signaled and try to clear some entity's dependency, should set this entity guilty to prevent its job really run since the dependency is fake signaled.
v2:
splitting drm_sched_entity_fini() into two functions:
1)The first one is does the waiting, removes the entity from the runqueue and returns an error when the process was killed. 2)The second one then goes over the entity, install it as completion signal for the remaining jobs and signals all jobs with an error code.
v3:
1)Replace the fini1 and fini2 with better name 2)Call the first part before the VM teardown in amdgpu_driver_postclose_kms() and the second part after the VM teardown
3)Keep the original function drm_sched_entity_fini to refine the code.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 64 ++++++++++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 5 ++- drivers/gpu/drm/scheduler/gpu_scheduler.c | 74 ++++++++++++++++++++++++++----- include/drm/gpu_scheduler.h | 7 +++ 5 files changed, 131 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -681,6 +681,8 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,int amdgpu_ctx_wait_prev_fence (struct amdgpu_ctx *ctx,unsigned ring_id);void amdgpu_ctx_mgr_init (struct amdgpu_ctx_mgr *mgr); +void amdgpu_ctx_mgr_entity_cleanup (struct amdgpu_ctx_mgr *mgr); +void amdgpu_ctx_mgr_entity_fini (struct amdgpu_ctx_mgr *mgr);void amdgpu_ctx_mgr_fini (struct amdgpu_ctx_mgr *mgr);
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +56 -8
105 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -2
@@ -913,8 +913,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,return ;pm_runtime_get_sync (dev->dev); - -amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +amdgpu_ctx_mgr_entity_fini (&fpriv->ctx_mgr);if (adev->asic_type !=CHIP_RAVEN ) {amdgpu_uvd_free_handles (adev, file_priv);
@@ -935,6 +934,8 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, pd =amdgpu_bo_ref (fpriv->vm.root.base.bo);amdgpu_vm_fini (adev, &fpriv->vm); +amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +if (pasid)amdgpu_pasid_free_delayed (pd->tbo.resv, pasid);amdgpu_bo_unref (&pd);
drivers/gpu/drm/scheduler/gpu_scheduler.c +63 -11
132 lines not on this page · raw message
include/drm/gpu_scheduler.h +7 -0
@@ -65,6 +65,8 @@ struct drm_sched_entity {struct dma_fence *dependency;struct dma_fence_cb cb;atomic_t *guilty;/* points to ctx's guilty */ +uint32_t fini_status; +struct dma_fence *finished; };/**
@@ -119,6 +121,7 @@ struct drm_sched_job {uint64_t id;atomic_t karma;enum drm_sched_priority s_priority; +struct drm_sched_entity *entity; }; static inline bool drm_sched_invalidate_job(struct drm_sched_job *s_job,
@@ -186,6 +189,10 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity, struct drm_sched_rq *rq, uint32_t jobs, atomic_t *guilty); +void drm_sched_entity_do_release (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity); +void drm_sched_entity_cleanup (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity);void drm_sched_entity_fini (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity); void drm_sched_entity_push_job(struct drm_sched_job *sched_job,
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1523528532-12927-1-git-send-email-Emily.Deng-5C7GfCeVMHo@public.gmane.org
Ping....
Best Wishes,
Emily Deng
Quoted 402 lines
-----Original Message-----
From: Emily Deng [mailto:[email protected]]
Sent: Thursday, April 12, 2018 6:22 PM
To: [email protected]
Cc: Deng, Emily <[email protected]>; Liu, Monk <[email protected]>
Subject: [PATCH] drm/gpu-sched: fix force APP kill hang(v3)issue:
there are VMC page fault occurred if force APP kill during 3dmark test, the cause is inentity_finiwe manually signal all those jobs in entity's queue which confuse the sync/dep
mechanism:1)page fault occurred in sdma's clear job which operate on shadow buffer, and shadow buffer's Gart table is cleaned by
ttm_bo_releasesince the fence in its reservation was fake signaled byentity_fini()under the case of SIGKILL received.2)page fault occurred in gfx' job because during the lifetime of gfx job we manually fake signal all jobs from its entity in
entity_fini(), thus the unmapping/clear PTE job depend on those result fence is satisfied and sdma start clearing the PTE and lead to GFX page fault.fix:
1)should at least wait all jobs already scheduled complete inentity_fini()if SIGKILL is the case.2)if a fence signaled and try to clear some entity's dependency, should set this entity guilty to prevent its job really run since the dependency is fake signaled.
v2:
splittingdrm_sched_entity_fini()into two functions:
1)The first one is does the waiting, removes the entity from the runqueue and returns an error when the process was killed.
2)The second one then goes over the entity, install it as completion signal for the remaining jobs and signals all jobs with an error code.v3:
1)Replace the fini1 and fini2 with better name 2)Call the first part before the VM teardown inamdgpu_driver_postclose_kms()and the second part after the VM teardown 3)Keep the original functiondrm_sched_entity_finito refine the code.Signed-off-by Monk Liu <[email protected]>Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 64 ++++++++++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 5 ++- drivers/gpu/drm/scheduler/gpu_scheduler.c | 74 ++++++++++++++++++++++++++----- include/drm/gpu_scheduler.h | 7 +++ 5 files changed, 131 insertions(+), 21 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -681,6 +681,8 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data, int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx, unsigned ring_id);void amdgpu_ctx_mgr_init (struct amdgpu_ctx_mgr *mgr); +void amdgpu_ctx_mgr_entity_cleanup (struct amdgpu_ctx_mgr *mgr);void +amdgpu_ctx_mgr_entity_fini (struct amdgpu_ctx_mgr *mgr);void amdgpu_ctx_mgr_fini (struct amdgpu_ctx_mgr *mgr);drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +5
-5@@ -111,8 +111,9 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev, return r; } -static void amdgpu_ctx_fini (struct amdgpu_ctx *ctx) +static void amdgpu_ctx_fini (struct kref *ref) { + struct amdgpu_ctx *ctx = container_of(ref, struct amdgpu_ctx, +refcount);struct amdgpu_device *adev = ctx->adev;unsigned i, j;@@ -125,13 +126,11 @@ static void amdgpu_ctx_fini(struct amdgpu_ctx *ctx)kfree (ctx->fences); ctx->fences =NULL ; -for (i =0 ; i < adev->num_rings; i++) -drm_sched_entity_fini (&adev->rings[i]->sched, - &ctx->rings[i].entity); -amdgpu_queue_mgr_fini (adev, &ctx->queue_mgr);mutex_destroy (&ctx->lock); + +kfree (ctx); }static int amdgpu_ctx_alloc(struct
amdgpu_device*adev, @@ -170,12
+169,15 @@ static int amdgpu_ctx_alloc(structamdgpu_device*adev, static voidamdgpu_ctx_do_release(struct kref *ref){drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +5
-2struct amdgpu_ctx *ctx; +u32 i; ctx = container_of(ref, struct amdgpu_ctx, refcount); -amdgpu_ctx_fini (ctx); +for (i =0 ; i < ctx->adev->num_rings; i++) +drm_sched_entity_fini (&ctx->adev->rings[i]->sched, + &ctx->rings[i].entity); -kfree (ctx); +amdgpu_ctx_fini (ref); } static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id) @@ -435,16 +437,62 @@ void
amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +15
-0idr_init (&mgr->ctx_handles); } +void amdgpu_ctx_mgr_entity_fini (struct amdgpu_ctx_mgr *mgr) { +struct amdgpu_ctx *ctx; +struct idr *idp; +uint32_t id, i; + + idp = &mgr->ctx_handles; + +idr_for_each_entry (idp, ctx, id) { + +if (!ctx->adev) +return ; + +for (i =0 ; i < ctx->adev->num_rings; i++) +if (kref_read (&ctx->refcount) ==1 ) + drm_sched_entity_do_release(&ctx->adev-Quoted 1 line
rings[i]->sched,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +21
-0+ &ctx->rings[i].entity); + else + DRM_ERROR("ctx %p is still alive\n", ctx); + } +} + +void amdgpu_ctx_mgr_entity_cleanup (struct amdgpu_ctx_mgr *mgr) { +struct amdgpu_ctx *ctx; +struct idr *idp; +uint32_t id, i; + + idp = &mgr->ctx_handles; + +idr_for_each_entry (idp, ctx, id) { + +if (!ctx->adev) +return ; + +for (i =0 ; i < ctx->adev->num_rings; i++) +if (kref_read (&ctx->refcount) ==1 ) + drm_sched_entity_cleanup(&ctx->adev-Quoted 1 line
rings[i]->sched,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +9
-1+ &ctx->rings[i].entity); + else + DRM_ERROR("ctx %p is still alive\n", ctx); + } +} +void amdgpu_ctx_mgr_fini (struct amdgpu_ctx_mgr *mgr) {struct amdgpu_ctx *ctx;struct idr *idp;uint32_t id; +amdgpu_ctx_mgr_entity_cleanup (mgr); + idp = &mgr->ctx_handles;idr_for_each_entry (idp, ctx, id) { -if (kref_put (&ctx->refcount, amdgpu_ctx_do_release) !=1 ) +if (kref_put (&ctx->refcount, amdgpu_ctx_fini) !=1 )DRM_ERROR ("ctx %p is still alive\n" , ctx); }drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1
-2@@ -913,8 +913,7 @@ void amdgpu_driver_postclose_kms(structdrm_device *dev, return;pm_runtime_get_sync (dev->dev); - -amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +amdgpu_ctx_mgr_entity_fini (&fpriv->ctx_mgr);if (adev->asic_type !=CHIP_RAVEN ) {drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3
-0amdgpu_uvd_free_handles(adev, file_priv); @@ -935,6 +934,8 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, pd = amdgpu_bo_ref(fpriv->vm.root.base.bo);amdgpu_vm_fini (adev, &fpriv->vm); +amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +if (pasid)amdgpu_pasid_free_delayed (pd->tbo.resv, pasid);amdgpu_bo_unref (&pd);drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-0@@ -136,6 +136,8 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched, entity->rq = rq; entity->sched = sched; entity->guilty = guilty; + entity->fini_status =0 ; + entity->finished =NULL ;spin_lock_init (&entity->rq_lock);drivers/gpu/drm/scheduler/gpu_scheduler.c +15
-1spin_lock_init (&entity->queue_lock);@@ -197,19 +199,30 @@ static bool drm_sched_entity_is_ready(struct drm_sched_entity *entity)return true; } +static void drm_sched_entity_fini_job_cb (struct dma_fence *f, +struct dma_fence_cb *cb) +{ + struct drm_sched_job *job = container_of(cb, struct drm_sched_job, + finish_cb); +drm_sched_fence_finished (job->s_fence); +WARN_ON (job->s_fence->parent); +dma_fence_put (&job->s_fence->finished); + job->sched->ops->free_job (job); +} + +/** * Destroy a context entity * * @sched Pointer to scheduler instance * @entity The pointer to a valid scheduler entity * -* Cleanup and free the allocated resources. +* Splitting drm_sched_entity_fini() into two functions, The first one +is does the waiting, +* removes the entity from the runqueue and returns an error when the process was killed.
*/drivers/gpu/drm/scheduler/gpu_scheduler.c +13
-6-void drm_sched_entity_fini (struct drm_gpu_scheduler *sched, +void drm_sched_entity_do_release (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity) { -int r; -if (!drm_sched_entity_is_initialized (sched, entity))return ;/** @@ -217,13 +230,28 @@ void drm_sched_entity_fini(structdrm_gpu_scheduler *sched, * queued IBs or discard them on SIGKILL */ if ((current->flags &PF_SIGNALED ) && current->exit_code ==SIGKILL ) - r = -ERESTARTSYS ; + entity->fini_status = -ERESTARTSYS ;else - r =wait_event_killable (sched->job_scheduled, + entity->fini_status =wait_event_killable (sched- >job_scheduled,drm_sched_entity_is_idle (entity));drm_sched_entity_set_rq (entity,NULL ); -if (r) { +} +EXPORT_SYMBOL (drm_sched_entity_do_release); + +/** +* Destroy a context entity +* +* @sched Pointer to scheduler instance +* @entity The pointer to a valid scheduler entity +* +* The second one then goes over the entity and signals all jobs with an error code.
+ */drivers/gpu/drm/scheduler/gpu_scheduler.c +5
-0+void drm_sched_entity_cleanup (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity) +{ +if (entity->fini_status) {struct drm_sched_job *job; +int r;/* Park the kernel for a moment to make sure it isn't processing
drivers/gpu/drm/scheduler/gpu_scheduler.c +18
-4* our enity. @@ -241,13 +269,28 @@ void drm_sched_entity_fini(structdrm_gpu_scheduler *sched, struct drm_sched_fence *s_fence = job->s_fence;drm_sched_fence_scheduled (s_fence);dma_fence_set_error (&s_fence->finished, -ESRCH ); -drm_sched_fence_finished (s_fence); -WARN_ON (s_fence->parent); -dma_fence_put (&s_fence->finished); - sched->ops->free_job (job); + r =dma_fence_add_callback (entity->finished, &job- >finish_cb, + drm_sched_entity_fini_job_cb); +if (r == -ENOENT ) +drm_sched_entity_fini_job_cb (entity- >finished, &job->finish_cb); +else if (r) +DRM_ERROR ("fence add callback failed (%d)\n", r); + } + +if (entity->finished) { +dma_fence_put (entity->finished); + entity->finished =NULL ; } } } +EXPORT_SYMBOL (drm_sched_entity_cleanup); + +void drm_sched_entity_fini (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity) +{ +drm_sched_entity_do_release (sched, entity); +drm_sched_entity_cleanup (sched, entity); }EXPORT_SYMBOL (drm_sched_entity_fini); static void drm_sched_entity_wakeup(struct dma_fence *f, struct
dma_fence_cb*cb) @@ -530,6 +573,11 @@ voiddrm_sched_job_recovery(struct drm_gpu_scheduler *sched)drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0spin_unlock (&sched->job_list_lock); fence = sched->ops->run_job (s_job);atomic_inc (&sched->hw_rq_count); + +if (s_job->entity->finished) +dma_fence_put (s_job->entity->finished); + s_job->entity->finished = dma_fence_get(&s_fence-Quoted 1 line
finished);
drivers/gpu/drm/scheduler/gpu_scheduler.c +5
-0+if (fence) { s_fence->parent =dma_fence_get (fence); r = dma_fence_add_callback(fence, &s_fence->cb,@@ -556,6 +604,7 @@ int drm_sched_job_init(struct drm_sched_job *job, void *owner) { job->sched = sched; + job->entity = entity; job->s_priority = entity->rq - sched->sched_rq; job->s_fence =drm_sched_fence_create (entity, owner);if (!job->s_fence)@@ -668,6 +717,9 @@ static int drm_sched_main(void *param) fence = sched->ops->run_job (sched_job);drm_sched_fence_scheduled (s_fence); +if (entity->finished) +dma_fence_put (entity->finished); + entity->finished =dma_fence_get (&s_fence->finished);if (fence) { s_fence->parent = dma_fence_get(fence); diff --git
a/include/drm/gpu_scheduler.hb/include/drm/gpu_scheduler.hindex c053a32..a0dd947 100644include/drm/gpu_scheduler.h +7
-0@@ -65,6 +65,8 @@ struct drm_sched_entity {struct dma_fence *dependency;struct dma_fence_cb cb;atomic_t *guilty;/* points to ctx's guilty */ +uint32_t fini_status; +struct dma_fence *finished; };/** @@ -119,6 +121,7 @@ struct drm_sched_job {uint64_t id;atomic_t karma;enum drm_sched_priority s_priority; +struct drm_sched_entity *entity; }; static inline bool drm_sched_invalidate_job(struct drm_sched_job *s_job,@@ -186,6 +189,10 @@ int drm_sched_entity_init(structdrm_gpu_scheduler *sched, struct drm_sched_entity *entity, struct drm_sched_rq *rq, uint32_t jobs, atomic_t *guilty); +void drm_sched_entity_do_release (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity);void +drm_sched_entity_cleanup (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity);void drm_sched_entity_fini (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity);void
Quoted 3 lines
drm_sched_entity_push_job(struct
drm_sched_job*sched_job, --
2.7.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CY4PR12MB112549115E05700C66DE25F18FB30-rpdhrqHFk07v2MZdTKcfDgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
Hi Christian & Emily
This v3 version looks pretty good to me, but still some parts need to improve:
e.g.
1)entity->finished doesn't presenting what it really means, better rename it to entity->last_scheduled.
2)drm_sched_entity_fini_job_cb() better renamed to drm_sched_entity_kill_jobs_cb()
3) no need to pass "entity->finished" (line275 of gpu_schedulers.c) to drm_sched_entity_fini_job_cb() if -ENOENT returned after dma_fence_add_callback since this parm is not needed at all in this callback routine
4)better change type of entity->fini_status to "int" instead of "uint32_t" ... it should be aligned with the return type of wait_event_killable()
5)
+ if (entity->finished) {
+ dma_fence_put(entity->finished);
+ entity->finished = NULL;
}
no need to check entity->finished because dma_fence_put() will do it inside...
and the same here in job_recovery:
+
+ if (s_job->entity->finished)
+ dma_fence_put(s_job->entity->finished);
and the same here in sched_main:
+ if (entity->finished)
+ dma_fence_put(entity->finished);
6) why put amdgpu_ctx_mgr_fini() beneath amdgpu_vm_fini() ? any reason for that ?
thanks
/Monk
Quoted 398 lines · Emily
Ping....
Best Wishes,
Emily DengQuoted 390 lines
-----Original Message-----
From: Emily Deng [mailto:[email protected]]
Sent: Thursday, April 12, 2018 6:22 PM
To: [email protected]
Cc: Deng, Emily <[email protected]>; Liu, Monk <[email protected]>
Subject: [PATCH] drm/gpu-sched: fix force APP kill hang(v3)issue:
there are VMC page fault occurred if force APP kill during 3dmark test, the cause is inentity_finiwe manually signal all those jobs in entity's queue which confuse the sync/dep
mechanism:1)page fault occurred in sdma's clear job which operate on shadow buffer, and shadow buffer's Gart table is cleaned by
ttm_bo_releasesince the fence in its reservation was fake signaled byentity_fini()under the case of SIGKILL received.2)page fault occurred in gfx' job because during the lifetime of gfx job we manually fake signal all jobs from its entity in
entity_fini(), thus the unmapping/clear PTE job depend on those result fence is satisfied and sdma start clearing the PTE and lead to GFX page fault.fix:
1)should at least wait all jobs already scheduled complete inentity_fini()if SIGKILL is the case.2)if a fence signaled and try to clear some entity's dependency, should set this entity guilty to prevent its job really run since the dependency is fake signaled.
v2:
splittingdrm_sched_entity_fini()into two functions:
1)The first one is does the waiting, removes the entity from the runqueue and returns an error when the process was killed.
2)The second one then goes over the entity, install it as completion signal for the remaining jobs and signals all jobs with an error code.v3:
1)Replace the fini1 and fini2 with better name 2)Call the first part before the VM teardown inamdgpu_driver_postclose_kms()and the second part after the VM teardown 3)Keep the original functiondrm_sched_entity_finito refine the code.Signed-off-by Monk Liu <[email protected]>Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 64 ++++++++++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 5 ++- drivers/gpu/drm/scheduler/gpu_scheduler.c | 74 ++++++++++++++++++++++++++----- include/drm/gpu_scheduler.h | 7 +++ 5 files changed, 131 insertions(+), 21 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -681,6 +681,8 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data, int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx, unsigned ring_id);void amdgpu_ctx_mgr_init (struct amdgpu_ctx_mgr *mgr); +void amdgpu_ctx_mgr_entity_cleanup (struct amdgpu_ctx_mgr *mgr);void +amdgpu_ctx_mgr_entity_fini (struct amdgpu_ctx_mgr *mgr);void amdgpu_ctx_mgr_fini (struct amdgpu_ctx_mgr *mgr);drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +5
-5@@ -111,8 +111,9 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev, return r; } -static void amdgpu_ctx_fini (struct amdgpu_ctx *ctx) +static void amdgpu_ctx_fini (struct kref *ref) { + struct amdgpu_ctx *ctx = container_of(ref, struct amdgpu_ctx, +refcount);struct amdgpu_device *adev = ctx->adev;unsigned i, j;@@ -125,13 +126,11 @@ static void amdgpu_ctx_fini(struct amdgpu_ctx *ctx)kfree (ctx->fences); ctx->fences =NULL ; -for (i =0 ; i < adev->num_rings; i++) -drm_sched_entity_fini (&adev->rings[i]->sched, - &ctx->rings[i].entity); -amdgpu_queue_mgr_fini (adev, &ctx->queue_mgr);mutex_destroy (&ctx->lock); + +kfree (ctx); }static int amdgpu_ctx_alloc(struct
amdgpu_device*adev, @@ -170,12
+169,15 @@ static int amdgpu_ctx_alloc(structamdgpu_device*adev, static voidamdgpu_ctx_do_release(struct kref *ref){
structamdgpu_ctx*ctx;drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +5
-2+u32 i; ctx = container_of(ref, struct amdgpu_ctx, refcount); -amdgpu_ctx_fini (ctx); +for (i =0 ; i < ctx->adev->num_rings; i++) +drm_sched_entity_fini (&ctx->adev->rings[i]->sched, + &ctx->rings[i].entity); -kfree (ctx); +amdgpu_ctx_fini (ref); } static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id) @@ -435,16 +437,62 @@ void
amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
idr_init(&mgr->ctx_handles);
}drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +15
-0+void amdgpu_ctx_mgr_entity_fini (struct amdgpu_ctx_mgr *mgr) { +struct amdgpu_ctx *ctx; +struct idr *idp; +uint32_t id, i; + + idp = &mgr->ctx_handles; + +idr_for_each_entry (idp, ctx, id) { + +if (!ctx->adev) +return ; + +for (i =0 ; i < ctx->adev->num_rings; i++) +if (kref_read (&ctx->refcount) ==1 ) + drm_sched_entity_do_release(&ctx->adev-Quoted 1 line
rings[i]->sched,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +21
-0+ &ctx->rings[i].entity); + else + DRM_ERROR("ctx %p is still alive\n", ctx); + } +} + +void amdgpu_ctx_mgr_entity_cleanup (struct amdgpu_ctx_mgr *mgr) { +struct amdgpu_ctx *ctx; +struct idr *idp; +uint32_t id, i; + + idp = &mgr->ctx_handles; + +idr_for_each_entry (idp, ctx, id) { + +if (!ctx->adev) +return ; + +for (i =0 ; i < ctx->adev->num_rings; i++) +if (kref_read (&ctx->refcount) ==1 ) + drm_sched_entity_cleanup(&ctx->adev-Quoted 1 line
rings[i]->sched,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +9
-1+ &ctx->rings[i].entity); + else + DRM_ERROR("ctx %p is still alive\n", ctx); + } +} +void amdgpu_ctx_mgr_fini (struct amdgpu_ctx_mgr *mgr) {struct amdgpu_ctx *ctx;struct idr *idp;uint32_t id; +amdgpu_ctx_mgr_entity_cleanup (mgr); + idp = &mgr->ctx_handles;idr_for_each_entry (idp, ctx, id) { -if (kref_put (&ctx->refcount, amdgpu_ctx_do_release) !=1 ) +if (kref_put (&ctx->refcount, amdgpu_ctx_fini) !=1 )DRM_ERROR ("ctx %p is still alive\n" , ctx); }drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1
-2@@ -913,8 +913,7 @@ void amdgpu_driver_postclose_kms(structdrm_device *dev, return;pm_runtime_get_sync (dev->dev); - -amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +amdgpu_ctx_mgr_entity_fini (&fpriv->ctx_mgr);if (adev->asic_type !=CHIP_RAVEN ) {
amdgpu_uvd_free_handles(adev, file_priv); @@ -935,6
+934,8 @@ void amdgpu_driver_postclose_kms(structdrm_device*dev,
pd =amdgpu_bo_ref(fpriv->vm.root.base.bo);amdgpu_vm_fini(adev, &fpriv->vm);drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2
-0+amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +if (pasid)amdgpu_pasid_free_delayed (pd->tbo.resv, pasid);amdgpu_bo_unref (&pd);drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-0@@ -136,6 +136,8 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched, entity->rq = rq; entity->sched = sched; entity->guilty = guilty; + entity->fini_status =0 ; + entity->finished =NULL ;spin_lock_init (&entity->rq_lock);spin_lock_init(&entity->queue_lock);drivers/gpu/drm/scheduler/gpu_scheduler.c +15
-1@@ -197,19 +199,30 @@ static bool drm_sched_entity_is_ready(struct drm_sched_entity *entity)return true; } +static void drm_sched_entity_fini_job_cb (struct dma_fence *f, +struct dma_fence_cb *cb) +{ + struct drm_sched_job *job = container_of(cb, struct drm_sched_job, + finish_cb); +drm_sched_fence_finished (job->s_fence); +WARN_ON (job->s_fence->parent); +dma_fence_put (&job->s_fence->finished); + job->sched->ops->free_job (job); +} + +/** * Destroy a context entity * * @sched Pointer to scheduler instance * @entity The pointer to a valid scheduler entity * -* Cleanup and free the allocated resources. +* Splitting drm_sched_entity_fini() into two functions, The first one +is does the waiting, +* removes the entity from the runqueue and returns an error when the process was killed.
*/drivers/gpu/drm/scheduler/gpu_scheduler.c +13
-6-void drm_sched_entity_fini (struct drm_gpu_scheduler *sched, +void drm_sched_entity_do_release (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity) { -int r; -if (!drm_sched_entity_is_initialized (sched, entity))return ;/** @@ -217,13 +230,28 @@ void drm_sched_entity_fini(structdrm_gpu_scheduler *sched, * queued IBs or discard them on SIGKILL */ if ((current->flags &PF_SIGNALED ) && current->exit_code ==SIGKILL ) - r = -ERESTARTSYS ; + entity->fini_status = -ERESTARTSYS ;else - r =wait_event_killable (sched->job_scheduled, + entity->fini_status =wait_event_killable (sched- > job_scheduled,drm_sched_entity_is_idle (entity));drm_sched_entity_set_rq (entity,NULL ); -if (r) { +} +EXPORT_SYMBOL (drm_sched_entity_do_release); + +/** +* Destroy a context entity +* +* @sched Pointer to scheduler instance +* @entity The pointer to a valid scheduler entity +* +* The second one then goes over the entity and signals all jobs with an error code.
+ */drivers/gpu/drm/scheduler/gpu_scheduler.c +5
-0+void drm_sched_entity_cleanup (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity) +{ +if (entity->fini_status) {struct drm_sched_job *job; +int r;/* Park the kernel for a moment to make sure it isn't processing
* our enity.drivers/gpu/drm/scheduler/gpu_scheduler.c +18
-4@@ -241,13 +269,28 @@ void drm_sched_entity_fini(structdrm_gpu_scheduler *sched, struct drm_sched_fence *s_fence = job->s_fence;drm_sched_fence_scheduled (s_fence);dma_fence_set_error (&s_fence->finished, -ESRCH ); -drm_sched_fence_finished (s_fence); -WARN_ON (s_fence->parent); -dma_fence_put (&s_fence->finished); - sched->ops->free_job (job); + r =dma_fence_add_callback (entity->finished, &job- > finish_cb, + drm_sched_entity_fini_job_cb); +if (r == -ENOENT ) +drm_sched_entity_fini_job_cb (entity- > finished, &job->finish_cb); +else if (r) +DRM_ERROR ("fence add callback failed (%d)\n", r); + } + +if (entity->finished) { +dma_fence_put (entity->finished); + entity->finished =NULL ; } } } +EXPORT_SYMBOL (drm_sched_entity_cleanup); + +void drm_sched_entity_fini (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity) +{ +drm_sched_entity_do_release (sched, entity); +drm_sched_entity_cleanup (sched, entity); }EXPORT_SYMBOL (drm_sched_entity_fini); static void drm_sched_entity_wakeup(struct dma_fence *f, struct
dma_fence_cb*cb) @@ -530,6 +573,11 @@ voiddrm_sched_job_recovery(struct drm_gpu_scheduler *sched)
spin_unlock(&sched->job_list_lock); fence =sched->ops->run_job(s_job);atomic_inc(&sched->hw_rq_count);drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0+ +if (s_job->entity->finished) +dma_fence_put (s_job->entity->finished); + s_job->entity->finished = dma_fence_get(&s_fence-Quoted 1 line
finished);
drivers/gpu/drm/scheduler/gpu_scheduler.c +5
-0+if (fence) { s_fence->parent =dma_fence_get (fence); r = dma_fence_add_callback(fence, &s_fence->cb,@@ -556,6 +604,7 @@ int drm_sched_job_init(struct drm_sched_job *job, void *owner) { job->sched = sched; + job->entity = entity; job->s_priority = entity->rq - sched->sched_rq; job->s_fence =drm_sched_fence_create (entity, owner);if (!job->s_fence)@@ -668,6 +717,9 @@ static int drm_sched_main(void *param) fence = sched->ops->run_job (sched_job);drm_sched_fence_scheduled (s_fence); +if (entity->finished) +dma_fence_put (entity->finished); + entity->finished =dma_fence_get (&s_fence->finished);if (fence) { s_fence->parent = dma_fence_get(fence); diff --git
a/include/drm/gpu_scheduler.hb/include/drm/gpu_scheduler.hindex c053a32..a0dd947 100644include/drm/gpu_scheduler.h +3
-0@@ -65,6 +65,8 @@ struct drm_sched_entity {struct dma_fence *dependency;struct dma_fence_cb cb;atomic_t *guilty;/* points to ctx's guilty */ +uint32_t fini_status; +struct dma_fence *finished; };/** @@ -119,6 +121,7 @@ struct drm_sched_job {uint64_t id;atomic_t karma;enum drm_sched_priority s_priority; +struct drm_sched_entity *entity; };
Quoted 15 lines
Quoted 12 lines
include/drm/gpu_scheduler.h +4
-0static inline bool drm_sched_invalidate_job(struct drm_sched_job *s_job,@@ -186,6 +189,10 @@ int drm_sched_entity_init(structdrm_gpu_scheduler *sched, struct drm_sched_entity *entity, struct drm_sched_rq *rq, uint32_t jobs, atomic_t *guilty); +void drm_sched_entity_do_release (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity);void +drm_sched_entity_cleanup (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity);void drm_sched_entity_fini (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity);void Quoted 3 lines
drm_sched_entity_push_job(struct
drm_sched_job*sched_job, --
2.7.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 5239ad87-7449-b6eb-737b-69b6dc05b7a8-5C7GfCeVMHo@public.gmane.org
Hi Monk,
Thanks your review, I will refine the code as your suggestion 1),2),3), 4),5). About 6): I think it is no relation to put the amdgpu_ctx_mgr_fini before or after amdgpu_vm_fini.
Hi Christian,
Do you have any thoughts about 6)?
Best Wishes,
Emily Deng
Quoted 483 lines
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of monk
Sent: Friday, April 13, 2018 1:01 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/gpu-sched: fix force APP kill hang(v3)Hi Christian & Emily
This v3 version looks pretty good to me, but still some parts need to improve:
e.g.
1)entity->finished doesn't presenting what it really means, better rename it to
entity->last_scheduled.2)drm_sched_entity_fini_job_cb() better renamed to
drm_sched_entity_kill_jobs_cb()3) no need to pass "
entity->finished" (line275 ofgpu_schedulers.c) todrm_sched_entity_fini_job_cb()if-ENOENTreturned afterdma_fence_add_callbacksince this parm is not needed at all in this callback routine4)better change type of
entity->fini_statusto "int" instead of "uint32_t" ... it should be aligned with the return type ofwait_event_killable()5)
drivers/gpu/drm/scheduler/gpu_scheduler.c +3
-0+if (entity->finished) { +dma_fence_put (entity->finished); + entity->finished =NULL ; }no need to check
entity->finishedbecausedma_fence_put()will do it inside...and the same here in
job_recovery:drivers/gpu/drm/scheduler/gpu_scheduler.c +3
-0+ +if (s_job->entity->finished) +dma_fence_put (s_job->entity->finished);and the same here in
sched_main:drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-0+if (entity->finished) +dma_fence_put (entity->finished);6) why put
amdgpu_ctx_mgr_fini()beneathamdgpu_vm_fini()? any reason for that ?thanks
/Monk
Quoted 13 lines · Emily
Ping....
Best Wishes,
Emily DengQuoted 5 lines
-----Original Message-----
From: Emily Deng [mailto:[email protected]]
Sent: Thursday, April 12, 2018 6:22 PM
To: [email protected]
Cc: Deng, Emily <[email protected]>; Liu, MonkQuoted 13 lines
Quoted 13 lines
Subject: [PATCH] drm/gpu-sched: fix force APP kill hang(v3)
issue:
there are VMC page fault occurred if force APP kill during 3dmark test, the cause is inentity_finiwe manually signal all those jobs in entity's queue which confuse the sync/dep
mechanism:1)page fault occurred in sdma's clear job which operate on shadow buffer, and shadow buffer's Gart table is cleaned by
ttm_bo_releasesince the fence in its reservation was fake signaled byentity_fini()under the case of SIGKILL received.Quoted 4 lines
Quoted 4 lines
2)page fault occurred in gfx' job because during the lifetime of gfx job we manually fake signal all jobs from its entity in
entity_fini(), thus the unmapping/clear PTE job depend on those result fence is satisfied and sdma start clearing the PTE and lead to GFXpage fault.
Quoted 16 lines
Quoted 16 lines
fix:
1)should at least wait all jobs already scheduled complete inentity_fini()if SIGKILL is the case.2)if a fence signaled and try to clear some entity's dependency, should set this entity guilty to prevent its job really run since the dependency is fake signaled.
v2:
splittingdrm_sched_entity_fini()into two functions:
1)The first one is does the waiting, removes the entity from the runqueue and returns an error when the process was killed. 2)The second one then goes over the entity, install it as completion signal for the remaining jobs and signals all jobs with an error code.Quoted 5 lines
Quoted 5 lines
v3:
1)Replace the fini1 and fini2 with better name 2)Call the first part before the VM teardown inamdgpu_driver_postclose_kms()and the second part after the VM teardown 3)Keep the original functiondrm_sched_entity_finito refine thecode.
Quoted 13 lines
Quoted 13 lines
Signed-off-by Monk Liu <[email protected]>Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 64 ++++++++++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 5 ++- drivers/gpu/drm/scheduler/gpu_scheduler.c | 74 ++++++++++++++++++++++++++----- include/drm/gpu_scheduler.h | 7 +++ 5 files changed, 131 insertions(+), 21 deletions(-)Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h int amdgpu_ctx_ioctl(struct drm_device *dev,
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -681,6 +681,8 @@ int amdgpu_ctx_ioctl(struct drm_device *dev,void
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h int amdgpu_ctx_ioctl(struct drm_device *dev, void *data, · line 684
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0*data, int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,unsigned ring_id);void amdgpu_ctx_mgr_init (struct amdgpu_ctx_mgr *mgr); +void amdgpu_ctx_mgr_entity_cleanup (struct amdgpu_ctx_mgr *mgr);void
Quoted 233 lines
Quoted 233 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr);void amdgpu_ctx_mgr_fini (struct amdgpu_ctx_mgr *mgr);drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +5
-5@@ -111,8 +111,9 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev, return r; } -static void amdgpu_ctx_fini (struct amdgpu_ctx *ctx) +static void amdgpu_ctx_fini (struct kref *ref) { + struct amdgpu_ctx *ctx = container_of(ref, struct amdgpu_ctx, +refcount);struct amdgpu_device *adev = ctx->adev;unsigned i, j;@@ -125,13 +126,11 @@ static void amdgpu_ctx_fini(struct amdgpu_ctx *ctx)kfree (ctx->fences); ctx->fences =NULL ; -for (i =0 ; i < adev->num_rings; i++) -drm_sched_entity_fini (&adev->rings[i]->sched, - &ctx->rings[i].entity); -amdgpu_queue_mgr_fini (adev, &ctx->queue_mgr);mutex_destroy (&ctx->lock); + +kfree (ctx); }static int amdgpu_ctx_alloc(struct
amdgpu_device*adev, @@ -170,12
+169,15 @@ static int amdgpu_ctx_alloc(structamdgpu_device*adev, static voidamdgpu_ctx_do_release(struct kref *ref){
structamdgpu_ctx*ctx;drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +5
-2+u32 i; ctx = container_of(ref, struct amdgpu_ctx, refcount); -amdgpu_ctx_fini (ctx); +for (i =0 ; i < ctx->adev->num_rings; i++) +drm_sched_entity_fini (&ctx->adev->rings[i]->sched, + &ctx->rings[i].entity); -kfree (ctx); +amdgpu_ctx_fini (ref); }static int amdgpu_ctx_free (struct amdgpu_fpriv *fpriv,uint32_t id)@@ -
435,16 +437,62 @@ voidamdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
idr_init(&mgr->ctx_handles);
}drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +15
-0+void amdgpu_ctx_mgr_entity_fini (struct amdgpu_ctx_mgr *mgr) { +struct amdgpu_ctx *ctx; +struct idr *idp; +uint32_t id, i; + + idp = &mgr->ctx_handles; + +idr_for_each_entry (idp, ctx, id) { + +if (!ctx->adev) +return ; + +for (i =0 ; i < ctx->adev->num_rings; i++) +if (kref_read (&ctx->refcount) ==1 ) + drm_sched_entity_do_release(&ctx->adev-Quoted 1 line
rings[i]->sched,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +21
-0+ &ctx->rings[i].entity); + else + DRM_ERROR("ctx %p is still alive\n", ctx); + } +} + +void amdgpu_ctx_mgr_entity_cleanup (struct amdgpu_ctx_mgr *mgr) { +struct amdgpu_ctx *ctx; +struct idr *idp; +uint32_t id, i; + + idp = &mgr->ctx_handles; + +idr_for_each_entry (idp, ctx, id) { + +if (!ctx->adev) +return ; + +for (i =0 ; i < ctx->adev->num_rings; i++) +if (kref_read (&ctx->refcount) ==1 ) + drm_sched_entity_cleanup(&ctx->adev-Quoted 1 line
rings[i]->sched,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +9
-1+ &ctx->rings[i].entity); + else + DRM_ERROR("ctx %p is still alive\n", ctx); + } +} +void amdgpu_ctx_mgr_fini (struct amdgpu_ctx_mgr *mgr) {struct amdgpu_ctx *ctx;struct idr *idp;uint32_t id; +amdgpu_ctx_mgr_entity_cleanup (mgr); + idp = &mgr->ctx_handles;idr_for_each_entry (idp, ctx, id) { -if (kref_put (&ctx->refcount, amdgpu_ctx_do_release) !=1 ) +if (kref_put (&ctx->refcount, amdgpu_ctx_fini) !=1 )DRM_ERROR ("ctx %p is still alive\n" , ctx); }drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1
-2@@ -913,8 +913,7 @@ void amdgpu_driver_postclose_kms(structdrm_device *dev, return;pm_runtime_get_sync (dev->dev); - -amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +amdgpu_ctx_mgr_entity_fini (&fpriv->ctx_mgr);if (adev->asic_type !=CHIP_RAVEN ) {
amdgpu_uvd_free_handles(adev, file_priv); @@ -935,6
+934,8 @@ void amdgpu_driver_postclose_kms(structdrm_device*dev,
pd =amdgpu_bo_ref(fpriv->vm.root.base.bo);amdgpu_vm_fini(adev, &fpriv->vm);drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2
-0+amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +if (pasid)amdgpu_pasid_free_delayed (pd->tbo.resv, pasid);amdgpu_bo_unref (&pd);drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-0@@ -136,6 +136,8 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched, entity->rq = rq; entity->sched = sched; entity->guilty = guilty; + entity->fini_status =0 ; + entity->finished =NULL ;spin_lock_init (&entity->rq_lock);spin_lock_init(&entity->queue_lock);drivers/gpu/drm/scheduler/gpu_scheduler.c +16
-1@@ -197,19 +199,30 @@ static bool drm_sched_entity_is_ready(struct drm_sched_entity *entity)return true; } +static void drm_sched_entity_fini_job_cb (struct dma_fence *f, +struct dma_fence_cb *cb) +{ + struct drm_sched_job *job = container_of(cb, struct drm_sched_job, + finish_cb); +drm_sched_fence_finished (job->s_fence); +WARN_ON (job->s_fence->parent); +dma_fence_put (&job->s_fence->finished); + job->sched->ops->free_job (job); +} + +/** * Destroy a context entity * * @sched Pointer to scheduler instance * @entity The pointer to a valid scheduler entity * -* Cleanup and free the allocated resources. +* Splitting drm_sched_entity_fini() into two functions, The first +one is does the waiting, +* removes the entity from the runqueue and returns an error when +the process was killed.
*/drivers/gpu/drm/scheduler/gpu_scheduler.c +14
-6-void drm_sched_entity_fini (struct drm_gpu_scheduler *sched, +void drm_sched_entity_do_release (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity) { -int r; -if (!drm_sched_entity_is_initialized (sched, entity))return ;/** @@ -217,13 +230,28 @@ void drm_sched_entity_fini(structdrm_gpu_scheduler *sched, * queued IBs or discard them on SIGKILL */ if ((current->flags &PF_SIGNALED ) && current->exit_code ==SIGKILL ) - r = -ERESTARTSYS ; + entity->fini_status = -ERESTARTSYS ;else - r =wait_event_killable (sched->job_scheduled, + entity->fini_status =wait_event_killable (sched- > job_scheduled,drm_sched_entity_is_idle (entity));drm_sched_entity_set_rq (entity,NULL ); -if (r) { +} +EXPORT_SYMBOL (drm_sched_entity_do_release); + +/** +* Destroy a context entity +* +* @sched Pointer to scheduler instance +* @entity The pointer to a valid scheduler entity +* +* The second one then goes over the entity and signals all jobs +with an error code.
+ */drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0+void drm_sched_entity_cleanup (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity) { +if (entity->fini_status) {struct drm_sched_job *job; +int r;Quoted 1 line
Quoted 1 line
/* Park the kernel for a moment to make sure it isn't
processing
Quoted 46 lines
Quoted 46 lines
* our enity.
drivers/gpu/drm/scheduler/gpu_scheduler.c +17
-4@@ -241,13 +269,28 @@ void drm_sched_entity_fini(structdrm_gpu_scheduler *sched, struct drm_sched_fence *s_fence = job->s_fence;drm_sched_fence_scheduled (s_fence);dma_fence_set_error (&s_fence->finished, -ESRCH ); -drm_sched_fence_finished (s_fence); -WARN_ON (s_fence->parent); -dma_fence_put (&s_fence->finished); - sched->ops->free_job (job); + r =dma_fence_add_callback (entity->finished, &job- > finish_cb, + drm_sched_entity_fini_job_cb); +if (r == -ENOENT ) +drm_sched_entity_fini_job_cb (entity- > finished, &job->finish_cb); +else if (r) +DRM_ERROR ("fence add callback failed (%d)\n", r); + } + +if (entity->finished) { +dma_fence_put (entity->finished); + entity->finished =NULL ; } } } +EXPORT_SYMBOL (drm_sched_entity_cleanup); + +void drm_sched_entity_fini (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity) { +drm_sched_entity_do_release (sched, entity); +drm_sched_entity_cleanup (sched, entity); }EXPORT_SYMBOL (drm_sched_entity_fini); static void drm_sched_entity_wakeup(struct dma_fence *f, struct
dma_fence_cb*cb) @@ -530,6 +573,11 @@ voiddrm_sched_job_recovery(struct drm_gpu_scheduler *sched)
spin_unlock(&sched->job_list_lock); fence =sched->ops->run_job(s_job);atomic_inc(&sched->hw_rq_count);drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0+ +if (s_job->entity->finished) +dma_fence_put (s_job->entity->finished); + s_job->entity->finished = dma_fence_get(&s_fence-Quoted 5 lines
Quoted 5 lines
Quoted 1 line
finished);
+
if (fence) {
s_fence->parent=dma_fence_get(fence); r = dma_fence_add_callback(fence,&s_fence->cb,@@ -556,6 +604,7
Quoted 50 lines
Quoted 50 lines
@@ int drm_sched_job_init(struct
drm_sched_job*job,
void *owner)
{
job->sched= sched;drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0+ job->entity = entity; job->s_priority = entity->rq - sched->sched_rq; job->s_fence =drm_sched_fence_create (entity, owner);if (!job->s_fence)@@ -668,6 +717,9 @@ static int drm_sched_main(void *param) fence = sched->ops->run_job (sched_job);drm_sched_fence_scheduled (s_fence); +if (entity->finished) +dma_fence_put (entity->finished); + entity->finished =dma_fence_get (&s_fence->finished);if (fence) { s_fence->parent = dma_fence_get(fence); diff --git
a/include/drm/gpu_scheduler.hb/include/drm/gpu_scheduler.hindex c053a32..a0dd947 100644include/drm/gpu_scheduler.h +3
-0@@ -65,6 +65,8 @@ struct drm_sched_entity {struct dma_fence *dependency;struct dma_fence_cb cb;atomic_t *guilty;/* points to ctx's guilty */ +uint32_t fini_status; +struct dma_fence *finished; };/** @@ -119,6 +121,7 @@ struct drm_sched_job {uint64_t id;atomic_t karma;enum drm_sched_priority s_priority; +struct drm_sched_entity *entity; }; static inline bool drm_sched_invalidate_job(struct drm_sched_job
*s_job, @@ -186,6 +189,10 @@ int drm_sched_entity_init(structdrm_gpu_scheduler*sched,
structdrm_sched_entity*entity, structdrm_sched_rq*rq,uint32_tjobs,atomic_t*guilty);include/drm/gpu_scheduler.h +4
-0+void drm_sched_entity_do_release (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity);void +drm_sched_entity_cleanup (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity);void drm_sched_entity_fini (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity);void
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
drm_sched_entity_push_job(struct
drm_sched_job*sched_job, --
2.7.4_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CY4PR12MB1125E426CA7E9205536D7EB58FB30-rpdhrqHFk07v2MZdTKcfDgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
Hi Monk,
Another consideration, it will be better to put amdgpu_ctx_mgr_fini() beneath amdgpu_vm_fini, in
this case, it will first set all ctx and vm entity rq to null, then set all the not scheduled job's fence to signal.
Best Wishes,
Emily Deng
Quoted 518 lines
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Deng, Emily
Sent: Friday, April 13, 2018 2:08 PM
To: Liu, Monk <[email protected]>; Christian König <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH] drm/gpu-sched: fix force APP kill hang(v3)Hi Monk,
Thanks your review, I will refine the code as your suggestion 1),2),3), 4),5). About 6): I think it is no relation to put theamdgpu_ctx_mgr_finibefore or
afteramdgpu_vm_fini.Hi Christian,
Do you have any thoughts about 6)?Best Wishes,
Emily DengQuoted 36 lines
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of monk
Sent: Friday, April 13, 2018 1:01 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/gpu-sched: fix force APP kill hang(v3)Hi Christian & Emily
This v3 version looks pretty good to me, but still some parts need to improve:
e.g.
1)entity->finished doesn't presenting what it really means, better rename it to
entity->last_scheduled.2)drm_sched_entity_fini_job_cb() better renamed to
drm_sched_entity_kill_jobs_cb()3) no need to pass "
entity->finished" (line275 ofgpu_schedulers.c) todrm_sched_entity_fini_job_cb()if-ENOENTreturned afterdma_fence_add_callbacksince this parm is not needed at all in this callback routine4)better change type of
entity->fini_statusto "int" instead of "uint32_t" ... it should be aligned with the return type ofwait_event_killable()5)
(quoted diff) +3
-0+ if (entity->finished) { + dma_fence_put(entity->finished); + entity->finished = NULL; }Quoted 1 line
no need to check
entity->finishedbecausedma_fence_put()will do itinside...
Quoted 56 lines
and the same here in
job_recovery:(quoted diff) +3
-0+ + if (s_job->entity->finished) + dma_fence_put(s_job->entity->finished);and the same here in
sched_main:(quoted diff) +2
-0+ if (entity->finished) + dma_fence_put(entity->finished);6) why put
amdgpu_ctx_mgr_fini()beneathamdgpu_vm_fini()? any reason for that ?thanks
/Monk
Quoted 13 lines · Emily
Ping....
Best Wishes,
Emily DengQuoted 5 lines
-----Original Message-----
From: Emily Deng [mailto:[email protected]]
Sent: Thursday, April 12, 2018 6:22 PM
To: [email protected]
Cc: Deng, Emily <[email protected]>; Liu, MonkQuoted 13 lines
Quoted 13 lines
Subject: [PATCH] drm/gpu-sched: fix force APP kill hang(v3)
issue:
there are VMC page fault occurred if force APP kill during 3dmark test, the cause is inentity_finiwe manually signal all those jobs in entity's queue which confuse the sync/dep
mechanism:1)page fault occurred in sdma's clear job which operate on shadow buffer, and shadow buffer's Gart table is cleaned by
ttm_bo_releasesince the fence in its reservation was fake signaled byentity_fini()under the case of SIGKILL received.Quoted 21 lines
Quoted 5 lines
Quoted 5 lines
2)page fault occurred in gfx' job because during the lifetime of gfx job we manually fake signal all jobs from its entity in
entity_fini(), thus the unmapping/clear PTE job depend on those result fence is satisfied and sdma start clearing the PTE and lead to GFXpage fault.
Quoted 15 lines
Quoted 15 lines
fix:
1)should at least wait all jobs already scheduled complete inentity_fini()if SIGKILL is the case.2)if a fence signaled and try to clear some entity's dependency, should set this entity guilty to prevent its job really run since the dependency is fake signaled.
v2:
splittingdrm_sched_entity_fini()into two functions:
1)The first one is does the waiting, removes the entity from the runqueue and returns an error when the process was killed. 2)The second one then goes over the entity, install it as completion signal for the remaining jobs and signals all jobs with anerror code.
Quoted 38 lines
Quoted 7 lines
Quoted 7 lines
v3:
1)Replace the fini1 and fini2 with better name 2)Call the first part before the VM teardown inamdgpu_driver_postclose_kms()and the second part after the VM teardown 3)Keep the original functiondrm_sched_entity_finito refine thecode.
Quoted 13 lines
Quoted 13 lines
Signed-off-by Monk Liu <[email protected]>Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 64 ++++++++++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 5 ++- drivers/gpu/drm/scheduler/gpu_scheduler.c | 74 ++++++++++++++++++++++++++----- include/drm/gpu_scheduler.h | 7 +++ 5 files changed, 131 insertions(+), 21 deletions(-)Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h int amdgpu_ctx_ioctl(struct drm_device *dev,
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -681,6 +681,8 @@ int amdgpu_ctx_ioctl(struct drm_device *dev,void
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h int amdgpu_ctx_ioctl(struct drm_device *dev, · line 685
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0*data, int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,unsigned ring_id);void amdgpu_ctx_mgr_init (struct amdgpu_ctx_mgr *mgr); +void amdgpu_ctx_mgr_entity_cleanup (struct amdgpu_ctx_mgr *mgr);void
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr);void amdgpu_ctx_mgr_fini (struct amdgpu_ctx_mgr *mgr);Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_init(struct
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0
-0@@ -111,8 +111,9 @@ static int amdgpu_ctx_init(struct
amdgpu_deviceQuoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +3
-1*adev, return r; } -static void amdgpu_ctx_fini (struct amdgpu_ctx *ctx) +static void amdgpu_ctx_fini (struct kref *ref) { + struct amdgpu_ctx *ctx = container_of(ref, struct amdgpu_ctx, +refcount);struct amdgpu_device *adev = ctx->adev;unsigned i, j;Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static void amdgpu_ctx_fini(struct
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0
-0@@ -125,13 +126,11 @@ static void amdgpu_ctx_fini(struct
amdgpu_ctxQuoted 315 lines
Quoted 211 lines
Quoted 211 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2
-4*ctx)kfree (ctx->fences); ctx->fences =NULL ; -for (i =0 ; i < adev->num_rings; i++) -drm_sched_entity_fini (&adev->rings[i]->sched, - &ctx->rings[i].entity); -amdgpu_queue_mgr_fini (adev, &ctx->queue_mgr);mutex_destroy (&ctx->lock); + +kfree (ctx); }static int amdgpu_ctx_alloc(struct
amdgpu_device*adev, @@
-170,12
+169,15 @@ static int amdgpu_ctx_alloc(structamdgpu_device*adev, static voidamdgpu_ctx_do_release(struct kref *ref){
structamdgpu_ctx*ctx;drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +5
-2+u32 i; ctx = container_of(ref, struct amdgpu_ctx, refcount); -amdgpu_ctx_fini (ctx); +for (i =0 ; i < ctx->adev->num_rings; i++) +drm_sched_entity_fini (&ctx->adev->rings[i]->sched, + &ctx->rings[i].entity); -kfree (ctx); +amdgpu_ctx_fini (ref); } static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_tid) @@ -
435,16 +437,62 @@ voidamdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
idr_init(&mgr->ctx_handles);
}drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +15
-0+void amdgpu_ctx_mgr_entity_fini (struct amdgpu_ctx_mgr *mgr) { +struct amdgpu_ctx *ctx; +struct idr *idp; +uint32_t id, i; + + idp = &mgr->ctx_handles; + +idr_for_each_entry (idp, ctx, id) { + +if (!ctx->adev) +return ; + +for (i =0 ; i < ctx->adev->num_rings; i++) +if (kref_read (&ctx->refcount) ==1 ) + drm_sched_entity_do_release(&ctx->adev-Quoted 1 line
rings[i]->sched,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +21
-0+ &ctx->rings[i].entity); + else + DRM_ERROR("ctx %p is still alive\n", ctx); + } +} + +void amdgpu_ctx_mgr_entity_cleanup (struct amdgpu_ctx_mgr *mgr) { +struct amdgpu_ctx *ctx; +struct idr *idp; +uint32_t id, i; + + idp = &mgr->ctx_handles; + +idr_for_each_entry (idp, ctx, id) { + +if (!ctx->adev) +return ; + +for (i =0 ; i < ctx->adev->num_rings; i++) +if (kref_read (&ctx->refcount) ==1 ) + drm_sched_entity_cleanup(&ctx->adev-Quoted 1 line
rings[i]->sched,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +9
-1+ &ctx->rings[i].entity); + else + DRM_ERROR("ctx %p is still alive\n", ctx); + } +} +void amdgpu_ctx_mgr_fini (struct amdgpu_ctx_mgr *mgr) {struct amdgpu_ctx *ctx;struct idr *idp;uint32_t id; +amdgpu_ctx_mgr_entity_cleanup (mgr); + idp = &mgr->ctx_handles;idr_for_each_entry (idp, ctx, id) { -if (kref_put (&ctx->refcount, amdgpu_ctx_do_release) !=1 ) +if (kref_put (&ctx->refcount, amdgpu_ctx_fini) !=1 )DRM_ERROR ("ctx %p is still alive\n" , ctx); }drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1
-2@@ -913,8 +913,7 @@ void amdgpu_driver_postclose_kms(structdrm_device *dev, return;pm_runtime_get_sync (dev->dev); - -amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +amdgpu_ctx_mgr_entity_fini (&fpriv->ctx_mgr);if (adev->asic_type !=CHIP_RAVEN ) {
amdgpu_uvd_free_handles(adev, file_priv); @@ -935,6
+934,8 @@ void amdgpu_driver_postclose_kms(structdrm_device*dev,
pd =amdgpu_bo_ref(fpriv->vm.root.base.bo);amdgpu_vm_fini(adev, &fpriv->vm);drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2
-0+amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +if (pasid)amdgpu_pasid_free_delayed (pd->tbo.resv, pasid);amdgpu_bo_unref (&pd);drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-0@@ -136,6 +136,8 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched, entity->rq = rq; entity->sched = sched; entity->guilty = guilty; + entity->fini_status =0 ; + entity->finished =NULL ;spin_lock_init (&entity->rq_lock);spin_lock_init(&entity->queue_lock);drivers/gpu/drm/scheduler/gpu_scheduler.c +16
-1@@ -197,19 +199,30 @@ static bool drm_sched_entity_is_ready(struct drm_sched_entity *entity)return true; } +static void drm_sched_entity_fini_job_cb (struct dma_fence *f, +struct dma_fence_cb *cb) +{ + struct drm_sched_job *job = container_of(cb, struct drm_sched_job, + finish_cb); +drm_sched_fence_finished (job->s_fence); +WARN_ON (job->s_fence->parent); +dma_fence_put (&job->s_fence->finished); + job->sched->ops->free_job (job); +} + +/** * Destroy a context entity * * @sched Pointer to scheduler instance * @entity The pointer to a valid scheduler entity * -* Cleanup and free the allocated resources. +* Splitting drm_sched_entity_fini() into two functions, The first +one is does the waiting, +* removes the entity from the runqueue and returns an error when +the process was killed.
*/drivers/gpu/drm/scheduler/gpu_scheduler.c +14
-6-void drm_sched_entity_fini (struct drm_gpu_scheduler *sched, +void drm_sched_entity_do_release (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity) { -int r; -if (!drm_sched_entity_is_initialized (sched, entity))return ;/** @@ -217,13 +230,28 @@ void drm_sched_entity_fini(structdrm_gpu_scheduler *sched, * queued IBs or discard them on SIGKILL */ if ((current->flags &PF_SIGNALED ) && current->exit_code ==SIGKILL ) - r = -ERESTARTSYS ; + entity->fini_status = -ERESTARTSYS ;else - r =wait_event_killable (sched->job_scheduled, + entity->fini_status =wait_event_killable (sched- > job_scheduled,drm_sched_entity_is_idle (entity));drm_sched_entity_set_rq (entity,NULL ); -if (r) { +} +EXPORT_SYMBOL (drm_sched_entity_do_release); + +/** +* Destroy a context entity +* +* @sched Pointer to scheduler instance +* @entity The pointer to a valid scheduler entity +* +* The second one then goes over the entity and signals all jobs +with an error code.
+ */drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0+void drm_sched_entity_cleanup (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity) { +if (entity->fini_status) {struct drm_sched_job *job; +int r;Quoted 1 line
Quoted 1 line
/* Park the kernel for a moment to make sure it isn't
processing
Quoted 46 lines
Quoted 46 lines
* our enity.
drivers/gpu/drm/scheduler/gpu_scheduler.c +17
-4@@ -241,13 +269,28 @@ void drm_sched_entity_fini(structdrm_gpu_scheduler *sched, struct drm_sched_fence *s_fence = job->s_fence;drm_sched_fence_scheduled (s_fence);dma_fence_set_error (&s_fence->finished, -ESRCH ); -drm_sched_fence_finished (s_fence); -WARN_ON (s_fence->parent); -dma_fence_put (&s_fence->finished); - sched->ops->free_job (job); + r =dma_fence_add_callback (entity->finished, &job- > finish_cb, + drm_sched_entity_fini_job_cb); +if (r == -ENOENT ) +drm_sched_entity_fini_job_cb (entity- > finished, &job->finish_cb); +else if (r) +DRM_ERROR ("fence add callback failed (%d)\n", r); + } + +if (entity->finished) { +dma_fence_put (entity->finished); + entity->finished =NULL ; } } } +EXPORT_SYMBOL (drm_sched_entity_cleanup); + +void drm_sched_entity_fini (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity) { +drm_sched_entity_do_release (sched, entity); +drm_sched_entity_cleanup (sched, entity); }EXPORT_SYMBOL (drm_sched_entity_fini); static void drm_sched_entity_wakeup(struct dma_fence *f, struct
dma_fence_cb*cb) @@ -530,6 +573,11 @@ voiddrm_sched_job_recovery(struct drm_gpu_scheduler *sched)
spin_unlock(&sched->job_list_lock); fence =sched->ops->run_job(s_job);atomic_inc(&sched->hw_rq_count);drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0+ +if (s_job->entity->finished) +dma_fence_put (s_job->entity->finished); + s_job->entity->finished = dma_fence_get(&s_fence-Quoted 5 lines
Quoted 5 lines
Quoted 1 line
finished);
+
if (fence) {
s_fence->parent=dma_fence_get(fence); r = dma_fence_add_callback(fence,&s_fence->cb,@@ -556,6 +604,7
Quoted 50 lines
Quoted 50 lines
@@ int drm_sched_job_init(struct
drm_sched_job*job,
void *owner)
{
job->sched= sched;drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0+ job->entity = entity; job->s_priority = entity->rq - sched->sched_rq; job->s_fence =drm_sched_fence_create (entity, owner);if (!job->s_fence)@@ -668,6 +717,9 @@ static int drm_sched_main(void *param) fence = sched->ops->run_job (sched_job);drm_sched_fence_scheduled (s_fence); +if (entity->finished) +dma_fence_put (entity->finished); + entity->finished =dma_fence_get (&s_fence->finished);if (fence) { s_fence->parent = dma_fence_get(fence); diff --git
a/include/drm/gpu_scheduler.hb/include/drm/gpu_scheduler.hindex c053a32..a0dd947 100644include/drm/gpu_scheduler.h +3
-0@@ -65,6 +65,8 @@ struct drm_sched_entity {struct dma_fence *dependency;struct dma_fence_cb cb;atomic_t *guilty;/* points to ctx's guilty */ +uint32_t fini_status; +struct dma_fence *finished; };/** @@ -119,6 +121,7 @@ struct drm_sched_job {uint64_t id;atomic_t karma;enum drm_sched_priority s_priority; +struct drm_sched_entity *entity; }; static inline bool drm_sched_invalidate_job(struct drm_sched_job
*s_job, @@ -186,6 +189,10 @@ int drm_sched_entity_init(structdrm_gpu_scheduler*sched,
structdrm_sched_entity*entity, structdrm_sched_rq*rq,uint32_tjobs,atomic_t*guilty);include/drm/gpu_scheduler.h +4
-0+void drm_sched_entity_do_release (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity);void +drm_sched_entity_cleanup (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity);void drm_sched_entity_fini (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity);void Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
drm_sched_entity_push_job(struct
drm_sched_job*sched_job, --
2.7.4_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CY4PR12MB1125A98A324BD4CA292729AE8FB30-rpdhrqHFk07v2MZdTKcfDgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
Hi Monk/Emily,
give me the weekend to take a closer look since I'm very busy this morning.
In general the order of ctx_fini and vm fini is very important cause we otherwise dereference invalid pointers here.
Regards,
Christian.
Am 13.04.2018 um 08:18 schrieb Deng, Emily:
Quoted 4 lines
Hi Monk,
Another consideration, it will be better to putamdgpu_ctx_mgr_fini()beneathamdgpu_vm_fini, in
this case, it will first set all ctx and vm entity rq to null, then set all the not scheduled job's fence to signal.
Quoted 520 lines
Best Wishes,
Emily DengQuoted 517 lines
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Deng, Emily
Sent: Friday, April 13, 2018 2:08 PM
To: Liu, Monk <[email protected]>; Christian König <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH] drm/gpu-sched: fix force APP kill hang(v3)Hi Monk,
Thanks your review, I will refine the code as your suggestion 1),2),3), 4),5). About 6): I think it is no relation to put theamdgpu_ctx_mgr_finibefore or
afteramdgpu_vm_fini.Hi Christian,
Do you have any thoughts about 6)?Best Wishes,
Emily DengQuoted 36 lines
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of monk
Sent: Friday, April 13, 2018 1:01 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/gpu-sched: fix force APP kill hang(v3)Hi Christian & Emily
This v3 version looks pretty good to me, but still some parts need to improve:
e.g.
1)entity->finished doesn't presenting what it really means, better rename it to
entity->last_scheduled.2)drm_sched_entity_fini_job_cb() better renamed to
drm_sched_entity_kill_jobs_cb()3) no need to pass "
entity->finished" (line275 ofgpu_schedulers.c) todrm_sched_entity_fini_job_cb()if-ENOENTreturned afterdma_fence_add_callbacksince this parm is not needed at all in this callback routine4)better change type of
entity->fini_statusto "int" instead of "uint32_t" ... it should be aligned with the return type ofwait_event_killable()5)
(quoted diff) +3
-0+ if (entity->finished) { + dma_fence_put(entity->finished); + entity->finished = NULL; }Quoted 1 line
no need to check
entity->finishedbecausedma_fence_put()will do itinside...
Quoted 55 lines
and the same here in
job_recovery:(quoted diff) +3
-0+ + if (s_job->entity->finished) + dma_fence_put(s_job->entity->finished);and the same here in
sched_main:(quoted diff) +2
-0+ if (entity->finished) + dma_fence_put(entity->finished);6) why put
amdgpu_ctx_mgr_fini()beneathamdgpu_vm_fini()? any reason for that ?thanks
/Monk
Quoted 13 lines · Emily
Ping....
Best Wishes,
Emily DengQuoted 5 lines
-----Original Message-----
From: Emily Deng [mailto:[email protected]]
Sent: Thursday, April 12, 2018 6:22 PM
To: [email protected]
Cc: Deng, Emily <[email protected]>; Liu, MonkQuoted 13 lines
Quoted 13 lines
Subject: [PATCH] drm/gpu-sched: fix force APP kill hang(v3)
issue:
there are VMC page fault occurred if force APP kill during 3dmark test, the cause is inentity_finiwe manually signal all those jobs in entity's queue which confuse the sync/dep
mechanism:1)page fault occurred in sdma's clear job which operate on shadow buffer, and shadow buffer's Gart table is cleaned by
ttm_bo_releasesince the fence in its reservation was fake signaled byentity_fini()under the case of SIGKILL received.Quoted 20 lines
Quoted 5 lines
Quoted 5 lines
2)page fault occurred in gfx' job because during the lifetime of gfx job we manually fake signal all jobs from its entity in
entity_fini(), thus the unmapping/clear PTE job depend on those result fence is satisfied and sdma start clearing the PTE and lead to GFXpage fault.
Quoted 14 lines
Quoted 14 lines
fix:
1)should at least wait all jobs already scheduled complete inentity_fini()if SIGKILL is the case.2)if a fence signaled and try to clear some entity's dependency, should set this entity guilty to prevent its job really run since the dependency is fake signaled.
v2:
splittingdrm_sched_entity_fini()into two functions:
1)The first one is does the waiting, removes the entity from the runqueue and returns an error when the process was killed. 2)The second one then goes over the entity, install it as completion signal for the remaining jobs and signals all jobs with anerror code.
Quoted 36 lines
Quoted 6 lines
Quoted 6 lines
v3:
1)Replace the fini1 and fini2 with better name 2)Call the first part before the VM teardown inamdgpu_driver_postclose_kms()and the second part after the VM teardown 3)Keep the original functiondrm_sched_entity_finito refine thecode.
Quoted 12 lines
Quoted 12 lines
Signed-off-by Monk Liu <[email protected]>Signed-off-by Emily Deng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 64 ++++++++++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 5 ++- drivers/gpu/drm/scheduler/gpu_scheduler.c | 74 ++++++++++++++++++++++++++----- include/drm/gpu_scheduler.h | 7 +++ 5 files changed, 131 insertions(+), 21 deletions(-)Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h int amdgpu_ctx_ioctl(struct drm_device *dev,
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -681,6 +681,8 @@ int amdgpu_ctx_ioctl(struct drm_device *dev,void
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h int amdgpu_ctx_ioctl(struct drm_device *dev, · line 685
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0*data, int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,unsigned ring_id);void amdgpu_ctx_mgr_init (struct amdgpu_ctx_mgr *mgr); +void amdgpu_ctx_mgr_entity_cleanup (struct amdgpu_ctx_mgr *mgr);void
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr);void amdgpu_ctx_mgr_fini (struct amdgpu_ctx_mgr *mgr);Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_init(struct
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0
-0@@ -111,8 +111,9 @@ static int amdgpu_ctx_init(struct
amdgpu_deviceQuoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +3
-1*adev, return r; } -static void amdgpu_ctx_fini (struct amdgpu_ctx *ctx) +static void amdgpu_ctx_fini (struct kref *ref) { + struct amdgpu_ctx *ctx = container_of(ref, struct amdgpu_ctx, +refcount);struct amdgpu_device *adev = ctx->adev;unsigned i, j;Quoted 1 line
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static void amdgpu_ctx_fini(struct
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0
-0@@ -125,13 +126,11 @@ static void amdgpu_ctx_fini(struct
amdgpu_ctxQuoted 314 lines
Quoted 211 lines
Quoted 211 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2
-4*ctx)kfree (ctx->fences); ctx->fences =NULL ; -for (i =0 ; i < adev->num_rings; i++) -drm_sched_entity_fini (&adev->rings[i]->sched, - &ctx->rings[i].entity); -amdgpu_queue_mgr_fini (adev, &ctx->queue_mgr);mutex_destroy (&ctx->lock); + +kfree (ctx); }static int amdgpu_ctx_alloc(struct
amdgpu_device*adev, @@
-170,12
+169,15 @@ static int amdgpu_ctx_alloc(structamdgpu_device*adev,static void amdgpu_ctx_do_release(struct kref *ref) { struct amdgpu_ctx *ctx;drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +5
-2+u32 i; ctx = container_of(ref, struct amdgpu_ctx, refcount); -amdgpu_ctx_fini (ctx); +for (i =0 ; i < ctx->adev->num_rings; i++) +drm_sched_entity_fini (&ctx->adev->rings[i]->sched, + &ctx->rings[i].entity); -kfree (ctx); +amdgpu_ctx_fini (ref); } static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_tid) @@ -
435,16 +437,62 @@ voidamdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)idr_init(&mgr->ctx_handles); }drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +15
-0+void amdgpu_ctx_mgr_entity_fini (struct amdgpu_ctx_mgr *mgr) { +struct amdgpu_ctx *ctx; +struct idr *idp; +uint32_t id, i; + + idp = &mgr->ctx_handles; + +idr_for_each_entry (idp, ctx, id) { + +if (!ctx->adev) +return ; + +for (i =0 ; i < ctx->adev->num_rings; i++) +if (kref_read (&ctx->refcount) ==1 ) + drm_sched_entity_do_release(&ctx->adev-Quoted 1 line
rings[i]->sched,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +21
-0+ &ctx->rings[i].entity); + else + DRM_ERROR("ctx %p is still alive\n", ctx); + } +} + +void amdgpu_ctx_mgr_entity_cleanup (struct amdgpu_ctx_mgr *mgr) { +struct amdgpu_ctx *ctx; +struct idr *idp; +uint32_t id, i; + + idp = &mgr->ctx_handles; + +idr_for_each_entry (idp, ctx, id) { + +if (!ctx->adev) +return ; + +for (i =0 ; i < ctx->adev->num_rings; i++) +if (kref_read (&ctx->refcount) ==1 ) + drm_sched_entity_cleanup(&ctx->adev-Quoted 1 line
rings[i]->sched,
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +9
-1+ &ctx->rings[i].entity); + else + DRM_ERROR("ctx %p is still alive\n", ctx); + } +} +void amdgpu_ctx_mgr_fini (struct amdgpu_ctx_mgr *mgr) {struct amdgpu_ctx *ctx;struct idr *idp;uint32_t id; +amdgpu_ctx_mgr_entity_cleanup (mgr); + idp = &mgr->ctx_handles;idr_for_each_entry (idp, ctx, id) { -if (kref_put (&ctx->refcount, amdgpu_ctx_do_release) !=1 ) +if (kref_put (&ctx->refcount, amdgpu_ctx_fini) !=1 )DRM_ERROR ("ctx %p is still alive\n" , ctx); }drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1
-2@@ -913,8 +913,7 @@ void amdgpu_driver_postclose_kms(structdrm_device *dev, return;pm_runtime_get_sync (dev->dev); - -amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +amdgpu_ctx_mgr_entity_fini (&fpriv->ctx_mgr);if (adev->asic_type !=CHIP_RAVEN ) {amdgpu_uvd_free_handles(adev, file_priv); @@ -935,6+934,8 @@ void amdgpu_driver_postclose_kms(struct
drm_device*dev,
pd =amdgpu_bo_ref(fpriv->vm.root.base.bo);amdgpu_vm_fini(adev, &fpriv->vm);drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2
-0+amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr); +if (pasid)amdgpu_pasid_free_delayed (pd->tbo.resv, pasid);amdgpu_bo_unref (&pd);drivers/gpu/drm/scheduler/gpu_scheduler.c +2
-0@@ -136,6 +136,8 @@ int drm_sched_entity_init(struct drm_gpu_scheduler *sched, entity->rq = rq; entity->sched = sched; entity->guilty = guilty; + entity->fini_status =0 ; + entity->finished =NULL ;spin_lock_init (&entity->rq_lock);spin_lock_init(&entity->queue_lock);drivers/gpu/drm/scheduler/gpu_scheduler.c +16
-1@@ -197,19 +199,30 @@ static bool drm_sched_entity_is_ready(struct drm_sched_entity *entity)return true; } +static void drm_sched_entity_fini_job_cb (struct dma_fence *f, +struct dma_fence_cb *cb) +{ + struct drm_sched_job *job = container_of(cb, struct drm_sched_job, + finish_cb); +drm_sched_fence_finished (job->s_fence); +WARN_ON (job->s_fence->parent); +dma_fence_put (&job->s_fence->finished); + job->sched->ops->free_job (job); +} + +/** * Destroy a context entity * * @sched Pointer to scheduler instance * @entity The pointer to a valid scheduler entity * -* Cleanup and free the allocated resources. +* Splitting drm_sched_entity_fini() into two functions, The first +one is does the waiting, +* removes the entity from the runqueue and returns an error when +the process was killed.
*/drivers/gpu/drm/scheduler/gpu_scheduler.c +14
-6-void drm_sched_entity_fini (struct drm_gpu_scheduler *sched, +void drm_sched_entity_do_release (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity) { -int r; -if (!drm_sched_entity_is_initialized (sched, entity))return ;/** @@ -217,13 +230,28 @@ void drm_sched_entity_fini(structdrm_gpu_scheduler *sched, * queued IBs or discard them on SIGKILL */ if ((current->flags &PF_SIGNALED ) && current->exit_code ==SIGKILL ) - r = -ERESTARTSYS ; + entity->fini_status = -ERESTARTSYS ;else - r =wait_event_killable (sched->job_scheduled, + entity->fini_status =wait_event_killable (sched- > job_scheduled,drm_sched_entity_is_idle (entity));drm_sched_entity_set_rq (entity,NULL ); -if (r) { +} +EXPORT_SYMBOL (drm_sched_entity_do_release); + +/** +* Destroy a context entity +* +* @sched Pointer to scheduler instance +* @entity The pointer to a valid scheduler entity +* +* The second one then goes over the entity and signals all jobs +with an error code.
+ */drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0+void drm_sched_entity_cleanup (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity) { +if (entity->fini_status) {struct drm_sched_job *job; +int r;Quoted 1 line
Quoted 1 line
/* Park the kernel for a moment to make sure it isn'tprocessing
Quoted 46 lines
Quoted 46 lines
* our enity.
drivers/gpu/drm/scheduler/gpu_scheduler.c +17
-4@@ -241,13 +269,28 @@ void drm_sched_entity_fini(structdrm_gpu_scheduler *sched, struct drm_sched_fence *s_fence = job->s_fence;drm_sched_fence_scheduled (s_fence);dma_fence_set_error (&s_fence->finished, -ESRCH ); -drm_sched_fence_finished (s_fence); -WARN_ON (s_fence->parent); -dma_fence_put (&s_fence->finished); - sched->ops->free_job (job); + r =dma_fence_add_callback (entity->finished, &job- > finish_cb, + drm_sched_entity_fini_job_cb); +if (r == -ENOENT ) +drm_sched_entity_fini_job_cb (entity- > finished, &job->finish_cb); +else if (r) +DRM_ERROR ("fence add callback failed (%d)\n", r); + } + +if (entity->finished) { +dma_fence_put (entity->finished); + entity->finished =NULL ; } } } +EXPORT_SYMBOL (drm_sched_entity_cleanup); + +void drm_sched_entity_fini (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity) { +drm_sched_entity_do_release (sched, entity); +drm_sched_entity_cleanup (sched, entity); }EXPORT_SYMBOL (drm_sched_entity_fini); static void drm_sched_entity_wakeup(struct dma_fence *f, struct
dma_fence_cb*cb) @@ -530,6 +573,11 @@ voiddrm_sched_job_recovery(struct drm_gpu_scheduler *sched)spin_unlock(&sched->job_list_lock); fence = sched->ops->run_job(s_job); atomic_inc(&sched->hw_rq_count);drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0+ +if (s_job->entity->finished) +dma_fence_put (s_job->entity->finished); + s_job->entity->finished = dma_fence_get(&s_fence-Quoted 5 lines
Quoted 5 lines
Quoted 1 line
finished);
+
if (fence) { s_fence->parent = dma_fence_get(fence); r = dma_fence_add_callback(fence, &s_fence->cb,@@ -556,6 +604,7
Quoted 49 lines
Quoted 49 lines
@@ int drm_sched_job_init(struct
drm_sched_job*job,
void *owner){ job->sched = sched;drivers/gpu/drm/scheduler/gpu_scheduler.c +4
-0+ job->entity = entity; job->s_priority = entity->rq - sched->sched_rq; job->s_fence =drm_sched_fence_create (entity, owner);if (!job->s_fence)@@ -668,6 +717,9 @@ static int drm_sched_main(void *param) fence = sched->ops->run_job (sched_job);drm_sched_fence_scheduled (s_fence); +if (entity->finished) +dma_fence_put (entity->finished); + entity->finished =dma_fence_get (&s_fence->finished);if (fence) { s_fence->parent = dma_fence_get(fence); diff --git
a/include/drm/gpu_scheduler.hb/include/drm/gpu_scheduler.hindex c053a32..a0dd947 100644include/drm/gpu_scheduler.h +3
-0@@ -65,6 +65,8 @@ struct drm_sched_entity {struct dma_fence *dependency;struct dma_fence_cb cb;atomic_t *guilty;/* points to ctx's guilty */ +uint32_t fini_status; +struct dma_fence *finished; };/** @@ -119,6 +121,7 @@ struct drm_sched_job {uint64_t id;atomic_t karma;enum drm_sched_priority s_priority; +struct drm_sched_entity *entity; }; static inline bool drm_sched_invalidate_job(struct drm_sched_job
*s_job, @@ -186,6 +189,10 @@ int drm_sched_entity_init(structdrm_gpu_scheduler*sched,
structdrm_sched_entity*entity, structdrm_sched_rq*rq,uint32_tjobs,atomic_t*guilty);include/drm/gpu_scheduler.h +4
-0+void drm_sched_entity_do_release (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity);void +drm_sched_entity_cleanup (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity); void drm_sched_entity_fini(struct drm_gpu_scheduler *sched,Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
struct
drm_sched_entity*entity); void
drm_sched_entity_push_job(structdrm_sched_job*sched_job, --
2.7.4_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx