mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 04:48:08 +02:00
pan/kmod: Make default allocator thread-safe
Allocations targeting a pan_kmod_dev can happen concurrently, so we
need the pan_kmod_dev allocator to be thread-safe.
ralloc() is not thread-safe, and we don't really need a hierarchical
allocator in this context anyway, so let's just switch to calloc/free
instead.
Fixes: d95ec56f8c ("panfrost: Abstract kernel driver operations")
Reported-by: Eric Smith <eric.smith@collabora.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Tested-by: Eric Smith <eric.smith@collabora.com>
Reviewed-by: Eric Smith <eric.smith@collabora.com>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28926>
This commit is contained in:
parent
068d111884
commit
4c74d14730
1 changed files with 9 additions and 32 deletions
|
|
@ -7,6 +7,7 @@
|
|||
#include <string.h>
|
||||
#include <xf86drm.h>
|
||||
|
||||
#include "util/u_memory.h"
|
||||
#include "util/macros.h"
|
||||
#include "pan_kmod.h"
|
||||
|
||||
|
|
@ -31,28 +32,19 @@ static void *
|
|||
default_zalloc(const struct pan_kmod_allocator *allocator, size_t size,
|
||||
UNUSED bool transient)
|
||||
{
|
||||
return rzalloc_size(allocator, size);
|
||||
return os_calloc(1, size);
|
||||
}
|
||||
|
||||
static void
|
||||
default_free(const struct pan_kmod_allocator *allocator, void *data)
|
||||
{
|
||||
return ralloc_free(data);
|
||||
os_free(data);
|
||||
}
|
||||
|
||||
static const struct pan_kmod_allocator *
|
||||
create_default_allocator(void)
|
||||
{
|
||||
struct pan_kmod_allocator *allocator =
|
||||
rzalloc(NULL, struct pan_kmod_allocator);
|
||||
|
||||
if (allocator) {
|
||||
allocator->zalloc = default_zalloc;
|
||||
allocator->free = default_free;
|
||||
}
|
||||
|
||||
return allocator;
|
||||
}
|
||||
static const struct pan_kmod_allocator default_allocator = {
|
||||
.zalloc = default_zalloc,
|
||||
.free = default_free,
|
||||
};
|
||||
|
||||
struct pan_kmod_dev *
|
||||
pan_kmod_dev_create(int fd, uint32_t flags,
|
||||
|
|
@ -64,28 +56,18 @@ pan_kmod_dev_create(int fd, uint32_t flags,
|
|||
if (!version)
|
||||
return NULL;
|
||||
|
||||
if (!allocator) {
|
||||
allocator = create_default_allocator();
|
||||
if (!allocator)
|
||||
goto out_free_version;
|
||||
}
|
||||
if (!allocator)
|
||||
allocator = &default_allocator;
|
||||
|
||||
for (unsigned i = 0; i < ARRAY_SIZE(drivers); i++) {
|
||||
if (!strcmp(drivers[i].name, version->name)) {
|
||||
const struct pan_kmod_ops *ops = drivers[i].ops;
|
||||
|
||||
dev = ops->dev_create(fd, flags, version, allocator);
|
||||
if (dev)
|
||||
goto out_free_version;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allocator->zalloc == default_zalloc)
|
||||
ralloc_free((void *)allocator);
|
||||
|
||||
out_free_version:
|
||||
drmFreeVersion(version);
|
||||
return dev;
|
||||
}
|
||||
|
|
@ -93,12 +75,7 @@ out_free_version:
|
|||
void
|
||||
pan_kmod_dev_destroy(struct pan_kmod_dev *dev)
|
||||
{
|
||||
const struct pan_kmod_allocator *allocator = dev->allocator;
|
||||
|
||||
dev->ops->dev_destroy(dev);
|
||||
|
||||
if (allocator->zalloc == default_zalloc)
|
||||
ralloc_free((void *)allocator);
|
||||
}
|
||||
|
||||
struct pan_kmod_bo *
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue