Add support for passing crtc_id to page flip events.
Subsystems (2)
Maarten Lankhorst
maintainercover Add support for passing crtc_id to page flip events.
When generating events for a atomic commit involving multiple crtc's it's not possible to distinguish which crtc belongs to which page flip event. Solve this by putting crtc_id in the reserved member of page_flip_event.
I've checked weston, and the following ddx: modesetting (xserver), i915, nouveau, ati, vmwgfx.
None of them depend in any way on the reserved member, so setting it to non-zero should be safe. A lot of them use libdrm, which hides the page flip event struct and only passes its members.
This is why I also changed libdrm to pass crtc_id in page_flip_handler2. Any compositor that uses drmHandleEvent will be able to get information about the crtc_id too, if available.
Maarten Lankhorst (2):
(kernel) drm/core: Reuse the reserved member in drm_event_vblank for crtc_id. (libdrm) Add support for crtc_id in page flip events
Kernel:
drivers/gpu/drm/drm_irq.c | 2 ++ include/uapi/drm/drm.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
Libdrm:
include/drm/drm.h | 2 +- tests/modetest/modetest.c | 20 ++++++++++++++++++-- xf86drm.h | 16 +++++++++++++++- xf86drmMode.c | 23 ++++++++++++++++------- 4 files changed, 50 insertions(+), 11 deletions(-)
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maarten Lankhorst
maintainerPATCH 1/2 drm/core: Reuse the reserved member in drm_event_vblank for crtc_id.
When doing a atomic commit affecting multiple crtc's, multiple events are generated. The user_data member does not allow you to distinguish, because they all have the same pointer.
I've chosen to use crtc_id, because using pipe would create ambiguity when pipe = 0. A test for != 0 is easier to implement, and crtc_id will never be 0.
--- drivers/gpu/drm/drm_irq.c | 2 ++ include/uapi/drm/drm.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_irq.c +2 -0
@@ -1021,6 +1021,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);
@@ -1048,6 +1049,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 +1 -1
@@ -850,7 +850,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.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 1/2] drm/core: Reuse the reserved member in drm_event_vblank for crtc_id.
Quoted 41 lines · Maarten Lankhorst
When doing a atomic commit affecting multiple crtc's, multiple events are generated. The
user_datamember does not allow you to distinguish, because they all have the same pointer.I've chosen to use
crtc_id, because using pipe would create ambiguity when pipe = 0. A test for != 0 is easier to implement, andcrtc_idwill never be 0.Signed-off-by Maarten Lankhorst <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Stone <[email protected]>--- drivers/gpu/drm/drm_irq.c | 2 ++ include/uapi/drm/drm.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_irq.c +2
-0@@ -1021,6 +1021,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);@@ -1048,6 +1049,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 +0
-0
include/uapi/drm/drm.h struct drm_event_vblank { · line 853
Quoted 5 lines
include/uapi/drm/drm.h +1
-1@@ -850,7 +850,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 */
Same comment as in reply to Michel's patch: Is there really no existing userspace which would fail to compile now because we renamed this? Simply creating a new drm_event_vblank2 struct would fix that. -Daniel
Quoted 10 lines
include/uapi/drm/drm.h +0
-0};/* typedef area */ Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maarten Lankhorst
maintainerRe: [PATCH 1/2] drm/core: Reuse the reserved member in drm_event_vblank for crtc_id.
Op 10-08-16 om 16:14 schreef Daniel Vetter:
Quoted 42 lines · Maarten Lankhorst
Quoted 41 lines
When doing a atomic commit affecting multiple crtc's, multiple events are generated. The
user_datamember does not allow you to distinguish, because they all have the same pointer.I've chosen to use
crtc_id, because using pipe would create ambiguity when pipe = 0. A test for != 0 is easier to implement, andcrtc_idwill never be 0.Signed-off-by Maarten Lankhorst <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Stone <[email protected]>--- drivers/gpu/drm/drm_irq.c | 2 ++ include/uapi/drm/drm.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_irq.c +2
-0@@ -1021,6 +1021,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);@@ -1048,6 +1049,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 +0
-0@@ -850,7 +850,7 @@ struct drm_event_vblank {
Quoted 8 lines
include/uapi/drm/drm.h struct drm_event_vblank { · line 853
Quoted 5 lines
include/uapi/drm/drm.h +1
-1__u32 tv_sec;__u32 tv_usec;__u32 sequence; -__u32 reserved; +__u32 crtc_id;/* 0 on older kernels that do not support this */ Same comment as in reply to Michel's patch: Is there really no existing userspace which would fail to compile now because we renamed this? Simply creating a new
drm_event_vblank2struct would fix that.
Hey,
This comment must have fallen through, I haven't found any case in which this happened. All of them use a memset or allocate it zero'd.
~Maarten
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Maarten Lankhorst
maintainerPATCH 2/2 Add support for crtc_id in page flip events
In reply to Maarten LankhorstAdd a page_flip_handler2 member to drmEventContext and bump DRM_EVENT_CONTEXT.
To make sure that the new api works as intended, modetest is changed to use it.
--- include/drm/drm.h | 2 +- tests/modetest/modetest.c | 20 ++++++++++++++++++-- xf86drm.h | 16 +++++++++++++++- xf86drmMode.c | 23 ++++++++++++++++------- 4 files changed, 50 insertions(+), 11 deletions(-)
include/drm/drm.h +1 -1
@@ -844,7 +844,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 */
tests/modetest/modetest.c +18 -2
@@ -913,8 +913,8 @@ static void set_property(struct device *dev, struct property_arg *p)/* -------------------------------------------------------------------------- */ static void -page_flip_handler (int fd,unsigned int frame, -unsigned int sec,unsigned int usec,void *data) +page_flip_handler2 (int fd,unsigned int crtc_id,unsigned int frame, +unsigned int sec,unsigned int usec,void *data) {struct pipe_arg *pipe;unsigned int new_fb_id;
@@ -927,6 +927,8 @@ page_flip_handler(int fd, unsigned int frame,else new_fb_id = pipe->fb_id[0 ]; +assert (crtc_id == pipe->crtc->crtc->crtc_id); +drmModePageFlip (fd, pipe->crtc->crtc->crtc_id, new_fb_id,DRM_MODE_PAGE_FLIP_EVENT , pipe); pipe->current_fb_id = new_fb_id;
@@ -941,6 +943,19 @@ page_flip_handler(int fd, unsigned int frame, } } +static void +page_flip_handler (int fd,unsigned int frame, +unsigned int sec,unsigned int usec,void *data) +{ +struct pipe_arg *pipe = data; +static int once =0 ; + +if (!once++) +fprintf (stderr,"kernel doesn't pass crtc_id, or using older libdrm\n" ); + +page_flip_handler2 (fd, pipe->crtc->crtc->crtc_id, frame, sec, usec, data); +} +static bool format_support (const drmModePlanePtr ovr,uint32_t fmt) {unsigned int i;
@@ -1233,6 +1248,7 @@ static void test_page_flip(struct device *dev, struct pipe_arg *pipes, unsigned evctx.version =DRM_EVENT_CONTEXT_VERSION ; evctx.vblank_handler =NULL ; evctx.page_flip_handler = page_flip_handler; + evctx.page_flip_handler2 = page_flip_handler2;while (1 ) {#if 0
xf86drm.h +15 -1
@@ -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,20 @@ typedef struct _drmEventContext {unsigned int tv_usec, void *user_data); +/* +* Page flip handler used when kernel supports passing crtc_id +* to userspace. +* +* If the kernel doesn't support passing crtc_id, the old +* page_flip_handler() member will be called if set, +* if it's NULL, this function will be called with crtc_id set to 0. +*/ +void (*page_flip_handler2)(int fd, +unsigned int crtc_id, +unsigned int sequence, +unsigned int tv_sec, +unsigned int tv_usec, +void *user_data); } drmEventContext, *drmEventContextPtr;extern int drmHandleEvent (int fd,drmEventContextPtr evctx);
xf86drmMode.c +16 -7
@@ -902,15 +902,24 @@ 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 ) +if (evctx->version <2 )break ; vblank = (struct drm_event_vblank *) e; - evctx->page_flip_handler (fd, - vblank->sequence, - vblank->tv_sec, - vblank->tv_usec, -U642VOID (vblank->user_data)); + +if (evctx->version >=3 && evctx->page_flip_handler2 && + (vblank->crtc_id || !evctx->page_flip_handler)) + evctx->page_flip_handler2 (fd, + vblank->crtc_id, + vblank->sequence, + vblank->tv_sec, + vblank->tv_usec, +U642VOID (vblank->user_data)); +else if (evctx->page_flip_handler) + evctx->page_flip_handler (fd, + vblank->sequence, + vblank->tv_sec, + vblank->tv_usec, +U642VOID (vblank->user_data));break ;default :break ;
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel