Skip to contentSkip to conversation

libdrm: Move intel_atomic.h to libdrm core for sharing. (V2)

PATCH In review Pauli Nieminen 2 participants 3 messages Mar 10, 2010 – Mar 11, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 libdrm: Move intel_atomic.h to libdrm core for sharing. (V2)

intel_atomic.h includes very usefull atomic operations for lock free parrallel access of variables. Moving these to core libdrm for code sharing with radeon.

V2: Fix remaining references to intel_atomic.h and libdrm-intel.

---
 Makefile.am          |    2 +-
 configure.ac         |    2 +-
 intel/intel_atomic.h |   56 +-----------------------------
 xf86atomic.h         |   93 ++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+), 57 deletions(-)
 create mode 100644 xf86atomic.h
Makefile.am +1 -1
index ee3ccc7..295121f 100644
@@ -59,7 +59,7 @@ libdrm_la_SOURCES =				\
 	libdrm_lists.h
 
 libdrmincludedir = ${includedir}
-libdrminclude_HEADERS = xf86drm.h xf86drmMode.h
+libdrminclude_HEADERS = xf86drm.h xf86drmMode.h xf86atomic.h
 
 EXTRA_DIST = libdrm.pc.in include/drm/*
 
configure.ac +1 -1
index aaa8efa..953a758 100644
@@ -198,7 +198,7 @@ if test "x$INTEL" != "xno"; then
 
     ])
     if test "x$drm_cv_atomic_primitives" = xIntel; then
-	    AC_DEFINE(HAVE_INTEL_ATOMIC_PRIMITIVES, 1,
+	    AC_DEFINE(HAVE_LIBDRM_ATOMIC_PRIMITIVES, 1,
 		      [Enable if your compiler supports the Intel __sync_* atomic primitives])
     fi
     if test "x$drm_cv_atomic_primitives" = "xlibatomic-ops"; then
intel/intel_atomic.h +1 -55

61 lines not on this page · raw message

xf86atomic.h new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
1.6.3.3

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev

--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel

#1 lore raw

PATCH 2/2 libdrm_radeon: Optimize cs_gem_reloc to do less looping.

bo->referenced_in_cs is checked if bo is already in cs. Adding and removing reference in bo is done with atomic operations to allow parallel access to a bo from multiple contexts.

cs->id generation code quarentees there is not duplicated ids which limits number of cs->ids to 32. If there is more cs objects rest will get id 0.

This optimization decreases cs_write_reloc share of torcs profiling from 4.3% to 2.6%.

---
 radeon/radeon_bo_gem.c |    1 +
 radeon/radeon_bo_int.h |    4 +-
 radeon/radeon_cs.c     |    6 ++
 radeon/radeon_cs.h     |    2 +-
 radeon/radeon_cs_gem.c |  123 ++++++++++++++++++++++++++++++++++++------------
 radeon/radeon_cs_int.h |    1 +
 xf86atomic.h           |    6 ++
 7 files changed, 110 insertions(+), 33 deletions(-)
radeon/radeon_bo_gem.c +1 -0
index bc8058d..fb51f4a 100644
@@ -80,6 +80,7 @@ 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->base.referenced_in_cs, 0);
     bo->map_count = 0;
     if (handle) {
         struct drm_gem_open open_arg;
radeon/radeon_bo_int.h +3 -1
index 9589ead..9c0ae68 100644
@@ -1,6 +1,8 @@
 #ifndef RADEON_BO_INT
 #define RADEON_BO_INT
 
+#include <xf86atomic.h>
+
 struct radeon_bo_manager {
     struct radeon_bo_funcs  *funcs;
     int                     fd;
@@ -17,7 +19,7 @@ struct radeon_bo_int {
     unsigned                    cref;
     struct radeon_bo_manager    *bom;
     uint32_t                    space_accounted;
-    uint32_t                    referenced_in_cs;
+    atomic_t                    referenced_in_cs;
 };
 
 /* bo functions */
radeon/radeon_cs.c +6 -0
index cc9be39..d0e922b 100644
@@ -88,3 +88,9 @@ void radeon_cs_space_set_flush(struct radeon_cs *cs, void (*fn)(void *), void *d
     csi->space_flush_fn = fn;
     csi->space_flush_data = data;
 }
+
+uint32_t radeon_cs_get_id(struct radeon_cs *cs)
+{
+    struct radeon_cs_int *csi = (struct radeon_cs_int *)cs;
+    return csi->id;
+}
radeon/radeon_cs.h +1 -1
index 49d5d9a..7f6ee68 100644
@@ -85,7 +85,7 @@ extern int radeon_cs_write_reloc(struct radeon_cs *cs,
                                  uint32_t read_domain,
                                  uint32_t write_domain,
                                  uint32_t flags);
