amdgpu: use handle table for KMS handles
Instead of the hash use the handle table. Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Michel Dänzer <michel.daenzer@amd.com> Reviewed-and-Tested-by: Junwei Zhang <Jerry.Zhang@amd.com>main
parent
52370cc6eb
commit
bde850bc32
|
@ -90,8 +90,12 @@ int amdgpu_bo_alloc(amdgpu_device_handle dev,
|
||||||
|
|
||||||
pthread_mutex_init(&bo->cpu_access_mutex, NULL);
|
pthread_mutex_init(&bo->cpu_access_mutex, NULL);
|
||||||
|
|
||||||
*buf_handle = bo;
|
if (r)
|
||||||
return 0;
|
amdgpu_bo_free(bo);
|
||||||
|
else
|
||||||
|
*buf_handle = bo;
|
||||||
|
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
int amdgpu_bo_set_metadata(amdgpu_bo_handle bo,
|
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)
|
static void amdgpu_add_handle_to_table(amdgpu_bo_handle bo)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&bo->dev->bo_table_mutex);
|
pthread_mutex_lock(&bo->dev->bo_table_mutex);
|
||||||
util_hash_table_set(bo->dev->bo_handles,
|
handle_table_insert(&bo->dev->bo_handles, bo->handle, bo);
|
||||||
(void*)(uintptr_t)bo->handle, bo);
|
|
||||||
pthread_mutex_unlock(&bo->dev->bo_table_mutex);
|
pthread_mutex_unlock(&bo->dev->bo_table_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,8 +306,7 @@ int amdgpu_bo_import(amdgpu_device_handle dev,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case amdgpu_bo_handle_type_dma_buf_fd:
|
case amdgpu_bo_handle_type_dma_buf_fd:
|
||||||
bo = util_hash_table_get(dev->bo_handles,
|
bo = handle_table_lookup(&dev->bo_handles, shared_handle);
|
||||||
(void*)(uintptr_t)shared_handle);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case amdgpu_bo_handle_type_kms:
|
case amdgpu_bo_handle_type_kms:
|
||||||
|
@ -387,7 +389,7 @@ int amdgpu_bo_import(amdgpu_device_handle dev,
|
||||||
bo->dev = dev;
|
bo->dev = dev;
|
||||||
pthread_mutex_init(&bo->cpu_access_mutex, NULL);
|
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);
|
pthread_mutex_unlock(&dev->bo_table_mutex);
|
||||||
|
|
||||||
output->buf_handle = bo;
|
output->buf_handle = bo;
|
||||||
|
@ -406,8 +408,7 @@ int amdgpu_bo_free(amdgpu_bo_handle buf_handle)
|
||||||
|
|
||||||
if (update_references(&bo->refcount, NULL)) {
|
if (update_references(&bo->refcount, NULL)) {
|
||||||
/* Remove the buffer from the hash tables. */
|
/* Remove the buffer from the hash tables. */
|
||||||
util_hash_table_remove(dev->bo_handles,
|
handle_table_remove(&dev->bo_handles, bo->handle);
|
||||||
(void*)(uintptr_t)bo->handle);
|
|
||||||
|
|
||||||
if (bo->flink_name) {
|
if (bo->flink_name) {
|
||||||
util_hash_table_remove(dev->bo_flink_names,
|
util_hash_table_remove(dev->bo_flink_names,
|
||||||
|
|
|
@ -122,8 +122,8 @@ static void amdgpu_device_free_internal(amdgpu_device_handle dev)
|
||||||
amdgpu_vamgr_deinit(&dev->vamgr);
|
amdgpu_vamgr_deinit(&dev->vamgr);
|
||||||
amdgpu_vamgr_deinit(&dev->vamgr_high_32);
|
amdgpu_vamgr_deinit(&dev->vamgr_high_32);
|
||||||
amdgpu_vamgr_deinit(&dev->vamgr_high);
|
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_flink_names);
|
||||||
util_hash_table_destroy(dev->bo_handles);
|
|
||||||
pthread_mutex_destroy(&dev->bo_table_mutex);
|
pthread_mutex_destroy(&dev->bo_table_mutex);
|
||||||
free(dev->marketing_name);
|
free(dev->marketing_name);
|
||||||
free(dev);
|
free(dev);
|
||||||
|
@ -230,7 +230,6 @@ int amdgpu_device_initialize(int fd,
|
||||||
|
|
||||||
dev->bo_flink_names = util_hash_table_create(handle_hash,
|
dev->bo_flink_names = util_hash_table_create(handle_hash,
|
||||||
handle_compare);
|
handle_compare);
|
||||||
dev->bo_handles = util_hash_table_create(handle_hash, handle_compare);
|
|
||||||
pthread_mutex_init(&dev->bo_table_mutex, NULL);
|
pthread_mutex_init(&dev->bo_table_mutex, NULL);
|
||||||
|
|
||||||
/* Check if acceleration is working. */
|
/* Check if acceleration is working. */
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "xf86atomic.h"
|
#include "xf86atomic.h"
|
||||||
#include "amdgpu.h"
|
#include "amdgpu.h"
|
||||||
#include "util_double_list.h"
|
#include "util_double_list.h"
|
||||||
|
#include "handle_table.h"
|
||||||
|
|
||||||
#define AMDGPU_CS_MAX_RINGS 8
|
#define AMDGPU_CS_MAX_RINGS 8
|
||||||
/* do not use below macro if b is not power of 2 aligned value */
|
/* do not use below macro if b is not power of 2 aligned value */
|
||||||
|
@ -73,7 +74,7 @@ struct amdgpu_device {
|
||||||
|
|
||||||
char *marketing_name;
|
char *marketing_name;
|
||||||
/** List of buffer handles. Protected by bo_table_mutex. */
|
/** 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. */
|
/** List of buffer GEM flink names. Protected by bo_table_mutex. */
|
||||||
struct util_hash_table *bo_flink_names;
|
struct util_hash_table *bo_flink_names;
|
||||||
/** This protects all hash tables. */
|
/** This protects all hash tables. */
|
||||||
|
|
Loading…
Reference in New Issue