]> www.infradead.org Git - users/willy/xarray.git/commitdiff
habanalabs: Convert ctx_handles to XArray
authorMatthew Wilcox <willy@infradead.org>
Fri, 15 Mar 2019 12:21:44 +0000 (08:21 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:19 +0000 (21:38 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/misc/habanalabs/context.c
drivers/misc/habanalabs/habanalabs.h

index 8682590e3f6ef14ee397e767d339d71eeee00e2f..f22fe5ef6011ef9c7b234d49e3e9ce7d4571f63a 100644 (file)
@@ -59,7 +59,7 @@ int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv)
 {
        struct hl_ctx_mgr *mgr = &hpriv->ctx_mgr;
        struct hl_ctx *ctx;
-       int rc;
+       int rc, id;
 
        ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
        if (!ctx) {
@@ -78,12 +78,9 @@ int hl_ctx_create(struct hl_device *hdev, struct hl_fpriv *hpriv)
        hpriv->ctx = ctx;
        hdev->user_ctx = ctx;
 
-       mutex_lock(&mgr->ctx_lock);
-       rc = idr_alloc(&mgr->ctx_handles, ctx, 1, 0, GFP_KERNEL);
-       mutex_unlock(&mgr->ctx_lock);
-
+       rc = xa_alloc(&mgr->ctx_handles, &id, ctx, xa_limit_31b, GFP_KERNEL);
        if (rc < 0) {
-               dev_err(hdev->dev, "Failed to allocate IDR for a new CTX\n");
+               dev_err(hdev->dev, "Failed to allocate ID for a new CTX\n");
                hl_ctx_free(hdev, ctx);
                goto out_err;
        }
@@ -201,8 +198,7 @@ struct dma_fence *hl_ctx_get_fence(struct hl_ctx *ctx, u64 seq)
  */
 void hl_ctx_mgr_init(struct hl_ctx_mgr *mgr)
 {
-       mutex_init(&mgr->ctx_lock);
-       idr_init(&mgr->ctx_handles);
+       xa_init_flags(&mgr->ctx_handles, XA_FLAGS_ALLOC1);
 }
 
 /*
@@ -217,14 +213,8 @@ void hl_ctx_mgr_init(struct hl_ctx_mgr *mgr)
 void hl_ctx_mgr_fini(struct hl_device *hdev, struct hl_ctx_mgr *mgr)
 {
        struct hl_ctx *ctx;
-       struct idr *idp;
-       u32 id;
-
-       idp = &mgr->ctx_handles;
+       unsigned long id;
 
-       idr_for_each_entry(idp, ctx, id)
+       xa_for_each(&mgr->ctx_handles, id, ctx)
                hl_ctx_free(hdev, ctx);
-
-       idr_destroy(&mgr->ctx_handles);
-       mutex_destroy(&mgr->ctx_lock);
 }
index 399093ee50cd9d70438471981461fa0b962879dd..d91332a9b876b0919690e7083aa90c3220504f9b 100644 (file)
@@ -652,12 +652,10 @@ struct hl_ctx {
 
 /**
  * struct hl_ctx_mgr - for handling multiple contexts.
- * @ctx_lock: protects ctx_handles.
- * @ctx_handles: idr to hold all ctx handles.
+ * @ctx_handles: holds all ctx handles.
  */
 struct hl_ctx_mgr {
-       struct mutex            ctx_lock;
-       struct idr              ctx_handles;
+       struct xarray           ctx_handles;
 };