Skip to contentSkip to conversation

drm: use idr_init_base() over idr_init() if applicable

PATCH RESEND In review Danilo Krummrich 2 participants 12 messages Jul 20, 2022 – Jul 23, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover drm: use idr_init_base() over idr_init() if applicable

This patch series initializes IDRs with idr_init_base(&idr, 1) rather than idr_init(&idr) in case for the particular IDR no IDs < 1 are ever requested - this avoids unnecessary tree walks.

Danilo Krummrich (10):
drm/amdgpu: use idr_init_base() to initialize mgr->ctx_handles drm/amdgpu: use idr_init_base() to initialize fpriv->bo_list_handles
drm: use idr_init_base() to initialize master->magic_map
drm: use idr_init_base() to initialize master->lessee_idr
drm: use idr_init_base() to initialize mode_config.object_idr
drm: use idr_init_base() to initialize mode_config.tile_idr drm/sis: use idr_init_base() to initialize dev_priv->object_idr drm/v3d: use idr_init_base() to initialize v3d_priv->perfmon.idr drm/via: use idr_init_base() to initialize dev_priv->object_idr drm/todo: remove task for idr_init_base()

 Documentation/gpu/todo.rst              | 12 ------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  2 +-
 drivers/gpu/drm/drm_auth.c              |  4 ++--
 drivers/gpu/drm/drm_mode_config.c       |  4 ++--
 drivers/gpu/drm/sis/sis_drv.c           |  2 +-
 drivers/gpu/drm/v3d/v3d_perfmon.c       |  2 +-
 drivers/gpu/drm/via/via_map.c           |  2 +-
 8 files changed, 9 insertions(+), 21 deletions(-)
Signature · 1 line
2.36.1
#1 lore raw

PATCH RESEND 1/10 drm/amdgpu: use idr_init_base() to initialize mgr->ctx_handles

idr_init_base(), implemented by commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient"), let us set an arbitrary base other than idr_init(), which uses base 0.

Since, for this IDR, no ID < 1 is ever requested, using idr_init_base(&idr, 1) avoids unnecessary tree walks.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -1
index 7dc92ef36b2b..cc87c3809a8d 100644
@@ -841,7 +841,7 @@ void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr,
 
 	mgr->adev = adev;
 	mutex_init(&mgr->lock);
-	idr_init(&mgr->ctx_handles);
+	idr_init_base(&mgr->ctx_handles, 1);
 
 	for (i = 0; i < AMDGPU_HW_IP_NUM; ++i)
 		atomic64_set(&mgr->time_spend[i], 0);
Signature · 1 line
2.36.1
#2 lore raw

PATCH RESEND 2/10 drm/amdgpu: use idr_init_base() to initialize fpriv->bo_list_handles

In reply to Danilo Krummrich

idr_init_base(), implemented by commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient"), let us set an arbitrary base other than idr_init(), which uses base 0.

Since, for this IDR, no ID < 1 is ever requested/allocated, using idr_init_base(&idr, 1) avoids unnecessary tree walks.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
index 6de63ea6687e..103927c48d05 100644
@@ -1148,7 +1148,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 	}
 
 	mutex_init(&fpriv->bo_list_lock);
-	idr_init(&fpriv->bo_list_handles);
+	idr_init_base(&fpriv->bo_list_handles, 1);
 
 	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr, adev);
 
Signature · 1 line
2.36.1
#3 lore raw

PATCH RESEND 3/10 drm: use idr_init_base() to initialize master->magic_map

In reply to Danilo Krummrich

idr_init_base(), implemented by commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient"), let us set an arbitrary base other than idr_init(), which uses base 0.

Since, for this IDR, no ID < 1 is ever requested/allocated, using idr_init_base(&idr, 1) avoids unnecessary tree walks.

---
 drivers/gpu/drm/drm_auth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_auth.c +1 -1
index 6e433d465f41..63395bebaa6b 100644
@@ -140,7 +140,7 @@ struct drm_master *drm_master_create(struct drm_device *dev)
 
 	kref_init(&master->refcount);
 	drm_master_legacy_init(master);
-	idr_init(&master->magic_map);
+	idr_init_base(&master->magic_map, 1);
 	master->dev = dev;
 
 	/* initialize the tree of output resource lessees */
Signature · 1 line
2.36.1
#4 lore raw

PATCH RESEND 4/10 drm: use idr_init_base() to initialize master->lessee_idr

In reply to Danilo Krummrich

idr_init_base(), implemented by commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient"), let us set an arbitrary base other than idr_init(), which uses base 0.

