]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fixed semaphore vector clock updating / simplified semaphore tracing.
authorBart Van Assche <bvanassche@acm.org>
Wed, 17 Dec 2008 19:20:13 +0000 (19:20 +0000)
committerBart Van Assche <bvanassche@acm.org>
Wed, 17 Dec 2008 19:20:13 +0000 (19:20 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8836

drd/drd_clientobj.h
drd/drd_semaphore.c
drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3
drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b
drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5
drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc
drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8

index 39e97f94f32a7fad3fedcbc1dd834afd1c99358c..98f4fd93c3d25fd8e6fcf1bf61b0d1727a28d813 100644 (file)
@@ -32,6 +32,7 @@
 #include "pub_tool_basics.h"
 #include "pub_tool_execontext.h" /* ExeContext */
 #include "pub_tool_oset.h"
+#include "pub_tool_xarray.h"
 
 
 // Forward declarations.
@@ -91,7 +92,7 @@ struct semaphore_info
   UInt        value;             // Semaphore value.
   UWord       waiters;           // Number of threads inside sem_wait().
   DrdThreadId last_sem_post_tid; // Thread ID associated with last sem_post().
-  Segment*    last_sem_post_segment;
+  XArray*     last_sem_post_seg; // array of Segment*, used as a stack.
 };
 
 struct barrier_info
index 0f163053d04bef7be2b63e1f5f441c83b431ae01..2cc59dc3ad70f1aea10be300551313d31f7a8f37 100644 (file)
@@ -31,6 +31,7 @@
 #include "pub_tool_libcassert.h"  // tl_assert()
 #include "pub_tool_libcprint.h"   // VG_(printf)()
 #include "pub_tool_machine.h"     // VG_(get_IP)()
+#include "pub_tool_mallocfree.h"  // VG_(malloc), VG_(free)
 #include "pub_tool_threadstate.h" // VG_(get_running_tid)()
 
 
@@ -47,6 +48,39 @@ static ULong s_semaphore_segment_creation_count;
 
 // Function definitions.
 
+static void segment_push(struct semaphore_info* p, Segment* sg)
+{
+  Word n;
+
+  tl_assert(sg);
+  n = VG_(addToXA)(p->last_sem_post_seg, &sg);
+#if 0
+  VG_(message)(Vg_UserMsg, "0x%lx push: added at position %ld/%ld",
+               p->a1, n, VG_(sizeXA)(p->last_sem_post_seg));
+#endif
+  tl_assert(*(Segment**)VG_(indexXA)(p->last_sem_post_seg, n) == sg);
+}
+
+static Segment* segment_pop(struct semaphore_info* p)
+{
+  Word sz;
+  Segment* sg;
+
+  sz = VG_(sizeXA)(p->last_sem_post_seg);
+#if 0
+  VG_(message)(Vg_UserMsg, "0x%lx pop:  removed from position %ld/%ld",
+               p->a1, sz - 1, sz);
+#endif
+  sg = 0;
+  if (sz > 0)
+  {
+    sg = *(Segment**)VG_(indexXA)(p->last_sem_post_seg, sz - 1);
+    tl_assert(sg);
+    VG_(dropTailXA)(p->last_sem_post_seg, 1);
+  }
+  return sg;
+}
+
 void semaphore_set_trace(const Bool trace_semaphore)
 {
   s_trace_semaphore = trace_semaphore;
@@ -64,7 +98,8 @@ void semaphore_initialize(struct semaphore_info* const p,
   p->value     = value;
   p->waiters   = 0;
   p->last_sem_post_tid = DRD_INVALID_THREADID;
-  p->last_sem_post_segment = 0;
+  p->last_sem_post_seg = VG_(newXA)(VG_(malloc), "drd.sg-stack",
+                                    VG_(free), sizeof(Segment*));
 }
 
 /** Free the memory that was allocated by semaphore_initialize(). Called by
@@ -72,6 +107,8 @@ void semaphore_initialize(struct semaphore_info* const p,
  */
 static void semaphore_cleanup(struct semaphore_info* p)
 {
+  Segment* sg;
+
   if (p->waiters > 0)
   {
     SemaphoreErrInfo sei = { p->a1 };
@@ -82,7 +119,9 @@ static void semaphore_cleanup(struct semaphore_info* p)
                             " upon",
                             &sei);
   }
-  sg_put(p->last_sem_post_segment);
+  while ((sg = segment_pop(p)))
+    sg_put(sg);
+  VG_(deleteXA)(p->last_sem_post_seg);
 }
 
 static
@@ -180,15 +219,6 @@ void semaphore_pre_wait(const Addr semaphore)
   struct semaphore_info* p;
 
   p = semaphore_get_or_allocate(semaphore);
-  if (s_trace_semaphore)
-  {
-    VG_(message)(Vg_UserMsg,
-                 "[%d/%d] semaphore_pre_wait  0x%lx value %u",
-                 VG_(get_running_tid)(),
-                 thread_get_running_tid(),
-                 semaphore,
-                 p->value);
-  }
   tl_assert(p);
   tl_assert((int)p->waiters >= 0);
   p->waiters++;
@@ -203,17 +233,20 @@ void semaphore_post_wait(const DrdThreadId tid, const Addr semaphore,
                          const Bool waited)
 {
   struct semaphore_info* p;
+  Segment* sg;
 
   p = semaphore_get(semaphore);
   if (s_trace_semaphore)
   {
     VG_(message)(Vg_UserMsg,
-                 "[%d/%d] semaphore_post_wait 0x%lx value %u",
+                 "[%d/%d] semaphore_wait      0x%lx value %u -> %u",
                  VG_(get_running_tid)(),
                  thread_get_running_tid(),
                  semaphore,
+                 p ? p->value : 0,
                  p ? p->value - 1 : 0);
   }
+  tl_assert(p);
   tl_assert(p->waiters > 0);
   p->waiters--;
   tl_assert((int)p->waiters >= 0);
@@ -230,20 +263,25 @@ void semaphore_post_wait(const DrdThreadId tid, const Addr semaphore,
   }
   p->value--;
   tl_assert((int)p->value >= 0);
-  if (p->last_sem_post_tid != tid
-      && p->last_sem_post_tid != DRD_INVALID_THREADID)
+  sg = segment_pop(p);
+  if (sg)
   {
-    tl_assert(p->last_sem_post_segment);
-    thread_combine_vc2(tid, &p->last_sem_post_segment->vc);
+    if (p->last_sem_post_tid != tid
+        && p->last_sem_post_tid != DRD_INVALID_THREADID)
+    {
+      thread_combine_vc2(tid, &sg->vc);
+    }
+    sg_put(sg);
+    thread_new_segment(tid);
+    s_semaphore_segment_creation_count++;
   }
-  thread_new_segment(tid);
-  s_semaphore_segment_creation_count++;
 }
 
 /** Called before sem_post(). */
 void semaphore_pre_post(const DrdThreadId tid, const Addr semaphore)
 {
   struct semaphore_info* p;
+  Segment* sg;
 
   p = semaphore_get_or_allocate(semaphore);
   p->value++;
@@ -251,20 +289,20 @@ void semaphore_pre_post(const DrdThreadId tid, const Addr semaphore)
   if (s_trace_semaphore)
   {
     VG_(message)(Vg_UserMsg,
-                 "[%d/%d] semaphore_post      0x%lx value %u",
+                 "[%d/%d] semaphore_post      0x%lx value %u -> %u",
                  VG_(get_running_tid)(),
                  thread_get_running_tid(),
                  semaphore,
-                 p->value);
+                 p->value - 1, p->value);
   }
 
-  if (p->value == 1)
-  {
-    p->last_sem_post_tid = tid;
-    thread_new_segment(tid);
-    thread_get_latest_segment(&p->last_sem_post_segment, tid);
-    s_semaphore_segment_creation_count++;
-  }
+  p->last_sem_post_tid = tid;
+  thread_new_segment(tid);
+  sg = 0;
+  thread_get_latest_segment(&sg, tid);
+  tl_assert(sg);
+  segment_push(p, sg);
+  s_semaphore_segment_creation_count++;
 }
 
 /** Called after sem_post() finished successfully. */
index 987a55b4cd6c605f4216bc29ae525d65d93af6e5..9e29a244e5e72dbf24ef9e6fb5de9ae60d80cef5 100644 (file)
@@ -140,8 +140,7 @@ semaphore 0x........ was first observed at:
 
 FIXME: can't figure out how to verify wrap of sem_destroy
 
-[1/1] semaphore_pre_wait  0x........ value 0
-[1/1] semaphore_post_wait 0x........ value 4294967295
+[1/1] semaphore_wait      0x........ value 0 -> 4294967295
 
 Invalid semaphore: semaphore 0x........
    at 0x........: sem_wait* (drd_pthread_intercepts.c:?)
@@ -149,7 +148,7 @@ Invalid semaphore: semaphore 0x........
 semaphore 0x........ was first observed at:
    at 0x........: sem_init* (drd_pthread_intercepts.c:?)
    by 0x........: main (tc20_verifywrap.c:228)
