Dmitry Adamushko wrote:
> On 28/06/06, Gilles Chanteperdrix <[EMAIL PROTECTED]> wrote:
>> Jan Kiszka wrote:
>>  >
>>  > Ok, then we also need a fix for the latency test (this is where I
>>  > grabbed that pattern from). Is there a high risk that this locks up? I
>>  > wonder why I never observed or heard of problems with latency.
>>
>> The latency test used to deadlock, that is why the summary printed on
>> signal is printed on stderr. Unfortunately, there seem to be one display
>> left on stdout, so it should still deadlock. The reason why we never see
>> the deadlock is (perhaps) that the continuous intermediate results are
>> printed on the context of the "display" thread, whereas the termination
>> signals are preferably delivered by the kernel to the "main" thread,
>> that only calls pause. Which makes the use of stderr in signals handlers
>> pointless.
> 
> It's very likely so.
> 
> The main thread would use instead something like :
> ...
> while (!sig_term_received)
>    pause();
> 
> do_cleanup_chores();
> return 0;
> 
> cleanup_upon_sig() should only set the sig_term_received flag up.
> 
> Then all other threads must block signal delivering with sigprocmask()
> so that the main thread is the only one which "accepts" signals.

Is that required, i.e. does pause() only wake up if the signal handler
executed in the main thread's context? Then cyclictest contains a bug as
well...

> 
> btw, according to POSIX 1003.1-2003, the write() call is amongst "safe"
> ones.
> http://www.die.net/doc/linux/man/man2/signal.2.html
> 
> So write(1, ....); heh... not that nice? :)
> 
> 

Something like this? Developed on top of my prio-switch patch. So far
without signal masking.

Jan
---
 src/testsuite/latency/latency.c |   46 ++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

Index: xenomai/src/testsuite/latency/latency.c
===================================================================
--- xenomai.orig/src/testsuite/latency/latency.c
+++ xenomai/src/testsuite/latency/latency.c
@@ -293,7 +293,7 @@ double dump_histogram (long *histogram, 
     double avg = 0;             /* used to sum hits 1st */
 
     if (do_histogram)
-        fprintf(stderr,"---|--param|----range-|--samples\n");
+        printf("---|--param|----range-|--samples\n");
 
     for (n = 0; n < histogram_size; n++)
         {
@@ -304,12 +304,11 @@ double dump_histogram (long *histogram, 
             total_hits += hits;
             avg += n * hits;
             if (do_histogram)
-                fprintf(stderr,
-                        "HSD|    %s| %3d -%3d | %8ld\n",
-                        kind,
-                        n,
-                        n+1,
-                        hits);
+                printf("HSD|    %s| %3d -%3d | %8ld\n",
+                       kind,
+                       n,
+                       n+1,
+                       hits);
             }
         }
 
@@ -338,8 +337,8 @@ void dump_stats (long *histogram, char* 
     variance /= total_hits - 1;
     variance = sqrt(variance);
 
-    fprintf(stderr,"HSS|    %s| %9d| %10.3f| %10.3f\n",
-            kind, total_hits, avg, variance);
+    printf("HSS|    %s| %9d| %10.3f| %10.3f\n",
+           kind, total_hits, avg, variance);
 }
 
 void dump_hist_stats (void)
@@ -351,23 +350,18 @@ void dump_hist_stats (void)
     avgavg = dump_histogram (histogram_avg, "avg");
     maxavg = dump_histogram (histogram_max, "max");
 
-    fprintf(stderr,"HSH|--param|--samples-|--average--|---stddev--\n");
+    printf("HSH|--param|--samples-|--average--|---stddev--\n");
 
     dump_stats (histogram_min, "min", minavg);
     dump_stats (histogram_avg, "avg", avgavg);
     dump_stats (histogram_max, "max", maxavg);
 }
 
-void cleanup_upon_sig(int sig __attribute__((unused)))
+void cleanup(void)
 {
     time_t actual_duration;
     long gmaxj, gminj, gavgj;
 
-    if (finished)
-        return;
-
-    finished = 1;
-
     if (test_mode == USER_TASK) {
         rt_sem_delete(&display_sem);
 
@@ -421,6 +415,11 @@ void cleanup_upon_sig(int sig __attribut
     exit(0);
 }
 
+void sighand(int sig __attribute__((unused)))
+{
+    finished = 1;
+}
+
 int main (int argc, char **argv)
 {
     int c, err;
@@ -532,7 +531,7 @@ int main (int argc, char **argv)
     histogram_min = calloc(histogram_size, sizeof(long));
 
     if (!(histogram_avg && histogram_max && histogram_min)) 
-        cleanup_upon_sig(0);
+        cleanup();
 
     if (period_ns == 0)
         period_ns = 100000LL; /* ns */
@@ -542,10 +541,10 @@ int main (int argc, char **argv)
     else if (priority > T_HIPRIO)
         priority = T_HIPRIO;
 
-    signal(SIGINT, cleanup_upon_sig);
-    signal(SIGTERM, cleanup_upon_sig);
-    signal(SIGHUP, cleanup_upon_sig);
-    signal(SIGALRM, cleanup_upon_sig);
+    signal(SIGINT, sighand);
+    signal(SIGTERM, sighand);
+    signal(SIGHUP, sighand);
+    signal(SIGALRM, sighand);
 
     setlinebuf(stdout);
 
@@ -610,7 +609,10 @@ int main (int argc, char **argv)
             }
     }
 
-    pause();
+    while (!finished)
+        pause();
+
+    cleanup();
 
     return 0;
 }

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core

Reply via email to