[Mesa-dev] [PATCH v5 09/11] vmwgfx: use common pipe_screen ref counting
Rob Herring
robh at kernel.org
Mon Aug 7 22:58:14 UTC 2017
Use the common pipe_screen ref counting and fd hashing functions.
The mutex can be dropped as the pipe loader serializes the
create_screen() and destroy() calls.
Signed-off-by: Rob Herring <robh at kernel.org>
---
src/gallium/auxiliary/target-helpers/drm_helper.h | 2 +-
src/gallium/drivers/svga/svga_public.h | 2 +-
src/gallium/drivers/svga/svga_screen.c | 7 ++-
src/gallium/targets/pipe-loader/pipe_vmwgfx.c | 2 +-
src/gallium/winsys/svga/drm/vmw_screen.c | 57 +++++------------------
src/gallium/winsys/svga/drm/vmw_screen.h | 6 ---
6 files changed, 20 insertions(+), 56 deletions(-)
diff --git a/src/gallium/auxiliary/target-helpers/drm_helper.h b/src/gallium/auxiliary/target-helpers/drm_helper.h
index 95b4a27111cb..8831ab3cb658 100644
--- a/src/gallium/auxiliary/target-helpers/drm_helper.h
+++ b/src/gallium/auxiliary/target-helpers/drm_helper.h
@@ -225,7 +225,7 @@ pipe_vmwgfx_create_screen(int fd, const struct pipe_screen_config *config)
if (!sws)
return NULL;
- screen = svga_screen_create(sws);
+ screen = svga_screen_create(sws, fd);
return screen ? debug_screen_wrap(screen) : NULL;
}
diff --git a/src/gallium/drivers/svga/svga_public.h b/src/gallium/drivers/svga/svga_public.h
index ded2e2482a7f..5a95660586d2 100644
--- a/src/gallium/drivers/svga/svga_public.h
+++ b/src/gallium/drivers/svga/svga_public.h
@@ -37,6 +37,6 @@ struct pipe_screen;
struct svga_winsys_screen;
struct pipe_screen *
-svga_screen_create(struct svga_winsys_screen *sws);
+svga_screen_create(struct svga_winsys_screen *sws, int fd);
#endif /* SVGA_PUBLIC_H_ */
diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c
index ef3e07ea38f4..7edc36f87fae 100644
--- a/src/gallium/drivers/svga/svga_screen.c
+++ b/src/gallium/drivers/svga/svga_screen.c
@@ -29,6 +29,7 @@
#include "util/u_inlines.h"
#include "util/u_string.h"
#include "util/u_math.h"
+#include "util/u_screen.h"
#include "os/os_process.h"
@@ -46,6 +47,8 @@
#include "svga3d_shaderdefs.h"
#include "VGPU10ShaderTokens.h"
+#include <fcntl.h>
+
/* NOTE: this constant may get moved into a svga3d*.h header file */
#define SVGA3D_DX_MAX_RESOURCE_SIZE (128 * 1024 * 1024)
@@ -999,7 +1002,7 @@ svga_destroy_screen( struct pipe_screen *screen )
* Create a new svga_screen object
*/
struct pipe_screen *
-svga_screen_create(struct svga_winsys_screen *sws)
+svga_screen_create(struct svga_winsys_screen *sws, int fd)
{
struct svga_screen *svgascreen;
struct pipe_screen *screen;
@@ -1192,6 +1195,8 @@ svga_screen_create(struct svga_winsys_screen *sws)
init_logging(screen);
+ pipe_screen_reference_init(screen, fcntl(fd, F_DUPFD_CLOEXEC, 3));
+
return screen;
error2:
FREE(svgascreen);
diff --git a/src/gallium/targets/pipe-loader/pipe_vmwgfx.c b/src/gallium/targets/pipe-loader/pipe_vmwgfx.c
index 68bf92ce82e5..979401161176 100644
--- a/src/gallium/targets/pipe-loader/pipe_vmwgfx.c
+++ b/src/gallium/targets/pipe-loader/pipe_vmwgfx.c
@@ -14,7 +14,7 @@ create_screen(int fd, const struct pipe_screen_config *config)
if (!sws)
return NULL;
- screen = svga_screen_create(sws);
+ screen = svga_screen_create(sws, fd);
if (!screen)
return NULL;
diff --git a/src/gallium/winsys/svga/drm/vmw_screen.c b/src/gallium/winsys/svga/drm/vmw_screen.c
index e122e0c9902c..94a058abc162 100644
--- a/src/gallium/winsys/svga/drm/vmw_screen.c
+++ b/src/gallium/winsys/svga/drm/vmw_screen.c
@@ -29,31 +29,17 @@
#include "vmw_context.h"
#include "util/u_memory.h"
+#include "util/u_screen.h"
#include "pipe/p_compiler.h"
-#include "util/u_hash_table.h"
#ifdef MAJOR_IN_MKDEV
#include <sys/mkdev.h>
#endif
#ifdef MAJOR_IN_SYSMACROS
#include <sys/sysmacros.h>
#endif
-#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
-static struct util_hash_table *dev_hash = NULL;
-
-static int vmw_dev_compare(void *key1, void *key2)
-{
- return (major(*(dev_t *)key1) == major(*(dev_t *)key2) &&
- minor(*(dev_t *)key1) == minor(*(dev_t *)key2)) ? 0 : 1;
-}
-
-static unsigned vmw_dev_hash(void *key)
-{
- return (major(*(dev_t *) key) << 16) | minor(*(dev_t *) key);
-}
-
/* Called from vmw_drm_create_screen(), creates and initializes the
* vmw_winsys_screen structure, which is the main entity in this
* module.
@@ -66,29 +52,15 @@ struct vmw_winsys_screen *
vmw_winsys_create( int fd )
{
struct vmw_winsys_screen *vws;
- struct stat stat_buf;
-
- if (dev_hash == NULL) {
- dev_hash = util_hash_table_create(vmw_dev_hash, vmw_dev_compare);
- if (dev_hash == NULL)
- return NULL;
- }
+ struct pipe_screen *pscreen = pipe_screen_reference(fd);
- if (fstat(fd, &stat_buf))
- return NULL;
-
- vws = util_hash_table_get(dev_hash, &stat_buf.st_rdev);
- if (vws) {
- vws->open_count++;
- return vws;
- }
+ if (pscreen)
+ return vmw_winsys_screen(svga_winsys_screen(pscreen));
vws = CALLOC_STRUCT(vmw_winsys_screen);
if (!vws)
goto out_no_vws;
- vws->device = stat_buf.st_rdev;
- vws->open_count = 1;
vws->ioctl.drm_fd = fcntl(fd, F_DUPFD_CLOEXEC, 3);
vws->base.have_gb_dma = TRUE;
vws->base.need_to_rebind_resources = FALSE;
@@ -106,14 +78,10 @@ vmw_winsys_create( int fd )
if (!vmw_winsys_screen_init_svga(vws))
goto out_no_svga;
- if (util_hash_table_set(dev_hash, &vws->device, vws) != PIPE_OK)
- goto out_no_hash_insert;
-
cnd_init(&vws->cs_cond);
mtx_init(&vws->cs_mutex, mtx_plain);
return vws;
-out_no_hash_insert:
out_no_svga:
vmw_pools_cleanup(vws);
out_no_pools:
@@ -130,14 +98,11 @@ out_no_vws:
void
vmw_winsys_destroy(struct vmw_winsys_screen *vws)
{
- if (--vws->open_count == 0) {
- util_hash_table_remove(dev_hash, &vws->device);
- vmw_pools_cleanup(vws);
- vws->fence_ops->destroy(vws->fence_ops);
- vmw_ioctl_cleanup(vws);
- close(vws->ioctl.drm_fd);
- mtx_destroy(&vws->cs_mutex);
- cnd_destroy(&vws->cs_cond);
- FREE(vws);
- }
+ vmw_pools_cleanup(vws);
+ vws->fence_ops->destroy(vws->fence_ops);
+ vmw_ioctl_cleanup(vws);
+ close(vws->ioctl.drm_fd);
+ mtx_destroy(&vws->cs_mutex);
+ cnd_destroy(&vws->cs_cond);
+ FREE(vws);
}
diff --git a/src/gallium/winsys/svga/drm/vmw_screen.h b/src/gallium/winsys/svga/drm/vmw_screen.h
index f21cabb51f93..e5faf36e73dc 100644
--- a/src/gallium/winsys/svga/drm/vmw_screen.h
+++ b/src/gallium/winsys/svga/drm/vmw_screen.h
@@ -94,12 +94,6 @@ struct vmw_winsys_screen
struct pb_fence_ops *fence_ops;
- /*
- * Screen instances
- */
- dev_t device;
- int open_count;
-
cnd_t cs_cond;
mtx_t cs_mutex;
};
--
2.11.0
More information about the mesa-dev
mailing list