Since, for this IDR, no ID < 1 is ever requested/allocated, using idr_init_base(&idr, 1) avoids unnecessary tree walks.

---
 drivers/gpu/drm/drm_auth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_auth.c +1 -1
index 63395bebaa6b..cf92a9ae8034 100644
@@ -147,7 +147,7 @@ struct drm_master *drm_master_create(struct drm_device *dev)
 	INIT_LIST_HEAD(&master->lessees);
 	INIT_LIST_HEAD(&master->lessee_list);
 	idr_init(&master->leases);
-	idr_init(&master->lessee_idr);
+	idr_init_base(&master->lessee_idr, 1);
 
 	return master;
 }
Signature · 1 line
2.36.1
#5 lore raw

PATCH RESEND 5/10 drm: use idr_init_base() to initialize mode_config.object_idr

In reply to Danilo Krummrich

idr_init_base(), implemented by commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient"), let us set an arbitrary base other than idr_init(), which uses base 0.

Since, for this IDR, no ID < 1 is ever requested/allocated, using idr_init_base(&idr, 1) avoids unnecessary tree walks.

---
 drivers/gpu/drm/drm_mode_config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_mode_config.c +1 -1
index 37b4b9f0e468..e2a295a4ee0b 100644
@@ -411,7 +411,7 @@ int drmm_mode_config_init(struct drm_device *dev)
 	INIT_LIST_HEAD(&dev->mode_config.property_blob_list);
 	INIT_LIST_HEAD(&dev->mode_config.plane_list);
 	INIT_LIST_HEAD(&dev->mode_config.privobj_list);
-	idr_init(&dev->mode_config.object_idr);
+	idr_init_base(&dev->mode_config.object_idr, 1);
 	idr_init(&dev->mode_config.tile_idr);
 	ida_init(&dev->mode_config.connector_ida);
 	spin_lock_init(&dev->mode_config.connector_list_lock);
Signature · 1 line
2.36.1
#6 lore raw

PATCH RESEND 6/10 drm: use idr_init_base() to initialize mode_config.tile_idr

In reply to Danilo Krummrich

idr_init_base(), implemented by commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient"), let us set an arbitrary base other than idr_init(), which uses base 0.

Since, for this IDR, no ID < 1 is ever requested/allocated, using idr_init_base(&idr, 1) avoids unnecessary tree walks.

---
 drivers/gpu/drm/drm_mode_config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_mode_config.c +1 -1
index e2a295a4ee0b..3d1c1ade5a25 100644
@@ -412,7 +412,7 @@ int drmm_mode_config_init(struct drm_device *dev)
 	INIT_LIST_HEAD(&dev->mode_config.plane_list);
 	INIT_LIST_HEAD(&dev->mode_config.privobj_list);
 	idr_init_base(&dev->mode_config.object_idr, 1);
-	idr_init(&dev->mode_config.tile_idr);
+	idr_init_base(&dev->mode_config.tile_idr, 1);
 	ida_init(&dev->mode_config.connector_ida);
 	spin_lock_init(&dev->mode_config.connector_list_lock);
 
Signature · 1 line
2.36.1
#7 lore raw

PATCH RESEND 7/10 drm/sis: use idr_init_base() to initialize dev_priv->object_idr

In reply to Danilo Krummrich

idr_init_base(), implemented by commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient"), let us set an arbitrary base other than idr_init(), which uses base 0.

Since, for this IDR, no ID < 1 is ever requested/allocated, using idr_init_base(&idr, 1) avoids unnecessary tree walks.

---
 drivers/gpu/drm/sis/sis_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/sis/sis_drv.c +1 -1
index e35e719cf315..6173020a9bf5 100644
@@ -50,7 +50,7 @@ static int sis_driver_load(struct drm_device *dev, unsigned long chipset)
 	if (dev_priv == NULL)
 		return -ENOMEM;
 
-	idr_init(&dev_priv->object_idr);
+	idr_init_base(&dev_priv->object_idr, 1);
 	dev->dev_private = (void *)dev_priv;
 	dev_priv->chipset = chipset;
 
Signature · 1 line
2.36.1
#8 lore raw

PATCH RESEND 8/10 drm/v3d: use idr_init_base() to initialize v3d_priv->perfmon.idr

In reply to Danilo Krummrich

idr_init_base(), implemented by commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient"), let us set an arbitrary base other than idr_init(), which uses base 0.

Since, for this IDR, no ID < 1 is ever requested/allocated, using idr_init_base(&idr, 1) avoids unnecessary tree walks.

