mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 11:18:08 +02:00
venus: fix image reqs cache store locking
lock the entire scope when storing image reqs cache entry to prevent
entry being added between the split locks.
Fixes: b51ff22fbe ("venus: support caching image memory requirements")
Signed-off-by: Juston Li <justonli@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27401>
This commit is contained in:
parent
5178ad761c
commit
f3de6f17c1
1 changed files with 17 additions and 12 deletions
|
|
@ -231,8 +231,15 @@ vn_image_store_reqs_in_cache(struct vn_device *dev,
|
|||
assert(cache->ht);
|
||||
|
||||
simple_mtx_lock(&cache->mutex);
|
||||
uint32_t cache_entry_count = _mesa_hash_table_num_entries(cache->ht);
|
||||
if (cache_entry_count == IMAGE_REQS_CACHE_MAX_ENTRIES) {
|
||||
|
||||
/* Check if entry was added before lock */
|
||||
if (_mesa_hash_table_search(cache->ht, key)) {
|
||||
simple_mtx_unlock(&cache->mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_mesa_hash_table_num_entries(cache->ht) ==
|
||||
IMAGE_REQS_CACHE_MAX_ENTRIES) {
|
||||
/* Evict/use the last entry in the lru list for this new entry */
|
||||
cache_entry =
|
||||
list_last_entry(&cache->lru, struct vn_image_reqs_cache_entry, head);
|
||||
|
|
@ -242,11 +249,11 @@ vn_image_store_reqs_in_cache(struct vn_device *dev,
|
|||
} else {
|
||||
cache_entry = vk_zalloc(alloc, sizeof(*cache_entry), VN_DEFAULT_ALIGN,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
if (!cache_entry) {
|
||||
simple_mtx_unlock(&cache->mutex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
simple_mtx_unlock(&cache->mutex);
|
||||
|
||||
if (!cache_entry)
|
||||
return;
|
||||
|
||||
for (uint32_t i = 0; i < plane_count; i++)
|
||||
cache_entry->requirements[i] = requirements[i];
|
||||
|
|
@ -254,12 +261,10 @@ vn_image_store_reqs_in_cache(struct vn_device *dev,
|
|||
memcpy(cache_entry->key, key, SHA1_DIGEST_LENGTH);
|
||||
cache_entry->plane_count = plane_count;
|
||||
|
||||
simple_mtx_lock(&cache->mutex);
|
||||
if (!_mesa_hash_table_search(cache->ht, cache_entry->key)) {
|
||||
_mesa_hash_table_insert(dev->image_reqs_cache.ht, cache_entry->key,
|
||||
cache_entry);
|
||||
list_add(&cache_entry->head, &cache->lru);
|
||||
}
|
||||
_mesa_hash_table_insert(dev->image_reqs_cache.ht, cache_entry->key,
|
||||
cache_entry);
|
||||
list_add(&cache_entry->head, &cache->lru);
|
||||
|
||||
simple_mtx_unlock(&cache->mutex);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue