Skip to contentSkip to conversation

Add CRTC ID to vblank events

PATCH New Daniel Stone 5 participants 10 messages Apr 4, 2017 – Apr 5, 2017 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add CRTC ID to vblank events

Hi,
Following the annual tradition, I've rebased Ander/Maarten's patches to include the CRTC ID in vblank events. Specifically, this makes it possible to know which CRTC an atomic request-completion event refers to.

I'm using this in Weston, for which I can ack it as good API, and a second opinion of this should be on the way shortly.

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

#1 lore raw

PATCH 2/2 Add CRTC ID to vblank event

From: Ander Conselvan de Oliveira <[email protected]>

When using the atomic API, one request can span multiple CRTCs, however one event is generated per CRTC. As we cannot disambiguate the CRTC with user data (since we only have one piece of user data to pass in), newer kernels can include the CRTC ID in the page flip event.

Add a new vfunc to dispatch vblank events carrying a CRTC ID to clients who negotiate a higher interface version.

[daniels: Rebased, include new cap, call page_flip_handler if it is set
but page_flip_handler2 isn't even on newer contexts, write a commit message.]

---
 include/drm/drm.h |  3 ++-
 xf86drm.h         |  9 ++++++++-
 xf86drmMode.c     | 24 ++++++++++++++++--------
 3 files changed, 26 insertions(+), 10 deletions(-)
include/drm/drm.h +2 -1
index 09d4262f..c4492372 100644
@@ -641,6 +641,7 @@ struct drm_gem_open {
 #define DRM_CAP_CURSOR_HEIGHT		0x9
 #define DRM_CAP_ADDFB2_MODIFIERS	0x10
 #define DRM_CAP_PAGE_FLIP_TARGET	0x11
+#define DRM_CAP_CRTC_IN_VBLANK_EVENT	0x12
 
 /** DRM_IOCTL_GET_CAP ioctl argument type */
 struct drm_get_cap {
@@ -846,7 +847,7 @@ struct drm_event_vblank {
 	__u32 tv_sec;
 	__u32 tv_usec;
 	__u32 sequence;
-	__u32 reserved;
+	__u32 crtc_id;
 };
 
 /* typedef area */
xf86drm.h +8 -1
index 0d927018..d75ca8ce 100644
@@ -728,7 +728,7 @@ extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2);
 extern int drmSetMaster(int fd);
 extern int drmDropMaster(int fd);
 
-#define DRM_EVENT_CONTEXT_VERSION 2
+#define DRM_EVENT_CONTEXT_VERSION 3
 
 typedef struct _drmEventContext {
 
@@ -748,6 +748,13 @@ typedef struct _drmEventContext {
 				  unsigned int tv_usec,
 				  void *user_data);
 
+	void (*page_flip_handler2)(int fd,
+				   unsigned int sequence,
+				   unsigned int tv_sec,
+				   unsigned int tv_usec,
+				   unsigned int crtc_id,
+				   void *user_data);
+
 } drmEventContext, *drmEventContextPtr;
 
 extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
xf86drmMode.c +16 -8
index fb47fa8b..b71520aa 100644
@@ -889,6 +889,7 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx)
 	int len, i;
 	struct drm_event *e;
 	struct drm_event_vblank *vblank;
+	void *user_data;
 
 	/* The DRM read semantics guarantees that we always get only
 	 * complete events. */
@@ -915,15 +916,22 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx)
 					      U642VOID (vblank->user_data));
 			break;
 		case DRM_EVENT_FLIP_COMPLETE:
-			if (evctx->version < 2 ||
-			    evctx->page_flip_handler == NULL)
-				break;
 			vblank = (struct drm_event_vblank *) e;
-			evctx->page_flip_handler(fd,
-						 vblank->sequence,
-						 vblank->tv_sec,
-						 vblank->tv_usec,
-						 U642VOID (vblank->user_data));
+			user_data = U642VOID (vblank->user_data);
+
+			if (evctx->version >= 3 && evctx->page_flip_handler2)
+				evctx->page_flip_handler2(fd,
+							 vblank->sequence,
+							 vblank->tv_sec,
+							 vblank->tv_usec,
+							 vblank->crtc_id,
+							 user_data);
+			else if (evctx->version >= 2 && evctx->page_flip_handler)
+				evctx->page_flip_handler(fd,
+							 vblank->sequence,
+							 vblank->tv_sec,
+							 vblank->tv_usec,
+							 user_data);
 			break;
 		default:
 			break;
