[Xenomai-git] Philippe Gerum : demo/alchemy/latency: revamp for removing legacy

2014-09-24 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 1d290f9b623aa450a59ced64b6455e94bf95d41e
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1d290f9b623aa450a59ced64b6455e94bf95d41e

Author: Philippe Gerum 
Date:   Tue Sep 23 17:16:29 2014 +0200

demo/alchemy/latency: revamp for removing legacy

NOTE: we stop using TSC as the time reference unit, as this is
unreliable for long durations, due to accumulated rounding errors.

---

 demo/alchemy/Makefile.am |9 ++
 demo/alchemy/Makefile.in |9 ++
 demo/alchemy/latency.c   |  229 +-
 3 files changed, 101 insertions(+), 146 deletions(-)

diff --git a/demo/alchemy/Makefile.am b/demo/alchemy/Makefile.am
index c2bd0e5..406bccb 100644
--- a/demo/alchemy/Makefile.am
+++ b/demo/alchemy/Makefile.am
@@ -22,3 +22,12 @@ latency_SOURCES = latency.c
 latency_CPPFLAGS = $(cppflags)
 latency_LDADD = $(ldadd) -lpthread -lrt -lm
 latency_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
+
+# This demo mixes the Alchemy and Xenomai-enabled POSIX APIs over
+# Cobalt, so we ask for both set of flags. --posix along with
+# --ldflags will get us the linker switches causing the symbol
+# wrapping for open/read/write/ioctl and friends.  Over Mercury,
+# --posix is ignored since it's implicitly enabled.
+#
+# CFLAGS =  $(shell xeno-config --alchemy --posix --cflags)
+# LDFLAGS = $(shell xeno-config --alchemy --posix --ldflags)
diff --git a/demo/alchemy/Makefile.in b/demo/alchemy/Makefile.in
index b7abefa..f606a03 100644
--- a/demo/alchemy/Makefile.in
+++ b/demo/alchemy/Makefile.in
@@ -816,6 +816,15 @@ uninstall-am: uninstall-demoPROGRAMS
uninstall-am uninstall-demoPROGRAMS
 
 
+# This demo mixes the Alchemy and Xenomai-enabled POSIX APIs over
+# Cobalt, so we ask for both set of flags. --posix along with
+# --ldflags will get us the linker switches causing the symbol
+# wrapping for open/read/write/ioctl and friends.  Over Mercury,
+# --posix is ignored since it's implicitly enabled.
+#
+# CFLAGS =  $(shell xeno-config --alchemy --posix --cflags)
+# LDFLAGS = $(shell xeno-config --alchemy --posix --ldflags)
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff --git a/demo/alchemy/latency.c b/demo/alchemy/latency.c
index 70c717e..7d1bf0a 100644
--- a/demo/alchemy/latency.c
+++ b/demo/alchemy/latency.c
@@ -3,12 +3,10 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
-#include 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -30,8 +28,7 @@ long long period_ns = 0;
 int test_duration = 0; /* sec of testing, via -T , 0 is inf */
 int data_lines = 21;   /* data lines per header line, -l  to 
change */
 int quiet = 0; /* suppress printing of RTH, RTD lines when -T 
given */
-int benchdev_no = 0;
-int benchdev = -1;
+int devfd = -1;
 int freeze_max = 0;
 int priority = T_HIPRIO;
 int stop_upon_switch = 0;
