drm-vblank: Always return true vblank count of scheduled vblank event.
Subsystems (2)
PATCH 1/1 drm-vblank: Always return true vblank count of scheduled vblank event.
-------- Original Message --------
Subject: [PATCH] drm-vblank: Always return true vblank count of scheduled vblank event.
Date: Fri, 10 Dec 2010 15:58:10 +0100
From: Mario Kleiner <[email protected]>
To: [email protected]
CC: [email protected], [email protected], Mario Kleiner <[email protected]>
This patch tries to make sure that the vbl.reply.sequence vblank count for a queued or emitted vblank event always corresponds to the true vblank count of queueing/emission, so the ddx can rely on the returned target_msc for consistency checks and implementation of swap_intervals in glXSwapBuffers().
Without this there is a small race-condition between the userspace ddx queueing a vblank event and the vblank counter incrementing before the event gets queued in the kernel.
--- drivers/gpu/drm/drm_irq.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/gpu/drm/drm_irq.c +3 -0
@@ -1086,15 +1086,18 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe, e->event.sequence = vblwait->request.sequence;if ((seq - vblwait->request.sequence) <= (1 <<23 )) { + e->event.sequence = seq; e->event.tv_sec = now.tv_sec; e->event.tv_usec = now.tv_usec;drm_vblank_put (dev, e->pipe);list_add_tail (&e->base.link, &e->base.file_priv->event_list);wake_up_interruptible (&e->base.file_priv->event_wait); + vblwait->reply.sequence = seq;trace_drm_vblank_event_delivered (current->pid, pipe, vblwait->request.sequence); }else {list_add_tail (&e->base.link, &dev->vblank_event_list); + vblwait->reply.sequence = vblwait->request.sequence; }spin_unlock_irqrestore (&dev->event_lock, flags);
Signature · 1 line
1.7.0.4
Quoted 35 lines · On Fri, 10 Dec 2010 16:00:19 +0100 Mario Kleiner…
-------- Original Message --------
Subject: [PATCH] drm-vblank: Always return true vblank count of scheduled vblank event.
Date: Fri, 10 Dec 2010 15:58:10 +0100
From: Mario Kleiner <[email protected]>
To: [email protected]
CC: [email protected], [email protected], Mario Kleiner
<[email protected]>This patch tries to make sure that the vbl.reply.sequence vblank count for a queued or emitted vblank event always corresponds to the true vblank count of queueing/emission, so the ddx can rely on the returned
target_mscfor consistency checks and implementation ofswap_intervalsinglXSwapBuffers().Without this there is a small race-condition between the userspace ddx queueing a vblank event and the vblank counter incrementing before the event gets queued in the kernel.
Signed-off-by Mario Kleiner <[email protected]>--- drivers/gpu/drm/drm_irq.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)drivers/gpu/drm/drm_irq.c +0
-0@@ -1086,15 +1086,18 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe, e->event.sequence = vblwait->request.sequence;
drivers/gpu/drm/drm_irq.c static int drm_queue_vblank_event(struct · line 1098
Quoted 10 lines
drivers/gpu/drm/drm_irq.c +2
-0if ((seq - vblwait->request.sequence) <= (1 <<23 )) { + e->event.sequence = seq; e->event.tv_sec = now.tv_sec; e->event.tv_usec = now.tv_usec;drm_vblank_put (dev, e->pipe);list_add_tail (&e->base.link, &e->base.file_priv->event_list);wake_up_interruptible (&e->base.file_priv->event_wait); + vblwait->reply.sequence = seq;trace_drm_vblank_event_delivered (current->pid, pipe, vblwait->request.sequence);
But this actually causes us to return the current count rather than the requested count if the event requested is in the past, right?
drivers/gpu/drm/drm_irq.c static int drm_queue_vblank_event(struct drm_device *dev, int pipe, · line 1101
Quoted 4 lines
drivers/gpu/drm/drm_irq.c +1
-0}else {list_add_tail (&e->base.link, &dev->vblank_event_list); + vblwait->reply.sequence = vblwait->request.sequence; }
This one makes sense; we want to make sure the returned sequence is the one requested (assuming it was in the future at the time of the request anyway).
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Quoted 37 lines · Jesse Barnes
Quoted 34 lines · On Fri, 10 Dec 2010 16:00:19 +0100 Mario Kleiner…
-------- Original Message --------
Subject: [PATCH] drm-vblank: Always return true vblank count of scheduled vblank event.
Date: Fri, 10 Dec 2010 15:58:10 +0100
From: Mario Kleiner <[email protected]>
To: [email protected]
CC: [email protected], [email protected], Mario Kleiner
<[email protected]>This patch tries to make sure that the vbl.reply.sequence vblank count for a queued or emitted vblank event always corresponds to the true vblank count of queueing/emission, so the ddx can rely on the returned
target_mscfor consistency checks and implementation ofswap_intervalsinglXSwapBuffers().Without this there is a small race-condition between the userspace ddx queueing a vblank event and the vblank counter incrementing before the event gets queued in the kernel.
Signed-off-by Mario Kleiner <[email protected]>--- drivers/gpu/drm/drm_irq.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)drivers/gpu/drm/drm_irq.c +0
-0@@ -1086,15 +1086,18 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe,
Quoted 15 lines
drivers/gpu/drm/drm_irq.c static int drm_queue_vblank_event(struct drm_device *dev, int pipe, · line 1097
Quoted 11 lines
drivers/gpu/drm/drm_irq.c +2
-0e->event.sequence = vblwait->request.sequence;if ((seq - vblwait->request.sequence) <= (1 <<23 )) { + e->event.sequence = seq; e->event.tv_sec = now.tv_sec; e->event.tv_usec = now.tv_usec;drm_vblank_put (dev, e->pipe);list_add_tail (&e->base.link, &e->base.file_priv->event_list);wake_up_interruptible (&e->base.file_priv->event_wait); + vblwait->reply.sequence = seq;trace_drm_vblank_event_delivered (current->pid, pipe, vblwait->request.sequence);But this actually causes us to return the current count rather than the requested count if the event requested is in the past, right?
Yes. But i think that's what the spec wants. The wording in the spec is usually "...and then will return the current values for UST, MSC,
and SBC...". If it just returned what was passed to it, it
wouldn't provide any new information to the calling client.
Currently there are three uses for queuing of vblank events:
a) Copy-Swaps: Queue a vblank event for target_msc to trigger a blit once the event is received. Because we set the DRM_VBLANK_NEXT_ON_MISS flag when queuing this event, the requested target_msc is automatically adapted by the drm to current_msc + 1 and this new adapted value is returned to the ddx. So for copy swaps the kernel returns the true expected count and time of the swap. The above path isn't ever taken.
b) Pageflip-Swaps: Queue a vblank event for target_msc - 1, even if target_msc -1 is already over. This will deliver the event immediately if current_msc >= target_msc - 1, but without the patch it would deliver it with a vbl.reply.sequence that has nothing to do with the real count at swap.
So a) and b) with the old code don't have a negative effect on scheduling a swap, but b) can have a a negative effect for the scheduling of the next pageflipped swap: The ddx uses the returned value as last_swap_target to implement swap_interval correctly, so the next swap may not obey the swap_interval correctly if case b) delivered an outdated vbl.reply.sequence number.
c) WaitForMscOML: Like b), but here it would return the "wrong" count for a target_msc in the past. The client would get the information back that it passed into the call, instead of the information that reflects reality.
d) Some correctness check for pageflipping in the ddx that can work more reliable / detect more possible errors if the returned value is always precise.
Quoted 9 lines
drivers/gpu/drm/drm_irq.c static int drm_queue_vblank_event(struct drm_device *dev, int pipe, · line 1101
Quoted 4 lines
drivers/gpu/drm/drm_irq.c +1
-0}else {list_add_tail (&e->base.link, &dev->vblank_event_list); + vblwait->reply.sequence = vblwait->request.sequence; }This one makes sense; we want to make sure the returned sequence is the one requested (assuming it was in the future at the time of the request anyway).
Yes, but the requested number gets adapted by the function if DRM_VBLANK_NEXT_ON_MISS is set. Also this statement is a bit redundant, because vblwait is a union iirc, so vblwait->reply.sequence and vblwait->request.sequence are actually the same field. It's just added for clarity.
-mario
Jesse Barnes
Acked-byQuoted 105 lines · On Mon, 13 Dec 2010 18:21:20 +0100 Mario Kleiner…
Quoted 37 lines · Jesse Barnes
Quoted 34 lines · On Fri, 10 Dec 2010 16:00:19 +0100 Mario Kleiner…
-------- Original Message --------
Subject: [PATCH] drm-vblank: Always return true vblank count of scheduled vblank event.
Date: Fri, 10 Dec 2010 15:58:10 +0100
From: Mario Kleiner <[email protected]>
To: [email protected]
CC: [email protected], [email protected], Mario Kleiner
<[email protected]>This patch tries to make sure that the vbl.reply.sequence vblank count for a queued or emitted vblank event always corresponds to the true vblank count of queueing/emission, so the ddx can rely on the returned
target_mscfor consistency checks and implementation ofswap_intervalsinglXSwapBuffers().Without this there is a small race-condition between the userspace ddx queueing a vblank event and the vblank counter incrementing before the event gets queued in the kernel.
Signed-off-by Mario Kleiner <[email protected]>--- drivers/gpu/drm/drm_irq.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)drivers/gpu/drm/drm_irq.c +0
-0@@ -1086,15 +1086,18 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe,Quoted 16 lines
drivers/gpu/drm/drm_irq.c static int drm_queue_vblank_event(struct drm_device *dev, int pipe, · line 1097
Quoted 11 lines
drivers/gpu/drm/drm_irq.c +2
-0e->event.sequence = vblwait->request.sequence;if ((seq - vblwait->request.sequence) <= (1 <<23 )) { + e->event.sequence = seq; e->event.tv_sec = now.tv_sec; e->event.tv_usec = now.tv_usec;drm_vblank_put (dev, e->pipe);list_add_tail (&e->base.link, &e->base.file_priv->event_list);wake_up_interruptible (&e->base.file_priv->event_wait); + vblwait->reply.sequence = seq;trace_drm_vblank_event_delivered (current->pid, pipe, vblwait->request.sequence);But this actually causes us to return the current count rather than the
requested count if the event requested is in the past, right?Yes. But i think that's what the spec wants. The wording in the spec is usually "...and then will return the current values for UST, MSC,
and SBC...". If it just returned what was passed to it, it
wouldn't provide any new information to the calling client.Currently there are three uses for queuing of vblank events:
a) Copy-Swaps: Queue a vblank event for
target_mscto trigger a blit once the event is received. Because we set theDRM_VBLANK_NEXT_ON_MISSflag when queuing this event, the requestedtarget_mscis automatically adapted by the drm tocurrent_msc+ 1 and this new adapted value is returned to the ddx. So for copy swaps the kernel returns the true expected count and time of the swap. The above path isn't ever taken.b) Pageflip-Swaps: Queue a vblank event for
target_msc- 1, even iftarget_msc-1 is already over. This will deliver the event immediately ifcurrent_msc>=target_msc- 1, but without the patch it would deliver it with a vbl.reply.sequence that has nothing to do with the real count at swap.So a) and b) with the old code don't have a negative effect on scheduling a swap, but b) can have a a negative effect for the scheduling of the next pageflipped swap: The ddx uses the returned value as
last_swap_targetto implementswap_intervalcorrectly, so the next swap may not obey theswap_intervalcorrectly if case b) delivered an outdated vbl.reply.sequence number.c) WaitForMscOML: Like b), but here it would return the "wrong" count for a
target_mscin the past. The client would get the information back that it passed into the call, instead of the information that reflects reality.d) Some correctness check for pageflipping in the ddx that can work more reliable / detect more possible errors if the returned value is always precise.
Quoted 11 lines
drivers/gpu/drm/drm_irq.c static int drm_queue_vblank_event(struct drm_device *dev, int pipe, · line 1101
Quoted 4 lines
drivers/gpu/drm/drm_irq.c +1
-0}else {list_add_tail (&e->base.link, &dev->vblank_event_list); + vblwait->reply.sequence = vblwait->request.sequence; }This one makes sense; we want to make sure the returned sequence is the
one requested (assuming it was in the future at the time of the request
anyway).
Quoted 5 lines
Yes, but the requested number gets adapted by the function if
DRM_VBLANK_NEXT_ON_MISSis set. Also this statement is a bit redundant, because vblwait is a union iirc, so vblwait-Quoted 1 line
reply.sequence and
vblwait->request.sequenceare actually the samefield. It's just added for clarity.
Right; thanks for the additional explanation, it looks good to me.
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center