amdgpu: use handle table for flink names
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
bde850bc32
commit
9a38e850a5
|
@ -37,7 +37,6 @@
|
||||||
#include "xf86drm.h"
|
#include "xf86drm.h"
|
||||||
#include "amdgpu_drm.h"
|
#include "amdgpu_drm.h"
|
||||||
#include "amdgpu_internal.h"
|
#include "amdgpu_internal.h"
|
||||||
#include "util_hash_table.h"
|
|
||||||
#include "util_math.h"
|
#include "util_math.h"
|
||||||
|
|
||||||
static void amdgpu_close_kms_handle(amdgpu_device_handle dev,
|
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);
|
pthread_mutex_lock(&bo->dev->bo_table_mutex);
|
||||||
util_hash_table_set(bo->dev->bo_flink_names,
|
r = handle_table_insert(&bo->dev->bo_flink_names, bo->flink_name, bo);
|
||||||
(void*)(uintptr_t)bo->flink_name,
|
|
||||||
bo);
|
|
||||||
pthread_mutex_unlock(&bo->dev->bo_table_mutex);
|
pthread_mutex_unlock(&bo->dev->bo_table_mutex);
|
||||||
|
|
||||||
return 0;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
int amdgpu_bo_export(amdgpu_bo_handle bo,
|
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. */
|
/* If we have already created a buffer with this handle, find it. */
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case amdgpu_bo_handle_type_gem_flink_name:
|
case amdgpu_bo_handle_type_gem_flink_name:
|
||||||
bo = util_hash_table_get(dev->bo_flink_names,
|
bo = handle_table_lookup(&dev->bo_flink_names, shared_handle);
|
||||||
(void*)(uintptr_t)shared_handle);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case amdgpu_bo_handle_type_dma_buf_fd:
|
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->flink_name = shared_handle;
|
||||||
bo->alloc_size = open_arg.size;
|
bo->alloc_size = open_arg.size;
|
||||||
util_hash_table_set(dev->bo_flink_names,
|
r = handle_table_insert(&dev->bo_flink_names, shared_handle,
|
||||||
(void*)(uintptr_t)bo->flink_name, bo);
|
bo);
|
||||||
|
if (r) {
|
||||||
|
pthread_mutex_unlock(&dev->bo_table_mutex);
|
||||||
|
amdgpu_bo_free(bo);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case amdgpu_bo_handle_type_dma_buf_fd:
|
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. */
|
/* Remove the buffer from the hash tables. */
|
||||||
handle_table_remove(&dev->bo_handles, bo->handle);
|
handle_table_remove(&dev->bo_handles, bo->handle);
|
||||||
|
|
||||||
if (bo->flink_name) {
|
if (bo->flink_name)
|
||||||
util_hash_table_remove(dev->bo_flink_names,
|
handle_table_remove(&dev->bo_flink_names,
|
||||||
(void*)(uintptr_t)bo->flink_name);
|
bo->flink_name);
|
||||||
}
|
|
||||||
|
|
||||||
/* Release CPU access. */
|
/* Release CPU access. */
|
||||||
if (bo->cpu_map_count > 0) {
|
if (bo->cpu_map_count > 0) {
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
#include "xf86drm.h"
|
#include "xf86drm.h"
|
||||||
#include "amdgpu_drm.h"
|
#include "amdgpu_drm.h"
|
||||||
#include "amdgpu_internal.h"
|
#include "amdgpu_internal.h"
|
||||||
#include "util_hash_table.h"
|
|
||||||
#include "util_math.h"
|
#include "util_math.h"
|
||||||
|
|
||||||
#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
|
#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
|
||||||
|
@ -47,16 +46,6 @@
|
||||||
static pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t fd_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static amdgpu_device_handle fd_list;
|
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)
|
static int fd_compare(int fd1, int fd2)
|
||||||
{
|
{
|
||||||
char *name1 = drmGetPrimaryDeviceNameFromFd(fd1);
|
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_32);
|
||||||
amdgpu_vamgr_deinit(&dev->vamgr_high);
|
amdgpu_vamgr_deinit(&dev->vamgr_high);
|
||||||
handle_table_fini(&dev->bo_handles);
|
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);
|
pthread_mutex_destroy(&dev->bo_table_mutex);
|
||||||
free(dev->marketing_name);
|
free(dev->marketing_name);
|
||||||
free(dev);
|
free(dev);
|
||||||
|
@ -228,8 +217,6 @@ int amdgpu_device_initialize(int fd,
|
||||||
dev->minor_version = version->version_minor;
|
dev->minor_version = version->version_minor;
|
||||||
drmFreeVersion(version);
|
drmFreeVersion(version);
|
||||||
|
|
||||||
dev->bo_flink_names = 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. */
|
||||||
|
|
|
@ -76,7 +76,7 @@ struct amdgpu_device {
|
||||||
/** List of buffer handles. Protected by bo_table_mutex. */
|
/** List of buffer handles. Protected by bo_table_mutex. */
|
||||||
struct handle_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 handle_table bo_flink_names;
|
||||||
/** This protects all hash tables. */
|
/** This protects all hash tables. */
|
||||||
pthread_mutex_t bo_table_mutex;
|
pthread_mutex_t bo_table_mutex;
|
||||||
struct drm_amdgpu_info_device dev_info;
|
struct drm_amdgpu_info_device dev_info;
|
||||||
|
|
Loading…
Reference in New Issue