@@ -51,9 +48,6 @@ const char *test_mode_names[] = {
 time_t test_start, test_end;   /* report test duration */
 int test_loops = 0;/* outer loop count */
 
-#define MEASURE_PERIOD ONE_BILLION
-#define SAMPLE_COUNT (MEASURE_PERIOD / period_ns)
-
 /* Warmup time : in order to avoid spurious cache effects on low-end machines. 
*/
 #define WARMUP_TIME 1
 #define HISTOGRAM_CELLS 300
@@ -69,52 +63,39 @@ int bucketsize = 1000;  /* default = 1000ns, -B 
 to override */
 static inline void add_histogram(long *histogram, long addval)
 {
/* bucketsize steps */
-   long inabs =
-   rt_timer_tsc2ns(addval >= 0 ? addval : -addval) / bucketsize;
+   long inabs = (addval >= 0 ? addval : -addval) / bucketsize;
histogram[inabs < histogram_size ? inabs : histogram_size - 1]++;
 }
 
 static void latency(void *cookie)
 {
-   int err, count, nsamples, warmup = 1;
-   RTIME expected_tsc, period_tsc, start_ticks, fault_threshold;
-   RT_TIMER_INFO timer_info;
-   unsigned old_relaxed = 0;
-
-   err = rt_timer_inquire(&timer_info);
-
-   if (err) {
-   fprintf(stderr, "latency: rt_timer_inquire, code %d\n", err);
-   return;
-   }
-
-   fault_threshold = rt_timer_ns2tsc(CONFIG_XENO_DEFAULT_PERIOD);
-   nsamples = ONE_BILLION / period_ns;
-   period_tsc = rt_timer_ns2tsc(period_ns);
-   /* start time: one millisecond from now. */
-   start_ticks = timer_info.date + rt_timer_ns2ticks(100);
-   expected_tsc = timer_info.tsc + rt_timer_ns2tsc(100);
-
-   err = rt_task_set_periodic(NULL, start_ticks,
-  rt_timer_ns2ticks(period_ns));
-   if (err) {
+   RTIME expected_ns, start_ns, fault_threshold;
+   unsigned int old_relaxed = 0, new_relaxed;
+   int ret, count, nsamples, warmup = 1;
+   long minj, maxj, dt, overrun, sumj;
+   unsigned long ov;
+
+   fault_threshold = CONFIG_XE

[Xenomai-git] Philippe Gerum : demo/alchemy/latency: revamp for removing legacy

2014-09-24 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 1d290f9b623aa450a59ced64b6455e94bf95d41e
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=1d290f9b623aa450a59ced64b6455e94bf95d41e

Author: Philippe Gerum 
Date:   Tue Sep 23 17:16:29 2014 +0200

demo/alchemy/latency: revamp for removing legacy

NOTE: we stop using TSC as the time reference unit, as this is
unreliable for long durations, due to accumulated rounding errors.

---

 demo/alchemy/Makefile.am |9 ++
 demo/alchemy/Makefile.in |9 ++
 demo/alchemy/latency.c   |  229 +-
 3 files changed, 101 insertions(+), 146 deletions(-)

diff --git a/demo/alchemy/Makefile.am b/demo/alchemy/Makefile.am
index c2bd0e5..406bccb 100644
--- a/demo/alchemy/Makefile.am
+++ b/demo/alchemy/Makefile.am
@@ -22,3 +22,12 @@ latency_SOURCES = latency.c
 latency_CPPFLAGS = $(cppflags)
 latency_LDADD = $(ldadd) -lpthread -lrt -lm
 latency_LDFLAGS = @XENO_AUTOINIT_LDFLAGS@ $(XENO_POSIX_WRAPPERS)
+
+# This demo mixes the Alchemy and Xenomai-enabled POSIX APIs over
+# Cobalt, so we ask for both set of flags. --posix along with
+# --ldflags will get us the linker switches causing the symbol
+# wrapping for open/read/write/ioctl and friends.  Over Mercury,
+# --posix is ignored since it's implicitly enabled.
+#
+# CFLAGS =  $(shell xeno-config --alchemy --posix --cflags)
+# LDFLAGS = $(shell xeno-config --alchemy --posix --ldflags)
diff --git a/demo/alchemy/Makefile.in b/demo/alchemy/Makefile.in
index b7abefa..f606a03 100644
--- a/demo/alchemy/Makefile.in
+++ b/demo/alchemy/Makefile.in
@@ -816,6 +816,15 @@ uninstall-am: uninstall-demoPROGRAMS
uninstall-am uninstall-demoPROGRAMS
 
 
+# This demo mixes the Alchemy and Xenomai-enabled POSIX APIs over
+# Cobalt, so we ask for both set of flags. --posix along with
+# --ldflags will get us the linker switches causing the symbol
+# wrapping for open/read/write/ioctl and friends.  Over Mercury,
+# --posix is ignored since it's implicitly enabled.
+#
+# CFLAGS =  $(shell xeno-config --alchemy --posix --cflags)
+# LDFLAGS = $(shell xeno-config --alchemy --posix --ldflags)
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff --git a/demo/alchemy/latency.c b/demo/alchemy/latency.c
index 70c717e..7d1bf0a 100644
--- a/demo/alchemy/latency.c
+++ b/demo/alchemy/latency.c
@@ -3,12 +3,10 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
-#include 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -30,8 +28,7 @@ long long period_ns = 0;
 int test_duration = 0; /* sec of testing, via -T , 0 is inf */
 int data_lines = 21;   /* data lines per header line, -l  to 
change */
 int quiet = 0; /* suppress printing of RTH, RTD lines when -T 
given */
-int benchdev_no = 0;
-int benchdev = -1;
+int devfd = -1;
 int freeze_max = 0;
 int priority = T_HIPRIO;
 int stop_upon_switch = 0;
@@ -51,9 +48,6 @@ const char *test_mode_names[] = {
 time_t test_start, test_end;   /* report test duration */
 int test_loops = 0;/* outer loop count */
 
-#define MEASURE_PERIOD ONE_BILLION
-#define SAMPLE_COUNT (MEASURE_PERIOD / period_ns)
-
 /* Warmup time : in order to avoid spurious cache effects on low-end machines. 
*/
 #define WARMUP_TIME 1
 #define HISTOGRAM_CELLS 300
@@ -69,52 +63,39 @@ int bucketsize = 1000;  /* default = 1000ns, -B 
 to override */
 static inline void add_histogram(long *histogram, long addval)
 {
/* bucketsize steps */
-   long inabs =
-   rt_timer_tsc2ns(addval >= 0 ? addval : -addval) / bucketsize;
+   long inabs = (addval >= 0 ? addval : -addval) / bucketsize;
histogram[inabs < histogram_size ? inabs : histogram_size - 1]++;
 }
 
 static void latency(void *cookie)
 {
-   int err, count, nsamples, warmup = 1;
-   RTIME expected_tsc, period_tsc, start_ticks, fault_threshold;
-   RT_TIMER_INFO timer_info;
-   unsigned old_relaxed = 0;
-
-   err = rt_timer_inquire(&timer_info);
-
-   if (err) {
-   fprintf(stderr, "latency: rt_timer_inquire, code %d\n", err);
-   return;
-   }
-
-   fault_threshold = rt_timer_ns2tsc(CONFIG_XENO_DEFAULT_PERIOD);
-   nsamples = ONE_BILLION / period_ns;
-   period_tsc = rt_timer_ns2tsc(period_ns);
-   /* start time: one millisecond from now. */
-   start_ticks = timer_info.date + rt_timer_ns2ticks(100);
-   expected_tsc = timer_info.tsc + rt_timer_ns2tsc(100);
-
-   err = rt_task_set_periodic(NULL, start_ticks,
-  rt_timer_ns2ticks(period_ns));
-   if (err) {
+   RTIME expected_ns, start_ns, fault_threshold;
+   unsigned int old_relaxed = 0, new_relaxed;
+   int ret, count, nsamples, warmup = 1;
+   long minj, maxj, dt, overrun, sumj;
+   unsigned long ov;
+
+   fault_threshold = CONFIG_XENO