-
+extern uint32_t radeon_cs_get_id(struct radeon_cs *cs);
 /*
  * add a persistent BO to the list
  * a persistent BO is one that will be referenced across flushes,
radeon/radeon_cs_gem.c +92 -31

178 lines not on this page · raw message

radeon/radeon_cs_int.h +1 -0
index 8ba76bf..6cee574 100644
@@ -28,6 +28,7 @@ struct radeon_cs_int {
     int                         bo_count;
     void                        (*space_flush_fn)(void *);
     void                        *space_flush_data;
+    uint32_t                    id;
 };
 
 /* cs functions */
xf86atomic.h +6 -0
index de8e220..854187a 100644
@@ -50,6 +50,8 @@ typedef struct {
 # define atomic_set(x, val) ((x)->atomic = (val))
 # define atomic_inc(x) ((void) __sync_fetch_and_add (&(x)->atomic, 1))
 # define atomic_dec_and_test(x) (__sync_fetch_and_add (&(x)->atomic, -1) == 1)
+# define atomic_add(x, v) ((void) __sync_add_and_fetch(&(x)->atomic, (v)))
+# define atomic_dec(x, v) ((void) __sync_sub_and_fetch(&(x)->atomic, (v)))
 # define atomic_cmpxchg(x, oldv, newv) __sync_val_compare_and_swap (&(x)->atomic, oldv, newv)
 
 #endif
@@ -66,6 +68,8 @@ typedef struct {
 # define atomic_read(x) AO_load_full(&(x)->atomic)
 # define atomic_set(x, val) AO_store_full(&(x)->atomic, (val))
 # define atomic_inc(x) ((void) AO_fetch_and_add1_full(&(x)->atomic))
+# define atomic_add(x, v) ((void) AO_fetch_and_add_full(&(x)->atomic, (v)))
+# define atomic_dec(x, v) ((void) AO_fetch_and_add_full(&(x)->atomic, -(v)))
 # define atomic_dec_and_test(x) (AO_fetch_and_sub1_full(&(x)->atomic) == 1)
 # define atomic_cmpxchg(x, oldv, newv) AO_compare_and_swap_full(&(x)->atomic, oldv, newv)
 
@@ -82,6 +86,8 @@ typedef struct { uint_t atomic; } atomic_t;
 # define atomic_set(x, val) ((x)->atomic = (uint_t)(val))
 # define atomic_inc(x) (atomic_inc_uint (&(x)->atomic))
 # define atomic_dec_and_test(x) (atomic_dec_uint_nv(&(x)->atomic) == 1)
+# define atomic_add(x, v) (atomic_add_uint(&(x)->atomic, (v)))
+# define atomic_dec(x, v) (atomic_dec_uint(&(x)->atomic, (v)))
 # define atomic_cmpxchg(x, oldv, newv) atomic_cas_uint (&(x)->atomic, oldv, newv)
 
 #endif
Signature · 10 lines
1.6.3.3


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
--
#2 lore raw

Re: [PATCH 2/2] libdrm_radeon: Optimize cs_gem_reloc to do less looping.

Quoted 11 lines · Pauli Nieminen

bo->referenced_in_cs is checked if bo is already in cs. Adding and removing reference in bo is done with atomic operations to allow parallel access to a bo from multiple contexts.

cs->id generation code quarentees there is not duplicated ids which limits number of cs->ids to 32. If there is more cs objects rest will get id 0.

This optimization decreases cs_write_reloc share of torcs profiling from 4.3% to 2.6%.

This also needs something like the below for configure to verify that atomic ops are available.

configure.ac +13 -3
index fe00176..e419dd7 100644
@@ -173,7 +173,7 @@ if test "x$HAVE_LIBUDEV" = xyes; then
 fi
 AM_CONDITIONAL(HAVE_LIBUDEV, [test "x$HAVE_LIBUDEV" = xyes])
 
-if test "x$INTEL" != "xno"; then
+if test "x$INTEL" != "xno" || test "x$RADEON" != "xno"; then
     # Check for atomic intrinsics
     AC_CACHE_CHECK([for native atomic primitives], drm_cv_atomic_primitives,
     [
@@ -206,13 +206,23 @@ if test "x$INTEL" != "xno"; then
     fi
 
     if test "x$drm_cv_atomic_primitives" = "xnone"; then
-	    if test "x$INTEL" != "xauto"; then
+	    if test "x$INTEL" = "xyes"; then
 		    AC_MSG_ERROR([libdrm_intel depends upon atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package, or, failing both of those, disable support for Intel GPUs by passing --disable-intel to ./configure])
 	   else
 		    INTEL=no
 	   fi
+	    if test "x$RADEON" = "xyes"; then
+		    AC_MSG_ERROR([libdrm_radeon depends upon atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package, or, failing both of those, disable support for Radeon GPUs by passing --disable-radeon to ./configure])
+	   else
+		    RADEON=no
+	   fi
     else
-	   INTEL=yes
+	    if test "x$INTEL" != "xno"; then
+		INTEL=yes
+	    fi
+	    if test "x$RADEON" != "xno"; then
+		RADEON=yes
+	    fi
     fi
 fi
 
Signature · 14 lines
Earthling Michel Dänzer           |                http://www.vmware.com
Libre software enthusiast         |          Debian, X and DRI developer

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
--
_______________________________________________
Dri-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dri-devel