[RFC 5/5] modesetting: Implement page flipping support for Present.

2015-02-13 Thread Nick Sarnie
Hi guys,

I'm testing the five patches Kenneth posted in January that result in
pageflipping support for Present. I'm using Xserver git, plus Kenneth's
five patches and the modesetting DDX. If I run World of Warcraft on Gallium
Nine, load into the game, and alt-tab out, my Xserver crashes. If I don't
use the five patches, there is no issue.

Here is a backtrace obtained from gdb over ssh:
http://pastebin.com/raw.php?i=nhRKPZzS

Any ideas on this?

Thanks,
Nick Sarnie
___
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Re: [RFC 5/5] modesetting: Implement page flipping support for Present.

2015-02-08 Thread Mario Kleiner
Hi Kenneth,

i reviewed and tested the pageflip patches on top of XOrg 1.17.0.

Testing results so far:

My own pageflip stress tests on Intel HD 4000 Ivybridge mobile,
KDE/KWin, with external timing measurement equipment attached to get
true flip completion time and compare it against the present
timestamps, show it mostly works nicely, with robust and precise onset
time (almost no skipped frames) and precise onset timestamps, so
that's good. Tested both single display and dual-display, on a single
x-screen.

I also stress tested once on nouveau single display, without the
measurement equipment, looked mostly ok.

And i ran it the last few days on Intel HD Ironlake mobile, single
display on KDE/KWin, stress test and regular desktop use, all mostly
good.

However, i had a few crashes, usually after a few hours of light
desktop use, always ending with no backtrace, but :

[ 11093.538] (WW) modeset(0): flip queue failed: Device or resource busy

- There seems to be bugs in the error handling for that path, see my
comments interspersed below in the code for likely reason and fix, so
far untested.

Testing on GNOME-3 once got me a hang at the end of a testing session,
followed by a crash with this backtrace:

[ 38554.786] (EE) Backtrace:
[ 38554.786] (EE) 0: /usr/local/bin/X (xorg_backtrace+0x56) [0x58f246]
[ 38554.786] (EE) 1: /usr/local/bin/X (0x40+0x193399) [0x593399]
[ 38554.786] (EE) 2: /lib/x86_64-linux-gnu/libc.so.6
(0x7fd28bcfc000+0x36eb0) [0x7fd28bd32eb0]
[ 38554.786] (EE) 3: /usr/local/bin/X (dixDestroyPixmap+0x4) [0x4347a4]
[ 38554.786] (EE) 4: /usr/local/bin/X (0x40+0x5ba92) [0x45ba92]
[ 38554.786] (EE) 5: /usr/local/bin/X (FreeClientResources+0x6c) [0x45cb4c]
[ 38554.786] (EE) 6: /usr/local/bin/X (CloseDownClient+0x70) [0x438680]
[ 38554.786] (EE) 7: /usr/local/bin/X (0x40+0x391ee) [0x4391ee]
[ 38554.786] (EE) 8: /usr/local/bin/X (0x40+0x3d34b) [0x43d34b]
[ 38554.786] (EE) 9: /lib/x86_64-linux-gnu/libc.so.6
(__libc_start_main+0xf5) [0x7fd28bd1dec5]
[ 38554.787] (EE) 10: /usr/local/bin/X (0x40+0x277ce) [0x4277ce]
[ 38554.787] (EE)
[ 38554.787] (EE) Segmentation fault at address 0xb40337

Could be unrelated to pageflipping bugs, just triggered by it?

See code below for review comments. Other than those it so far looks good to me.

On 1/29/15, Kenneth Graunke kenn...@whitecape.org wrote:
 Based on code by Keith Packard, Eric Anholt, and Jason Ekstrand.

 Signed-off-by: Kenneth Graunke kenn...@whitecape.org
 ---
  hw/xfree86/drivers/modesetting/driver.h  |  10 +
  hw/xfree86/drivers/modesetting/drmmode_display.c |  33 ++-
  hw/xfree86/drivers/modesetting/drmmode_display.h |   3 +
  hw/xfree86/drivers/modesetting/present.c | 363
 ++-
  4 files changed, 404 insertions(+), 5 deletions(-)

  Here's a first stab at implementing page flipping support for the
  modesetting driver, assuming you're using DRI3/Present.

  I've been running this all day, with cloned eDP and external DP monitors,
  with and without compositing, and it appears to be working fine.  I haven't
  seen any tearing with this patch; it was consistently present before while
  playing a game.  Jason Ekstrand also tested it.  drago01 also tested it on
  AMD.

  A couple of thoughts:
  1. The page flipping fields may need to be moved from modesettingRec to
 drmmode_crtc.  Not sure.
  2. Do we need to alter drmmode-front_bo at all?
  3. We can probably do this without Glamor, I just haven't tried it and
 hooked up the dumb BO stuff properly.  We should.
  4. DRI2 pageflipping?  I don't see any real point - it's a bunch of extra
 complexity for no real gain.  DRI3 is working fine.  We do need to port
 Mesa's EGL code to use DRI3, still, but that's doable.
  5. Option Pageflip...we should probably add one.  And man page updates.

  I doubt this is ready to merge, but I figured I'd send it so people could
  take a look and provide initial feedback.  This is pretty unfamiliar
  territory for me, so don't assume I know what I'm doing :)

 diff --git a/hw/xfree86/drivers/modesetting/driver.h
 b/hw/xfree86/drivers/modesetting/driver.h
 index 843a105..2d63cae 100644
 --- a/hw/xfree86/drivers/modesetting/driver.h
 +++ b/hw/xfree86/drivers/modesetting/driver.h
 @@ -101,6 +101,16 @@ typedef struct _modesettingRec {

  drmEventContext event_context;

 +/**
 + * Page flipping stuff.
 + *  @{
 + */
 +int flip_count;
 +uint64_t fe_msc;
 +uint64_t fe_usec;
 +struct ms_present_vblank_event *flip_vblank_event;
 +/** @} */
 +
  DamagePtr damage;
  Bool dirty_enabled;

 diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c
 b/hw/xfree86/drivers/modesetting/drmmode_display.c
 index 1ea799b..7fd8669 100644
 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c
 +++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
 @@ -50,7 +50,7 @@

  #include driver.h

 -static int
 +int
  drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo)
 

[RFC 5/5] modesetting: Implement page flipping support for Present.

2015-01-29 Thread Kenneth Graunke
Based on code by Keith Packard, Eric Anholt, and Jason Ekstrand.

Signed-off-by: Kenneth Graunke kenn...@whitecape.org
---
 hw/xfree86/drivers/modesetting/driver.h  |  10 +
 hw/xfree86/drivers/modesetting/drmmode_display.c |  33 ++-
 hw/xfree86/drivers/modesetting/drmmode_display.h |   3 +
 hw/xfree86/drivers/modesetting/present.c | 363 ++-
 4 files changed, 404 insertions(+), 5 deletions(-)

 Here's a first stab at implementing page flipping support for the
 modesetting driver, assuming you're using DRI3/Present.

 I've been running this all day, with cloned eDP and external DP monitors,
 with and without compositing, and it appears to be working fine.  I haven't
 seen any tearing with this patch; it was consistently present before while
 playing a game.  Jason Ekstrand also tested it.  drago01 also tested it on
 AMD.

 A couple of thoughts:
 1. The page flipping fields may need to be moved from modesettingRec to
drmmode_crtc.  Not sure.
 2. Do we need to alter drmmode-front_bo at all?
 3. We can probably do this without Glamor, I just haven't tried it and
hooked up the dumb BO stuff properly.  We should.
 4. DRI2 pageflipping?  I don't see any real point - it's a bunch of extra
