From: Adrian Salido Date: Wed, 24 Apr 2019 17:08:40 +0000 (-0700) Subject: libdrm: reduce number of reallocations in drmModeAtomicAddProperty X-Git-Tag: android-x86-8.1-r6~79 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=763f646d7fee7c2457469d681b97029d4fd5e9d4;p=android-x86%2Fexternal-libdrm.git 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 Cc: Alistair Strachan Cc: Marissa Wall Reviewed-by: Alex Deucher Reviewed-by: Emil Velikov [jstultz: Expanded commit message] Signed-off-by: John Stultz --- diff --git a/xf86drmMode.c b/xf86drmMode.c index 8f8633ed..c878d9ea 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -1259,7 +1259,7 @@ drm_public drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr old) return NULL; } memcpy(new->items, old->items, - old->size_items * sizeof(*new->items)); + old->cursor * sizeof(*new->items)); } else { new->items = NULL; } @@ -1322,12 +1322,13 @@ drm_public int drmModeAtomicAddProperty(drmModeAtomicReqPtr req, return -EINVAL; if (req->cursor >= req->size_items) { + const uint32_t item_size_inc = getpagesize() / sizeof(*req->items); drmModeAtomicReqItemPtr new; - req->size_items += 16; + req->size_items += item_size_inc; new = realloc(req->items, req->size_items * sizeof(*req->items)); if (!new) { - req->size_items -= 16; + req->size_items -= item_size_inc; return -ENOMEM; } req->items = new;