vkr: use the newer hash_table to manage objects

The newer hash_table is supposed to be faster.

Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
macos/master
Chia-I Wu 3 years ago
parent 5683f40ce5
commit a68284a380
  1. 1
      src/venus/vkr_common.h
  2. 23
      src/venus/vkr_context.c
  3. 23
      src/venus/vkr_context.h
  4. 3
      src/venus/vkr_cs.c
  5. 9
      src/venus/vkr_cs.h

@ -22,7 +22,6 @@
#include "util/hash_table.h" #include "util/hash_table.h"
#include "util/os_misc.h" #include "util/os_misc.h"
#include "util/u_double_list.h" #include "util/u_double_list.h"
#include "util/u_hash_table.h"
#include "util/u_math.h" #include "util/u_math.h"
#include "util/u_memory.h" #include "util/u_memory.h"
#include "util/u_pointer.h" #include "util/u_pointer.h"

@ -553,7 +553,7 @@ vkr_context_destroy(struct virgl_context *base)
} }
_mesa_hash_table_destroy(ctx->resource_table, vkr_context_free_resource); _mesa_hash_table_destroy(ctx->resource_table, vkr_context_free_resource);
util_hash_table_destroy(ctx->object_table); _mesa_hash_table_destroy(ctx->object_table, vkr_context_free_object);
struct vkr_queue_sync *sync, *tmp; struct vkr_queue_sync *sync, *tmp;
LIST_FOR_EACH_ENTRY_SAFE (sync, tmp, &ctx->signaled_syncs, head) LIST_FOR_EACH_ENTRY_SAFE (sync, tmp, &ctx->signaled_syncs, head)
@ -585,22 +585,22 @@ vkr_context_init_base(struct vkr_context *ctx)
ctx->base.submit_fence = vkr_context_submit_fence; ctx->base.submit_fence = vkr_context_submit_fence;
} }
static unsigned static uint32_t
vkr_hash_u64(void *key) vkr_hash_u64(const void *key)
{ {
return XXH32(key, sizeof(uint64_t), 0); return XXH32(key, sizeof(uint64_t), 0);
} }
static int static bool
vkr_key_u64_equal(void *key1, void *key2) vkr_key_u64_equal(const void *key1, const void *key2)
{ {
return *(const uint64_t *)key1 != *(const uint64_t *)key2; return *(const uint64_t *)key1 == *(const uint64_t *)key2;
} }
static void void
destroy_func_object(void *val) vkr_context_free_object(struct hash_entry *entry)
{ {
struct vkr_object *obj = val; struct vkr_object *obj = entry->data;
free(obj); free(obj);
} }
@ -654,8 +654,7 @@ vkr_context_create(size_t debug_len, const char *debug_name)
list_inithead(&ctx->rings); list_inithead(&ctx->rings);
ctx->object_table = ctx->object_table = _mesa_hash_table_create(NULL, vkr_hash_u64, vkr_key_u64_equal);
util_hash_table_create(vkr_hash_u64, vkr_key_u64_equal, destroy_func_object);
ctx->resource_table = ctx->resource_table =
_mesa_hash_table_create(NULL, _mesa_hash_u32, _mesa_key_u32_equal); _mesa_hash_table_create(NULL, _mesa_hash_u32, _mesa_key_u32_equal);
if (!ctx->object_table || !ctx->resource_table) if (!ctx->object_table || !ctx->resource_table)
@ -685,7 +684,7 @@ vkr_context_create(size_t debug_len, const char *debug_name)
fail: fail:
if (ctx->object_table) if (ctx->object_table)
util_hash_table_destroy(ctx->object_table); _mesa_hash_table_destroy(ctx->object_table, vkr_context_free_object);
if (ctx->resource_table) if (ctx->resource_table)
_mesa_hash_table_destroy(ctx->resource_table, vkr_context_free_resource); _mesa_hash_table_destroy(ctx->resource_table, vkr_context_free_resource);
mtx_destroy(&ctx->mutex); mtx_destroy(&ctx->mutex);

