Module: xenomai-3
Branch: next
Commit: 610e0a4429065b3816b90f9f64ccee1fb5365742
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=610e0a4429065b3816b90f9f64ccee1fb5365742

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Oct 30 11:10:03 2014 +0100

smokey/sched-quota: throttle test threads to stop calibration

It is not totally clear why we need that, but as a matter of fact the
test control thread appears to be stuck in glibc's pthread_cancel() on
SMP/x86 during the first couple of runs while calibrating, despite it
has higher priority than the threads to cancel.

There is some suspicion on the adverse effect of running the
glibc-internal pthread_cancel_init() code at the first invocation of
pthread_cancel(), but no formal proof. It behaves like the test
control thread waits for some event completion in pthread_cancel() -
even before sys_tkill is issued - which never happens, as the test
threads spinning on the same CPU tend to lock it out.

Bottom-line is that something looks fishy here, and this change is
more a workaround than a fix.

---

 testsuite/smokey/sched-quota/sched-quota.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/testsuite/smokey/sched-quota/sched-quota.c 
b/testsuite/smokey/sched-quota/sched-quota.c
index da1c471..9c08924 100644
--- a/testsuite/smokey/sched-quota/sched-quota.c
+++ b/testsuite/smokey/sched-quota/sched-quota.c
@@ -16,6 +16,7 @@
 #include <error.h>
 #include <boilerplate/time.h>
 #include <boilerplate/ancillaries.h>
+#include <boilerplate/atomic.h>
 #include <smokey/smokey.h>
 
 smokey_test_plugin(sched_quota,
@@ -57,6 +58,8 @@ static int started;
 
 static sem_t ready;
 
+static atomic_t throttle;
+
 static unsigned long __attribute__(( noinline ))
 __do_work(unsigned long count)
 {
@@ -93,7 +96,9 @@ static void *thread_body(void *arg)
 
        for (;;) {
                do_work(loops, count_r);
-               if (nrthreads > 1)
+               if (atomic_read(&throttle))
+                       sleep(1);
+               else if (nrthreads > 1)
                        sched_yield();
        }
 
@@ -255,12 +260,16 @@ static unsigned long long calibrate(void)
                pthread_kill(threads[n], SIGDEMT);
        }
 
+       atomic_set(&throttle, 1);
+       smp_wmb();
+
        for (n = 0; n < nrthreads; n++) {
                pthread_cancel(threads[n]);
                pthread_join(threads[n], NULL);
        }
 
        started = 0;
+       atomic_set(&throttle, 0);
 
        return lps;
 }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to