mirror of
https://github.com/torvalds/linux.git
synced 2026-08-01 12:11:59 +02:00
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
This commit is contained in:
parent
e8c28e16c3
commit
fec2c3c01f
|
|
@ -250,14 +250,14 @@ struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
|
||||||
{
|
{
|
||||||
struct drm_syncobj *syncobj;
|
struct drm_syncobj *syncobj;
|
||||||
|
|
||||||
spin_lock(&file_private->syncobj_table_lock);
|
xa_lock(&file_private->syncobj_xa);
|
||||||
|
|
||||||
/* Check if we currently have a reference on the object */
|
/* Check if we currently have a reference on the object */
|
||||||
syncobj = idr_find(&file_private->syncobj_idr, handle);
|
syncobj = xa_load(&file_private->syncobj_xa, handle);
|
||||||
if (syncobj)
|
if (syncobj)
|
||||||
drm_syncobj_get(syncobj);
|
drm_syncobj_get(syncobj);
|
||||||
|
|
||||||
spin_unlock(&file_private->syncobj_table_lock);
|
xa_unlock(&file_private->syncobj_xa);
|
||||||
|
|
||||||
return syncobj;
|
return syncobj;
|
||||||
}
|
}
|
||||||
|
|
@ -598,23 +598,15 @@ int drm_syncobj_get_handle(struct drm_file *file_private,
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* take a reference to put in the idr */
|
/* take a reference to put in the xarray */
|
||||||
drm_syncobj_get(syncobj);
|
drm_syncobj_get(syncobj);
|
||||||
|
|
||||||
idr_preload(GFP_KERNEL);
|
ret = xa_alloc(&file_private->syncobj_xa, handle, syncobj, xa_limit_32b,
|
||||||
spin_lock(&file_private->syncobj_table_lock);
|
GFP_NOWAIT);
|
||||||
ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT);
|
if (ret)
|
||||||
spin_unlock(&file_private->syncobj_table_lock);
|
|
||||||
|
|
||||||
idr_preload_end();
|
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
drm_syncobj_put(syncobj);
|
drm_syncobj_put(syncobj);
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
*handle = ret;
|
return ret;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(drm_syncobj_get_handle);
|
EXPORT_SYMBOL(drm_syncobj_get_handle);
|
||||||
|
|
||||||
|
|
@ -638,10 +630,7 @@ static int drm_syncobj_destroy(struct drm_file *file_private,
|
||||||
{
|
{
|
||||||
struct drm_syncobj *syncobj;
|
struct drm_syncobj *syncobj;
|
||||||
|
|
||||||
spin_lock(&file_private->syncobj_table_lock);
|
syncobj = xa_erase(&file_private->syncobj_xa, handle);
|
||||||
syncobj = idr_remove(&file_private->syncobj_idr, handle);
|
|
||||||
spin_unlock(&file_private->syncobj_table_lock);
|
|
||||||
|
|
||||||
if (!syncobj)
|
if (!syncobj)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
|
@ -722,20 +711,13 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
|
||||||
if (fd_file(f)->f_op != &drm_syncobj_file_fops)
|
if (fd_file(f)->f_op != &drm_syncobj_file_fops)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/* take a reference to put in the idr */
|
/* take a reference to put in the xarray */
|
||||||
syncobj = fd_file(f)->private_data;
|
syncobj = fd_file(f)->private_data;
|
||||||
drm_syncobj_get(syncobj);
|
drm_syncobj_get(syncobj);
|
||||||
|
|
||||||
idr_preload(GFP_KERNEL);
|
ret = xa_alloc(&file_private->syncobj_xa, handle, syncobj, xa_limit_32b,
|
||||||
spin_lock(&file_private->syncobj_table_lock);
|
GFP_NOWAIT);
|
||||||
ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT);
|
if (ret)
|
||||||
spin_unlock(&file_private->syncobj_table_lock);
|
|
||||||
idr_preload_end();
|
|
||||||
|
|
||||||
if (ret > 0) {
|
|
||||||
*handle = ret;
|
|
||||||
ret = 0;
|
|
||||||
} else
|
|
||||||
drm_syncobj_put(syncobj);
|
drm_syncobj_put(syncobj);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -814,17 +796,7 @@ static int drm_syncobj_export_sync_file(struct drm_file *file_private,
|
||||||
void
|
void
|
||||||
drm_syncobj_open(struct drm_file *file_private)
|
drm_syncobj_open(struct drm_file *file_private)
|
||||||
{
|
{
|
||||||
idr_init_base(&file_private->syncobj_idr, 1);
|
xa_init_flags(&file_private->syncobj_xa, XA_FLAGS_ALLOC1);
|
||||||
spin_lock_init(&file_private->syncobj_table_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
drm_syncobj_release_handle(int id, void *ptr, void *data)
|
|
||||||
{
|
|
||||||
struct drm_syncobj *syncobj = ptr;
|
|
||||||
|
|
||||||
drm_syncobj_put(syncobj);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -838,9 +810,12 @@ drm_syncobj_release_handle(int id, void *ptr, void *data)
|
||||||
void
|
void
|
||||||
drm_syncobj_release(struct drm_file *file_private)
|
drm_syncobj_release(struct drm_file *file_private)
|
||||||
{
|
{
|
||||||
idr_for_each(&file_private->syncobj_idr,
|
struct drm_syncobj *syncobj;
|
||||||
&drm_syncobj_release_handle, file_private);
|
unsigned long handle;
|
||||||
idr_destroy(&file_private->syncobj_idr);
|
|
||||||
|
xa_for_each(&file_private->syncobj_xa, handle, syncobj)
|
||||||
|
drm_syncobj_put(syncobj);
|
||||||
|
xa_destroy(&file_private->syncobj_xa);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
#include <linux/completion.h>
|
#include <linux/completion.h>
|
||||||
#include <linux/idr.h>
|
#include <linux/idr.h>
|
||||||
|
#include <linux/xarray.h>
|
||||||
|
|
||||||
#include <uapi/drm/drm.h>
|
#include <uapi/drm/drm.h>
|
||||||
|
|
||||||
|
|
@ -316,10 +317,8 @@ struct drm_file {
|
||||||
/** @table_lock: Protects @object_idr. */
|
/** @table_lock: Protects @object_idr. */
|
||||||
spinlock_t table_lock;
|
spinlock_t table_lock;
|
||||||
|
|
||||||
/** @syncobj_idr: Mapping of sync object handles to object pointers. */
|
/** @syncobj_xa: Mapping of sync object handles to object pointers. */
|
||||||
struct idr syncobj_idr;
|
struct xarray syncobj_xa;
|
||||||
/** @syncobj_table_lock: Protects @syncobj_idr. */
|
|
||||||
spinlock_t syncobj_table_lock;
|
|
||||||
|
|
||||||
/** @filp: Pointer to the core file structure. */
|
/** @filp: Pointer to the core file structure. */
|
||||||
struct file *filp;
|
struct file *filp;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user