]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Implemented cache rotation.
authorBart Van Assche <bvanassche@acm.org>
Mon, 9 Jun 2008 19:50:51 +0000 (19:50 +0000)
committerBart Van Assche <bvanassche@acm.org>
Mon, 9 Jun 2008 19:50:51 +0000 (19:50 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8209

exp-drd/Testing.txt
exp-drd/drd_bitmap.c
exp-drd/drd_bitmap.h
exp-drd/pub_drd_bitmap.h

index 2664147d677d171ddaa045f95ee57cacaaf5b245..077bd93c3e55d08a4731997b389cfcb90f680792 100644 (file)
@@ -5,8 +5,8 @@ How to test DRD
    command:
      perl tests/vg_regtest exp-drd
 2. Test the slowdown for matinv for various matrix sizes via the script
-   exp-drd/scripts/run-matinv (must be about 27 for i == 1 and about
-   36 for i == 10).
+   exp-drd/scripts/run-matinv (must be about 24 for i == 1 and about
+   33 for i == 10 with n == 200).
 3. Test whether DRD works with standard KDE applications and whether it does
    not print any false positives:
      ./vg-in-place --tool=exp-drd kate
index 301d0e9295c1abf40f374aba8cfe06bd88fc01b3..ab72a0d0d34420ef3615e60148d4c8e3417e256c 100644 (file)
@@ -250,7 +250,7 @@ void bm_access_store_8(struct bitmap* const bm, const Addr a1)
     bm_access_range(bm, a1, a1 + 8, eStore);
 }
 
