Skip to contentSkip to conversation

libdrm: Patches from AOSP

PATCH In review John Stultz 2 participants 8 messages Apr 24, 2019 – Apr 25, 2019

lore
Share & tools
lore
#0 lore raw

v2 cover libdrm: Patches from AOSP

Recently 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.

thanks
-john

Cc Emil Velikov <[email protected]>
Cc Sean Paul <[email protected]>
Cc Alistair Strachan <[email protected]>
Cc Marissa Wall <[email protected]>

Adrian Salido (1):
libdrm: reduce number of reallocations in drmModeAtomicAddProperty

Hemant Hariyani (1):
libdrm: omap: Add DRM_RDWR flag to dmabuf export

John Stultz (2):
libdrm: Android.mk: Add minimal Android platform check
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

 Android.mk         | 5 +++++
 amdgpu/amdgpu_cs.c | 9 ++++++---
 libdrm_macros.h    | 4 +---
 omap/omap_drm.c    | 2 +-
 xf86drm.c          | 4 ++--
 xf86drmMode.c      | 7 ++++---
 6 files changed, 19 insertions(+), 12 deletions(-)
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH v2 1/6 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]>

Cc Emil Velikov <[email protected]>
Cc Sean Paul <[email protected]>
Cc Alistair Strachan <[email protected]>
Cc Marissa Wall <[email protected]>
[jstultz: Folded in Stéphane's fix]
---
 libdrm_macros.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
libdrm_macros.h +1 -3
index 95f0ef5..0dca827 100644
@@ -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
#2 lore raw

PATCH v2 2/6 libdrm: Android.mk: Add minimal Android platform check

In reply to John Stultz

Add a check to error out on Android version K(4.4) or lower.

This is due to dependency added in a previous commit on mmap64, which was introduced with Android L.

Cc Emil Velikov <[email protected]>
Cc Sean Paul <[email protected]>
Cc Alistair Strachan <[email protected]>
Cc Marissa Wall <[email protected]>

---
NOTE: This change was suggested by Emil, and I've implemented it as suggested, but due to the fact that the Android.mk files are no longer usable with AOSP/master, I'm not able to test this change. Help in validating would be appreciated.

---
 Android.mk | 5 +++++
 1 file changed, 5 insertions(+)
Android.mk +5 -0
index 1b77c53..0ab6f0f 100644
@@ -21,6 +21,11 @@
 # IN THE SOFTWARE.
 #
 
+LIBDRM_ANDROID_MAJOR_VERSION := $(word 1, $(subst ., , $(PLATFORM_VERSION)))
+ifneq ($(filter 2 4, $(LIBDRM_ANDROID_MAJOR_VERSION)),)
+$(error "Android 4.4 and earlier not supported")
+endif
+
 LIBDRM_COMMON_MK := $(call my-dir)/Android.common.mk
 
 LOCAL_PATH := $(call my-dir)
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

PATCH v2 3/6 libdrm: amdgpu: Initialize unions with memset rather than "= {0}"

In reply to John Stultz

Clang 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
index 7ee844f..7c5b9d1 100644
@@ -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
#4 lore raw

PATCH v2 4/6 libdrm: Avoid additional drm open close

In reply to 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]>
---
 xf86drm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xf86drm.c +2 -2
index fe822ca..2c19376 100644
@@ -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
#5 lore raw

PATCH v2 5/6 libdrm: reduce number of reallocations in drmModeAtomicAddProperty

In reply to 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.

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 Emil Velikov <[email protected]>
Cc Sean Paul <[email protected]>
Cc Alistair Strachan <[email protected]>
Cc Marissa Wall <[email protected]>
[jstultz: Expanded commit message]

---
v2: Improved commit message

---
 xf86drmMode.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
xf86drmMode.c +4 -3
index 8f8633e..c878d9e 100644
@@ -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
#6 lore raw

PATCH v2 6/6 libdrm: omap: Add DRM_RDWR flag to dmabuf export

In reply to John Stultz

From: Hemant Hariyani <[email protected]>

Allows mmap on dmabuf fd with MAP_SHARED and PROT_WRITE.

This fixes boot failures with Android (likely w/ closed source user-space drivers) that were caused due to mmap() returning error.

Cc Emil Velikov <[email protected]>
Cc Sean Paul <[email protected]>
Cc Alistair Strachan <[email protected]>
Cc Marissa Wall <[email protected]>
[picked and updated commitmsg from http://git.ti.com/cgit/cgit.cgi/android/external-libdrm.git/]
[jstultz: Tweaked commit message]

---
v2: Tweaked commit message

---
 omap/omap_drm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
omap/omap_drm.c +1 -1
index 3aed4e0..ffacea6 100644
@@ -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
#7 lore raw
In reply to John Stultz
Quoted 4 lines · John Stultz

Recently I've been trying to sync the AOSP libdrm tree with the upstream freedesktop branch.

Quoted 8 lines

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.

Thanks for the follow-up John. I've swapped the order of 1/6 and 2/6 and pushed the series to master.

-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel