From: Sidhartha Kumar <sidhartha.kumar@oracle.com>
To: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org
Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org,
tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch,
willy@infradead.org, sidhartha.kumar@oracle.com,
jani.nikula@linux.intel.com
Subject: [PATCH v3 3/6] drm: Convert syncobj_idr to XArray
Date: Tue, 26 Aug 2025 15:48:57 +0000 [thread overview]
Message-ID: <20250826154900.405480-4-sidhartha.kumar@oracle.com> (raw)
In-Reply-To: <20250826154900.405480-1-sidhartha.kumar@oracle.com>
From: Matthew Wilcox <willy@infradead.org>
From: Matthew Wilcox <willy@infradead.org>
Remove syncobj_table_lock by converting the syncobj_idr to an XArray.
handle and syncobj is not modified in this change so the indentifier value
remains the same.
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
---
drivers/gpu/drm/drm_syncobj.c | 64 +++++++++++------------------------
include/drm/drm_file.h | 6 ++--
2 files changed, 22 insertions(+), 48 deletions(-)
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index e1b0fa4000cd..091f43cf11ba 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -250,14 +250,12 @@ struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
{
struct drm_syncobj *syncobj;
- spin_lock(&file_private->syncobj_table_lock);
-
- /* Check if we currently have a reference on the object */
- syncobj = idr_find(&file_private->syncobj_idr, handle);
+ /* Get a reference on the object */
+ xa_lock(&file_private->syncobjs);
+ syncobj = xa_load(&file_private->syncobjs, handle);
if (syncobj)
drm_syncobj_get(syncobj);
-
- spin_unlock(&file_private->syncobj_table_lock);
+ xa_unlock(&file_private->syncobjs);
return syncobj;
}
@@ -598,23 +596,16 @@ int drm_syncobj_get_handle(struct drm_file *file_private,
{
int ret;
- /* take a reference to put in the idr */
+ /* take a reference to put in the XArray */
drm_syncobj_get(syncobj);
- idr_preload(GFP_KERNEL);
- spin_lock(&file_private->syncobj_table_lock);
- ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT);
- spin_unlock(&file_private->syncobj_table_lock);
+ ret = xa_alloc(&file_private->syncobjs, handle, syncobj, xa_limit_31b,
+ GFP_KERNEL);
- idr_preload_end();
-
- if (ret < 0) {
+ if (ret < 0)
drm_syncobj_put(syncobj);
- return ret;
- }
- *handle = ret;
- return 0;
+ return ret;
}
EXPORT_SYMBOL(drm_syncobj_get_handle);
@@ -638,9 +629,7 @@ static int drm_syncobj_destroy(struct drm_file *file_private,
{
struct drm_syncobj *syncobj;
- spin_lock(&file_private->syncobj_table_lock);
- syncobj = idr_remove(&file_private->syncobj_idr, handle);
- spin_unlock(&file_private->syncobj_table_lock);
+ syncobj = xa_erase(&file_private->syncobjs, handle);
if (!syncobj)
return -EINVAL;
@@ -726,16 +715,10 @@ static int drm_syncobj_fd_to_handle(struct drm_file *file_private,
syncobj = fd_file(f)->private_data;
drm_syncobj_get(syncobj);
- idr_preload(GFP_KERNEL);
- spin_lock(&file_private->syncobj_table_lock);
- ret = idr_alloc(&file_private->syncobj_idr, syncobj, 1, 0, GFP_NOWAIT);
- spin_unlock(&file_private->syncobj_table_lock);
- idr_preload_end();
+ ret = xa_alloc(&file_private->syncobjs, handle, syncobj, xa_limit_31b,
+ GFP_KERNEL);
- if (ret > 0) {
- *handle = ret;
- ret = 0;
- } else
+ if (ret < 0)
drm_syncobj_put(syncobj);
return ret;
@@ -814,17 +797,7 @@ static int drm_syncobj_export_sync_file(struct drm_file *file_private,
void
drm_syncobj_open(struct drm_file *file_private)
{
- idr_init_base(&file_private->syncobj_idr, 1);
- 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;
+ xa_init_flags(&file_private->syncobjs, XA_FLAGS_ALLOC1);
}
/**
@@ -838,9 +811,12 @@ drm_syncobj_release_handle(int id, void *ptr, void *data)
void
drm_syncobj_release(struct drm_file *file_private)
{
- idr_for_each(&file_private->syncobj_idr,
- &drm_syncobj_release_handle, file_private);
- idr_destroy(&file_private->syncobj_idr);
+ struct drm_syncobj *syncobj;
+ unsigned long index;
+
+ xa_for_each(&file_private->syncobjs, index, syncobj)
+ drm_syncobj_put(syncobj);
+ xa_destroy(&file_private->syncobjs);
}
int
diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
index 115763799625..ee5a16338c86 100644
--- a/include/drm/drm_file.h
+++ b/include/drm/drm_file.h
@@ -309,10 +309,8 @@ struct drm_file {
/** @table_lock: Protects @object_idr. */
spinlock_t table_lock;
- /** @syncobj_idr: Mapping of sync object handles to object pointers. */
- struct idr syncobj_idr;
- /** @syncobj_table_lock: Protects @syncobj_idr. */
- spinlock_t syncobj_table_lock;
+ /** @syncobjs: Mapping of sync object handles to object pointers. */
+ struct xarray syncobjs;
/** @filp: Pointer to the core file structure. */
struct file *filp;
--
2.43.0
next prev parent reply other threads:[~2025-08-26 15:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 15:48 [PATCH v3 0/6] DRM IDR to Xarray conversions Sidhartha Kumar
2025-08-26 15:48 ` [PATCH v3 1/6] drm: Convert aux_idr to XArray Sidhartha Kumar
2025-08-26 15:48 ` [PATCH v3 2/6] drm: Convert object_name_idr " Sidhartha Kumar
2025-08-26 15:48 ` Sidhartha Kumar [this message]
2025-08-26 15:48 ` [PATCH v3 4/6] drm: Convert magic_map " Sidhartha Kumar
2025-08-26 15:48 ` [PATCH v3 5/6] drm: Convert lessee_idr " Sidhartha Kumar
2025-08-26 15:49 ` [PATCH v3 6/6] drm: Convert tile_idr " Sidhartha Kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250826154900.405480-4-sidhartha.kumar@oracle.com \
--to=sidhartha.kumar@oracle.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).