-Bool bm_has(const struct bitmap* const bm, const Addr a1, const Addr a2,
+Bool bm_has(struct bitmap* const bm, const Addr a1, const Addr a2,
             const BmAccessTypeT access_type)
 {
   Addr b;
@@ -264,8 +264,7 @@ Bool bm_has(const struct bitmap* const bm, const Addr a1, const Addr a2,
   return True;
 }
 
-Bool bm_has_any_load(const struct bitmap* const bm,
-                     const Addr a1, const Addr a2)
+Bool bm_has_any_load(struct bitmap* const bm, const Addr a1, const Addr a2)
 {
   Addr b, b_next;
 
@@ -317,7 +316,7 @@ Bool bm_has_any_load(const struct bitmap* const bm,
   return 0;
 }
 
-Bool bm_has_any_store(const struct bitmap* const bm,
+Bool bm_has_any_store(struct bitmap* const bm,
                       const Addr a1, const Addr a2)
 {
   Addr b, b_next;
@@ -372,7 +371,7 @@ Bool bm_has_any_store(const struct bitmap* const bm,
 
 /* Return True if there is a read access, write access or both   */
 /* to any of the addresses in the range [ a1, a2 [ in bitmap bm. */
-Bool bm_has_any_access(const struct bitmap* const bm,
+Bool bm_has_any_access(struct bitmap* const bm,
                        const Addr a1, const Addr a2)
 {
   Addr b, b_next;
@@ -428,7 +427,7 @@ Bool bm_has_any_access(const struct bitmap* const bm,
 /** Report whether an access of type access_type at address a is recorded in
  *  bitmap bm.
  */
-Bool bm_has_1(const struct bitmap* const bm,
+Bool bm_has_1(struct bitmap* const bm,
               const Addr a, const BmAccessTypeT access_type)
 {
   const struct bitmap2* p2;
@@ -448,7 +447,7 @@ Bool bm_has_1(const struct bitmap* const bm,
   return False;
 }
 
-void bm_clear(const struct bitmap* const bm,
+void bm_clear(struct bitmap* const bm,
               const Addr a1,
               const Addr a2)
 {
@@ -510,7 +509,7 @@ void bm_clear(const struct bitmap* const bm,
 /** Clear all references to loads in bitmap bm starting at address a1 and
  *  up to but not including address a2.
  */
-void bm_clear_load(const struct bitmap* const bm,
+void bm_clear_load(struct bitmap* const bm,
                    const Addr a1, const Addr a2)
 {
   Addr a;
@@ -528,7 +527,7 @@ void bm_clear_load(const struct bitmap* const bm,
 /** Clear all references to stores in bitmap bm starting at address a1 and
  *  up to but not including address a2.
  */
-void bm_clear_store(const struct bitmap* const bm,
+void bm_clear_store(struct bitmap* const bm,
                     const Addr a1, const Addr a2)
 {
   Addr a;
@@ -547,7 +546,7 @@ void bm_clear_store(const struct bitmap* const bm,
  *  a2. Return True if and only if any of the addresses was set before
  *  clearing.
  */
-Bool bm_test_and_clear(const struct bitmap* const bm,
+Bool bm_test_and_clear(struct bitmap* const bm,
                        const Addr a1, const Addr a2)
 {
   Bool result;
@@ -557,7 +556,7 @@ Bool bm_test_and_clear(const struct bitmap* const bm,
   return result;
 }
 
-Bool bm_has_conflict_with(const struct bitmap* const bm,
+Bool bm_has_conflict_with(struct bitmap* const bm,
                           const Addr a1, const Addr a2,
                           const BmAccessTypeT access_type)
 {
@@ -623,18 +622,18 @@ Bool bm_has_conflict_with(const struct bitmap* const bm,
   return False;
 }
 
-Bool bm_load_has_conflict_with(const struct bitmap* const bm,
+Bool bm_load_has_conflict_with(struct bitmap* const bm,
                                const Addr a1, const Addr a2)
 {
   return bm_has_conflict_with(bm, a1, a2, eLoad);
 }
 
-Bool bm_load_1_has_conflict_with(const struct bitmap* const bm, const Addr a1)
+Bool bm_load_1_has_conflict_with(struct bitmap* const bm, const Addr a1)
 {
   return bm_aligned_load_has_conflict_with(bm, a1, 1);
 }
 
-Bool bm_load_2_has_conflict_with(const struct bitmap* const bm, const Addr a1)
+Bool bm_load_2_has_conflict_with(struct bitmap* const bm, const Addr a1)
 {
   if ((a1 & 1) == 0)
     return bm_aligned_load_has_conflict_with(bm, a1, 2);
@@ -642,7 +641,7 @@ Bool bm_load_2_has_conflict_with(const struct bitmap* const bm, const Addr a1)
     return bm_has_conflict_with(bm, a1, a1 + 2, eLoad);
 }
 
-Bool bm_load_4_has_conflict_with(const struct bitmap* const bm, const Addr a1)
+Bool bm_load_4_has_conflict_with(struct bitmap* const bm, const Addr a1)
 {
   if ((a1 & 3) == 0)
     return bm_aligned_load_has_conflict_with(bm, a1, 4);
@@ -650,7 +649,7 @@ Bool bm_load_4_has_conflict_with(const struct bitmap* const bm, const Addr a1)
     return bm_has_conflict_with(bm, a1, a1 + 4, eLoad);
 }
 
-Bool bm_load_8_has_conflict_with(const struct bitmap* const bm, const Addr a1)
+Bool bm_load_8_has_conflict_with(struct bitmap* const bm, const Addr a1)
 {
   if ((a1 & 7) == 0)
     return bm_aligned_load_has_conflict_with(bm, a1, 8);
@@ -658,12 +657,12 @@ Bool bm_load_8_has_conflict_with(const struct bitmap* const bm, const Addr a1)
     return bm_has_conflict_with(bm, a1, a1 + 8, eLoad);
 }
 
-Bool bm_store_1_has_conflict_with(const struct bitmap* const bm, const Addr a1)
+Bool bm_store_1_has_conflict_with(struct bitmap* const bm, const Addr a1)
 {
   return bm_aligned_store_has_conflict_with(bm, a1, 1);
 }
 
-Bool bm_store_2_has_conflict_with(const struct bitmap* const bm, const Addr a1)
+Bool bm_store_2_has_conflict_with(struct bitmap* const bm, const Addr a1)
 {
   if ((a1 & 1) == 0)
     return bm_aligned_store_has_conflict_with(bm, a1, 2);
@@ -671,7 +670,7 @@ Bool bm_store_2_has_conflict_with(const struct bitmap* const bm, const Addr a1)
     return bm_has_conflict_with(bm, a1, a1 + 2, eStore);
 }
 
-Bool bm_store_4_has_conflict_with(const struct bitmap* const bm, const Addr a1)
+Bool bm_store_4_has_conflict_with(struct bitmap* const bm, const Addr a1)
 {
   if ((a1 & 3) == 0)
     return bm_aligned_store_has_conflict_with(bm, a1, 4);
@@ -679,7 +678,7 @@ Bool bm_store_4_has_conflict_with(const struct bitmap* const bm, const Addr a1)
     return bm_has_conflict_with(bm, a1, a1 + 4, eStore);
 }
 
-Bool bm_store_8_has_conflict_with(const struct bitmap* const bm, const Addr a1)
+Bool bm_store_8_has_conflict_with(struct bitmap* const bm, const Addr a1)
 {
   if ((a1 & 7) == 0)
     return bm_aligned_store_has_conflict_with(bm, a1, 8);
@@ -687,7 +686,7 @@ Bool bm_store_8_has_conflict_with(const struct bitmap* const bm, const Addr a1)
     return bm_has_conflict_with(bm, a1, a1 + 8, eStore);
 }
 
-Bool bm_store_has_conflict_with(const struct bitmap* const bm,
+Bool bm_store_has_conflict_with(struct bitmap* const bm,
                                 const Addr a1, const Addr a2)
 {
   return bm_has_conflict_with(bm, a1, a2, eStore);
@@ -696,7 +695,7 @@ Bool bm_store_has_conflict_with(const struct bitmap* const bm,
 /** Return True if the two bitmaps *lhs and *rhs are identical, and false
  *  if not.
  */
-Bool bm_equal(struct bitmap* const lhs, const struct bitmap* const rhs)
+Bool bm_equal(struct bitmap* const lhs, struct bitmap* const rhs)
 {
   struct bitmap2* bm2l;
   struct bitmap2ref* bm2l_ref;
@@ -778,7 +777,7 @@ void bm_swap(struct bitmap* const bm1, struct bitmap* const bm2)
 
 /** Merge bitmaps *lhs and *rhs into *lhs. */
 void bm_merge2(struct bitmap* const lhs,
-               const struct bitmap* const rhs)
+               struct bitmap* const rhs)
 {
   struct bitmap2* bm2l;
   struct bitmap2ref* bm2l_ref;
@@ -814,8 +813,8 @@ void bm_merge2(struct bitmap* const lhs,
  * @param rhs Bitmap to be compared with lhs.
  * @return !=0 if there are data races, == 0 if there are none.
  */
-int bm_has_races(const struct bitmap* const lhs,
-                 const struct bitmap* const rhs)
+int bm_has_races(struct bitmap* const lhs,
+                 struct bitmap* const rhs)
 {
   VG_(OSetGen_ResetIter)(lhs->oset);
   VG_(OSetGen_ResetIter)(rhs->oset);
@@ -868,7 +867,7 @@ int bm_has_races(const struct bitmap* const lhs,
   return 0;
 }
 
-void bm_print(const struct bitmap* const bm)
+void bm_print(struct bitmap* const bm)
 {
   struct bitmap2* bm2;
   struct bitmap2ref* bm2ref;
index 4b8afa19394050b58352425f3ea1cc5c04bc35de..969ea1e1ec48381a97b25103eb0aea00340fd1cd 100644 (file)
@@ -202,13 +202,40 @@ static struct bitmap2* bm2_new(const UWord a1);
 static struct bitmap2* bm2_make_exclusive(struct bitmap* const bm,
                                           struct bitmap2ref* const bm2ref);
 
+/** Rotate elements cache[0..n-1] such that the element at position n-1 is
+ *  moved to position 0. This allows to speed up future cache lookups.
+ */
+static __inline__
+void bm_cache_rotate(struct bm_cache_elem cache[], const int n)
+{
+  struct bm_cache_elem t;
+
+  t = cache[0];
+  if (n > 1)
+    cache[0] = cache[1];
+  if (n > 2)
+    cache[1] = cache[2];
+  if (n > 3)
+    cache[2] = cache[3];
+  if (n > 4)
+    cache[3] = cache[4];
+  if (n > 5)
+    cache[4] = cache[5];
+  if (n > 6)
+    cache[5] = cache[6];
+  if (n > 7)
+    cache[6] = cache[7];
+  cache[n - 1] = t;
+}
 
 static __inline__
-Bool bm_cache_lookup(const struct bitmap* const bm, const UWord a1,
+Bool bm_cache_lookup(struct bitmap* const bm, const UWord a1,
                      struct bitmap2** bm2)
 {
+#if 0
   tl_assert(bm);
   tl_assert(bm2);
+#endif
 
 #if N_CACHE_ELEM > 8
 #error Please update the code below.
@@ -231,6 +258,7 @@ Bool bm_cache_lookup(const struct bitmap* const bm, const UWord a1,
   if (a1 == bm->cache[2].a1)
   {
     *bm2 = bm->cache[2].bm2;
+    bm_cache_rotate(bm->cache, 3);
     return True;
   }
 #endif
@@ -238,6 +266,7 @@ Bool bm_cache_lookup(const struct bitmap* const bm, const UWord a1,
   if (a1 == bm->cache[3].a1)
   {
     *bm2 = bm->cache[3].bm2;
+    bm_cache_rotate(bm->cache, 4);
     return True;
   }
 #endif
@@ -245,6 +274,7 @@ Bool bm_cache_lookup(const struct bitmap* const bm, const UWord a1,
   if (a1 == bm->cache[4].a1)
   {
     *bm2 = bm->cache[4].bm2;
+    bm_cache_rotate(bm->cache, 5);
     return True;
   }
 #endif
@@ -252,6 +282,7 @@ Bool bm_cache_lookup(const struct bitmap* const bm, const UWord a1,
   if (a1 == bm->cache[5].a1)
   {
     *bm2 = bm->cache[5].bm2;
+    bm_cache_rotate(bm->cache, 6);
     return True;
   }
 #endif
@@ -259,6 +290,7 @@ Bool bm_cache_lookup(const struct bitmap* const bm, const UWord a1,
   if (a1 == bm->cache[6].a1)
   {
     *bm2 = bm->cache[6].bm2;
+    bm_cache_rotate(bm->cache, 7);
     return True;
   }
 #endif
@@ -266,6 +298,7 @@ Bool bm_cache_lookup(const struct bitmap* const bm, const UWord a1,
   if (a1 == bm->cache[7].a1)
   {
     *bm2 = bm->cache[7].bm2;
+    bm_cache_rotate(bm->cache, 8);
     return True;
   }
 #endif
@@ -316,7 +349,7 @@ void bm_update_cache(struct bitmap* const bm,
  *  @param bm bitmap pointer.
  */
 static __inline__
-const struct bitmap2* bm2_lookup(const struct bitmap* const bm, const UWord a1)
+const struct bitmap2* bm2_lookup(struct bitmap* const bm, const UWord a1)
 {
   struct bitmap2*    bm2;
   struct bitmap2ref* bm2ref;
@@ -342,7 +375,7 @@ const struct bitmap2* bm2_lookup(const struct bitmap* const bm, const UWord a1)
  */
 static __inline__
 struct bitmap2*
-bm2_lookup_exclusive(const struct bitmap* const bm, const UWord a1)
+bm2_lookup_exclusive(struct bitmap* const bm, const UWord a1)
 {
   struct bitmap2ref* bm2ref;
   struct bitmap2* bm2;
@@ -383,7 +416,7 @@ bm2_lookup_exclusive(const struct bitmap* const bm, const UWord a1)
  *  @param bm bitmap pointer.
  */
 static __inline__
-struct bitmap2* bm2_insert(const struct bitmap* const bm, const UWord a1)
+struct bitmap2* bm2_insert(struct bitmap* const bm, const UWord a1)
 {
   struct bitmap2ref* bm2ref;
   struct bitmap2* bm2;
@@ -405,7 +438,7 @@ struct bitmap2* bm2_insert(const struct bitmap* const bm, const UWord a1)
  *  *bm2. This means that *bm2 becomes shared over two or more bitmaps.
  */
 static __inline__
-struct bitmap2* bm2_insert_addref(const struct bitmap* const bm,
+struct bitmap2* bm2_insert_addref(struct bitmap* const bm,
                                   struct bitmap2* const bm2)
 {
   struct bitmap2ref* bm2ref;
@@ -432,8 +465,7 @@ struct bitmap2* bm2_insert_addref(const struct bitmap* const bm,
  *  @param bm bitmap pointer.
  */
 static __inline__
-struct bitmap2* bm2_lookup_or_insert(const struct bitmap* const bm,
-                                     const UWord a1)
+struct bitmap2* bm2_lookup_or_insert(struct bitmap* const bm, const UWord a1)
 {
   struct bitmap2ref* bm2ref;
   struct bitmap2* bm2;
@@ -507,7 +539,7 @@ void bm_access_aligned_store(struct bitmap* const bm,
 }
 
 static __inline__
-Bool bm_aligned_load_has_conflict_with(const struct bitmap* const bm,
+Bool bm_aligned_load_has_conflict_with(struct bitmap* const bm,
                                        const Addr a1, const SizeT size)
 {
   const struct bitmap2* bm2;
@@ -518,7 +550,7 @@ Bool bm_aligned_load_has_conflict_with(const struct bitmap* const bm,
 }
 
 static __inline__
-Bool bm_aligned_store_has_conflict_with(const struct bitmap* const bm,
+Bool bm_aligned_store_has_conflict_with(struct bitmap* const bm,
                                         const Addr a1, const SizeT size)
 {
   const struct bitmap2* bm2;
index 981e74ef71dfc9dfedd2003b1f76e575b805c62c..596f4b4f51befdbf39e6e69962e19b013f2da2ed 100644 (file)
@@ -71,50 +71,50 @@ void bm_access_store_1(struct bitmap* const bm, const Addr a1);
 void bm_access_store_2(struct bitmap* const bm, const Addr a1);
 void bm_access_store_4(struct bitmap* const bm, const Addr a1);
 void bm_access_store_8(struct bitmap* const bm, const Addr a1);
-Bool bm_has(const struct bitmap* const bm,
+Bool bm_has(struct bitmap* const bm,
             const Addr a1, const Addr a2,
             const BmAccessTypeT access_type);
-Bool bm_has_any_load(const struct bitmap* const bm,
+Bool bm_has_any_load(struct bitmap* const bm,
                      const Addr a1, const Addr a2);
-Bool bm_has_any_store(const struct bitmap* const bm,
+Bool bm_has_any_store(struct bitmap* const bm,
                       const Addr a1, const Addr a2);
-Bool bm_has_any_access(const struct bitmap* const bm,
+Bool bm_has_any_access(struct bitmap* const bm,
                        const Addr a1, const Addr a2);
-Bool bm_has_1(const struct bitmap* const bm,
+Bool bm_has_1(struct bitmap* const bm,
               const Addr address, const BmAccessTypeT access_type);
-void bm_clear(const struct bitmap* const bm,
+void bm_clear(struct bitmap* const bm,
               const Addr a1, const Addr a2);
-void bm_clear_load(const struct bitmap* const bm,
+void bm_clear_load(struct bitmap* const bm,
                    const Addr a1, const Addr a2);
-void bm_clear_store(const struct bitmap* const bm,
+void bm_clear_store(struct bitmap* const bm,
                     const Addr a1, const Addr a2);
-Bool bm_test_and_clear(const struct bitmap* const bm,
+Bool bm_test_and_clear(struct bitmap* const bm,
                        const Addr a1, const Addr a2);
-Bool bm_has_conflict_with(const struct bitmap* const bm,
+Bool bm_has_conflict_with(struct bitmap* const bm,
                           const Addr a1, const Addr a2,
                           const BmAccessTypeT access_type);
-Bool bm_load_1_has_conflict_with(const struct bitmap* const bm, const Addr a1);
-Bool bm_load_2_has_conflict_with(const struct bitmap* const bm, const Addr a1);
-Bool bm_load_4_has_conflict_with(const struct bitmap* const bm, const Addr a1);
-Bool bm_load_8_has_conflict_with(const struct bitmap* const bm, const Addr a1);
-Bool bm_load_has_conflict_with(const struct bitmap* const bm,
+Bool bm_load_1_has_conflict_with(struct bitmap* const bm, const Addr a1);
+Bool bm_load_2_has_conflict_with(struct bitmap* const bm, const Addr a1);
+Bool bm_load_4_has_conflict_with(struct bitmap* const bm, const Addr a1);
+Bool bm_load_8_has_conflict_with(struct bitmap* const bm, const Addr a1);
+Bool bm_load_has_conflict_with(struct bitmap* const bm,
                                const Addr a1, const Addr a2);
-Bool bm_store_1_has_conflict_with(const struct bitmap* const bm,const Addr a1);
-Bool bm_store_2_has_conflict_with(const struct bitmap* const bm,const Addr a1);
-Bool bm_store_4_has_conflict_with(const struct bitmap* const bm,const Addr a1);
-Bool bm_store_8_has_conflict_with(const struct bitmap* const bm,const Addr a1);
-Bool bm_store_has_conflict_with(const struct bitmap* const bm,
+Bool bm_store_1_has_conflict_with(struct bitmap* const bm,const Addr a1);
+Bool bm_store_2_has_conflict_with(struct bitmap* const bm,const Addr a1);
+Bool bm_store_4_has_conflict_with(struct bitmap* const bm,const Addr a1);
+Bool bm_store_8_has_conflict_with(struct bitmap* const bm,const Addr a1);
+Bool bm_store_has_conflict_with(struct bitmap* const bm,
                                 const Addr a1, const Addr a2);
-Bool bm_equal(struct bitmap* const lhs, const struct bitmap* const rhs);
+Bool bm_equal(struct bitmap* const lhs, struct bitmap* const rhs);
 void bm_swap(struct bitmap* const bm1, struct bitmap* const bm2);
 void bm_merge2(struct bitmap* const lhs,
-               const struct bitmap* const rhs);
-int bm_has_races(const struct bitmap* const bm1,
-                 const struct bitmap* const bm2);
+               struct bitmap* const rhs);
+int bm_has_races(struct bitmap* const bm1,
+                 struct bitmap* const bm2);
 void bm_report_races(ThreadId const tid1, ThreadId const tid2,
-                     const struct bitmap* const bm1,
-                     const struct bitmap* const bm2);
-void bm_print(const struct bitmap* bm);
+                     struct bitmap* const bm1,
+                     struct bitmap* const bm2);
+void bm_print(struct bitmap* bm);
 ULong bm_get_bitmap_creation_count(void);
 ULong bm_get_bitmap2_node_creation_count(void);
 ULong bm_get_bitmap2_creation_count(void);