Skip to contentSkip to conversation

Avoid quadratic behavior in relocs/cs

RFC New Mathias Fröhlich 1 participant 1 message May 28, 2010

lore
Share & tools
lore
#0 lore raw

RFC 1/1 Avoid quadratic behavior in relocs/cs

Hi,

Attached is a change to the radeon reloc emitting code, that stores the reloc index in the buffer object. This avoids quadratic runtime behavior in the number of emitted buffer object relocs per command stream.
The reloc index is held in an array indexed by command stream number, which means that it should be safe to use with multiple command stream objects in place.

The patch itself is bigger than needed since it reindents the 'buffer object already has an index' case in cs_gem_write_reloc.

This change is driven by cs_gem_write_reloc already showing up noticable in profiles of some of my use cases.

Comments?

By the way, it appears to me that space_accounted should be also a per command stream member of the buffer object. True?

Greetings

Mathias

radeon/radeon_bo_gem.c +3 -10
index 081ccb9..6f0a1b7 100644
@@ -39,7 +39,6 @@
 #include <sys/mman.h>
 #include <errno.h>
 #include "xf86drm.h"
-#include "xf86atomic.h"
 #include "drm.h"
 #include "radeon_drm.h"
 #include "radeon_bo.h"
@@ -50,7 +49,6 @@ struct radeon_bo_gem {
     struct radeon_bo_int base;
     uint32_t            name;
     int                 map_count;
-    atomic_t            reloc_in_cs;
     void *priv_ptr;
 };
 
@@ -68,7 +66,7 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom,
                                  uint32_t flags)
 {
     struct radeon_bo_gem *bo;
-    int r;
+    int i, r;
 
     bo = (struct radeon_bo_gem*)calloc(1, sizeof(struct radeon_bo_gem));
     if (bo == NULL) {
@@ -82,7 +80,8 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom,
     bo->base.domains = domains;
     bo->base.flags = flags;
     bo->base.ptr = NULL;
-    atomic_set(&bo->reloc_in_cs, 0);
+    for (i = 0; i < sizeof(bo->base.idx_by_cs)/sizeof(bo->base.idx_by_cs[0]); ++i)
+        bo->base.idx_by_cs[i] = -1;
     bo->map_count = 0;
     if (handle) {
         struct drm_gem_open open_arg;
@@ -312,12 +311,6 @@ uint32_t radeon_gem_name_bo(struct radeon_bo *bo)
     return bo_gem->name;
 }
 
-void *radeon_gem_get_reloc_in_cs(struct radeon_bo *bo)
-{
-    struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo;
-    return &bo_gem->reloc_in_cs;
-}
-
 int radeon_gem_get_kernel_name(struct radeon_bo *bo, uint32_t *name)
 {
     struct radeon_bo_int *boi = (struct radeon_bo_int *)bo;
radeon/radeon_bo_gem.h +0 -1
index 0af8610..c56c58e 100644
@@ -38,7 +38,6 @@ struct radeon_bo_manager *radeon_bo_manager_gem_ctor(int fd);
 void radeon_bo_manager_gem_dtor(struct radeon_bo_manager *bom);
 
 uint32_t radeon_gem_name_bo(struct radeon_bo *bo);
-void *radeon_gem_get_reloc_in_cs(struct radeon_bo *bo);
 int radeon_gem_set_domain(struct radeon_bo *bo, uint32_t read_domains, uint32_t write_domain);
 int radeon_gem_get_kernel_name(struct radeon_bo *bo, uint32_t *name);
 #endif
radeon/radeon_bo_int.h +4 -0
index 9589ead..f47f790 100644
@@ -6,6 +6,8 @@ struct radeon_bo_manager {
     int                     fd;
 };
 
+#define MAX_CS_COUNT 32
+
 struct radeon_bo_int {
     void                        *ptr;
     uint32_t                    flags;
@@ -18,6 +20,8 @@ struct radeon_bo_int {
     struct radeon_bo_manager    *bom;
     uint32_t                    space_accounted;
     uint32_t                    referenced_in_cs;
+    /* store the reloc index indexed by the cs index number */
+    uint32_t                    idx_by_cs[MAX_CS_COUNT];
 };
 
 /* bo functions */
radeon/radeon_cs_gem.c +38 -47

134 lines not on this page · raw message

radeon/radeon_cs_int.h +1 -0
index 6cee574..4c2be36 100644
@@ -29,6 +29,7 @@ struct radeon_cs_int {
     void                        (*space_flush_fn)(void *);
     void                        *space_flush_data;
     uint32_t                    id;
+    uint32_t                    index;
 };
 
 /* cs functions */

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel