DRI2InvalidateWalk high in "perf top" profile

Chris Wilson chris at chris-wilson.co.uk
Mon Feb 16 12:56:23 PST 2015

On Mon, Feb 16, 2015 at 09:30:43PM +0100, Loïc Yhuel wrote:
> Hi,
> Please forgive me if my analysis is wrong for the current code, since
> I'm running Fedora 21, so xorg 1.16.3, but it doesn't seem to to have
> changed much.
> I was surprised to see DRI2InvalidateWalk high in "perf top" profile,
> both with an idle system, and when running some graphics tests, so I
> looked at callstacks with gdb : sna_present_vblank_handler calls
> present_execute, which calls present_set_tree_pixmap(screen->root,
> vblank->pixmap).
> For each affected window, DRI2SetWindowPixmap is called, and it calls
> DRI2InvalidateDrawableAll, which goes up back to the root and
> invalidates all windows which already have the new pixmap.
> So if I'm right, the invalidation added by
> 18744907d0766b1b57be12df5adafd0f93221006 "dri2: Invalidate DRI2Buffers
> upon SetWindowPixmap updates" is done in quadratic time.

Indeed, it is overkill to use DRI2InvalidateDrawableAll() as all callers
of pScreen->SetWindowPixmap will be traversing the tree themselves, so

diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
index e37f2de..1f33d16 100644
--- a/hw/xfree86/dri2/dri2.c
+++ b/hw/xfree86/dri2/dri2.c
@@ -1406,8 +1406,7 @@ DRI2ConfigNotify(WindowPtr pWin, int x, int y, int w, int h, int bw,
 static void
 DRI2SetWindowPixmap(WindowPtr pWin, PixmapPtr pPix)
-    DrawablePtr pDraw = (DrawablePtr) pWin;
-    ScreenPtr pScreen = pDraw->pScreen;
+    ScreenPtr pScreen = pWin->drawable.pScreen;
     DRI2ScreenPtr ds = DRI2GetScreen(pScreen);
     pScreen->SetWindowPixmap = ds->SetWindowPixmap;
@@ -1415,7 +1414,7 @@ DRI2SetWindowPixmap(WindowPtr pWin, PixmapPtr pPix)
     ds->SetWindowPixmap = pScreen->SetWindowPixmap;
     pScreen->SetWindowPixmap = DRI2SetWindowPixmap;
-    DRI2InvalidateDrawableAll(pDraw);
+    DRI2InvalidateDrawable(&pWin->drawable);

would suffice

Chris Wilson, Intel Open Source Technology Centre

More information about the xorg-devel mailing list