drm: Only bump object-reference count when adding first handle
We only need a single reference count for all handles (i.e. non-zero obj->handle_count) and so can trim a few atomic operations by only taking the reference on the first handle and dropping it after the last. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Link: http://patchwork.freedesktop.org/patch/msgid/1451902261-25380-2-git-send-email-chris@chris-wilson.co.uk Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
parent
6984128d01
commit
98a8883ad4
@ -220,6 +220,9 @@ static void drm_gem_object_exported_dma_buf_free(struct drm_gem_object *obj)
|
|||||||
static void
|
static void
|
||||||
drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
|
drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
|
||||||
{
|
{
|
||||||
|
struct drm_device *dev = obj->dev;
|
||||||
|
bool final = false;
|
||||||
|
|
||||||
if (WARN_ON(obj->handle_count == 0))
|
if (WARN_ON(obj->handle_count == 0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -229,14 +232,16 @@ drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
|
|||||||
* checked for a name
|
* checked for a name
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mutex_lock(&obj->dev->object_name_lock);
|
mutex_lock(&dev->object_name_lock);
|
||||||
if (--obj->handle_count == 0) {
|
if (--obj->handle_count == 0) {
|
||||||
drm_gem_object_handle_free(obj);
|
drm_gem_object_handle_free(obj);
|
||||||
drm_gem_object_exported_dma_buf_free(obj);
|
drm_gem_object_exported_dma_buf_free(obj);
|
||||||
|
final = true;
|
||||||
}
|
}
|
||||||
mutex_unlock(&obj->dev->object_name_lock);
|
mutex_unlock(&dev->object_name_lock);
|
||||||
|
|
||||||
drm_gem_object_unreference_unlocked(obj);
|
if (final)
|
||||||
|
drm_gem_object_unreference_unlocked(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -329,6 +334,8 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
WARN_ON(!mutex_is_locked(&dev->object_name_lock));
|
WARN_ON(!mutex_is_locked(&dev->object_name_lock));
|
||||||
|
if (obj->handle_count++ == 0)
|
||||||
|
drm_gem_object_reference(obj);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the user-visible handle using idr. Preload and perform
|
* Get the user-visible handle using idr. Preload and perform
|
||||||
@ -338,10 +345,10 @@ drm_gem_handle_create_tail(struct drm_file *file_priv,
|
|||||||
spin_lock(&file_priv->table_lock);
|
spin_lock(&file_priv->table_lock);
|
||||||
|
|
||||||
ret = idr_alloc(&file_priv->object_idr, obj, 1, 0, GFP_NOWAIT);
|
ret = idr_alloc(&file_priv->object_idr, obj, 1, 0, GFP_NOWAIT);
|
||||||
drm_gem_object_reference(obj);
|
|
||||||
obj->handle_count++;
|
|
||||||
spin_unlock(&file_priv->table_lock);
|
spin_unlock(&file_priv->table_lock);
|
||||||
idr_preload_end();
|
idr_preload_end();
|
||||||
|
|
||||||
mutex_unlock(&dev->object_name_lock);
|
mutex_unlock(&dev->object_name_lock);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto err_unref;
|
goto err_unref;
|
||||||
|
Loading…
Reference in New Issue
Block a user