---
 drivers/gpu/drm/v3d/v3d_perfmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/v3d/v3d_perfmon.c +1 -1
index f6a88abccc7d..48aaaa972c49 100644
@@ -95,7 +95,7 @@ struct v3d_perfmon *v3d_perfmon_find(struct v3d_file_priv *v3d_priv, int id)
 void v3d_perfmon_open_file(struct v3d_file_priv *v3d_priv)
 {
 	mutex_init(&v3d_priv->perfmon.lock);
-	idr_init(&v3d_priv->perfmon.idr);
+	idr_init_base(&v3d_priv->perfmon.idr, 1);
 }
 
 static int v3d_perfmon_idr_del(int id, void *elem, void *data)
Signature · 1 line
2.36.1
maintainer Reviewed-by on v1 8/10
#9 lore raw

Re: [PATCH RESEND 08/10] drm/v3d: use idr_init_base() to initialize v3d_priv->perfmon.idr

Quoted 18 lines · Danilo Krummrich

idr_init_base(), implemented by commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient"), let us set an arbitrary base other than idr_init(), which uses base 0.

Since, for this IDR, no ID < 1 is ever requested/allocated, using idr_init_base(&idr, 1) avoids unnecessary tree walks.

---
 drivers/gpu/drm/v3d/v3d_perfmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/v3d/v3d_perfmon.c +0 -0
index f6a88abccc7d..48aaaa972c49 100644

drivers/gpu/drm/v3d/v3d_perfmon.c struct v3d_perfmon *v3d_perfmon_find(struct v3d_file_priv *v3d_priv, int id) · line 98

Quoted 5 lines
drivers/gpu/drm/v3d/v3d_perfmon.c +1 -1
@@ -95,7 +95,7 @@ struct v3d_perfmon *v3d_perfmon_find(struct v3d_file_priv *v3d_priv, int id)
 void v3d_perfmon_open_file(struct v3d_file_priv *v3d_priv)
 {
 	mutex_init(&v3d_priv->perfmon.lock);
-	idr_init(&v3d_priv->perfmon.idr);
+	idr_init_base(&v3d_priv->perfmon.idr, 1);

Thanks

Quoted 6 lines
drivers/gpu/drm/v3d/v3d_perfmon.c +0 -0
 }
 
 static int v3d_perfmon_idr_del(int id, void *elem, void *data)
Signature · 1 line
2.36.1
#10 lore raw

PATCH RESEND 9/10 drm/via: use idr_init_base() to initialize dev_priv->object_idr

In reply to Danilo Krummrich

idr_init_base(), implemented by commit 6ce711f27500 ("idr: Make 1-based IDRs more efficient"), let us set an arbitrary base other than idr_init(), which uses base 0.

Since, for this IDR, no ID < 1 is ever requested/allocated, using idr_init_base(&idr, 1) avoids unnecessary tree walks.

---
 drivers/gpu/drm/via/via_map.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/via/via_map.c +1 -1
index a9f6b0c11966..c20bb20c0e09 100644
@@ -106,7 +106,7 @@ int via_driver_load(struct drm_device *dev, unsigned long chipset)
 	if (dev_priv == NULL)
 		return -ENOMEM;
 
-	idr_init(&dev_priv->object_idr);
+	idr_init_base(&dev_priv->object_idr, 1);
 	dev->dev_private = (void *)dev_priv;
 
 	dev_priv->chipset = chipset;
Signature · 1 line
2.36.1
#11 lore raw

PATCH RESEND 10/10 drm/todo: remove task for idr_init_base()

In reply to Danilo Krummrich

All IDRs in the DRM core and drivers which are applicable for using idr_init_base() over idr_init() should be set up to use a proper base in order to avoid unnecessary tree walks.

---
 Documentation/gpu/todo.rst | 12 ------------
 1 file changed, 12 deletions(-)
Documentation/gpu/todo.rst +0 -12
index 10bfb50908d1..de226ccc2c54 100644
@@ -322,18 +322,6 @@ Contact: Daniel Vetter, Noralf Tronnes
 
 Level: Advanced
 
-idr_init_base()
----------------
-
-DRM core&drivers uses a lot of idr (integer lookup directories) for mapping
-userspace IDs to internal objects, and in most places ID=0 means NULL and hence
-is never used. Switching to idr_init_base() for these would make the idr more
-efficient.
-
-Contact: Daniel Vetter
-
-Level: Starter
-
 struct drm_gem_object_funcs
 ---------------------------
 
Signature · 1 line
2.36.1