@ -49,7 +49,7 @@ struct vkr_context {
mtx_t mutex; mtx_t mutex;
struct list_head rings; struct list_head rings;
struct util_hash_table *object_table; struct hash_table *object_table;
struct hash_table *resource_table; struct hash_table *resource_table;
struct list_head newly_exported_memories; struct list_head newly_exported_memories;
@ -95,7 +95,7 @@ vkr_context_get_resource(struct vkr_context *ctx, uint32_t res_id)
static inline bool static inline bool
vkr_context_validate_object_id(struct vkr_context *ctx, vkr_object_id id) vkr_context_validate_object_id(struct vkr_context *ctx, vkr_object_id id)
{ {
if (unlikely(!id || util_hash_table_get(ctx->object_table, &id))) { if (unlikely(!id || _mesa_hash_table_search(ctx->object_table, &id))) {
vkr_cs_decoder_set_fatal(&ctx->decoder); vkr_cs_decoder_set_fatal(&ctx->decoder);
return false; return false;
} }
@ -116,23 +116,29 @@ vkr_context_alloc_object(UNUSED struct vkr_context *ctx,
return vkr_object_alloc(size, type, id); return vkr_object_alloc(size, type, id);
} }
void
vkr_context_free_object(struct hash_entry *entry);
static inline void static inline void
vkr_context_add_object(struct vkr_context *ctx, struct vkr_object *obj) vkr_context_add_object(struct vkr_context *ctx, struct vkr_object *obj)
{ {
assert(vkr_is_recognized_object_type(obj->type)); assert(vkr_is_recognized_object_type(obj->type));
assert(obj->id); assert(obj->id);
assert(!util_hash_table_get(ctx->object_table, &obj->id)); assert(!_mesa_hash_table_search(ctx->object_table, &obj->id));
util_hash_table_set(ctx->object_table, &obj->id, obj); _mesa_hash_table_insert(ctx->object_table, &obj->id, obj);
} }
static inline void static inline void
vkr_context_remove_object(struct vkr_context *ctx, struct vkr_object *obj) vkr_context_remove_object(struct vkr_context *ctx, struct vkr_object *obj)
{ {
assert(util_hash_table_get(ctx->object_table, &obj->id)); assert(_mesa_hash_table_search(ctx->object_table, &obj->id));
/* this frees obj */ struct hash_entry *entry = _mesa_hash_table_search(ctx->object_table, &obj->id);
util_hash_table_remove(ctx->object_table, &obj->id); if (likely(entry)) {
vkr_context_free_object(entry);
_mesa_hash_table_remove(ctx->object_table, entry);
}
} }
static inline void static inline void
@ -147,7 +153,8 @@ vkr_context_remove_objects(struct vkr_context *ctx, struct list_head *objects)
static inline void * static inline void *
vkr_context_get_object(struct vkr_context *ctx, vkr_object_id obj_id) vkr_context_get_object(struct vkr_context *ctx, vkr_object_id obj_id)
{ {
return util_hash_table_get(ctx->object_table, &obj_id); const struct hash_entry *entry = _mesa_hash_table_search(ctx->object_table, &obj_id);
return likely(entry) ? entry->data : NULL;
} }
static inline const char * static inline const char *

@ -168,8 +168,7 @@ vkr_cs_encoder_write_internal(struct vkr_cs_encoder *enc,
} }
void void
vkr_cs_decoder_init(struct vkr_cs_decoder *dec, vkr_cs_decoder_init(struct vkr_cs_decoder *dec, const struct hash_table *object_table)
const struct util_hash_table *object_table)
{ {
memset(dec, 0, sizeof(*dec)); memset(dec, 0, sizeof(*dec));
dec->object_table = object_table; dec->object_table = object_table;

@ -52,7 +52,7 @@ struct vkr_cs_decoder_temp_pool {
}; };
struct vkr_cs_decoder { struct vkr_cs_decoder {
const struct util_hash_table *object_table; const struct hash_table *object_table;
bool fatal_error; bool fatal_error;
struct vkr_cs_decoder_temp_pool temp_pool; struct vkr_cs_decoder_temp_pool temp_pool;
@ -112,8 +112,7 @@ vkr_cs_encoder_write(struct vkr_cs_encoder *enc,
} }
void void
vkr_cs_decoder_init(struct vkr_cs_decoder *dec, vkr_cs_decoder_init(struct vkr_cs_decoder *dec, const struct hash_table *object_table);
const struct util_hash_table *object_table);
void void
vkr_cs_decoder_fini(struct vkr_cs_decoder *dec); vkr_cs_decoder_fini(struct vkr_cs_decoder *dec);
@ -197,7 +196,9 @@ vkr_cs_decoder_lookup_object(const struct vkr_cs_decoder *dec,
if (!id) if (!id)
return NULL; return NULL;
obj = util_hash_table_get((struct util_hash_table *)dec->object_table, &id); const struct hash_entry *entry =
_mesa_hash_table_search((struct hash_table *)dec->object_table, &id);
obj = likely(entry) ? entry->data : NULL;
if (!obj || obj->type != type) if (!obj || obj->type != type)
vkr_cs_decoder_set_fatal(dec); vkr_cs_decoder_set_fatal(dec);

Loading…
Cancel
Save