[PATCH 3/3] DRI2: defer swap if relevant CRTC is in DMPS off state

Ilija Hadzic ilijahadzic at gmail.com
Thu Dec 13 11:46:33 PST 2012


From: Ilija Hadzic <ihadzic at research.bell-labs.com>

If drawable is displayed on a CRTC with a valid mode and
relevant CRTC is in DPMS off state, calculate the nominal
vblank period and defer the swap until the calulated time
elapses.

This patch fixes a bug that cuased an application to render
at uncontrolled rate when CRTC goes into DPMS "off" state,
thus thrashing the GPU and CPU and likely offseting the
power savings achieved by shutting off the display.

Signed-off-by: Ilija Hadzic <ihadzic at research.bell-labs.com>
---
 src/radeon_dri2.c  | 43 +++++++++++++++++++++++++++++++++++++------
 src/radeon_video.c |  3 +--
 src/radeon_video.h |  2 ++
 3 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/src/radeon_dri2.c b/src/radeon_dri2.c
index 8ebc687..a861fa1 100644
--- a/src/radeon_dri2.c
+++ b/src/radeon_dri2.c
@@ -1263,6 +1263,14 @@ void radeon_dri2_flip_event_handler(unsigned int frame, unsigned int tv_sec,
     free(flip);
 }
 
+static
+CARD32 radeon_dri2_deferred_swap(OsTimerPtr timer, CARD32 now, pointer data)
+{
+    TimerFree(timer);
+    radeon_dri2_frame_event_handler(0, 0, 0, data);
+    return 0;
+}
+
 /*
  * ScheduleSwap is responsible for requesting a DRM vblank event for the
  * appropriate frame.
@@ -1292,9 +1300,9 @@ static int radeon_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
     ScreenPtr screen = draw->pScreen;
     ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
     RADEONInfoPtr info = RADEONPTR(scrn);
-    xf86CrtcPtr crtc = radeon_dri2_drawable_crtc(draw, FALSE);
+    xf86CrtcPtr crtc = radeon_dri2_drawable_crtc(draw, TRUE);
     drmVBlank vbl;
-    int ret, flip = 0;
+    int ret, nominal_vblank_period, flip = 0;
     DRI2FrameEventPtr swap_info = NULL;
     enum DRI2FrameEventType swap_type = DRI2_SWAP;
     CARD64 current_msc;
@@ -1314,7 +1322,7 @@ static int radeon_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
     radeon_dri2_ref_buffer(front);
     radeon_dri2_ref_buffer(back);
 
-    /* Drawable not displayed... just complete the swap */
+    /* either off-screen or CRTC not usable... just complete the swap */
     if (crtc == NULL)
         goto blit_fallback;
 
@@ -1337,6 +1345,20 @@ static int radeon_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
         goto blit_fallback;
     }
 
+    nominal_vblank_period = crtc->mode.HTotal * crtc->mode.VTotal;
+    nominal_vblank_period /= crtc->mode.Clock;
+    /*
+     * CRTC is in DPMS off state, fallback to blit, but pace the
+     * application at the rate that roughly approximates the
+     * nominal frame rate of the relevant CRTC
+     */
+    if (!radeon_crtc_is_enabled(crtc)) {
+	TimerSet(NULL, 0, nominal_vblank_period, radeon_dri2_deferred_swap,
+		 swap_info);
+	*target_msc = 0;
+	return TRUE;
+    }
+
     /* Get current count */
     vbl.request.type = DRM_VBLANK_RELATIVE;
     vbl.request.type |= populate_vbl_request_type(info, crtc);
@@ -1346,7 +1368,10 @@ static int radeon_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
         xf86DrvMsg(scrn->scrnIndex, X_WARNING,
                 "first get vblank counter failed: %s\n",
                 strerror(errno));
-        goto blit_fallback;
+	TimerSet(NULL, 0, nominal_vblank_period, radeon_dri2_deferred_swap,
+		 swap_info);
+	*target_msc = 0;
+	return TRUE;
     }
 
     current_msc = vbl.reply.sequence;
@@ -1395,7 +1420,10 @@ static int radeon_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
             xf86DrvMsg(scrn->scrnIndex, X_WARNING,
                     "divisor 0 get vblank counter failed: %s\n",
                     strerror(errno));
-            goto blit_fallback;
+	    TimerSet(NULL, 0, nominal_vblank_period, radeon_dri2_deferred_swap,
+		     swap_info);
+	    *target_msc = 0;
+            return TRUE;
         }
 
         *target_msc = vbl.reply.sequence + flip;
@@ -1440,7 +1468,10 @@ static int radeon_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,
         xf86DrvMsg(scrn->scrnIndex, X_WARNING,
                 "final get vblank counter failed: %s\n",
                 strerror(errno));
-        goto blit_fallback;
+	TimerSet(NULL, 0, nominal_vblank_period, radeon_dri2_deferred_swap,
+		 swap_info);
+	*target_msc = 0;
+	return TRUE;
     }
 
     /* Adjust returned value for 1 fame pageflip offset of flip > 0 */
diff --git a/src/radeon_video.c b/src/radeon_video.c
index 63b4844..8999dd0 100644
--- a/src/radeon_video.c
+++ b/src/radeon_video.c
@@ -67,8 +67,7 @@ radeon_box_area(BoxPtr box)
     return (int) (box->x2 - box->x1) * (int) (box->y2 - box->y1);
 }
 
-static Bool
-radeon_crtc_is_enabled(xf86CrtcPtr crtc)
+Bool radeon_crtc_is_enabled(xf86CrtcPtr crtc)
 {
     drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
     return drmmode_crtc->dpms_mode == DPMSModeOn;
diff --git a/src/radeon_video.h b/src/radeon_video.h
index f097f2f..e6068e8 100644
--- a/src/radeon_video.h
+++ b/src/radeon_video.h
@@ -100,4 +100,6 @@ RADEONCopyMungedData(ScrnInfoPtr pScrn,
 		     unsigned int srcPitch, unsigned int srcPitch2,
 		     unsigned int dstPitch, unsigned int h, unsigned int w);
 
+Bool radeon_crtc_is_enabled(xf86CrtcPtr crtc);
+
 #endif
-- 
1.7.12.4



More information about the xorg-driver-ati mailing list