complexity for no real gain.  DRI3 is working fine.  We do need to port
Mesa's EGL code to use DRI3, still, but that's doable.
 5. Option Pageflip...we should probably add one.  And man page updates.

 I doubt this is ready to merge, but I figured I'd send it so people could
 take a look and provide initial feedback.  This is pretty unfamiliar
 territory for me, so don't assume I know what I'm doing :)

diff --git a/hw/xfree86/drivers/modesetting/driver.h 
b/hw/xfree86/drivers/modesetting/driver.h
index 843a105..2d63cae 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -101,6 +101,16 @@ typedef struct _modesettingRec {
 
 drmEventContext event_context;
 
+/**
+ * Page flipping stuff.
+ *  @{
+ */
+int flip_count;
+uint64_t fe_msc;
+uint64_t fe_usec;
+struct ms_present_vblank_event *flip_vblank_event;
+/** @} */
+
 DamagePtr damage;
 Bool dirty_enabled;
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c 
b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 1ea799b..7fd8669 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -50,7 +50,7 @@
 
 #include driver.h
 
-static int
+int
 drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo)
 {
 int ret;
@@ -71,7 +71,7 @@ drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo)
 return 0;
 }
 
-static uint32_t
+uint32_t
 drmmode_bo_get_pitch(drmmode_bo *bo)
 {
 #ifdef GLAMOR_HAS_GBM
@@ -142,6 +142,35 @@ drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo,
 }
 
 Bool
+drmmode_bo_for_pixmap(drmmode_ptr drmmode, drmmode_bo *bo, PixmapPtr pixmap)
+{
+ScreenPtr screen = xf86ScrnToScreen(drmmode-scrn);
+uint16_t pitch;
+uint32_t size;
+int fd;
+
+#ifdef GLAMOR_HAS_GBM
+if (drmmode-glamor) {
+bo-gbm = glamor_gbm_bo_from_pixmap(screen, pixmap);
+bo-dumb = NULL;
+return bo-gbm != NULL;
+}
+#endif
+
+fd = glamor_fd_from_pixmap(screen, pixmap, pitch, size);
+if (fd  0) {
+xf86DrvMsg(drmmode-scrn-scrnIndex, X_ERROR,
+   Failed to get fd for flip to new front.\n);
+return FALSE;
+}
+
+bo-dumb = dumb_get_bo_from_fd(drmmode-fd, fd, pitch, size);
+close(fd);
+
+return bo-dumb != NULL;
+}
+
+Bool
 drmmode_SetSlaveBO(PixmapPtr ppix,
drmmode_ptr drmmode, int fd_handle, int pitch, int size)
 {
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h 
b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 3a8959a..adc2de6 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -139,6 +139,9 @@ extern DevPrivateKeyRec msPixmapPrivateKeyRec;
 
 #define msGetPixmapPriv(drmmode, p) 
((msPixmapPrivPtr)dixGetPrivateAddr((p)-devPrivates, 
(drmmode)-pixmapPrivateKeyRec))
 
+Bool drmmode_bo_for_pixmap(drmmode_ptr drmmode, drmmode_bo *bo, PixmapPtr 
pixmap);
+int drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo);
+uint32_t drmmode_bo_get_pitch(drmmode_bo *bo);
 uint32_t drmmode_bo_get_handle(drmmode_bo *bo);
 Bool drmmode_glamor_handle_new_screen_pixmap(drmmode_ptr drmmode);
 void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv);
diff --git a/hw/xfree86/drivers/modesetting/present.c 
b/hw/xfree86/drivers/modesetting/present.c
index 359e113..3ca1b94 100644
--- a/hw/xfree86/drivers/modesetting/present.c
+++ b/hw/xfree86/drivers/modesetting/present.c
@@ -44,6 +44,7 @@
 #include present.h
 
 #include driver.h
+#include drmmode_display.h
 
 #if 0
 #define DebugPresent(x) ErrorF x
@@ -206,6 +207,360 @@ ms_present_flush(WindowPtr window)
 #endif
 }
 
+#ifdef GLAMOR