From fb8794611f49fb3c440292e0425b4722e2ed05e9 Mon Sep 17 00:00:00 2001 From: Matthew Wilcox Date: Fri, 15 Feb 2019 23:49:56 -0500 Subject: [PATCH] drm/amdgpu: Convert ctx_handles to XArray Signed-off-by: Matthew Wilcox --- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 40 +++++++++-------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c | 4 +-- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c index f539a2a92774..d8fbda5b5904 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c @@ -253,17 +253,17 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev, return -ENOMEM; mutex_lock(&mgr->lock); - r = idr_alloc(&mgr->ctx_handles, ctx, 1, AMDGPU_VM_MAX_NUM_CTX, GFP_KERNEL); + r = xa_alloc(&mgr->ctx_handles, id, ctx, + XA_LIMIT(0, AMDGPU_VM_MAX_NUM_CTX - 1), GFP_KERNEL); if (r < 0) { mutex_unlock(&mgr->lock); kfree(ctx); return r; } - *id = (uint32_t)r; r = amdgpu_ctx_init(adev, priority, filp, ctx); if (r) { - idr_remove(&mgr->ctx_handles, *id); + xa_erase(&mgr->ctx_handles, *id); *id = 0; kfree(ctx); } @@ -295,7 +295,7 @@ static int amdgpu_ctx_free(struct amdgpu_fpriv *fpriv, uint32_t id) struct amdgpu_ctx *ctx; mutex_lock(&mgr->lock); - ctx = idr_remove(&mgr->ctx_handles, id); + ctx = xa_erase(&mgr->ctx_handles, id); if (ctx) kref_put(&ctx->refcount, amdgpu_ctx_do_release); mutex_unlock(&mgr->lock); @@ -315,7 +315,7 @@ static int amdgpu_ctx_query(struct amdgpu_device *adev, mgr = &fpriv->ctx_mgr; mutex_lock(&mgr->lock); - ctx = idr_find(&mgr->ctx_handles, id); + ctx = xa_load(&mgr->ctx_handles, id); if (!ctx) { mutex_unlock(&mgr->lock); return -EINVAL; @@ -351,7 +351,7 @@ static int amdgpu_ctx_query2(struct amdgpu_device *adev, mgr = &fpriv->ctx_mgr; mutex_lock(&mgr->lock); - ctx = idr_find(&mgr->ctx_handles, id); + ctx = xa_load(&mgr->ctx_handles, id); if (!ctx) { mutex_unlock(&mgr->lock); return -EINVAL; @@ -440,7 +440,7 @@ struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id) mgr = &fpriv->ctx_mgr; mutex_lock(&mgr->lock); - ctx = idr_find(&mgr->ctx_handles, id); + ctx = xa_load(&mgr->ctx_handles, id); if (ctx) kref_get(&ctx->refcount); mutex_unlock(&mgr->lock); @@ -554,20 +554,17 @@ int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx, void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr) { mutex_init(&mgr->lock); - idr_init(&mgr->ctx_handles); + xa_init_flags(&mgr->ctx_handles, XA_FLAGS_ALLOC1); } long amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr, long timeout) { unsigned num_entities = amdgput_ctx_total_num_entities(); struct amdgpu_ctx *ctx; - struct idr *idp; - uint32_t id, i; - - idp = &mgr->ctx_handles; + unsigned long id, i; mutex_lock(&mgr->lock); - idr_for_each_entry(idp, ctx, id) { + xa_for_each(&mgr->ctx_handles, id, ctx) { for (i = 0; i < num_entities; i++) { struct drm_sched_entity *entity; @@ -583,12 +580,9 @@ void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr) { unsigned num_entities = amdgput_ctx_total_num_entities(); struct amdgpu_ctx *ctx; - struct idr *idp; - uint32_t id, i; - - idp = &mgr->ctx_handles; + unsigned long id, i; - idr_for_each_entry(idp, ctx, id) { + xa_for_each(&mgr->ctx_handles, id, ctx) { if (kref_read(&ctx->refcount) != 1) { DRM_ERROR("ctx %p is still alive\n", ctx); continue; @@ -602,18 +596,14 @@ void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr) void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr) { struct amdgpu_ctx *ctx; - struct idr *idp; - uint32_t id; + unsigned long id; amdgpu_ctx_mgr_entity_fini(mgr); - idp = &mgr->ctx_handles; - - idr_for_each_entry(idp, ctx, id) { + xa_for_each(&mgr->ctx_handles, id, ctx) { if (kref_put(&ctx->refcount, amdgpu_ctx_fini) != 1) DRM_ERROR("ctx %p is still alive\n", ctx); } - - idr_destroy(&mgr->ctx_handles); + xa_destroy(&mgr->ctx_handles); mutex_destroy(&mgr->lock); } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h index 5f1b54c9bcdb..caa58828c885 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h @@ -57,7 +57,7 @@ struct amdgpu_ctx_mgr { struct amdgpu_device *adev; struct mutex lock; /* protected by lock */ - struct idr ctx_handles; + struct xarray ctx_handles; }; extern const unsigned int amdgpu_ctx_num_entities[AMDGPU_HW_IP_NUM]; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c index c799691dfa84..306e2bc78cb7 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c @@ -59,7 +59,7 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev, struct fd f = fdget(fd); struct amdgpu_fpriv *fpriv; struct amdgpu_ctx *ctx; - uint32_t id; + unsigned long id; int r; if (!f.file) @@ -71,7 +71,7 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev, return r; } - idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id) + xa_for_each(&fpriv->ctx_mgr.ctx_handles, id, ctx) amdgpu_ctx_priority_override(ctx, priority); fdput(f); -- 2.50.1