libdrm: Patches from AOSP
cover libdrm: Patches from AOSP
Over the last few days I've been trying to sync the AOSP libdrm tree with the upstream freedesktop branch.
Thanks to input from Sean, Alistair and Marissa, we've managed to drop a bunch of stale patches AOSP was carrying, and get the AOSP libdrm updated to 2.4.97
I've gone through the remaining patch delta and wanted to submit the non-Android.bp changes, which seemed like they might be relevant for upstream, for review and feedback.
With the exception of one of these, I'm not the original author, so I do not have the full context for the patch. So if they don't really make sense anymore, let me know and I can see if we can drop them in AOSP.
Thoughts and feedback would be greatly appreciated!
thanks
-john
Adrian Salido (1):
libdrm: reduce number of reallocations in drmModeAtomicAddProperty
Hemant Hariyani (1):
libdrm: omap: Add DRM_RDWR flag to dmabuf export
John Stultz (1):
libdrm: amdgpu: Initialize unions with memset rather than "= {0}"
Prabhanjan Kandula (1):
libdrm: Avoid additional drm open close
Sean Paul (1):
libdrm: Use mmap64 instead of __mmap2
amdgpu/amdgpu_cs.c | 9 ++++++--- libdrm_macros.h | 4 +--- omap/omap_drm.c | 2 +- xf86drm.c | 4 ++-- xf86drmMode.c | 7 ++++--- 5 files changed, 14 insertions(+), 12 deletions(-)
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 1/5 libdrm: Use mmap64 instead of __mmap2
From: Sean Paul <[email protected]>
__mmap2 isn't supported on all platforms, mmap64 is the right way to do this in android.
Also folds in a fix from Stéphane Marchesin <[email protected]> to use an offset in bytes not pages, as that's what mmap64 takes.
--- libdrm_macros.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
libdrm_macros.h +1 -3
@@ -48,8 +48,6 @@#if defined(ANDROID ) && !defined(__LP64__)#include <errno.h> /* for EINVAL */ -extern void *__mmap2 (void *,size_t ,int ,int ,int ,size_t ); -static inline void *drm_mmap (void *addr,size_t length,int prot,int flags,int fd,loff_t offset) {
@@ -59,7 +57,7 @@ static inline void *drm_mmap(void *addr, size_t length, int prot, int flags,return MAP_FAILED ; } -return __mmap2 (addr, length, prot, flags, fd, (size_t ) (offset >>12 )); +return mmap64 (addr, length, prot, flags, fd, offset); }# define drm_munmap (addr, length) \
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH 1/5] libdrm: Use mmap64 instead of __mmap2
Quoted 9 lines · John Stultz
From: Sean Paul <[email protected]>
__mmap2isn't supported on all platforms, mmap64 is the right way to do this in android.Also folds in a fix from Stéphane Marchesin <[email protected]> to use an offset in bytes not pages, as that's what mmap64 takes.
Quoted 6 lines
Cc Emil Velikov <[email protected]>Cc Sean Paul <[email protected]>Cc Alistair Strachan <[email protected]>Cc Marissa Wall <[email protected]>Signed-off-by Sean Paul <[email protected]>Signed-off-by John Stultz <[email protected]>
Quoted 29 lines
--- libdrm_macros.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)libdrm_macros.h +1
-4@@ -48,8 +48,6 @@#if defined(ANDROID ) && !defined(__LP64__)#include <errno.h> /* for EINVAL */ -extern void *__mmap2 (void *,size_t ,int ,int ,int ,size_t ); -static inline void *drm_mmap (void *addr,size_t length,int prot,int flags,int fd,loff_t offset) {@@ -59,7 +57,7 @@ static inline void *drm_mmap(void *addr, size_t length, int prot, int flags,return MAP_FAILED ; } -return __mmap2 (addr, length, prot, flags, fd, (size_t ) (offset >>12 )); +return mmap64 (addr, length, prot, flags, fd, offset); }# define drm_munmap (addr, length) \ --2.7.4
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH 1/5] libdrm: Use mmap64 instead of __mmap2
In reply to John StultzQuoted 15 lines · John Stultz
From: Sean Paul <[email protected]>
__mmap2isn't supported on all platforms, mmap64 is the right way to do this in android.Also folds in a fix from Stéphane Marchesin <[email protected]> to use an offset in bytes not pages, as that's what mmap64 takes.
Cc Emil Velikov <[email protected]>Cc Sean Paul <[email protected]>Cc Alistair Strachan <[email protected]>Cc Marissa Wall <[email protected]>Signed-off-by Sean Paul <[email protected]>Signed-off-by John Stultz <[email protected]>
Quoted 4 lines
--- libdrm_macros.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
From a quick look mmap64 was introduced in bionic with Andoid 5 (Lollipop). A reasonable min. version although we're lacking a check.
As a separate commit, copy the PLATFORM_VERSION hunk (or equiv.) from Mesa's Android.mk.
Here I'd add a note "introduced with Android L which we require as of earlier commit" and drop the bytes/pages mention.
With that this patch is:
-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 2/5 libdrm: amdgpu: Initialize unions with memset rather than "= {0}"
In reply to John StultzClang complains when initializing unions using "= {0}" so instead use memset.
--- amdgpu/amdgpu_cs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
amdgpu/amdgpu_cs.c +6 -3
@@ -733,12 +733,13 @@ drm_public int amdgpu_cs_submit_raw(amdgpu_device_handle dev,struct drm_amdgpu_cs_chunk *chunks, uint64_t *seq_no) { - union drm_amdgpu_cs cs = {0}; + union drm_amdgpu_cs cs;uint64_t *chunk_array;int i, r;if (num_chunks ==0 )return -EINVAL ; +memset (&cs,0 ,sizeof (cs)); chunk_array =alloca (sizeof (uint64_t ) * num_chunks);for (i =0 ; i < num_chunks; i++) chunk_array[i] = (uint64_t )(uintptr_t )&chunks[i];
@@ -763,10 +764,11 @@ drm_public int amdgpu_cs_submit_raw2(amdgpu_device_handle dev,struct drm_amdgpu_cs_chunk *chunks, uint64_t *seq_no) { - union drm_amdgpu_cs cs = {0}; + union drm_amdgpu_cs cs;uint64_t *chunk_array;int i, r; +memset (&cs,0 ,sizeof (cs)); chunk_array =alloca (sizeof (uint64_t ) * num_chunks);for (i =0 ; i < num_chunks; i++) chunk_array[i] = (uint64_t )(uintptr_t )&chunks[i];
@@ -803,9 +805,10 @@ drm_public int amdgpu_cs_fence_to_handle(amdgpu_device_handle dev,uint32_t what, uint32_t *out_handle) { - union drm_amdgpu_fence_to_handle fth = {0}; + union drm_amdgpu_fence_to_handle fth;int r; +memset (&fth,0 ,sizeof (fth)); fth.in.fence.ctx_id = fence->context->id; fth.in.fence.ip_type = fence->ip_type; fth.in.fence.ip_instance = fence->ip_instance;
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH 2/5] libdrm: amdgpu: Initialize unions with memset rather than "= {0}"
Quoted 9 lines · John Stultz
Clang complains when initializing unions using "= {0}" so instead use memset.
Cc Emil Velikov <[email protected]>Cc Sean Paul <[email protected]>Cc Alistair Strachan <[email protected]>Cc Marissa Wall <[email protected]>Signed-off-by John Stultz <[email protected]>
Do you have commit rights?
Alex
Quoted 51 lines
--- amdgpu/amdgpu_cs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)amdgpu/amdgpu_cs.c +6
-4@@ -733,12 +733,13 @@ drm_public int amdgpu_cs_submit_raw(amdgpu_device_handle dev,struct drm_amdgpu_cs_chunk *chunks, uint64_t *seq_no) { - union drm_amdgpu_cs cs = {0}; + union drm_amdgpu_cs cs;uint64_t *chunk_array;int i, r;if (num_chunks ==0 )return -EINVAL ; +memset (&cs,0 ,sizeof (cs)); chunk_array =alloca (sizeof (uint64_t ) * num_chunks);for (i =0 ; i < num_chunks; i++) chunk_array[i] = (uint64_t )(uintptr_t )&chunks[i];@@ -763,10 +764,11 @@ drm_public int amdgpu_cs_submit_raw2(amdgpu_device_handle dev,struct drm_amdgpu_cs_chunk *chunks, uint64_t *seq_no) { - union drm_amdgpu_cs cs = {0}; + union drm_amdgpu_cs cs;uint64_t *chunk_array;int i, r; +memset (&cs,0 ,sizeof (cs)); chunk_array =alloca (sizeof (uint64_t ) * num_chunks);for (i =0 ; i < num_chunks; i++) chunk_array[i] = (uint64_t )(uintptr_t )&chunks[i];@@ -803,9 +805,10 @@ drm_public int amdgpu_cs_fence_to_handle(amdgpu_device_handle dev,uint32_t what, uint32_t *out_handle) { - union drm_amdgpu_fence_to_handle fth = {0}; + union drm_amdgpu_fence_to_handle fth;int r; +memset (&fth,0 ,sizeof (fth)); fth.in.fence.ctx_id = fence->context->id; fth.in.fence.ip_type = fence->ip_type; fth.in.fence.ip_instance = fence->ip_instance; --2.7.4
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH 2/5] libdrm: amdgpu: Initialize unions with memset rather than "= {0}"
Quoted 5 lines · Alex Deucher
Quoted 4 lines · John Stultz
Clang complains when initializing unions using "= {0}" so instead use memset.
Quoted 7 lines
Quoted 5 lines
Cc Emil Velikov <[email protected]>Cc Sean Paul <[email protected]>Cc Alistair Strachan <[email protected]>Cc Marissa Wall <[email protected]>Signed-off-by John Stultz <[email protected]>Reviewed-by Alex Deucher <[email protected]>
Thanks for the review!
Quoted 1 line
Do you have commit rights?
I don't.
thanks again,
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
Reviewed-byRe: [RFC][PATCH 2/5] libdrm: amdgpu: Initialize unions with memset rather than "= {0}"
Am 22.04.19 um 20:35 schrieb John Stultz:
Quoted 5 lines · Alex Deucher
Quoted 4 lines · John Stultz
Quoted 3 lines
Clang complains when initializing unions using "= {0}" so instead use memset.
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Cc Emil Velikov <[email protected]>Cc Sean Paul <[email protected]>Cc Alistair Strachan <[email protected]>Cc Marissa Wall <[email protected]>Signed-off-by John Stultz <[email protected]>Reviewed-by Alex Deucher <[email protected]>Thanks for the review!
We should probably do the same thing for the kernel as well.
Quoted 2 lines
Quoted 2 lines
Do you have commit rights?
We will take care of getting this committed then.
Christian.
Quoted 8 lines
I don't.
thanks again,
-john
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH 2/5] libdrm: amdgpu: Initialize unions with memset rather than "= {0}"
In reply to John StultzQuoted 9 lines · John Stultz
Clang complains when initializing unions using "= {0}" so instead use memset.
Cc Emil Velikov <[email protected]>Cc Sean Paul <[email protected]>Cc Alistair Strachan <[email protected]>Cc Marissa Wall <[email protected]>Signed-off-by John Stultz <[email protected]>
-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 3/5 libdrm: Avoid additional drm open close
In reply to John StultzFrom: Prabhanjan Kandula <[email protected]>
Avoid additional drm device open and close.
--- xf86drm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xf86drm.c +2 -2
@@ -750,8 +750,8 @@ drm_public int drmOpen(const char *name, const char *busid)*/ drm_public int drmOpenWithType(const char *name, const char *busid, int type) { -if (!drmAvailable () && name !=NULL && drm_server_info && - drm_server_info->load_module) { +if (name !=NULL && drm_server_info && + drm_server_info->load_module && !drmAvailable ()) {/* try to load the kernel module */ if (!drm_server_info->load_module (name)) {drmMsg ("[drm] failed to load kernel module \"%s\"\n" , name);
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH 3/5] libdrm: Avoid additional drm open close
Quoted 10 lines · John Stultz
From: Prabhanjan Kandula <[email protected]>
Avoid additional drm device open and close.
Cc Emil Velikov <[email protected]>Cc Sean Paul <[email protected]>Cc Alistair Strachan <[email protected]>Cc Marissa Wall <[email protected]>Signed-off-by John Stultz <[email protected]>
Quoted 22 lines
--- xf86drm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)xf86drm.c +2
-3@@ -750,8 +750,8 @@ drm_public int drmOpen(const char *name, const char *busid)*/ drm_public int drmOpenWithType(const char *name, const char *busid, int type) { -if (!drmAvailable () && name !=NULL && drm_server_info && - drm_server_info->load_module) { +if (name !=NULL && drm_server_info && + drm_server_info->load_module && !drmAvailable ()) {/* try to load the kernel module */ if (!drm_server_info->load_module (name)) {drmMsg ("[drm] failed to load kernel module \"%s\"\n" , name); --2.7.4
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 4/5 libdrm: reduce number of reallocations in drmModeAtomicAddProperty
In reply to John StultzFrom: Adrian Salido <[email protected]>
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.
--- xf86drmMode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
xf86drmMode.c +4 -3
@@ -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;
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH 4/5] libdrm: reduce number of reallocations in drmModeAtomicAddProperty
Quoted 7 lines · John Stultz
From: Adrian Salido <[email protected]>
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.
Quoted 8 lines
Increase this to as many as can fit in a memory PAGE to avoid having to reallocate memory too often.
Cc Emil Velikov <[email protected]>Cc Sean Paul <[email protected]>Cc Alistair Strachan <[email protected]>Cc Marissa Wall <[email protected]>Signed-off-by John Stultz <[email protected]>
Quoted 36 lines
--- xf86drmMode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)xf86drmMode.c +4
-4@@ -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; --2.7.4
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH 4/5] libdrm: reduce number of reallocations in drmModeAtomicAddProperty
In reply to John StultzQuoted 24 lines · John Stultz
From: Adrian Salido <[email protected]>
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.
Cc Emil Velikov <[email protected]>Cc Sean Paul <[email protected]>Cc Alistair Strachan <[email protected]>Cc Marissa Wall <[email protected]>Signed-off-by John Stultz <[email protected]>--- xf86drmMode.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)xf86drmMode.c +0
-0
xf86drmMode.c drm_public drmModeAtomicReqPtr drmModeAtomicDuplicate(drmModeAtomicReqPtr old) · line 1262
Quoted 5 lines
xf86drmMode.c +1
-1@@ -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));
This seems like another (unrelated) perf. tweak. Splitting to separate patch may be an overkill, so a trivial mention in the commit message will do.
With that:
-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 5/5 libdrm: omap: Add DRM_RDWR flag to dmabuf export
In reply to John StultzFrom: Hemant Hariyani <[email protected]>
Allows mmap on dmabuf fd with MAP_SHARED and PROT_WRITE.
This fixes boot failures caused due to mmap() returning error
--- omap/omap_drm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
omap/omap_drm.c +1 -1
@@ -414,7 +414,7 @@ drm_public int omap_bo_dmabuf(struct omap_bo *bo)if (bo->fd <0 ) {struct drm_prime_handle req = { .handle = bo->handle, - .flags =DRM_CLOEXEC , + .flags =DRM_CLOEXEC |DRM_RDWR , };int ret;
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH 5/5] libdrm: omap: Add DRM_RDWR flag to dmabuf export
Quoted 7 lines · John Stultz
From: Hemant Hariyani <[email protected]>
Allows mmap on dmabuf fd with
MAP_SHAREDandPROT_WRITE.This fixes boot failures caused due to
mmap()returning error
Commit message is quite meh - xf86-video-omap does not use the API, so things should work (tm) ;-)
Joking aside - Android and closed source user-space drivers are used, so please mention that.
Although I'd stick with Rob's input - he is the principal author of this code.
-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC][PATCH 5/5] libdrm: omap: Add DRM_RDWR flag to dmabuf export
Am 23.04.19 um 12:26 schrieb Emil Velikov:
Quoted 5 lines · John Stultz
Quoted 4 lines
From: Hemant Hariyani <[email protected]>
Allows mmap on dmabuf fd with
MAP_SHAREDandPROT_WRITE.
Quoted 8 lines
Quoted 2 lines
This fixes boot failures caused due to
mmap()returning errorCommit message is quite meh - xf86-video-omap does not use the API, so things should work (tm) ;-)
Joking aside - Android and closed source user-space drivers are used, so please mention that.Although I'd stick with Rob's input - he is the principal author of this code.
IIRC we had the same problem in amdgpu some time ago, so in general the patch looks correct to me.
Christian.
Quoted 6 lines
-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel