Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/syncobj: Convert syncobj idr to xarray

IDR is deprecated and syncobj looks pretty trivial to convert so lets
just do it.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: intel-xe@lists.freedesktop.org
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Tvrtko Ursulin <tursulin@ursulin.net>
Link: https://lore.kernel.org/r/20251205150910.92913-1-tvrtko.ursulin@igalia.com

authored by

Tvrtko Ursulin and committed by
Tvrtko Ursulin
fec2c3c0 e8c28e16

+23 -49
+20 -45
drivers/gpu/drm/drm_syncobj.c
··· 250 250 { 251 251 struct drm_syncobj *syncobj; 252 252 253 - spin_lock(&file_private->syncobj_table_lock); 253 + xa_lock(&file_private->syncobj_xa); 254 254 255 255 /* Check if we currently have a reference on the object */ 256 - syncobj = idr_find(&file_private->syncobj_idr, handle); 256 + syncobj = xa_load(&file_private->syncobj_xa, handle); 257 257 if (syncobj) 258 258 drm_syncobj_get(syncobj); 259 259 260 - spin_unlock(&file_private->syncobj_table_lock); 260 + xa_unlock(&file_private->syncobj_xa); 261 261 262 262 return syncobj; 263 263 } ··· 598 598 { 599 599 int ret; 600 600 601 - /* take a reference to put in the idr */ 601 + /* take a reference to put in the xarray */ 602 602 drm_syncobj_get(syncobj); 603 603 604 - idr_preload(GFP_KERNEL); 605 - spin_lock(&file_private->syncobj_table_lock); 606 - ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT); 607 - spin_unlock(&file_private->syncobj_table_lock); 608 - 609 - idr_preload_end(); 610 - 611 - if (ret < 0) { 604 + ret = xa_alloc(&file_private->syncobj_xa, handle, syncobj, xa_limit_32b, 605 + GFP_NOWAIT); 606 + if (ret) 612 607 drm_syncobj_put(syncobj); 613 - return ret; 614 - } 615 608 616 - *handle = ret; 617 - return 0; 609 + return ret; 618 610 } 619 611 EXPORT_SYMBOL(drm_syncobj_get_handle); 620 612 ··· 630 638 { 631 639 struct drm_syncobj *syncobj; 632 640 633 - spin_lock(&file_private->syncobj_table_lock); 634 - syncobj = idr_remove(&file_private->syncobj_idr, handle); 635 - spin_unlock(&file_private->syncobj_table_lock); 636 - 641 + syncobj = xa_erase(&file_private->syncobj_xa, handle); 637 642 if (!syncobj) 638 643 return -EINVAL; 639 644 ··· 711 722 if (fd_file(f)->f_op != &drm_syncobj_file_fops) 712 723 return -EINVAL; 713 724 714 - /* take a reference to put in the idr */ 725 + /* take a reference to put in the xarray */ 715 726 syncobj = fd_file(f)->private_data; 716 727 drm_syncobj_get(syncobj); 717 728 718 - idr_preload(GFP_KERNEL); 719 - spin_lock(&file_private->syncobj_table_lock); 720 - ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT); 721 - spin_unlock(&file_private->syncobj_table_lock); 722 - idr_preload_end(); 723 - 724 - if (ret > 0) { 725 - *handle = ret; 726 - ret = 0; 727 - } else 729 + ret = xa_alloc(&file_private->syncobj_xa, handle, syncobj, xa_limit_32b, 730 + GFP_NOWAIT); 731 + if (ret) 728 732 drm_syncobj_put(syncobj); 729 733 730 734 return ret; ··· 796 814 void 797 815 drm_syncobj_open(struct drm_file *file_private) 798 816 { 799 - idr_init_base(&file_private->syncobj_idr, 1); 800 - spin_lock_init(&file_private->syncobj_table_lock); 801 - } 802 - 803 - static int 804 - drm_syncobj_release_handle(int id, void *ptr, void *data) 805 - { 806 - struct drm_syncobj *syncobj = ptr; 807 - 808 - drm_syncobj_put(syncobj); 809 - return 0; 817 + xa_init_flags(&file_private->syncobj_xa, XA_FLAGS_ALLOC1); 810 818 } 811 819 812 820 /** ··· 810 838 void 811 839 drm_syncobj_release(struct drm_file *file_private) 812 840 { 813 - idr_for_each(&file_private->syncobj_idr, 814 - &drm_syncobj_release_handle, file_private); 815 - idr_destroy(&file_private->syncobj_idr); 841 + struct drm_syncobj *syncobj; 842 + unsigned long handle; 843 + 844 + xa_for_each(&file_private->syncobj_xa, handle, syncobj) 845 + drm_syncobj_put(syncobj); 846 + xa_destroy(&file_private->syncobj_xa); 816 847 } 817 848 818 849 int
+3 -4
include/drm/drm_file.h
··· 33 33 #include <linux/types.h> 34 34 #include <linux/completion.h> 35 35 #include <linux/idr.h> 36 + #include <linux/xarray.h> 36 37 37 38 #include <uapi/drm/drm.h> 38 39 ··· 317 316 /** @table_lock: Protects @object_idr. */ 318 317 spinlock_t table_lock; 319 318 320 - /** @syncobj_idr: Mapping of sync object handles to object pointers. */ 321 - struct idr syncobj_idr; 322 - /** @syncobj_table_lock: Protects @syncobj_idr. */ 323 - spinlock_t syncobj_table_lock; 319 + /** @syncobj_xa: Mapping of sync object handles to object pointers. */ 320 + struct xarray syncobj_xa; 324 321 325 322 /** @filp: Pointer to the core file structure. */ 326 323 struct file *filp;