From f4010a6da9720b1593ca34faf0d8722ca85ed6c2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michel=20D=C3=A4nzer?= Date: Mon, 30 Sep 2019 18:36:06 +0200 Subject: [PATCH] winsys/amdgpu: Keep a list of amdgpu_screen_winsyses in amdgpu_winsys v2: * Add dedicated mutex for the list. Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c | 22 ++++++++++++++++++- src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h | 7 ++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c index 2a341413033..dfdd6fb1631 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c @@ -138,6 +138,7 @@ static void do_winsys_deinit(struct amdgpu_winsys *ws) } pb_cache_deinit(&ws->bo_cache); util_hash_table_destroy(ws->bo_export_table); + simple_mtx_destroy(&ws->sws_list_lock); simple_mtx_destroy(&ws->global_bo_list_lock); simple_mtx_destroy(&ws->bo_export_table_lock); @@ -171,8 +172,21 @@ static void amdgpu_winsys_destroy(struct radeon_winsys *rws) simple_mtx_unlock(&dev_tab_mutex); - if (destroy) + if (destroy) { do_winsys_deinit(ws); + } else { + struct amdgpu_screen_winsys **sws_iter; + + /* Remove this amdgpu_screen_winsys from amdgpu_winsys' list */ + simple_mtx_lock(&ws->sws_list_lock); + for (sws_iter = &ws->sws_list; *sws_iter; sws_iter = &(*sws_iter)->next) { + if (*sws_iter == sws) { + *sws_iter = sws->next; + break; + } + } + simple_mtx_unlock(&ws->sws_list_lock); + } close(sws->fd); FREE(rws); @@ -385,6 +399,7 @@ amdgpu_winsys_create(int fd, const struct pipe_screen_config *config, list_inithead(&aws->global_bo_list); aws->bo_export_table = util_hash_table_create(hash_pointer, compare_pointers); + (void) simple_mtx_init(&aws->sws_list_lock, mtx_plain); (void) simple_mtx_init(&aws->global_bo_list_lock, mtx_plain); (void) simple_mtx_init(&aws->bo_fence_lock, mtx_plain); (void) simple_mtx_init(&aws->bo_export_table_lock, mtx_plain); @@ -435,6 +450,11 @@ amdgpu_winsys_create(int fd, const struct pipe_screen_config *config, return NULL; } + simple_mtx_lock(&aws->sws_list_lock); + ws->next = aws->sws_list; + aws->sws_list = ws; + simple_mtx_unlock(&aws->sws_list_lock); + /* We must unlock the mutex once the winsys is fully initialized, so that * other threads attempting to create the winsys from the same fd will * get a fully initialized winsys and not just half-way initialized. */ diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h index 1ff16072829..43e1df09ad5 100644 --- a/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h +++ b/src/gallium/winsys/amdgpu/drm/amdgpu_winsys.h @@ -87,6 +87,12 @@ struct amdgpu_winsys { struct list_head global_bo_list; unsigned num_buffers; + /* Single-linked list of all structs amdgpu_screen_winsys referencing this + * struct amdgpu_winsys + */ + simple_mtx_t sws_list_lock; + struct amdgpu_screen_winsys *sws_list; + /* For returning the same amdgpu_winsys_bo instance for exported * and re-imported buffers. */ struct util_hash_table *bo_export_table; @@ -97,6 +103,7 @@ struct amdgpu_screen_winsys { struct radeon_winsys base; struct amdgpu_winsys *aws; int fd; + struct amdgpu_screen_winsys *next; }; static inline struct amdgpu_screen_winsys * -- 2.30.2