Skip to contentSkip to conversation

Use EventCallback to avoid flushing every time in the FlushCallback

PATCH In review Michel Dänzer 2 participants 4 messages Aug 1, 2016 – Aug 2, 2016 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Use EventCallback to avoid flushing every time in the FlushCallback

From: Michel Dänzer <[email protected]>

We only need to flush for XDamageNotify events.

Significantly reduces compositing slowdown due to flushing overhead, in particular with glamor.

---
 src/radeon.h     |  2 ++
 src/radeon_kms.c | 79 +++++++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 66 insertions(+), 15 deletions(-)
src/radeon.h +2 -0
index 37d5fb6..25ff61c 100644
@@ -473,6 +473,8 @@ typedef struct {
     Bool              RenderAccel; /* Render */
     Bool              allowColorTiling;
     Bool              allowColorTiling2D;
+    int               callback_event_type;
+    uint_fast32_t     callback_needs_flush;
     uint_fast32_t     gpu_flushed;
     uint_fast32_t     gpu_synced;
     struct radeon_accel_state *accel_state;
src/radeon_kms.c +64 -15

126 lines not on this page · raw message

Signature · 6 lines
2.8.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1470045560-7220-1-git-send-email-michel-otUistvHUpPR7s880joybQ@public.gmane.org

#2 lore raw

PATCH 2/2 Keep track of damage event related flushes per-client

From: Michel Dänzer <[email protected]>

This further reduces the compositing slowdown due to flushing overhead, by only flushing when the X server actually sends XDamageNotify events to a client, and there hasn't been a flush yet in the meantime.

---

This patch can't have an effect without a corresponding xserver patch which passes the ClientPtr to the FlushCallback, so I'll only push this one once the xserver patch has landed.

 src/radeon.h     |  5 ++++-
 src/radeon_kms.c | 34 ++++++++++++++++++++++++++++------
 2 files changed, 32 insertions(+), 7 deletions(-)
src/radeon.h +4 -1
index 25ff61c..b119241 100644
@@ -448,6 +448,10 @@ struct radeon_accel_state {
     Bool              force;
 };
 
+struct radeon_client_priv {
+    uint_fast32_t     needs_flush[0];
+};
+
 typedef struct {
     EntityInfoPtr     pEnt;
     pciVideoPtr       PciInfo;
@@ -474,7 +478,6 @@ typedef struct {
     Bool              allowColorTiling;
     Bool              allowColorTiling2D;
     int               callback_event_type;
-    uint_fast32_t     callback_needs_flush;
     uint_fast32_t     gpu_flushed;
     uint_fast32_t     gpu_synced;
     struct radeon_accel_state *accel_state;
src/radeon_kms.c +28 -6
index da11358..7ede3a1 100644
@@ -40,6 +40,7 @@
 
 #include "radeon_version.h"
 #include "shadow.h"
+#include <xf86Priv.h>
 
 #include "atipciids.h"
 
@@ -59,6 +60,8 @@
 #include "radeon_cs_gem.h"
 #include "radeon_vbo.h"
 
+static DevPrivateKeyRec radeon_client_private_key;
+
 extern SymTabRec RADEONChipsets[];
 static Bool radeon_setup_kernel_mem(ScreenPtr pScreen);
 
@@ -241,9 +244,9 @@ radeonUpdatePacked(ScreenPtr pScreen, shadowBufPtr pBuf)
 }
 
 static Bool
-callback_needs_flush(RADEONInfoPtr info)
+callback_needs_flush(RADEONInfoPtr info, uint_fast32_t needs_flush)
 {
-    return (int)(info->callback_needs_flush - info->gpu_flushed) > 0;
+    return (int)(needs_flush - info->gpu_flushed) > 0;
 }
 
 static void
@@ -251,21 +254,28 @@ radeon_event_callback(CallbackListPtr *list,
 		      pointer user_data, pointer call_data)
 {
     EventInfoRec *eventinfo = call_data;
+    struct radeon_client_priv *client_priv =
+	dixLookupPrivate(&eventinfo->client->devPrivates, &radeon_client_private_key);
+    struct radeon_client_priv *server_priv =
+	dixLookupPrivate(&serverClient->devPrivates, &radeon_client_private_key);
     ScrnInfoPtr pScrn = user_data;
     RADEONInfoPtr info = RADEONPTR(pScrn);
     int i;
 
-    if (callback_needs_flush(info))
+    if (callback_needs_flush(info, client_priv->needs_flush[pScrn->scrnIndex]) ||
+	callback_needs_flush(info, server_priv->needs_flush[pScrn->scrnIndex]))
 	return;
 
     /* Don't let gpu_flushed get too far ahead of callback_needs_flush,
      * in order to prevent false positives in callback_needs_flush()
      */
-    info->callback_needs_flush = info->gpu_flushed;
+    client_priv->needs_flush[pScrn->scrnIndex] = info->gpu_flushed;
+    server_priv->needs_flush[pScrn->scrnIndex] = info->gpu_flushed;
     
     for (i = 0; i < eventinfo->count; i++) {
 	if (eventinfo->events[i].u.u.type == info->callback_event_type) {
-	    info->callback_needs_flush++;
+	    client_priv->needs_flush[pScrn->scrnIndex]++;
+	    server_priv->needs_flush[pScrn->scrnIndex]++;
 	    return;
 	}
     }
@@ -276,9 +286,13 @@ radeon_flush_callback(CallbackListPtr *list,
 		      pointer user_data, pointer call_data)
 {
     ScrnInfoPtr pScrn = user_data;
+    ClientPtr client = call_data ? call_data : serverClient;
+    struct radeon_client_priv *client_priv =
+	dixLookupPrivate(&client->devPrivates, &radeon_client_private_key);
     RADEONInfoPtr info = RADEONPTR(pScrn);
 
-    if (pScrn->vtSema && callback_needs_flush(info))
+    if (pScrn->vtSema &&
+	callback_needs_flush(info, client_priv->needs_flush[pScrn->scrnIndex]))
         radeon_cs_flush_indirect(pScrn);
 }
 
@@ -351,6 +365,14 @@ static Bool RADEONCreateScreenResources_KMS(ScreenPtr pScreen)
 	    DeleteCallback(&FlushCallback, radeon_flush_callback, pScrn);
 	    return FALSE;
 	}
+
+	if (!dixPrivateKeyRegistered(&radeon_client_private_key) &&
+	    !dixRegisterPrivateKey(&radeon_client_private_key, PRIVATE_CLIENT,
+				   xf86NumScreens * sizeof(uint_fast32_t))) {
+	    DeleteCallback(&FlushCallback, radeon_flush_callback, pScrn);
+	    DeleteCallback(&EventCallback, radeon_event_callback, pScrn);
+	    return FALSE;
+	}
     }
 
     return TRUE;
Signature · 6 lines
2.8.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1470045560-7220-2-git-send-email-michel-otUistvHUpPR7s880joybQ@public.gmane.org

Reviewed-by Alex Deucher
#4 lore raw

RE: [PATCH xf86-video-ati 2/2] Keep track of damage event related flushes per-client

Quoted 8 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Michel Dänzer
Sent: Monday, August 01, 2016 5:59 AM
To: [email protected]
Subject: [PATCH xf86-video-ati 2/2] Keep track of damage event related flushes per-client

Quoted 7 lines

From: Michel Dänzer <[email protected]>

This further reduces the compositing slowdown due to flushing overhead, by only flushing when the X server actually sends XDamageNotify events to a client, and there hasn't been a flush yet in the meantime.

For the series:

Quoted 136 lines

---

This patch can't have an effect without a corresponding xserver patch which passes the ClientPtr to the FlushCallback, so I'll only push this one once the xserver patch has landed.

 src/radeon.h     |  5 ++++-
 src/radeon_kms.c | 34 ++++++++++++++++++++++++++++------
 2 files changed, 32 insertions(+), 7 deletions(-)
src/radeon.h +4 -1
index 25ff61c..b119241 100644
@@ -448,6 +448,10 @@ struct radeon_accel_state {
     Bool              force;
 };
 
+struct radeon_client_priv {
+    uint_fast32_t     needs_flush[0];
+};
+
 typedef struct {
     EntityInfoPtr     pEnt;
     pciVideoPtr       PciInfo;
@@ -474,7 +478,6 @@ typedef struct {
     Bool              allowColorTiling;
     Bool              allowColorTiling2D;
     int               callback_event_type;
-    uint_fast32_t     callback_needs_flush;
     uint_fast32_t     gpu_flushed;
     uint_fast32_t     gpu_synced;
     struct radeon_accel_state *accel_state;
src/radeon_kms.c +5 -2
index da11358..7ede3a1 100644
@@ -40,6 +40,7 @@
 
 #include "radeon_version.h"
 #include "shadow.h"
+#include <xf86Priv.h>
 
 #include "atipciids.h"
 
@@ -59,6 +60,8 @@
 #include "radeon_cs_gem.h"
 #include "radeon_vbo.h"
 
+static DevPrivateKeyRec radeon_client_private_key;
+
 extern SymTabRec RADEONChipsets[];
 static Bool radeon_setup_kernel_mem(ScreenPtr pScreen);
 
@@ -241,9 +244,9 @@ radeonUpdatePacked(ScreenPtr pScreen,
 shadowBufPtr pBuf)
 }
 
 static Bool
-callback_needs_flush(RADEONInfoPtr info)
+callback_needs_flush(RADEONInfoPtr info, uint_fast32_t needs_flush)
 {
-    return (int)(info->callback_needs_flush - info->gpu_flushed) > 0;
+    return (int)(needs_flush - info->gpu_flushed) > 0;
 }
 

static void

src/radeon_kms.c +5 -1
@@ -251,21 +254,28 @@ radeon_event_callback(CallbackListPtr *list,
 		      pointer user_data, pointer call_data)
 {
     EventInfoRec *eventinfo = call_data;
+    struct radeon_client_priv *client_priv =
+	dixLookupPrivate(&eventinfo->client->devPrivates,
 &radeon_client_private_key);
+    struct radeon_client_priv *server_priv =
+	dixLookupPrivate(&serverClient->devPrivates,
 &radeon_client_private_key);
     ScrnInfoPtr pScrn = user_data;
     RADEONInfoPtr info = RADEONPTR(pScrn);
     int i;
 
-    if (callback_needs_flush(info))
+    if (callback_needs_flush(info, client_priv->needs_flush[pScrn-
Quoted 1 line

scrnIndex]) ||

src/radeon_kms.c +1 -0
+	callback_needs_flush(info, server_priv->needs_flush[pScrn-
Quoted 1 line

scrnIndex]))

src/radeon_kms.c +9 -3
 	return;
 
     /* Don't let gpu_flushed get too far ahead of callback_needs_flush,
      * in order to prevent false positives in callback_needs_flush()
      */
-    info->callback_needs_flush = info->gpu_flushed;
+    client_priv->needs_flush[pScrn->scrnIndex] = info->gpu_flushed;
+    server_priv->needs_flush[pScrn->scrnIndex] = info->gpu_flushed;
 
     for (i = 0; i < eventinfo->count; i++) {
 	if (eventinfo->events[i].u.u.type == info->callback_event_type) {
-	    info->callback_needs_flush++;
+	    client_priv->needs_flush[pScrn->scrnIndex]++;
+	    server_priv->needs_flush[pScrn->scrnIndex]++;
 	    return;
 	}
     }
@@ -276,9 +286,13 @@ radeon_flush_callback(CallbackListPtr *list,
 		      pointer user_data, pointer call_data)
 {
     ScrnInfoPtr pScrn = user_data;
+    ClientPtr client = call_data ? call_data : serverClient;
+    struct radeon_client_priv *client_priv =
+	dixLookupPrivate(&client->devPrivates,
 &radeon_client_private_key);
     RADEONInfoPtr info = RADEONPTR(pScrn);
 
-    if (pScrn->vtSema && callback_needs_flush(info))
+    if (pScrn->vtSema &&
+	callback_needs_flush(info, client_priv->needs_flush[pScrn-
 >scrnIndex]))
         radeon_cs_flush_indirect(pScrn);

}

src/radeon_kms.c +8 -0
@@ -351,6 +365,14 @@ static Bool
 RADEONCreateScreenResources_KMS(ScreenPtr pScreen)
 	    DeleteCallback(&FlushCallback, radeon_flush_callback, pScrn);
 	    return FALSE;
 	}
+
+	if (!dixPrivateKeyRegistered(&radeon_client_private_key) &&
+	    !dixRegisterPrivateKey(&radeon_client_private_key,
 PRIVATE_CLIENT,
+				   xf86NumScreens * sizeof(uint_fast32_t))) {
+	    DeleteCallback(&FlushCallback, radeon_flush_callback, pScrn);
+	    DeleteCallback(&EventCallback, radeon_event_callback, pScrn);
+	    return FALSE;
+	}
     }
Quoted 8 lines
     return TRUE;

--
2.8.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw

PATCH 1/1 Keep track of damage event related flushes per-client v2

In reply to a message not in the archive

From: Michel Dänzer <[email protected]>

This further reduces the compositing slowdown due to flushing overhead, by only flushing when the X server actually sends XDamageNotify events to a client, and there hasn't been a flush yet in the meantime.

v2: Use ScreenPrivateKey, fixes invalid memory access with GPU screens

---
 src/radeon.h     |  5 ++++-
 src/radeon_kms.c | 41 +++++++++++++++++++++++++++++++++--------
 2 files changed, 37 insertions(+), 9 deletions(-)
src/radeon.h +4 -1
index 25ff61c..f3a3e1c 100644
@@ -448,6 +448,10 @@ struct radeon_accel_state {
     Bool              force;
 };
 
+struct radeon_client_priv {
+    uint_fast32_t     needs_flush;
+};
+
 typedef struct {
     EntityInfoPtr     pEnt;
     pciVideoPtr       PciInfo;
@@ -474,7 +478,6 @@ typedef struct {
     Bool              allowColorTiling;
     Bool              allowColorTiling2D;
     int               callback_event_type;
-    uint_fast32_t     callback_needs_flush;
     uint_fast32_t     gpu_flushed;
     uint_fast32_t     gpu_synced;
     struct radeon_accel_state *accel_state;
src/radeon_kms.c +33 -8

89 lines not on this page · raw message

Signature · 6 lines
2.8.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx