|
From: <sv...@va...> - 2008-12-17 19:20:20
|
Author: bart
Date: 2008-12-17 19:20:13 +0000 (Wed, 17 Dec 2008)
New Revision: 8836
Log:
Fixed semaphore vector clock updating / simplified semaphore tracing.
Modified:
trunk/drd/drd_clientobj.h
trunk/drd/drd_semaphore.c
trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3
trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b
trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5
trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc
trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8
Modified: trunk/drd/drd_clientobj.h
===================================================================
--- trunk/drd/drd_clientobj.h 2008-12-17 19:15:58 UTC (rev 8835)
+++ trunk/drd/drd_clientobj.h 2008-12-17 19:20:13 UTC (rev 8836)
@@ -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 @@
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
Modified: trunk/drd/drd_semaphore.c
===================================================================
--- trunk/drd/drd_semaphore.c 2008-12-17 19:15:58 UTC (rev 8835)
+++ trunk/drd/drd_semaphore.c 2008-12-17 19:20:13 UTC (rev 8836)
@@ -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 @@
// 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 @@
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 @@
*/
static void semaphore_cleanup(struct semaphore_info* p)
{
+ Segment* sg;
+
if (p->waiters > 0)
{
SemaphoreErrInfo sei = { p->a1 };
@@ -82,7 +119,9 @@
" 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 @@
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 @@
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 @@
}
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 @@
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. */
Modified: trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3
===================================================================
--- trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3 2008-12-17 19:15:58 UTC (rev 8835)
+++ trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3 2008-12-17 19:20:13 UTC (rev 8836)
@@ -140,8 +140,7 @@
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 @@
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
Modified: trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b
===================================================================
--- trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b 2008-12-17 19:15:58 UTC (rev 8835)
+++ trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.3-b 2008-12-17 19:20:13 UTC (rev 8836)
@@ -140,8 +140,7 @@
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 @@
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
Modified: trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5
===================================================================
--- trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5 2008-12-17 19:15:58 UTC (rev 8835)
+++ trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5 2008-12-17 19:20:13 UTC (rev 8836)
@@ -146,8 +146,7 @@
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 @@
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
Modified: trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc
===================================================================
--- trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc 2008-12-17 19:15:58 UTC (rev 8835)
+++ trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.5-ppc 2008-12-17 19:20:13 UTC (rev 8836)
@@ -146,8 +146,7 @@
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 @@
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
Modified: trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8
===================================================================
--- trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8 2008-12-17 19:15:58 UTC (rev 8835)
+++ trunk/drd/tests/tc20_verifywrap2.stderr.exp-glibc2.8 2008-12-17 19:20:13 UTC (rev 8836)
@@ -139,8 +139,7 @@
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 @@
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
|