Skip to content

Commit fec2c3c

Browse files
Tvrtko Ursulintursulin
authored andcommitted
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
1 parent e8c28e1 commit fec2c3c

2 files changed

Lines changed: 23 additions & 49 deletions

File tree

drivers/gpu/drm/drm_syncobj.c

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
250250
{
251251
struct drm_syncobj *syncobj;
252252

253-
spin_lock(&file_private->syncobj_table_lock);
253+
xa_lock(&file_private->syncobj_xa);
254254

255255
/* 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);
257257
if (syncobj)
258258
drm_syncobj_get(syncobj);
259259

260-
spin_unlock(&file_private->syncobj_table_lock);
260+
xa_unlock(&file_private->syncobj_xa);
261261

262262
return syncobj;
263263
}
@@ -598,23 +598,15 @@ int drm_syncobj_get_handle(struct drm_file *file_private,
598598
{
599599
int ret;
600600

601-
/* take a reference to put in the idr */
601+
/* take a reference to put in the xarray */
602602
drm_syncobj_get(syncobj);
603603

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)
612607
drm_syncobj_put(syncobj);
613-
return ret;
614-
}
615608

616-
*handle = ret;
617-
return 0;
609+
return ret;
618610
}
619611
EXPORT_SYMBOL(drm_syncobj_get_handle);
620612

@@ -638,10 +630,7 @@ static int drm_syncobj_destroy(struct drm_file *file_private,
638630
{
639631
struct drm_syncobj *syncobj;
640632

641-
spin_lock(&file_private->syncobj_table_lock);
642-
syncobj = idr_remove(&file_private->syncobj_idr, handle);
643-
spin_unlock(&file_private->syncobj_table_lock);
644-
633+
syncobj = xa_erase(&file_private->syncobj_xa, handle);
645634
if (!syncobj)
646635
return -EINVAL;
647636

@@ -722,20 +711,13 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
722711
if (fd_file(f)->f_op != &drm_syncobj_file_fops)
723712
return -EINVAL;
724713

725-
/* take a reference to put in the idr */
714+
/* take a reference to put in the xarray */
726715
syncobj = fd_file(f)->private_data;
727716
drm_syncobj_get(syncobj);
728717

729-
idr_preload(GFP_KERNEL);
730-
spin_lock(&file_private->syncobj_table_lock);
731-
ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT);
732-
spin_unlock(&file_private->syncobj_table_lock);
733-
idr_preload_end();
734-
735-
if (ret > 0) {
736-
*handle = ret;
737-
ret = 0;
738-
} else
718+
ret = xa_alloc(&file_private->syncobj_xa, handle, syncobj, xa_limit_32b,
719+
GFP_NOWAIT);
720+
if (ret)
739721
drm_syncobj_put(syncobj);
740722

741723
return ret;
@@ -814,17 +796,7 @@ static int drm_syncobj_export_sync_file(struct drm_file *file_private,
814796
void
815797
drm_syncobj_open(struct drm_file *file_private)
816798
{
817-
idr_init_base(&file_private->syncobj_idr, 1);
818-
spin_lock_init(&file_private->syncobj_table_lock);
819-
}
820-
821-
static int
822-
drm_syncobj_release_handle(int id, void *ptr, void *data)
823-
{
824-
struct drm_syncobj *syncobj = ptr;
825-
826-
drm_syncobj_put(syncobj);
827-
return 0;
799+
xa_init_flags(&file_private->syncobj_xa, XA_FLAGS_ALLOC1);
828800
}
829801

830802
/**
@@ -838,9 +810,12 @@ drm_syncobj_release_handle(int id, void *ptr, void *data)
838810
void
839811
drm_syncobj_release(struct drm_file *file_private)
840812
{
841-
idr_for_each(&file_private->syncobj_idr,
842-
&drm_syncobj_release_handle, file_private);
843-
idr_destroy(&file_private->syncobj_idr);
813+
struct drm_syncobj *syncobj;
814+
unsigned long handle;
815+
816+
xa_for_each(&file_private->syncobj_xa, handle, syncobj)
817+
drm_syncobj_put(syncobj);
818+
xa_destroy(&file_private->syncobj_xa);
844819
}
845820

846821
int

include/drm/drm_file.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/types.h>
3434
#include <linux/completion.h>
3535
#include <linux/idr.h>
36+
#include <linux/xarray.h>
3637

3738
#include <uapi/drm/drm.h>
3839

@@ -316,10 +317,8 @@ struct drm_file {
316317
/** @table_lock: Protects @object_idr. */
317318
spinlock_t table_lock;
318319

319-
/** @syncobj_idr: Mapping of sync object handles to object pointers. */
320-
struct idr syncobj_idr;
321-
/** @syncobj_table_lock: Protects @syncobj_idr. */
322-
spinlock_t syncobj_table_lock;
320+
/** @syncobj_xa: Mapping of sync object handles to object pointers. */
321+
struct xarray syncobj_xa;
323322

324323
/** @filp: Pointer to the core file structure. */
325324
struct file *filp;

0 commit comments

Comments
 (0)