Signature · 6 lines
2.12.2

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

PATCH 1/2 drm: Pass CRTC ID in userspace vblank events

From: Ander Conselvan de Oliveira <[email protected]>

With the atomic API, it is possible that a single commit affects multiple crtcs. If the user requests an event with that commit, one event will be sent for each CRTC, but it is not possible to distinguish which crtc an event is for in user space. To solve this, the reserved field in struct drm_vblank_event is repurposed to include the crtc_id which the event is for.

The DRM_CAP_CRTC_IN_VBLANK_EVENT is added to allow userspace to query if the crtc field will be set properly.

[daniels: Rebased, using Maarten's forward-port.]

---
 drivers/gpu/drm/drm_ioctl.c | 3 +++
 drivers/gpu/drm/drm_irq.c   | 2 ++
 include/uapi/drm/drm.h      | 3 ++-
 3 files changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_ioctl.c +3 -0
index 7d6deaa91281..0793e2da9d21 100644
@@ -286,6 +286,9 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
 	case DRM_CAP_ADDFB2_MODIFIERS:
 		req->value = dev->mode_config.allow_fb_modifiers;
 		break;
+	case DRM_CAP_CRTC_IN_VBLANK_EVENT:
+		req->value = 1;
+		break;
 	default:
 		return -EINVAL;
 	}
drivers/gpu/drm/drm_irq.c +2 -0
index dac1b2593cb1..8c866cac62dd 100644
@@ -1026,6 +1026,7 @@ void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
 
 	e->pipe = pipe;
 	e->event.sequence = drm_vblank_count(dev, pipe);
+	e->event.crtc_id = crtc->base.id;
 	list_add_tail(&e->base.link, &dev->vblank_event_list);
 }
 EXPORT_SYMBOL(drm_crtc_arm_vblank_event);
@@ -1056,6 +1057,7 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 		now = get_drm_timestamp();
 	}
 	e->pipe = pipe;
+	e->event.crtc_id = crtc->base.id;
 	send_vblank_event(dev, e, seq, &now);
 }
 EXPORT_SYMBOL(drm_crtc_send_vblank_event);
include/uapi/drm/drm.h +2 -1
index b2c52843bc70..42d9f64ce416 100644
@@ -647,6 +647,7 @@ struct drm_gem_open {
 #define DRM_CAP_CURSOR_HEIGHT		0x9
 #define DRM_CAP_ADDFB2_MODIFIERS	0x10
 #define DRM_CAP_PAGE_FLIP_TARGET	0x11
+#define DRM_CAP_CRTC_IN_VBLANK_EVENT	0x12
 
 /** DRM_IOCTL_GET_CAP ioctl argument type */
 struct drm_get_cap {
@@ -851,7 +852,7 @@ struct drm_event_vblank {
 	__u32 tv_sec;
 	__u32 tv_usec;
 	__u32 sequence;
-	__u32 reserved;
+	__u32 crtc_id; /* 0 on older kernels that do not support this */
 };
 
 /* typedef area */
Signature · 6 lines
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH kernel 1/2] drm: Pass CRTC ID in userspace vblank events

Quoted 9 lines · Daniel Stone

From: Ander Conselvan de Oliveira <[email protected]>

With the atomic API, it is possible that a single commit affects multiple crtcs. If the user requests an event with that commit, one event will be sent for each CRTC, but it is not possible to distinguish which crtc an event is for in user space. To solve this, the reserved field in struct drm_vblank_event is repurposed to include the crtc_id which the event is for.

Quoted 7 lines

The DRM_CAP_CRTC_IN_VBLANK_EVENT is added to allow userspace to query if the crtc field will be set properly.

[daniels: Rebased, using Maarten's forward-port.]

Yeah, this seems like good use of the reserved field to me.

Quoted 69 lines
Cc Maarten Lankhorst <[email protected]>
---
 drivers/gpu/drm/drm_ioctl.c | 3 +++
 drivers/gpu/drm/drm_irq.c   | 2 ++
 include/uapi/drm/drm.h      | 3 ++-
 3 files changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_ioctl.c +3 -0
index 7d6deaa91281..0793e2da9d21 100644
@@ -286,6 +286,9 @@ static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_
 	case DRM_CAP_ADDFB2_MODIFIERS:
 		req->value = dev->mode_config.allow_fb_modifiers;
 		break;
+	case DRM_CAP_CRTC_IN_VBLANK_EVENT:
+		req->value = 1;
+		break;
 	default:
 		return -EINVAL;
 	}
drivers/gpu/drm/drm_irq.c +2 -0
index dac1b2593cb1..8c866cac62dd 100644
@@ -1026,6 +1026,7 @@ void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
 
 	e->pipe = pipe;
 	e->event.sequence = drm_vblank_count(dev, pipe);
+	e->event.crtc_id = crtc->base.id;
 	list_add_tail(&e->base.link, &dev->vblank_event_list);
 }
 EXPORT_SYMBOL(drm_crtc_arm_vblank_event);
