]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
drm: Apply kref_put_mutex() optimisations to drm_gem_object_unreference_unlocked()
authorChris Wilson <chris@chris-wilson.co.uk>
Tue, 6 Aug 2013 08:59:46 +0000 (09:59 +0100)
committerDave Airlie <airlied@redhat.com>
Wed, 7 Aug 2013 00:07:17 +0000 (10:07 +1000)
We can apply the same optimisation tricks as kref_put_mutex() in our
local equivalent function. However, we have a different locking semantic
(we unlock ourselves, in kref_put_mutex() the callee unlocks) so that we
can use the same callbacks for both locked and unlocked kref_put()s and
so can not simply convert to using kref_put_mutex() directly.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
include/drm/drmP.h

index a029dea13f48e944f56bb7585fa8d143b70743b2..3b7fda557b8dd16635a84568efba9cf36618446e 100644 (file)
@@ -1629,10 +1629,12 @@ drm_gem_object_unreference(struct drm_gem_object *obj)
 static inline void
 drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
 {
-       if (obj != NULL) {
+       if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
                struct drm_device *dev = obj->dev;
+
                mutex_lock(&dev->struct_mutex);
-               kref_put(&obj->refcount, drm_gem_object_free);
+               if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
+                       drm_gem_object_free(&obj->refcount);
                mutex_unlock(&dev->struct_mutex);
        }
 }