dri-devel Archive mirror
 help / color / mirror / Atom feed
* Vblank timestamping enhancements for drm-next and 2.6.38rc
@ 2011-02-21  4:41 Mario Kleiner
  2011-02-21  4:42 ` [PATCH 1/3] drm/vblank: Use abs64(diff_ns) for s64 diff_ns instead of abs(diff_ns) Mario Kleiner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mario Kleiner @ 2011-02-21  4:41 UTC (permalink / raw
  To: dri-devel; +Cc: airlied

Hi,

the following three patches are some small improvements and fixes to
the drm vblank timestamping. All fully tested on radeon rv530, r600 and
on i915 with 945gme chipset.

Please consider merging them for 2.6.38-rc as well.

Thanks,
-mario

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] drm/vblank: Use abs64(diff_ns) for s64 diff_ns instead of abs(diff_ns)
  2011-02-21  4:41 Vblank timestamping enhancements for drm-next and 2.6.38rc Mario Kleiner
@ 2011-02-21  4:42 ` Mario Kleiner
  2011-02-21  4:42 ` [PATCH 2/3] drm/vblank: Use memory barriers optimized for atomic_t instead of generics Mario Kleiner
  2011-02-21  4:42 ` [PATCH 3/3] drm/vblank: Enable precise vblank timestamps for interlaced and doublescan modes Mario Kleiner
  2 siblings, 0 replies; 4+ messages in thread
