AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Airlie <airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: [PATCH 1/6] amdgpu/dc: convert dc_transfer to use a kref.
Date: Tue,  3 Oct 2017 12:38:57 +1000	[thread overview]
Message-ID: <20171003023902.5036-2-airlied@gmail.com> (raw)
In-Reply-To: <20171003023902.5036-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

From: Dave Airlie <airlied@redhat.com>

Rolling your own atomic ref counts is frowned upon.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/display/dc/core/dc_surface.c | 17 +++++++++--------
 drivers/gpu/drm/amd/display/dc/dc.h              |  2 +-
 drivers/gpu/drm/amd/display/dc/os_types.h        |  2 ++
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_surface.c b/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
index ff07105..c2168df 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
@@ -161,17 +161,18 @@ struct dc_gamma *dc_create_gamma()
 
 void dc_transfer_func_retain(struct dc_transfer_func *tf)
 {
-	ASSERT(atomic_read(&tf->ref_count) > 0);
-	atomic_inc(&tf->ref_count);
+	kref_get(&tf->refcount);
 }
 
-void dc_transfer_func_release(struct dc_transfer_func *tf)
+static void dc_transfer_func_free(struct kref *kref)
 {
-	ASSERT(atomic_read(&tf->ref_count) > 0);
-	atomic_dec(&tf->ref_count);
+	struct dc_transfer_func *tf = container_of(kref, struct dc_transfer_func, refcount);
+	kfree(tf);
+}
 
-	if (atomic_read(&tf->ref_count) == 0)
-		kfree(tf);
+void dc_transfer_func_release(struct dc_transfer_func *tf)
+{
+	kref_put(&tf->refcount, dc_transfer_func_free);
 }
 
 struct dc_transfer_func *dc_create_transfer_func()
@@ -181,7 +182,7 @@ struct dc_transfer_func *dc_create_transfer_func()
 	if (tf == NULL)
 		goto alloc_fail;
 
-	atomic_inc(&tf->ref_count);
+	kref_init(&tf->refcount);
 
 	return tf;
 
diff --git a/drivers/gpu/drm/amd/display/dc/dc.h b/drivers/gpu/drm/amd/display/dc/dc.h
index 9c0e000..17f0c73 100644
--- a/drivers/gpu/drm/amd/display/dc/dc.h
+++ b/drivers/gpu/drm/amd/display/dc/dc.h
@@ -334,11 +334,11 @@ enum dc_transfer_func_predefined {
 };
 
 struct dc_transfer_func {
+	struct kref refcount;
 	struct dc_transfer_func_distributed_points tf_pts;
 	enum dc_transfer_func_type type;
 	enum dc_transfer_func_predefined tf;
 	struct dc_context *ctx;
-	atomic_t ref_count;
 };
 
 /*
diff --git a/drivers/gpu/drm/amd/display/dc/os_types.h b/drivers/gpu/drm/amd/display/dc/os_types.h
index 27ed2a6..e0cd527 100644
--- a/drivers/gpu/drm/amd/display/dc/os_types.h
+++ b/drivers/gpu/drm/amd/display/dc/os_types.h
@@ -32,6 +32,8 @@
 #include <linux/types.h>
 #include <drm/drmP.h>
 
+#include <linux/kref.h>
+
 #include "cgs_linux.h"
 
 #if defined(__BIG_ENDIAN) && !defined(BIGENDIAN_CPU)
-- 
2.9.5

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-10-03  2:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-03  2:38 convert dc to using krefs for object reference counts Dave Airlie
     [not found] ` <20171003023902.5036-1-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-03  2:38   ` Dave Airlie [this message]
     [not found]     ` <20171003023902.5036-2-airlied-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-10-03  7:48       ` [PATCH 1/6] amdgpu/dc: convert dc_transfer to use a kref Christian König
2017-10-03  2:38   ` [PATCH 2/6] amdgpu/dc: convert dc_gamma to kref reference counting Dave Airlie
2017-10-03  2:38   ` [PATCH 3/6] amdgpu/dc: use kref for dc_plane_state Dave Airlie
2017-10-03  2:39   ` [PATCH 4/6] amdgpu/dc: convert dc_stream_state to kref Dave Airlie
2017-10-03  2:39   ` [PATCH 5/6] amdgpu/dc: convert dc_sink " Dave Airlie
2017-10-03  2:39   ` [PATCH 6/6] amdgpu/dc: use kref for dc_state Dave Airlie
2017-10-03  7:50   ` convert dc to using krefs for object reference counts Christian König
2017-10-03 21:14   ` Harry Wentland

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=20171003023902.5036-2-airlied@gmail.com \
    --to=airlied-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.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