amdgpu: stop using the hash table for fd_tab
PATCH 1/6 amdgpu: stop using the hash table for fd_tab
We have so few devices that just walking a linked list is probably faster.
--- amdgpu/amdgpu_device.c | 49 ++++++++++++++++-------------------------------- amdgpu/amdgpu_internal.h | 1 + 2 files changed, 17 insertions(+), 33 deletions(-)
amdgpu/amdgpu_device.c +16 -33
@@ -43,10 +43,9 @@#include "util_math.h" #define PTR_TO_UINT (x) ((unsigned)((intptr_t)(x))) -#define UINT_TO_PTR (x) ((void *)((intptr_t)(x)))static pthread_mutex_t fd_mutex =PTHREAD_MUTEX_INITIALIZER ; -static struct util_hash_table *fd_tab; +static amdgpu_device_handle fd_list;static unsigned handle_hash (void *key) {
@@ -58,28 +57,8 @@ static int handle_compare(void *key1, void *key2)return PTR_TO_UINT (key1) !=PTR_TO_UINT (key2); } -static unsigned fd_hash (void *key) +static int fd_compare (int fd1,int fd2) { -int fd =PTR_TO_UINT (key); -char *name =drmGetPrimaryDeviceNameFromFd (fd); -unsigned result =0 ; -char *c; - -if (name ==NULL ) -return 0 ; - -for (c = name; *c; ++c) - result += *c; - -free (name); - -return result; -} - -static int fd_compare (void *key1,void *key2) -{ -int fd1 =PTR_TO_UINT (key1); -int fd2 =PTR_TO_UINT (key2);char *name1 =drmGetPrimaryDeviceNameFromFd (fd1);char *name2 =drmGetPrimaryDeviceNameFromFd (fd2);int result;
@@ -127,16 +106,17 @@ static int amdgpu_get_auth(int fd, int *auth)static void amdgpu_device_free_internal (amdgpu_device_handle dev) { +amdgpu_device_handle *node = &fd_list; +pthread_mutex_lock (&fd_mutex); -util_hash_table_remove (fd_tab,UINT_TO_PTR (dev->fd)); -if (util_hash_table_count (fd_tab) ==0 ) { -util_hash_table_destroy (fd_tab); - fd_tab =NULL ; - } +while (*node != dev && (*node)->next) + node = &(*node)->next; + *node = (*node)->next; +pthread_mutex_unlock (&fd_mutex); +close (dev->fd);if ((dev->flink_fd >=0 ) && (dev->fd != dev->flink_fd))close (dev->flink_fd); -pthread_mutex_unlock (&fd_mutex);amdgpu_vamgr_deinit (&dev->vamgr_32);amdgpu_vamgr_deinit (&dev->vamgr);
@@ -187,8 +167,6 @@ int amdgpu_device_initialize(int fd, *device_handle =NULL ;pthread_mutex_lock (&fd_mutex); -if (!fd_tab) - fd_tab =util_hash_table_create (fd_hash, fd_compare); r =amdgpu_get_auth (fd, &flag_auth);if (r) { fprintf(stderr, "%s: amdgpu_get_auth (1) failed (%i)\n",
@@ -196,7 +174,11 @@ int amdgpu_device_initialize(int fd,pthread_mutex_unlock (&fd_mutex);return r; } - dev =util_hash_table_get (fd_tab,UINT_TO_PTR (fd)); + +for (dev = fd_list; dev; dev = dev->next) +if (fd_compare (dev->fd, fd) ==0 ) +break ; +if (dev) { r =amdgpu_get_auth (dev->fd, &flag_authexist);if (r) {
@@ -297,7 +279,8 @@ int amdgpu_device_initialize(int fd, *major_version = dev->major_version; *minor_version = dev->minor_version; *device_handle = dev; -util_hash_table_set (fd_tab,UINT_TO_PTR (dev->fd), dev); + dev->next = fd_list; + fd_list = dev;pthread_mutex_unlock (&fd_mutex);return 0 ;
amdgpu/amdgpu_internal.h +1 -0
@@ -65,6 +65,7 @@ struct amdgpu_va {struct amdgpu_device {atomic_t refcount; +struct amdgpu_device *next;int fd;int flink_fd;unsigned major_version;
Signature · 6 lines
2.14.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20180803113458.28560-1-christian.koenig-5C7GfCeVMHo@public.gmane.org
PATCH 2/6 amdgpu: add handle table implementation v2
The kernel handles are dense and the kernel always tries to use the lowest free id. Use this to implement a more efficient handle table by using a resizeable array instead of a hash.
v2: add handle_table_fini function, extra key checks,
fix typo in function name
--- amdgpu/Makefile.sources | 4 ++- amdgpu/handle_table.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ amdgpu/handle_table.h | 41 ++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 amdgpu/handle_table.c create mode 100644 amdgpu/handle_table.h
amdgpu/Makefile.sources +3 -1
@@ -10,7 +10,9 @@ LIBDRM_AMDGPU_FILES := \ util_hash.c \ util_hash.h \ util_hash_table.c \ - util_hash_table.h + util_hash_table.h \ + handle_table.c \ + handle_table.h LIBDRM_AMDGPU_H_FILES := \ amdgpu.h
amdgpu/handle_table.c new file +72 -0
72 lines not on this page · raw message
amdgpu/handle_table.h new file +41 -0
41 lines not on this page · raw message
Signature · 6 lines
2.14.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20180803113458.28560-2-christian.koenig-5C7GfCeVMHo@public.gmane.org
Re: [PATCH libdrm 2/6] amdgpu: add handle table implementation v2
Quoted 63 lines · Christian König
The kernel handles are dense and the kernel always tries to use the lowest free id. Use this to implement a more efficient handle table by using a resizeable array instead of a hash.
v2: add
handle_table_finifunction, extra key checks,
fix typo in function nameSigned-off-by Christian König <[email protected]>--- amdgpu/Makefile.sources | 4 ++- amdgpu/handle_table.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ amdgpu/handle_table.h | 41 ++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-)create mode 100644
amdgpu/handle_table.c
create mode 100644amdgpu/handle_table.hamdgpu/Makefile.sources +3
-1@@ -10,7 +10,9 @@ LIBDRM_AMDGPU_FILES := \ util_hash.c \ util_hash.h \ util_hash_table.c \ - util_hash_table.h + util_hash_table.h \ + handle_table.c \ + handle_table.h LIBDRM_AMDGPU_H_FILES := \ amdgpu.hamdgpu/handle_table.c new file +26
-0@@ -0,0 +1,72 @@ +/* +* Copyright 2018 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +*/ + +#include <stdlib.h> +#include <string.h> +#include <errno.h>
amdgpu/handle_table.c line 36
Quoted 10 lines
amdgpu/handle_table.c new file +10
-0+#include <unistd.h> +#include "handle_table.h" +#include "util_math.h" + +drm_private int handle_table_insert(struct handle_table *table, uint32_t key, +void *value) +{ +if (key >= table->max_key) { +uint32_t alignment =sysconf (_SC_PAGESIZE) /sizeof (void *); +uint32_t max_key =ALIGN (key, alignment);
On 2nd thought, we may add table->count to take the role of current table->max_key, and table_max_key could be updated by key rather than aligned value.
Then we could traverse the table by max_key instead of the entire table.
Regards,
Jerry
Quoted 74 lines
amdgpu/handle_table.c new file +36
-0+void **values; + + values =realloc (table->values, max_key *sizeof (void *)); +if (!values) +return -ENOMEM ; + +memset (values + table->max_key,0 , (max_key - table->max_key) * +sizeof (void *)); + + table->max_key = max_key; + table->values = values; + } + table->values[key] = value; +return 0 ; +} + +drm_private void handle_table_remove(struct handle_table *table, uint32_t key) +{ +if (key < table->max_key) + table->values[key] =NULL ; +} + +drm_private void *handle_table_lookup(struct handle_table *table, uint32_t key) +{ +if (key < table->max_key) +return table->values[key]; +else +return NULL ; +} + +drm_private void handle_table_fini(struct handle_table *table) +{ +free (table->values); + table->max_key =0 ; + table->values =NULL ; +}amdgpu/handle_table.h new file +31
-0@@ -0,0 +1,41 @@ +/* +* Copyright 2018 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +*/ + +#ifndef _HANDLE_TABLE_H_ +#define _HANDLE_TABLE_H_ + +#include <stdint.h> +#include "libdrm_macros.h" + +struct handle_table { + uint32_t max_key;
amdgpu/handle_table.h line 41
Quoted 10 lines
amdgpu/handle_table.h new file +10
-0+void **values; +}; + +drm_private int handle_table_insert(struct handle_table *table, uint32_t key, +void *value); +drm_private void handle_table_remove(struct handle_table *table, uint32_t key); +drm_private void *handle_table_lookup(struct handle_table *table, uint32_t key); +drm_private void handle_table_fini(struct handle_table *table); + +#endif /* _HANDLE_TABLE_H_ */
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/6 amdgpu: use handle table for KMS handles
In reply to a message not in the archiveInstead of the hash use the handle table.
--- amdgpu/amdgpu_bo.c | 19 ++++++++++--------- amdgpu/amdgpu_device.c | 3 +-- amdgpu/amdgpu_internal.h | 3 ++- 3 files changed, 13 insertions(+), 12 deletions(-)
amdgpu/amdgpu_bo.c +10 -9
@@ -90,8 +90,12 @@ int amdgpu_bo_alloc(amdgpu_device_handle dev,pthread_mutex_init (&bo->cpu_access_mutex,NULL ); - *buf_handle = bo; -return 0 ; +if (r) +amdgpu_bo_free (bo); +else + *buf_handle = bo; + +return r; } int amdgpu_bo_set_metadata(amdgpu_bo_handle bo,
@@ -171,8 +175,7 @@ int amdgpu_bo_query_info(amdgpu_bo_handle bo,static void amdgpu_add_handle_to_table (amdgpu_bo_handle bo) {pthread_mutex_lock (&bo->dev->bo_table_mutex); -util_hash_table_set (bo->dev->bo_handles, - (void *)(uintptr_t )bo->handle, bo); +handle_table_insert (&bo->dev->bo_handles, bo->handle, bo);pthread_mutex_unlock (&bo->dev->bo_table_mutex); }
@@ -303,8 +306,7 @@ int amdgpu_bo_import(amdgpu_device_handle dev,break ;case amdgpu_bo_handle_type_dma_buf_fd: - bo =util_hash_table_get (dev->bo_handles, - (void *)(uintptr_t )shared_handle); + bo =handle_table_lookup (&dev->bo_handles, shared_handle);break ;case amdgpu_bo_handle_type_kms:
@@ -387,7 +389,7 @@ int amdgpu_bo_import(amdgpu_device_handle dev, bo->dev = dev;pthread_mutex_init (&bo->cpu_access_mutex,NULL ); -util_hash_table_set (dev->bo_handles, (void *)(uintptr_t )bo->handle, bo); +handle_table_insert (&dev->bo_handles, bo->handle, bo);pthread_mutex_unlock (&dev->bo_table_mutex); output->buf_handle = bo;
@@ -406,8 +408,7 @@ int amdgpu_bo_free(amdgpu_bo_handle buf_handle)if (update_references (&bo->refcount,NULL )) {/* Remove the buffer from the hash tables. */ -util_hash_table_remove (dev->bo_handles, - (void *)(uintptr_t )bo->handle); +handle_table_remove (&dev->bo_handles, bo->handle);if (bo->flink_name) { util_hash_table_remove(dev->bo_flink_names,
amdgpu/amdgpu_device.c +1 -2
@@ -122,8 +122,8 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev)amdgpu_vamgr_deinit (&dev->vamgr);amdgpu_vamgr_deinit (&dev->vamgr_high_32);amdgpu_vamgr_deinit (&dev->vamgr_high); +handle_table_fini (&dev->bo_handles);util_hash_table_destroy (dev->bo_flink_names); -util_hash_table_destroy (dev->bo_handles);pthread_mutex_destroy (&dev->bo_table_mutex);free (dev->marketing_name);free (dev);
@@ -230,7 +230,6 @@ int amdgpu_device_initialize(int fd, dev->bo_flink_names =util_hash_table_create (handle_hash, handle_compare); - dev->bo_handles =util_hash_table_create (handle_hash, handle_compare);pthread_mutex_init (&dev->bo_table_mutex,NULL );/* Check if acceleration is working. */
amdgpu/amdgpu_internal.h +2 -1
@@ -32,6 +32,7 @@#include "xf86atomic.h" #include "amdgpu.h" #include "util_double_list.h" +#include "handle_table.h" #define AMDGPU_CS_MAX_RINGS 8/* do not use below macro if b is not power of 2 aligned value */
@@ -73,7 +74,7 @@ struct amdgpu_device {char *marketing_name;/** List of buffer handles. Protected by bo_table_mutex. */ -struct util_hash_table *bo_handles; +struct handle_table bo_handles;/** List of buffer GEM flink names. Protected by bo_table_mutex. */ struct util_hash_table *bo_flink_names;/** This protects all hash tables. */
Signature · 6 lines
2.14.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/6 amdgpu: use handle table for flink names
In reply to a message not in the archiveInstead of the hash use the handle table.
--- amdgpu/amdgpu_bo.c | 26 +++++++++++++------------- amdgpu/amdgpu_device.c | 15 +-------------- amdgpu/amdgpu_internal.h | 2 +- 3 files changed, 15 insertions(+), 28 deletions(-)
amdgpu/amdgpu_bo.c +13 -13
@@ -37,7 +37,6 @@#include "xf86drm.h" #include "amdgpu_drm.h" #include "amdgpu_internal.h" -#include "util_hash_table.h" #include "util_math.h" static void amdgpu_close_kms_handle(amdgpu_device_handle dev,
@@ -219,12 +218,10 @@ static int amdgpu_bo_export_flink(amdgpu_bo_handle bo) }pthread_mutex_lock (&bo->dev->bo_table_mutex); -util_hash_table_set (bo->dev->bo_flink_names, - (void *)(uintptr_t )bo->flink_name, - bo); + r =handle_table_insert (&bo->dev->bo_flink_names, bo->flink_name, bo);pthread_mutex_unlock (&bo->dev->bo_table_mutex); -return 0 ; +return r; } int amdgpu_bo_export(amdgpu_bo_handle bo,
@@ -301,8 +298,7 @@ int amdgpu_bo_import(amdgpu_device_handle dev,/* If we have already created a buffer with this handle, find it. */ switch (type) {case amdgpu_bo_handle_type_gem_flink_name: - bo =util_hash_table_get (dev->bo_flink_names, - (void *)(uintptr_t )shared_handle); + bo =handle_table_lookup (&dev->bo_flink_names, shared_handle);break ;case amdgpu_bo_handle_type_dma_buf_fd:
@@ -370,8 +366,13 @@ int amdgpu_bo_import(amdgpu_device_handle dev, } bo->flink_name = shared_handle; bo->alloc_size = open_arg.size; -util_hash_table_set (dev->bo_flink_names, - (void *)(uintptr_t )bo->flink_name, bo); + r =handle_table_insert (&dev->bo_flink_names, shared_handle, + bo); +if (r) { +pthread_mutex_unlock (&dev->bo_table_mutex); +amdgpu_bo_free (bo); +return r; + }break ;case amdgpu_bo_handle_type_dma_buf_fd:
@@ -410,10 +411,9 @@ int amdgpu_bo_free(amdgpu_bo_handle buf_handle)/* Remove the buffer from the hash tables. */ handle_table_remove (&dev->bo_handles, bo->handle); -if (bo->flink_name) { -util_hash_table_remove (dev->bo_flink_names, - (void *)(uintptr_t )bo->flink_name); - } +if (bo->flink_name) +handle_table_remove (&dev->bo_flink_names, + bo->flink_name);/* Release CPU access. */ if (bo->cpu_map_count >0 ) {
amdgpu/amdgpu_device.c +1 -14
@@ -39,7 +39,6 @@#include "xf86drm.h" #include "amdgpu_drm.h" #include "amdgpu_internal.h" -#include "util_hash_table.h" #include "util_math.h" #define PTR_TO_UINT (x) ((unsigned)((intptr_t)(x)))
@@ -47,16 +46,6 @@static pthread_mutex_t fd_mutex =PTHREAD_MUTEX_INITIALIZER ;static amdgpu_device_handle fd_list; -static unsigned handle_hash (void *key) -{ -return PTR_TO_UINT (key); -} - -static int handle_compare (void *key1,void *key2) -{ -return PTR_TO_UINT (key1) !=PTR_TO_UINT (key2); -} -static int fd_compare (int fd1,int fd2) {char *name1 =drmGetPrimaryDeviceNameFromFd (fd1);
@@ -123,7 +112,7 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev)amdgpu_vamgr_deinit (&dev->vamgr_high_32);amdgpu_vamgr_deinit (&dev->vamgr_high);handle_table_fini (&dev->bo_handles); -util_hash_table_destroy (dev->bo_flink_names); +handle_table_fini (&dev->bo_flink_names);pthread_mutex_destroy (&dev->bo_table_mutex);free (dev->marketing_name);free (dev);
@@ -228,8 +217,6 @@ int amdgpu_device_initialize(int fd, dev->minor_version = version->version_minor;drmFreeVersion (version); - dev->bo_flink_names =util_hash_table_create (handle_hash, - handle_compare);pthread_mutex_init (&dev->bo_table_mutex,NULL );/* Check if acceleration is working. */
amdgpu/amdgpu_internal.h +1 -1
@@ -76,7 +76,7 @@ struct amdgpu_device {/** List of buffer handles. Protected by bo_table_mutex. */ struct handle_table bo_handles;/** List of buffer GEM flink names. Protected by bo_table_mutex. */ -struct util_hash_table *bo_flink_names; +struct handle_table bo_flink_names;/** This protects all hash tables. */ pthread_mutex_t bo_table_mutex;struct drm_amdgpu_info_device dev_info;
Signature · 6 lines
2.14.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 5/6 amdgpu: remove the hash table implementation
In reply to a message not in the archiveNot used any more.
--- amdgpu/Makefile.sources | 4 - amdgpu/util_hash.c | 383 ----------------------------------------------- amdgpu/util_hash.h | 103 ------------- amdgpu/util_hash_table.c | 270 --------------------------------- amdgpu/util_hash_table.h | 71 --------- 5 files changed, 831 deletions(-) delete mode 100644 amdgpu/util_hash.c delete mode 100644 amdgpu/util_hash.h delete mode 100644 amdgpu/util_hash_table.c delete mode 100644 amdgpu/util_hash_table.h
amdgpu/Makefile.sources +0 -4
@@ -7,10 +7,6 @@ LIBDRM_AMDGPU_FILES := \ amdgpu_internal.h \ amdgpu_vamgr.c \ amdgpu_vm.c \ - util_hash.c \ - util_hash.h \ - util_hash_table.c \ - util_hash_table.h \ handle_table.c \ handle_table.h
amdgpu/util_hash.c deleted +0 -383
383 lines not on this page · raw message
amdgpu/util_hash.h deleted +0 -103
103 lines not on this page · raw message
amdgpu/util_hash_table.c deleted +0 -270
270 lines not on this page · raw message
amdgpu/util_hash_table.h deleted +0 -71
71 lines not on this page · raw message
Signature · 6 lines
2.14.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 6/6 amdgpu: always add all BOs to lockup table
In reply to a message not in the archiveThis way we can always find a BO structure by its handle.
--- amdgpu/amdgpu_bo.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
amdgpu/amdgpu_bo.c +4 -10
@@ -87,6 +87,10 @@ int amdgpu_bo_alloc(amdgpu_device_handle dev, bo->handle = args.out.handle; +pthread_mutex_lock (&bo->dev->bo_table_mutex); + r =handle_table_insert (&bo->dev->bo_handles, bo->handle, bo); +pthread_mutex_unlock (&bo->dev->bo_table_mutex); +pthread_mutex_init (&bo->cpu_access_mutex,NULL );if (r)
@@ -171,13 +175,6 @@ int amdgpu_bo_query_info(amdgpu_bo_handle bo,return 0 ; } -static void amdgpu_add_handle_to_table (amdgpu_bo_handle bo) -{ -pthread_mutex_lock (&bo->dev->bo_table_mutex); -handle_table_insert (&bo->dev->bo_handles, bo->handle, bo); -pthread_mutex_unlock (&bo->dev->bo_table_mutex); -} -static int amdgpu_bo_export_flink (amdgpu_bo_handle bo) {struct drm_gem_flink flink;
@@ -240,14 +237,11 @@ int amdgpu_bo_export(amdgpu_bo_handle bo,return 0 ;case amdgpu_bo_handle_type_kms: -amdgpu_add_handle_to_table (bo); -/* fall through */ case amdgpu_bo_handle_type_kms_noimport: *shared_handle = bo->handle;return 0 ;case amdgpu_bo_handle_type_dma_buf_fd: -amdgpu_add_handle_to_table (bo);return drmPrimeHandleToFD (bo->dev->fd, bo->handle,DRM_CLOEXEC |DRM_RDWR , (int *)shared_handle);
Signature · 6 lines
2.14.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20180803113458.28560-6-christian.koenig-5C7GfCeVMHo@public.gmane.org
Michel Dänzer
Reviewed-byRe: [PATCH libdrm 6/6] amdgpu: always add all BOs to lockup table
Quoted 3 lines · Christian König
This way we can always find a BO structure by its handle.
Signed-off-by Christian König <[email protected]>
In the shortlog, should be "handle table" instead of "lockup table"?
With that fixed, the series is
Thanks for doing this!
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 98a57d99-4016-8896-1791-d5550cc2c277-otUistvHUpPR7s880joybQ@public.gmane.org
Re: [PATCH libdrm 6/6] amdgpu: always add all BOs to lockup table
Am 03.08.2018 um 15:52 schrieb Michel Dänzer:
Quoted 12 lines · Christian König
Quoted 3 lines
This way we can always find a BO structure by its handle.
Signed-off-by Christian König <[email protected]>In the shortlog, should be "handle table" instead of "lockup table"?
With that fixed, the series is
Reviewed-by Michel Dänzer <[email protected]>Thanks for doing this!
No, problem. Could you fix up the subject line and push it upstream?
I still don't have a working fdo account again :( Alternatively do you know an admin I can ping about that?
Thanks,
Christian.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): faabbb5b-fc6a-3c7e-a051-ce4283f45241-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH libdrm 6/6] amdgpu: always add all BOs to lockup table
Ping ajax or daniels or anholt on IRC.
Alex
________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Christian König <[email protected]>
Sent: Friday, August 3, 2018 9:54:42 AM
To: Michel Dänzer
Cc: [email protected]
Subject: Re: [PATCH libdrm 6/6] amdgpu: always add all BOs to lockup table
Am 03.08.2018 um 15:52 schrieb Michel Dänzer:
Quoted 12 lines · Christian König
Quoted 3 lines
This way we can always find a BO structure by its handle.
Signed-off-by Christian König <[email protected]>In the shortlog, should be "handle table" instead of "lockup table"?
With that fixed, the series is
Reviewed-by Michel Dänzer <[email protected]>Thanks for doing this!
No, problem. Could you fix up the subject line and push it upstream?
I still don't have a working fdo account again :( Alternatively do you know an admin I can ping about that?
Thanks,
Christian.
_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH libdrm 6/6] amdgpu: always add all BOs to lockup table
In reply to a message not in the archiveI don't think this is a good idea. Can you please explain why this won't cause performance regressions?
Thanks
Marek
Quoted 54 lines · Christian König
This way we can always find a BO structure by its handle.
Signed-off-by Christian König <[email protected]>--- amdgpu/amdgpu_bo.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)amdgpu/amdgpu_bo.c +4
-11@@ -87,6 +87,10 @@ int amdgpu_bo_alloc(amdgpu_device_handle dev, bo->handle = args.out.handle; +pthread_mutex_lock (&bo->dev->bo_table_mutex); + r =handle_table_insert (&bo->dev->bo_handles, bo->handle, bo); +pthread_mutex_unlock (&bo->dev->bo_table_mutex); +pthread_mutex_init (&bo->cpu_access_mutex,NULL );if (r)@@ -171,13 +175,6 @@ int amdgpu_bo_query_info(amdgpu_bo_handle bo,return 0 ; } -static void amdgpu_add_handle_to_table (amdgpu_bo_handle bo) -{ -pthread_mutex_lock (&bo->dev->bo_table_mutex); -handle_table_insert (&bo->dev->bo_handles, bo->handle, bo); -pthread_mutex_unlock (&bo->dev->bo_table_mutex); -} -static int amdgpu_bo_export_flink (amdgpu_bo_handle bo) {struct drm_gem_flink flink;@@ -240,14 +237,11 @@ int amdgpu_bo_export(amdgpu_bo_handle bo,return 0 ;case amdgpu_bo_handle_type_kms: -amdgpu_add_handle_to_table (bo); -/* fall through */ case amdgpu_bo_handle_type_kms_noimport: *shared_handle = bo->handle;return 0 ;case amdgpu_bo_handle_type_dma_buf_fd: -amdgpu_add_handle_to_table (bo);return drmPrimeHandleToFD (bo->dev->fd, bo->handle,DRM_CLOEXEC |DRM_RDWR , (int *)shared_handle); --2.14.1
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CAAxE2A51vBrphE3CVPVeKixKpxS3q0vqJ8NUkMfp+bM1M3qHbA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [PATCH libdrm 6/6] amdgpu: always add all BOs to lockup table
Why should it? Adding the handle is now not more than setting an array entry.
I've tested with allocating 250k BOs of 4k size each and there wasn't any measurable performance differences.
Christian.
Am 09.08.2018 um 18:56 schrieb Marek Olšák:
Quoted 62 lines
I don't think this is a good idea. Can you please explain why this won't cause performance regressions?
Thanks
MarekQuoted 54 lines · Christian König
This way we can always find a BO structure by its handle.
Signed-off-by Christian König <[email protected]>--- amdgpu/amdgpu_bo.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)amdgpu/amdgpu_bo.c +4
-11@@ -87,6 +87,10 @@ int amdgpu_bo_alloc(amdgpu_device_handle dev, bo->handle = args.out.handle; +pthread_mutex_lock (&bo->dev->bo_table_mutex); + r =handle_table_insert (&bo->dev->bo_handles, bo->handle, bo); +pthread_mutex_unlock (&bo->dev->bo_table_mutex); +pthread_mutex_init (&bo->cpu_access_mutex,NULL );if (r)@@ -171,13 +175,6 @@ int amdgpu_bo_query_info(amdgpu_bo_handle bo,return 0 ; } -static void amdgpu_add_handle_to_table (amdgpu_bo_handle bo) -{ -pthread_mutex_lock (&bo->dev->bo_table_mutex); -handle_table_insert (&bo->dev->bo_handles, bo->handle, bo); -pthread_mutex_unlock (&bo->dev->bo_table_mutex); -} -static int amdgpu_bo_export_flink (amdgpu_bo_handle bo) {struct drm_gem_flink flink;@@ -240,14 +237,11 @@ int amdgpu_bo_export(amdgpu_bo_handle bo,return 0 ;case amdgpu_bo_handle_type_kms: -amdgpu_add_handle_to_table (bo); -/* fall through */ case amdgpu_bo_handle_type_kms_noimport: *shared_handle = bo->handle;return 0 ;case amdgpu_bo_handle_type_dma_buf_fd: -amdgpu_add_handle_to_table (bo);return drmPrimeHandleToFD (bo->dev->fd, bo->handle,DRM_CLOEXEC |DRM_RDWR , (int *)shared_handle); --2.14.1
Quoted 4 lines
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 7c186502-199a-88cc-e5cf-6d3106bcc184-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH libdrm 6/6] amdgpu: always add all BOs to lockup table
OK. Thanks.
Marek
Quoted 74 lines · Christian König
Why should it? Adding the handle is now not more than setting an array entry.
I've tested with allocating 250k BOs of 4k size each and there wasn't any measurable performance differences.
Christian.
Am 09.08.2018 um 18:56 schrieb Marek Olšák:
Quoted 64 lines
I don't think this is a good idea. Can you please explain why this won't cause performance regressions?
Thanks
MarekQuoted 55 lines · Christian König
This way we can always find a BO structure by its handle.
Signed-off-by Christian König <[email protected]>--- amdgpu/amdgpu_bo.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)amdgpu/amdgpu_bo.c +4
-11@@ -87,6 +87,10 @@ int amdgpu_bo_alloc(amdgpu_device_handle dev, bo->handle = args.out.handle; +pthread_mutex_lock (&bo->dev->bo_table_mutex); + r =handle_table_insert (&bo->dev->bo_handles, bo->handle, bo); +pthread_mutex_unlock (&bo->dev->bo_table_mutex); +pthread_mutex_init (&bo->cpu_access_mutex,NULL );if (r)@@ -171,13 +175,6 @@ int amdgpu_bo_query_info(amdgpu_bo_handle bo,return 0 ; } -static void amdgpu_add_handle_to_table (amdgpu_bo_handle bo) -{ -pthread_mutex_lock (&bo->dev->bo_table_mutex); -handle_table_insert (&bo->dev->bo_handles, bo->handle, bo); -pthread_mutex_unlock (&bo->dev->bo_table_mutex); -} -static int amdgpu_bo_export_flink (amdgpu_bo_handle bo) {struct drm_gem_flink flink;@@ -240,14 +237,11 @@ int amdgpu_bo_export(amdgpu_bo_handle bo,return 0 ;case amdgpu_bo_handle_type_kms: -amdgpu_add_handle_to_table (bo); -/* fall through */ case amdgpu_bo_handle_type_kms_noimport: *shared_handle = bo->handle;return 0 ;case amdgpu_bo_handle_type_dma_buf_fd: -amdgpu_add_handle_to_table (bo);return drmPrimeHandleToFD (bo->dev->fd, bo->handle,DRM_CLOEXEC |DRM_RDWR , (int *)shared_handle); --2.14.1
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 4 lines · Christian König
We have so few devices that just walking a linked list is probably faster.
Signed-off-by Christian König <[email protected]>
Series is
Quoted 113 lines
--- amdgpu/amdgpu_device.c | 49 ++++++++++++++++-------------------------------- amdgpu/amdgpu_internal.h | 1 + 2 files changed, 17 insertions(+), 33 deletions(-)amdgpu/amdgpu_device.c +16
-33@@ -43,10 +43,9 @@#include "util_math.h" #define PTR_TO_UINT (x) ((unsigned)((intptr_t)(x))) -#define UINT_TO_PTR (x) ((void *)((intptr_t)(x)))static pthread_mutex_t fd_mutex =PTHREAD_MUTEX_INITIALIZER ; -static struct util_hash_table *fd_tab; +static amdgpu_device_handle fd_list;static unsigned handle_hash (void *key) {@@ -58,28 +57,8 @@ static int handle_compare(void *key1, void *key2)return PTR_TO_UINT (key1) !=PTR_TO_UINT (key2); } -static unsigned fd_hash (void *key) +static int fd_compare (int fd1,int fd2) { -int fd =PTR_TO_UINT (key); -char *name =drmGetPrimaryDeviceNameFromFd (fd); -unsigned result =0 ; -char *c; - -if (name ==NULL ) -return 0 ; - -for (c = name; *c; ++c) - result += *c; - -free (name); - -return result; -} - -static int fd_compare (void *key1,void *key2) -{ -int fd1 =PTR_TO_UINT (key1); -int fd2 =PTR_TO_UINT (key2);char *name1 =drmGetPrimaryDeviceNameFromFd (fd1);char *name2 =drmGetPrimaryDeviceNameFromFd (fd2);int result;@@ -127,16 +106,17 @@ static int amdgpu_get_auth(int fd, int *auth)static void amdgpu_device_free_internal (amdgpu_device_handle dev) { +amdgpu_device_handle *node = &fd_list; +pthread_mutex_lock (&fd_mutex); -util_hash_table_remove (fd_tab,UINT_TO_PTR (dev->fd)); -if (util_hash_table_count (fd_tab) ==0 ) { -util_hash_table_destroy (fd_tab); - fd_tab =NULL ; - } +while (*node != dev && (*node)->next) + node = &(*node)->next; + *node = (*node)->next; +pthread_mutex_unlock (&fd_mutex); +close (dev->fd);if ((dev->flink_fd >=0 ) && (dev->fd != dev->flink_fd))close (dev->flink_fd); -pthread_mutex_unlock (&fd_mutex);amdgpu_vamgr_deinit (&dev->vamgr_32);amdgpu_vamgr_deinit (&dev->vamgr);@@ -187,8 +167,6 @@ int amdgpu_device_initialize(int fd, *device_handle =NULL ;pthread_mutex_lock (&fd_mutex); -if (!fd_tab) - fd_tab =util_hash_table_create (fd_hash, fd_compare); r =amdgpu_get_auth (fd, &flag_auth);if (r) { fprintf(stderr, "%s: amdgpu_get_auth (1) failed (%i)\n",@@ -196,7 +174,11 @@ int amdgpu_device_initialize(int fd,pthread_mutex_unlock (&fd_mutex);return r; } - dev =util_hash_table_get (fd_tab,UINT_TO_PTR (fd)); + +for (dev = fd_list; dev; dev = dev->next) +if (fd_compare (dev->fd, fd) ==0 ) +break ; +if (dev) { r =amdgpu_get_auth (dev->fd, &flag_authexist);if (r) {@@ -297,7 +279,8 @@ int amdgpu_device_initialize(int fd, *major_version = dev->major_version; *minor_version = dev->minor_version; *device_handle = dev; -util_hash_table_set (fd_tab,UINT_TO_PTR (dev->fd), dev); + dev->next = fd_list; + fd_list = dev;pthread_mutex_unlock (&fd_mutex);return 0 ;amdgpu/amdgpu_internal.h +0
-0
amdgpu/amdgpu_internal.h struct amdgpu_va { · line 71
Quoted 7 lines
amdgpu/amdgpu_internal.h +1
-0@@ -65,6 +65,7 @@ struct amdgpu_va {struct amdgpu_device {atomic_t refcount; +struct amdgpu_device *next;int fd;int flink_fd;unsigned major_version;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx