]> www.infradead.org Git - users/willy/xarray.git/commitdiff
drm/amdkfd: Convert alloc_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Mon, 18 Feb 2019 13:25:32 +0000 (08:25 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 03:39:32 +0000 (23:39 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/gpu/drm/amd/amdkfd/kfd_priv.h
drivers/gpu/drm/amd/amdkfd/kfd_process.c

index 2387c96157ec062128e750b448cda04d7bf6ac7d..b74a97bb6ce76c6f8e8012d854ce378ac712ed40 100644 (file)
@@ -639,7 +639,7 @@ struct kfd_process_device {
        void *vm;
 
        /* GPUVM allocations storage */
-       struct idr alloc_idr;
+       struct xarray allocations;
 
        /* Flag used to tell the pdd has dequeued from the dqm.
         * This is used to prevent dev->dqm->ops.process_termination() from
index 8f1076c0c88a251b1d0b38418a3b527b8f7c86c1..a734b4477156a31df31887529fc2b00d9551c1a0 100644 (file)
@@ -372,13 +372,13 @@ static void kfd_process_device_free_bos(struct kfd_process_device *pdd)
 {
        struct kfd_process *p = pdd->process;
        void *mem;
-       int id;
+       unsigned long id;
 
        /*
-        * Remove all handles from idr and release appropriate
+        * Remove all handles and release appropriate
         * local memory object
         */
-       idr_for_each_entry(&pdd->alloc_idr, mem, id) {
+       xa_for_each(&pdd->allocations, id, mem) {
                struct kfd_process_device *peer_pdd;
 
                list_for_each_entry(peer_pdd, &p->per_device_data,
@@ -427,8 +427,6 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)
                                get_order(KFD_CWSR_TBA_TMA_SIZE));
 
                kfree(pdd->qpd.doorbell_bitmap);
-               idr_destroy(&pdd->alloc_idr);
-
                kfree(pdd);
        }
 }
@@ -756,8 +754,7 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_dev *dev,
        pdd->already_dequeued = false;
        list_add(&pdd->per_device_list, &p->per_device_data);
 
-       /* Init idr used for memory handle translation */
-       idr_init(&pdd->alloc_idr);
+       xa_init_flags(&pdd->allocations, XA_FLAGS_ALLOC);
 
        return pdd;
 }
@@ -874,35 +871,36 @@ bool kfd_has_process_device_data(struct kfd_process *p)
        return !(list_empty(&p->per_device_data));
 }
 
-/* Create specific handle mapped to mem from process local memory idr
+/* Create specific handle mapped to mem from process local memory
  * Assumes that the process lock is held.
  */
 int kfd_process_device_create_obj_handle(struct kfd_process_device *pdd,
                                        void *mem)
 {
-       return idr_alloc(&pdd->alloc_idr, mem, 0, 0, GFP_KERNEL);
+       int id, ret;
+
+       ret = xa_alloc(&pdd->allocations, &id, mem, xa_limit_31b, GFP_KERNEL);
+       if (ret < 0)
+               return ret;
+       return id;
 }
 
-/* Translate specific handle from process local memory idr
+/* Translate specific handle from process local memory
  * Assumes that the process lock is held.
  */
 void *kfd_process_device_translate_handle(struct kfd_process_device *pdd,
                                        int handle)
 {
-       if (handle < 0)
-               return NULL;
-
-       return idr_find(&pdd->alloc_idr, handle);
+       return xa_load(&pdd->allocations, handle);
 }
 
-/* Remove specific handle from process local memory idr
+/* Remove specific handle from process local memory
  * Assumes that the process lock is held.
  */
 void kfd_process_device_remove_obj_handle(struct kfd_process_device *pdd,
                                        int handle)
 {
-       if (handle >= 0)
-               idr_remove(&pdd->alloc_idr, handle);
+       xa_erase(&pdd->allocations, handle);
 }
 
 /* This increments the process->ref counter. */