mirror of
https://gitlab.freedesktop.org/mesa/drm.git
synced 2025-12-20 07:00:11 +01:00
libdrm: reduce number of reallocations in drmModeAtomicAddProperty
When calling drmModeAtomicAddProperty allocation of memory happens as needed in increments of 16 elements. This can be very slow if there are multiple properties to be updated in an Atomic Commit call. Increase this to as many as can fit in a memory PAGE to avoid having to reallocate memory too often. Also this patch has a small one line perf tweak in drmModeAtomicDuplicate() to only memcpy items to the cursor position in order avoid copying the entire item array if its mostly empty. Cc: Sean Paul <seanpaul@chromium.org> Cc: Alistair Strachan <astrachan@google.com> Cc: Marissa Wall <marissaw@google.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Reviewed-by: Emil Velikov <emil.velikov@collabora.com> [jstultz: Expanded commit message] Signed-off-by: John Stultz <john.stultz@linaro.org>
This commit is contained in:
parent
225d73fd3b
commit
763f646d7f
1 changed files with 4 additions and 3 deletions
|
|
@ -1259,7 +1259,7 @@ drm_public drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr old)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy(new->items, old->items,
|
memcpy(new->items, old->items,
|
||||||
old->size_items * sizeof(*new->items));
|
old->cursor * sizeof(*new->items));
|
||||||
} else {
|
} else {
|
||||||
new->items = NULL;
|
new->items = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1322,12 +1322,13 @@ drm_public int drmModeAtomicAddProperty(drmModeAtomicReqPtr req,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (req->cursor >= req->size_items) {
|
if (req->cursor >= req->size_items) {
|
||||||
|
const uint32_t item_size_inc = getpagesize() / sizeof(*req->items);
|
||||||
drmModeAtomicReqItemPtr new;
|
drmModeAtomicReqItemPtr new;
|
||||||
|
|
||||||
req->size_items += 16;
|
req->size_items += item_size_inc;
|
||||||
new = realloc(req->items, req->size_items * sizeof(*req->items));
|
new = realloc(req->items, req->size_items * sizeof(*req->items));
|
||||||
if (!new) {
|
if (!new) {
|
||||||
req->size_items -= 16;
|
req->size_items -= item_size_inc;
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
req->items = new;
|
req->items = new;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue