|
From: Philippe W. <phi...@sk...> - 2012-03-16 14:47:38
|
annotate_hbefore quite systematically loops forever
in an outer helgrind or sgcheck on an inner helgrind,
and I suspect also in other setups.
Digging into that, it seems related to (un-)fair scheduling.
The inner vgtest specifies fair scheduling. Even when
I enable fair scheduling on the outer, I see that the
test often fails due to what looks like unfair scheduling.
The change below ensures this test works ok even without
fair scheduling (with or without outer).
I think the below change does not impact what is being
tested.
Comments/feedback ?
Philippe
Index: helgrind/tests/annotate_hbefore.c
===================================================================
--- helgrind/tests/annotate_hbefore.c (revision 12445)
+++ helgrind/tests/annotate_hbefore.c (working copy)
@@ -235,10 +235,18 @@
int shared_var = 0; // is not raced upon
-void delay500ms ( void )
+void delayXms ( int i )
{
- struct timespec ts = { 0, 500 * 1000 * 1000 };
- nanosleep(&ts, NULL);
+ struct timespec ts = { 0, 1 * 1000 * 1000 };
+ // We do the sleep in small pieces to have scheduling
+ // events ensuring a fair switch between threads, even
+ // without --fair-sched=yes. This is a.o. needed for
+ // running this test under an outer helgrind or an outer
+ // sgcheck.
+ while (i > 0) {
+ nanosleep(&ts, NULL);
+ i--;
+ }
}
void do_wait ( UWord* w )
@@ -246,7 +254,7 @@
UWord w0 = *w;
UWord volatile * wV = w;
while (*wV == w0)
- ;
+ delayXms(1); // small sleeps, ensuring context switches
ANNOTATE_HAPPENS_AFTER(w);
}
@@ -261,11 +269,11 @@
void* thread_fn1 ( void* arg )
{
UWord* w = (UWord*)arg;
- delay500ms(); // ensure t2 gets to its wait first
+ delayXms(500); // ensure t2 gets to its wait first
shared_var = 1; // first access
do_signal(w); // cause h-b edge to second thread
- delay500ms();
+ delayXms(500);
return NULL;
}
@@ -275,7 +283,7 @@
do_wait(w); // wait for h-b edge from first thread
shared_var = 2; // second access
- delay500ms();
+ delayXms(500);
return NULL;
}
|