-[1/1] semaphore_post      0x........ value 1
+[1/1] semaphore_post      0x........ value 0 -> 1
 
 FIXME: can't figure out how to verify wrap of sem_post
 
index 9cf6853256acd9f1d64cd101f974bf3a4f6b01c2..4be55c3794f8611ec2372ec31447780ce74210df 100644 (file)
@@ -140,8 +140,7 @@ semaphore 0x........ was first observed at:
 
 FIXME: can't figure out how to verify wrap of sem_destroy
 
-[1/1] semaphore_pre_wait  0x........ value 0
-[1/1] semaphore_post_wait 0x........ value 4294967295
+[1/1] semaphore_wait      0x........ value 0 -> 4294967295
 
 Invalid semaphore: semaphore 0x........
    at 0x........: sem_wait* (drd_pthread_intercepts.c:?)
@@ -149,7 +148,7 @@ Invalid semaphore: semaphore 0x........
 semaphore 0x........ was first observed at:
    at 0x........: sem_init* (drd_pthread_intercepts.c:?)
    by 0x........: main (tc20_verifywrap.c:228)
-[1/1] semaphore_post      0x........ value 1
+[1/1] semaphore_post      0x........ value 0 -> 1
 
 FIXME: can't figure out how to verify wrap of sem_post
 
index 5eff6ac6bc0cd2108e256f416b882d4581bcb7a4..9b729075ea3c14a766ce9a55ef09c00cc0c2b6ff 100644 (file)
@@ -146,8 +146,7 @@ semaphore 0x........ was first observed at:
 
 FIXME: can't figure out how to verify wrap of sem_destroy
 
-[1/1] semaphore_pre_wait  0x........ value 0
-[1/1] semaphore_post_wait 0x........ value 4294967295
+[1/1] semaphore_wait      0x........ value 0 -> 4294967295
 
 Invalid semaphore: semaphore 0x........
    at 0x........: sem_wait* (drd_pthread_intercepts.c:?)
@@ -155,7 +154,7 @@ Invalid semaphore: semaphore 0x........
 semaphore 0x........ was first observed at:
    at 0x........: sem_init* (drd_pthread_intercepts.c:?)
    by 0x........: main (tc20_verifywrap.c:228)
-[1/1] semaphore_post      0x........ value 1
+[1/1] semaphore_post      0x........ value 0 -> 1
 
 FIXME: can't figure out how to verify wrap of sem_post
 
index 427e3f2e07b9ed15fc67337e52b823f99a9c23f2..0b7f0c14ae45f2ee8b0a3781bddcd1c1610f8477 100644 (file)
@@ -146,8 +146,7 @@ semaphore 0x........ was first observed at:
 
 FIXME: can't figure out how to verify wrap of sem_destroy
 
-[1/1] semaphore_pre_wait  0x........ value 0
-[1/1] semaphore_post_wait 0x........ value 4294967295
+[1/1] semaphore_wait      0x........ value 0 -> 4294967295
 
 Invalid semaphore: semaphore 0x........
    at 0x........: sem_wait* (drd_pthread_intercepts.c:?)
@@ -155,7 +154,7 @@ Invalid semaphore: semaphore 0x........
 semaphore 0x........ was first observed at:
    at 0x........: sem_init* (drd_pthread_intercepts.c:?)
    by 0x........: main (tc20_verifywrap.c:228)
-[1/1] semaphore_post      0x........ value 1
+[1/1] semaphore_post      0x........ value 0 -> 1
 
 FIXME: can't figure out how to verify wrap of sem_post
 
index accfaef18e5d383cdd898486876d40df254f364a..26410b6d4f036a2ef1d772bd78595b06ca37146d 100644 (file)
@@ -139,8 +139,7 @@ rwlock 0x........ was first observed at:
 
 FIXME: can't figure out how to verify wrap of sem_destroy
 
-[1/1] semaphore_pre_wait  0x........ value 0
-[1/1] semaphore_post_wait 0x........ value 4294967295
+[1/1] semaphore_wait      0x........ value 0 -> 4294967295
 
 Invalid semaphore: semaphore 0x........
    at 0x........: sem_wait* (drd_pthread_intercepts.c:?)
@@ -148,7 +147,7 @@ Invalid semaphore: semaphore 0x........
 semaphore 0x........ was first observed at:
    at 0x........: sem_init* (drd_pthread_intercepts.c:?)
    by 0x........: main (tc20_verifywrap.c:228)
-[1/1] semaphore_post      0x........ value 1
+[1/1] semaphore_post      0x........ value 0 -> 1
 
 FIXME: can't figure out how to verify wrap of sem_post