@@ -1056,6 +1057,7 @@ void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
 		now = get_drm_timestamp();
 	}
 	e->pipe = pipe;
+	e->event.crtc_id = crtc->base.id;
 	send_vblank_event(dev, e, seq, &now);
 }
 EXPORT_SYMBOL(drm_crtc_send_vblank_event);
include/uapi/drm/drm.h +2 -1
index b2c52843bc70..42d9f64ce416 100644
@@ -647,6 +647,7 @@ struct drm_gem_open {
 #define DRM_CAP_CURSOR_HEIGHT		0x9
 #define DRM_CAP_ADDFB2_MODIFIERS	0x10
 #define DRM_CAP_PAGE_FLIP_TARGET	0x11
+#define DRM_CAP_CRTC_IN_VBLANK_EVENT	0x12
 
 /** DRM_IOCTL_GET_CAP ioctl argument type */
 struct drm_get_cap {
@@ -851,7 +852,7 @@ struct drm_event_vblank {
 	__u32 tv_sec;
 	__u32 tv_usec;
 	__u32 sequence;
-	__u32 reserved;
+	__u32 crtc_id; /* 0 on older kernels that do not support this */
 };
 
 /* typedef area */
Signature · 6 lines
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

Re: [PATCH kernel 1/2] drm: Pass CRTC ID in userspace vblank events

Hi,

Quoted 8 lines · Sean Paul
Quoted 7 lines · Daniel Stone

With the atomic API, it is possible that a single commit affects multiple crtcs. If the user requests an event with that commit, one event will be sent for each CRTC, but it is not possible to distinguish which crtc an event is for in user space. To solve this, the reserved field in struct drm_vblank_event is repurposed to include the crtc_id which the event is for.

Quoted 8 lines
Quoted 4 lines

The DRM_CAP_CRTC_IN_VBLANK_EVENT is added to allow userspace to query if the crtc field will be set properly.

[daniels: Rebased, using Maarten's forward-port.]

Yeah, this seems like good use of the reserved field to me.

Thanks Sean for the review! I've pushed this to drm-misc-next ... without your R-b tag, as I botched my first dim. Oops.

libdrm v2 has been sent, and Weston atomic will be revved to use this with its real version number when that gets merged and released. FWIW, the Weston side was also acked by Pekka Paalanen, though I'll let him add his thoughts in his own words tomorrow.

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

#5 lore raw

Re: [PATCH libdrm 2/2] Add CRTC ID to vblank event

In reply to Daniel Stone

Hi Daniel,

Zero objections against the patch, just a couple of small notes.

Quoted 36 lines · Daniel Stone

From: Ander Conselvan de Oliveira <[email protected]>

When using the atomic API, one request can span multiple CRTCs, however one event is generated per CRTC. As we cannot disambiguate the CRTC with user data (since we only have one piece of user data to pass in), newer kernels can include the CRTC ID in the page flip event.

Add a new vfunc to dispatch vblank events carrying a CRTC ID to clients who negotiate a higher interface version.

[daniels: Rebased, include new cap, call page_flip_handler if it is set
but page_flip_handler2 isn't even on newer contexts, write a commit message.]

---
 include/drm/drm.h |  3 ++-
 xf86drm.h         |  9 ++++++++-
 xf86drmMode.c     | 24 ++++++++++++++++--------
 3 files changed, 26 insertions(+), 10 deletions(-)
include/drm/drm.h +1 -0
index 09d4262f..c4492372 100644
@@ -641,6 +641,7 @@ struct drm_gem_open {
 #define DRM_CAP_CURSOR_HEIGHT          0x9
 #define DRM_CAP_ADDFB2_MODIFIERS       0x10
 #define DRM_CAP_PAGE_FLIP_TARGET       0x11
+#define DRM_CAP_CRTC_IN_VBLANK_EVENT   0x12
 
 /** DRM_IOCTL_GET_CAP ioctl argument type */
 struct drm_get_cap {

include/drm/drm.h struct drm_event_vblank { · line 852

Quoted 7 lines
include/drm/drm.h +1 -1
@@ -846,7 +847,7 @@ struct drm_event_vblank {
        __u32 tv_sec;
        __u32 tv_usec;
        __u32 sequence;
-       __u32 reserved;
+       __u32 crtc_id;
 };
 

Please split these to a separate commit as mentioned in include/drm/README "When and how to update these files" ?

xf86drm.h extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2); · line 732

Quoted 12 lines
include/drm/drm.h +0 -0
 /* typedef area */
xf86drm.h +1 -1
index 0d927018..d75ca8ce 100644
@@ -728,7 +728,7 @@ extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2);
 extern int drmSetMaster(int fd);
 extern int drmDropMaster(int fd);
 
-#define DRM_EVENT_CONTEXT_VERSION 2
+#define DRM_EVENT_CONTEXT_VERSION 3
 

We really want to fix weston to _not_ use this define, but to set the version it actually supports/implements.
I'll send a patch for that in a minute.

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

#6 lore raw

Re: [PATCH libdrm 2/2] Add CRTC ID to vblank event

Hi Emil,

Quoted 12 lines · Emil Velikov

include/drm/drm.h struct drm_event_vblank { · line 852

Quoted 8 lines · Daniel Stone
include/drm/drm.h +1 -1
@@ -846,7 +847,7 @@ struct drm_event_vblank {
         __u32 tv_sec;
         __u32 tv_usec;
         __u32 sequence;
-       __u32 reserved;
+       __u32 crtc_id;
  };
 

Please split these to a separate commit as mentioned in include/drm/README "When and how to update these files" ?

OK, will do.

Quoted 5 lines
Quoted 5 lines
xf86drm.h +0 -0
@@ -728,7 +728,7 @@ extern void drmMsg(const char *format, ...)
 DRM_PRINTFLIKE(1, 2);
  extern int drmSetMaster(int fd);
  extern int drmDropMaster(int fd);
 
Quoted 7 lines

xf86drm.h extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2); · line 732

Quoted 3 lines
xf86drm.h +1 -1
-#define DRM_EVENT_CONTEXT_VERSION 2
+#define DRM_EVENT_CONTEXT_VERSION 3
 

We really want to fix weston to _not_ use this define, but to set the version it actually supports/implements.
I'll send a patch for that in a minute.

One step ahead of you:
-       evctx.version = DRM_EVENT_CONTEXT_VERSION; -       evctx.page_flip_handler = page_flip_handler; +       evctx.version = 3;

https://lists.freedesktop.org/archives/wayland-devel/2017-April/033747.
html

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

#7 lore raw

PATCH v2 1/2 Headers: Sync drm{,_mode}.h with the kernel

In reply to Emil Velikov

Generated using make headers_install, based on drm-misc-next commit 5db06a8a98f515f67446a69c57577c4c363ec65d.

This clarifies the comments around modifiers such that they are per-framebuffer rather than per-plane, adds the beginnings of aspect ratio mode flags, link status properties, and updates the 'reserved' field from vblank events to include the CRTC ID.

The define -> enum conversion from dee7a4fee730ca8908f335b6b66174cba4598ecd was manually reverted from this sync, to avoid any potential ABI issues.

---
 include/drm/drm.h      |  3 ++-
 include/drm/drm_mode.h | 45 ++++++++++++++++++++++++++++++++++-----------
 2 files changed, 36 insertions(+), 12 deletions(-)
include/drm/drm.h +2 -1
index f6fd5c2c..1e7a4bc7 100644
@@ -641,6 +641,7 @@ struct drm_gem_open {
 #define DRM_CAP_CURSOR_HEIGHT		0x9
 #define DRM_CAP_ADDFB2_MODIFIERS	0x10
 #define DRM_CAP_PAGE_FLIP_TARGET	0x11
+#define DRM_CAP_CRTC_IN_VBLANK_EVENT	0x12
 
 /** DRM_IOCTL_GET_CAP ioctl argument type */
 struct drm_get_cap {
@@ -845,7 +846,7 @@ struct drm_event_vblank {
 	__u32 tv_sec;
 	__u32 tv_usec;
 	__u32 sequence;
-	__u32 reserved;
+	__u32 crtc_id; /* 0 on older kernels that do not support this */
 };
 
 /* typedef area */
include/drm/drm_mode.h +34 -11

81 lines not on this page · raw message

Signature · 6 lines
2.11.0

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

PATCH v2 2/2 Add CRTC ID to vblank event

From: Ander Conselvan de Oliveira <[email protected]>

When using the atomic API, one request can span multiple CRTCs, however one event is generated per CRTC. As we cannot disambiguate the CRTC with user data (since we only have one piece of user data to pass in), newer kernels can include the CRTC ID in the page flip event.

Add a new vfunc to dispatch vblank events carrying a CRTC ID to clients who negotiate a higher interface version.

[daniels: Rebased, include new cap, call page_flip_handler if it is set
but page_flip_handler2 isn't even on newer contexts, write a commit message.]

---
 xf86drm.h     |  9 ++++++++-
 xf86drmMode.c | 24 ++++++++++++++++--------
 2 files changed, 24 insertions(+), 9 deletions(-)
xf86drm.h +8 -1
index 0d927018..d75ca8ce 100644
@@ -728,7 +728,7 @@ extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2);
 extern int drmSetMaster(int fd);
 extern int drmDropMaster(int fd);
 
-#define DRM_EVENT_CONTEXT_VERSION 2
+#define DRM_EVENT_CONTEXT_VERSION 3
 
 typedef struct _drmEventContext {
 
@@ -748,6 +748,13 @@ typedef struct _drmEventContext {
 				  unsigned int tv_usec,
 				  void *user_data);
 
+	void (*page_flip_handler2)(int fd,
+				   unsigned int sequence,
+				   unsigned int tv_sec,
+				   unsigned int tv_usec,
+				   unsigned int crtc_id,
+				   void *user_data);
+
 } drmEventContext, *drmEventContextPtr;
 
 extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
xf86drmMode.c +16 -8
index 0266bc10..d3bc20ea 100644
@@ -889,6 +889,7 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx)
 	int len, i;
 	struct drm_event *e;
 	struct drm_event_vblank *vblank;
+	void *user_data;
 
 	/* The DRM read semantics guarantees that we always get only
 	 * complete events. */
@@ -915,15 +916,22 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx)
 					      U642VOID (vblank->user_data));
 			break;
 		case DRM_EVENT_FLIP_COMPLETE:
-			if (evctx->version < 2 ||
-			    evctx->page_flip_handler == NULL)
-				break;
 			vblank = (struct drm_event_vblank *) e;
-			evctx->page_flip_handler(fd,
-						 vblank->sequence,
-						 vblank->tv_sec,
-						 vblank->tv_usec,
-						 U642VOID (vblank->user_data));
+			user_data = U642VOID (vblank->user_data);
+
+			if (evctx->version >= 3 && evctx->page_flip_handler2)
+				evctx->page_flip_handler2(fd,
+							 vblank->sequence,
+							 vblank->tv_sec,
+							 vblank->tv_usec,
+							 vblank->crtc_id,
+							 user_data);
+			else if (evctx->version >= 2 && evctx->page_flip_handler)
+				evctx->page_flip_handler(fd,
+							 vblank->sequence,
+							 vblank->tv_sec,
+							 vblank->tv_usec,
+							 user_data);
 			break;
 		default:
 			break;
Signature · 6 lines
2.11.0

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

A message that is not in the archive (sent off-list or not yet received): 20170404165221.28240-1-daniels-ZGY8ohtN/[email protected]

#10 lore raw

Re: [PATCH libdrm 2/2] Add CRTC ID to vblank event

Quoted 14 lines · On Tue, 4 Apr 2017 17:52:20 +0100 Daniel Stone…

From: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

When using the atomic API, one request can span multiple CRTCs, however one event is generated per CRTC. As we cannot disambiguate the CRTC with user data (since we only have one piece of user data to pass in), newer kernels can include the CRTC ID in the page flip event.

Add a new vfunc to dispatch vblank events carrying a CRTC ID to clients who negotiate a higher interface version.

[daniels: Rebased, include new cap, call page_flip_handler if it is set
but page_flip_handler2 isn't even on newer contexts, write a commit message.]

Quoted 9 lines
---
 include/drm/drm.h |  3 ++-
 xf86drm.h         |  9 ++++++++-
 xf86drmMode.c     | 24 ++++++++++++++++--------
 3 files changed, 26 insertions(+), 10 deletions(-)

Hi,

I'm replying to this patch to keep the scope rather than the split ones which are needed together and have unrelated changes.

Quoted 81 lines
include/drm/drm.h +2 -1
index 09d4262f..c4492372 100644
@@ -641,6 +641,7 @@ struct drm_gem_open {
 #define DRM_CAP_CURSOR_HEIGHT		0x9
 #define DRM_CAP_ADDFB2_MODIFIERS	0x10
 #define DRM_CAP_PAGE_FLIP_TARGET	0x11
+#define DRM_CAP_CRTC_IN_VBLANK_EVENT	0x12
 
 /** DRM_IOCTL_GET_CAP ioctl argument type */
 struct drm_get_cap {
@@ -846,7 +847,7 @@ struct drm_event_vblank {
 	__u32 tv_sec;
 	__u32 tv_usec;
 	__u32 sequence;
-	__u32 reserved;
+	__u32 crtc_id;
 };
 
 /* typedef area */
xf86drm.h +8 -1
index 0d927018..d75ca8ce 100644
@@ -728,7 +728,7 @@ extern void drmMsg(const char *format, ...) DRM_PRINTFLIKE(1, 2);
 extern int drmSetMaster(int fd);
 extern int drmDropMaster(int fd);
 
-#define DRM_EVENT_CONTEXT_VERSION 2
+#define DRM_EVENT_CONTEXT_VERSION 3
 
 typedef struct _drmEventContext {
 
@@ -748,6 +748,13 @@ typedef struct _drmEventContext {
 				  unsigned int tv_usec,
 				  void *user_data);
 
+	void (*page_flip_handler2)(int fd,
+				   unsigned int sequence,
+				   unsigned int tv_sec,
+				   unsigned int tv_usec,
+				   unsigned int crtc_id,
+				   void *user_data);
+
 } drmEventContext, *drmEventContextPtr;
 
 extern int drmHandleEvent(int fd, drmEventContextPtr evctx);
xf86drmMode.c +9 -8
index fb47fa8b..b71520aa 100644
@@ -889,6 +889,7 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx)
 	int len, i;
 	struct drm_event *e;
 	struct drm_event_vblank *vblank;
+	void *user_data;
 
 	/* The DRM read semantics guarantees that we always get only
 	 * complete events. */
@@ -915,15 +916,22 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx)
 					      U642VOID (vblank->user_data));
 			break;
 		case DRM_EVENT_FLIP_COMPLETE:
-			if (evctx->version < 2 ||
-			    evctx->page_flip_handler == NULL)
-				break;
 			vblank = (struct drm_event_vblank *) e;
-			evctx->page_flip_handler(fd,
-						 vblank->sequence,
-						 vblank->tv_sec,
-						 vblank->tv_usec,
-						 U642VOID (vblank->user_data));
+			user_data = U642VOID (vblank->user_data);
+
+			if (evctx->version >= 3 && evctx->page_flip_handler2)
+				evctx->page_flip_handler2(fd,
+							 vblank->sequence,
+							 vblank->tv_sec,
+							 vblank->tv_usec,
+							 vblank->crtc_id,

xf86drmMode.c int drmHandleEvent(int fd, drmEventContextPtr evctx) · line 937

Quoted 10 lines
xf86drmMode.c +7 -0
+							 user_data);
+			else if (evctx->version >= 2 && evctx->page_flip_handler)
+				evctx->page_flip_handler(fd,
+							 vblank->sequence,
+							 vblank->tv_sec,
+							 vblank->tv_usec,
+							 user_data);
 			break;
 		default:
 			break;

This is excellent.

I have browsed through Weston's DRM backend as of Daniel's atomic series v9, and the end result looks good. It depends on the CRTC ID in the pageflip events.

There Weston runs each CRTC independently, but at opportunity will coalesce updates to several CRTCs into the same atomic commit. As the repaint state machines are per CRTC in Weston, it is necessary to know which CRTC completed the pageflip at a time to avoid stalling everything until the last one or not being able to coalesce across CRTCs at all. Being able to coalesce across CRTCs is important particularly for modesets where programming all CRTCs in one go improves the chances of the transition succeeding in hardware.

I also cannot think of needing anything more in the event.

For instance, if DRM flip queue depth was grown beyond the current of one, we can use the user data pointer to identify which atomic commit is completing.

This patch gets all thumbs up from me on behalf of Weston.

Thanks,
pq

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