aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/drm_irq.c
diff options
context:
space:
mode:
authorImre Deak <imre.deak@intel.com>2012-10-23 14:53:25 -0400
committerDave Airlie <airlied@redhat.com>2012-11-20 01:06:15 -0500
commite62f2f5acba1d466da047983ae16f6b96b68b310 (patch)
tree08ff1fd73c55c3b781047415e816aeb3a3b45de4 /drivers/gpu/drm/drm_irq.c
parent11e686855c81c2e5e647b3dcfabd2a4e473c46f0 (diff)
drm: use monotonic time in drm_calc_vbltimestamp_from_scanoutpos
For measuring duration we want to avoid that our start/end timestamps jump, so use monotonic instead of real time for that. Signed-off-by: Imre Deak <imre.deak@intel.com> Reviewed-by: mario.kleiner Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/drm_irq.c')
-rw-r--r--drivers/gpu/drm/drm_irq.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 44602ef55afc..ef5b5f70735e 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -576,7 +576,8 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc,
576 unsigned flags, 576 unsigned flags,
577 struct drm_crtc *refcrtc) 577 struct drm_crtc *refcrtc)
578{ 578{
579 struct timeval stime, raw_time; 579 ktime_t stime, etime, mono_time_offset;
580 struct timeval tv_etime;
580 struct drm_display_mode *mode; 581 struct drm_display_mode *mode;
581 int vbl_status, vtotal, vdisplay; 582 int vbl_status, vtotal, vdisplay;
582 int vpos, hpos, i; 583 int vpos, hpos, i;
@@ -625,13 +626,14 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc,
625 preempt_disable(); 626 preempt_disable();
626 627
627 /* Get system timestamp before query. */ 628 /* Get system timestamp before query. */
628 do_gettimeofday(&stime); 629 stime = ktime_get();
629 630
630 /* Get vertical and horizontal scanout pos. vpos, hpos. */ 631 /* Get vertical and horizontal scanout pos. vpos, hpos. */
631 vbl_status = dev->driver->get_scanout_position(dev, crtc, &vpos, &hpos); 632 vbl_status = dev->driver->get_scanout_position(dev, crtc, &vpos, &hpos);
632 633
633 /* Get system timestamp after query. */ 634 /* Get system timestamp after query. */
634 do_gettimeofday(&raw_time); 635 etime = ktime_get();
636 mono_time_offset = ktime_get_monotonic_offset();
635 637
636 preempt_enable(); 638 preempt_enable();
637 639
@@ -642,7 +644,7 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc,
642 return -EIO; 644 return -EIO;
643 } 645 }
644 646
645 duration_ns = timeval_to_ns(&raw_time) - timeval_to_ns(&stime); 647 duration_ns = ktime_to_ns(etime) - ktime_to_ns(stime);
646 648
647 /* Accept result with < max_error nsecs timing uncertainty. */ 649 /* Accept result with < max_error nsecs timing uncertainty. */
648 if (duration_ns <= (s64) *max_error) 650 if (duration_ns <= (s64) *max_error)
@@ -689,14 +691,18 @@ int drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, int crtc,
689 vbl_status |= 0x8; 691 vbl_status |= 0x8;
690 } 692 }
691 693
694 etime = ktime_sub(etime, mono_time_offset);
695 /* save this only for debugging purposes */
696 tv_etime = ktime_to_timeval(etime);
692 /* Subtract time delta from raw timestamp to get final 697 /* Subtract time delta from raw timestamp to get final
693 * vblank_time timestamp for end of vblank. 698 * vblank_time timestamp for end of vblank.
694 */ 699 */
695 *vblank_time = ns_to_timeval(timeval_to_ns(&raw_time) - delta_ns); 700 etime = ktime_sub_ns(etime, delta_ns);
701 *vblank_time = ktime_to_timeval(etime);
696 702
697 DRM_DEBUG("crtc %d : v %d p(%d,%d)@ %ld.%ld -> %ld.%ld [e %d us, %d rep]\n", 703 DRM_DEBUG("crtc %d : v %d p(%d,%d)@ %ld.%ld -> %ld.%ld [e %d us, %d rep]\n",
698 crtc, (int)vbl_status, hpos, vpos, 704 crtc, (int)vbl_status, hpos, vpos,
699 (long)raw_time.tv_sec, (long)raw_time.tv_usec, 705 (long)tv_etime.tv_sec, (long)tv_etime.tv_usec,
700 (long)vblank_time->tv_sec, (long)vblank_time->tv_usec, 706 (long)vblank_time->tv_sec, (long)vblank_time->tv_usec,
701 (int)duration_ns/1000, i); 707 (int)duration_ns/1000, i);
702 708