From: Mario Kleiner @ 2011-02-21  4:42 UTC (permalink / raw
  To: dri-devel; +Cc: airlied, Mario Kleiner

Use of abs() wrongly wrapped diff_ns to 32 bit, which gives a 1/4000
probability of a missed vblank increment at each vblank irq reenable
if the kms driver doesn't support high precision vblank timestamping.
Not a big deal in practice, but let's make it nice.

Signed-off-by: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
---
 drivers/gpu/drm/drm_irq.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 0054e95..149805a 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -164,7 +164,7 @@ static void vblank_disable_and_save(struct drm_device *dev, int crtc)
 	 * available. In that case we can't account for this and just
 	 * hope for the best.
 	 */
-	if ((vblrc > 0) && (abs(diff_ns) > 1000000))
+	if ((vblrc > 0) && (abs64(diff_ns) > 1000000))
 		atomic_inc(&dev->_vblank_count[crtc]);
 
 	/* Invalidate all timestamps while vblank irq's are off. */
@@ -1293,7 +1293,7 @@ void drm_handle_vblank(struct drm_device *dev, int crtc)
 	 * e.g., due to spurious vblank interrupts. We need to
 	 * ignore those for accounting.
 	 */
-	if (abs(diff_ns) > DRM_REDUNDANT_VBLIRQ_THRESH_NS) {
+	if (abs64(diff_ns) > DRM_REDUNDANT_VBLIRQ_THRESH_NS) {
 		/* Store new timestamp in ringbuffer. */
 		vblanktimestamp(dev, crtc, vblcount + 1) = tvblank;
 		smp_wmb();
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] drm/vblank: Use memory barriers optimized for atomic_t instead of generics.
  2011-02-21  4:41 Vblank timestamping enhancements for drm-next and 2.6.38rc Mario Kleiner
  2011-02-21  4:42 ` [PATCH 1/3] drm/vblank: Use abs64(diff_ns) for s64 diff_ns instead of abs(diff_ns) Mario Kleiner
@ 2011-02-21  4:42 ` Mario Kleiner
  2011-02-21  4:42 ` [PATCH 3/3] drm/vblank: Enable precise vblank timestamps for interlaced and doublescan modes Mario Kleiner
  2 siblings, 0 replies; 4+ messages in thread
From: Mario Kleiner @ 2011-02-21  4:42 UTC (permalink / raw
  To: dri-devel; +Cc: airlied, Mario Kleiner

Documentation/atomic_ops.txt tells us that there are memory
barriers optimized for atomic_inc and other atomic_t ops.

Use these instead of smp_wmb(), and also to make the required
memory barriers around vblank counter increments more explicit.

Signed-off-by: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
---
 drivers/gpu/drm/drm_irq.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 149805a..891bf6d 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -164,8 +164,10 @@ static void vblank_disable_and_save(struct drm_device *dev, int crtc)
 	 * available. In that case we can't account for this and just
 	 * hope for the best.
 	 */
-	if ((vblrc > 0) && (abs64(diff_ns) > 1000000))
+	if ((vblrc > 0) && (abs64(diff_ns) > 1000000)) {
 		atomic_inc(&dev->_vblank_count[crtc]);
+		smp_mb__after_atomic_inc();
+	}
 
 	/* Invalidate all timestamps while vblank irq's are off. */
 	clear_vblank_timestamps(dev, crtc);
@@ -858,10 +860,11 @@ static void drm_update_vblank_count(struct drm_device *dev, int crtc)
 	if (rc) {
 		tslot = atomic_read(&dev->_vblank_count[crtc]) + diff;
 		vblanktimestamp(dev, crtc, tslot) = t_vblank;
-		smp_wmb();
 	}
 
+	smp_mb__before_atomic_inc();
 	atomic_add(diff, &dev->_vblank_count[crtc]);
+	smp_mb__after_atomic_inc();
 }
 
 /**
@@ -1296,12 +1299,13 @@ void drm_handle_vblank(struct drm_device *dev, int crtc)
 	if (abs64(diff_ns) > DRM_REDUNDANT_VBLIRQ_THRESH_NS) {
 		/* Store new timestamp in ringbuffer. */
 		vblanktimestamp(dev, crtc, vblcount + 1) = tvblank;
-		smp_wmb();
 
 		/* Increment cooked vblank count. This also atomically commits
 		 * the timestamp computed above.
 		 */
+		smp_mb__before_atomic_inc();
 		atomic_inc(&dev->_vblank_count[crtc]);
+		smp_mb__after_atomic_inc();
 	} else {
 		DRM_DEBUG("crtc %d: Redundant vblirq ignored. diff_ns = %d\n",
 			  crtc, (int) diff_ns);
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] drm/vblank: Enable precise vblank timestamps for interlaced and doublescan modes.
  2011-02-21  4:41 Vblank timestamping enhancements for drm-next and 2.6.38rc Mario Kleiner
  2011-02-21  4:42 ` [PATCH 1/3] drm/vblank: Use abs64(diff_ns) for s64 diff_ns instead of abs(diff_ns) Mario Kleiner
  2011-02-21  4:42 ` [PATCH 2/3] drm/vblank: Use memory barriers optimized for atomic_t instead of generics Mario Kleiner
@ 2011-02-21  4:42 ` Mario Kleiner
  2 siblings, 0 replies; 4+ messages in thread
From: Mario Kleiner @ 2011-02-21  4:42 UTC (permalink / raw
  To: dri-devel; +Cc: airlied, Mario Kleiner

Testing showed the current code can already handle doublescan
video modes just fine. A trivial tweak makes it work for interlaced
scanout as well.

Tested and shown to be precise on Radeon rv530, r600 and
Intel 945-GME.

Signed-off-by: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
---
 drivers/gpu/drm/drm_irq.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 891bf6d..2abcd15 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -493,6 +493,12 @@ void drm_calc_timestamping_constants(struct drm_crtc *crtc)
 	/* Dot clock in Hz: */
 	dotclock = (u64) crtc->hwmode.clock * 1000;
 
+	/* Fields of interlaced scanout modes are only halve a frame duration.
+	 * Double the dotclock to get halve the frame-/line-/pixelduration.
+	 */
+	if (crtc->hwmode.flags & DRM_MODE_FLAG_INTERLACE)
+		dotclock *= 2;
+
 	/* Valid dotclock? */
 	if (dotclock > 0) {
 		/* Convert scanline length in pixels and video dot clock to
@@ -605,14 +611,6 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc,
 		return -EAGAIN;
 	}
 
-	/* Don't know yet how to handle interlaced or
-	 * double scan modes. Just no-op for now.
-	 */
-	if (mode->flags & (DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLSCAN)) {
-		DRM_DEBUG("crtc %d: Noop due to unsupported mode.\n", crtc);
-		return -ENOTSUPP;
-	}
-
 	/* Get current scanout position with system timestamp.
 	 * Repeat query up to DRM_TIMESTAMP_MAXRETRIES times
 	 * if single query takes longer than max_error nanoseconds.
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-02-21  4:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-21  4:41 Vblank timestamping enhancements for drm-next and 2.6.38rc Mario Kleiner
2011-02-21  4:42 ` [PATCH 1/3] drm/vblank: Use abs64(diff_ns) for s64 diff_ns instead of abs(diff_ns) Mario Kleiner
2011-02-21  4:42 ` [PATCH 2/3] drm/vblank: Use memory barriers optimized for atomic_t instead of generics Mario Kleiner
2011-02-21  4:42 ` [PATCH 3/3] drm/vblank: Enable precise vblank timestamps for interlaced and doublescan modes Mario Kleiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).