[Mesa-dev] [PATCH v3 06/11] freedreno: use common screen ref counting

Rob Herring robh at kernel.org
Wed Jul 20 22:25:07 UTC 2016


Use the common pipe_screen ref counting and fd hashing functions. The
mutex can be dropped as the pipe loader protects the create_screen()
calls.

Signed-off-by: Rob Herring <robh at kernel.org>
Cc: Rob Clark <robclark at freedesktop.org>
---
 src/gallium/drivers/freedreno/freedreno_screen.c   |  1 -
 src/gallium/drivers/freedreno/freedreno_screen.h   | 10 ---
 .../winsys/freedreno/drm/freedreno_drm_winsys.c    | 94 ++--------------------
 3 files changed, 6 insertions(+), 99 deletions(-)

diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c b/src/gallium/drivers/freedreno/freedreno_screen.c
index 5255c10..324f712 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -565,7 +565,6 @@ fd_screen_create(struct fd_device *dev)
 	pscreen = &screen->base;
 
 	screen->dev = dev;
-	screen->refcnt = 1;
 
 	// maybe this should be in context?
 	screen->pipe = fd_pipe_new(screen->dev, FD_PIPE_3D);
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.h b/src/gallium/drivers/freedreno/freedreno_screen.h
index a81c778..8dcacca 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.h
+++ b/src/gallium/drivers/freedreno/freedreno_screen.h
@@ -42,16 +42,6 @@ struct fd_bo;
 struct fd_screen {
 	struct pipe_screen base;
 
-	/* it would be tempting to use pipe_reference here, but that
-	 * really doesn't work well if it isn't the first member of
-	 * the struct, so not quite so awesome to be adding refcnting
-	 * further down the inheritance hierarchy:
-	 */
-	int refcnt;
-
-	/* place for winsys to stash it's own stuff: */
-	void *winsys_priv;
-
 	uint32_t gmemsize_bytes;
 	uint32_t device_id;
 	uint32_t gpu_id;         /* 220, 305, etc */
diff --git a/src/gallium/winsys/freedreno/drm/freedreno_drm_winsys.c b/src/gallium/winsys/freedreno/drm/freedreno_drm_winsys.c
index e4785f8..56c021d 100644
--- a/src/gallium/winsys/freedreno/drm/freedreno_drm_winsys.c
+++ b/src/gallium/winsys/freedreno/drm/freedreno_drm_winsys.c
@@ -26,102 +26,20 @@
  *    Rob Clark <robclark at freedesktop.org>
  */
 
-#include <sys/stat.h>
-
-#include "pipe/p_context.h"
-#include "pipe/p_state.h"
-#include "util/u_format.h"
-#include "util/u_memory.h"
-#include "util/u_inlines.h"
-#include "util/u_hash_table.h"
-#include "os/os_thread.h"
+#include "util/u_screen.h"
 
 #include "freedreno_drm_public.h"
 
 #include "freedreno/freedreno_screen.h"
 
-static struct util_hash_table *fd_tab = NULL;
-
-pipe_static_mutex(fd_screen_mutex);
-
-static void
-fd_drm_screen_destroy(struct pipe_screen *pscreen)
-{
-	struct fd_screen *screen = fd_screen(pscreen);
-	boolean destroy;
-
-	pipe_mutex_lock(fd_screen_mutex);
-	destroy = --screen->refcnt == 0;
-	if (destroy) {
-		int fd = fd_device_fd(screen->dev);
-		util_hash_table_remove(fd_tab, intptr_to_pointer(fd));
-	}
-	pipe_mutex_unlock(fd_screen_mutex);
-
-	if (destroy) {
-		pscreen->destroy = screen->winsys_priv;
-		pscreen->destroy(pscreen);
-	}
-}
-
-static unsigned hash_fd(void *key)
-{
-	int fd = pointer_to_intptr(key);
-	struct stat stat;
-	fstat(fd, &stat);
-
-	return stat.st_dev ^ stat.st_ino ^ stat.st_rdev;
-}
-
-static int compare_fd(void *key1, void *key2)
-{
-	int fd1 = pointer_to_intptr(key1);
-	int fd2 = pointer_to_intptr(key2);
-	struct stat stat1, stat2;
-	fstat(fd1, &stat1);
-	fstat(fd2, &stat2);
-
-	return stat1.st_dev != stat2.st_dev ||
-			stat1.st_ino != stat2.st_ino ||
-			stat1.st_rdev != stat2.st_rdev;
-}
-
 struct pipe_screen *
 fd_drm_screen_create(int fd)
 {
-	struct pipe_screen *pscreen = NULL;
-
-	pipe_mutex_lock(fd_screen_mutex);
-	if (!fd_tab) {
-		fd_tab = util_hash_table_create(hash_fd, compare_fd);
-		if (!fd_tab)
-			goto unlock;
-	}
-
-	pscreen = util_hash_table_get(fd_tab, intptr_to_pointer(fd));
-	if (pscreen) {
-		fd_screen(pscreen)->refcnt++;
-	} else {
-		struct fd_device *dev = fd_device_new_dup(fd);
-		if (!dev)
-			goto unlock;
-
-		pscreen = fd_screen_create(dev);
-		if (pscreen) {
-			int fd = fd_device_fd(dev);
-
-			util_hash_table_set(fd_tab, intptr_to_pointer(fd), pscreen);
-
-			/* Bit of a hack, to avoid circular linkage dependency,
-			 * ie. pipe driver having to call in to winsys, we
-			 * override the pipe drivers screen->destroy():
-			 */
-			fd_screen(pscreen)->winsys_priv = pscreen->destroy;
-			pscreen->destroy = fd_drm_screen_destroy;
-		}
-	}
+        struct pipe_screen *pscreen = pipe_screen_reference(fd);
+        if (pscreen)
+            return pscreen;
 
-unlock:
-	pipe_mutex_unlock(fd_screen_mutex);
+	pscreen = fd_screen_create(fd_device_new(fd));
+	pipe_screen_reference_init(pscreen, fd);
 	return pscreen;
 }
-- 
2.9.2



More information about the mesa-dev mailing list