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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Sep 30 17:09:40 2014 +0200

utils/autotune: change load generator

Use switchtest -s 200, which is known to trigger early timer shots
with too pessimistic gravity values.

---

 doc/asciidoc/man1/autotune.adoc |    8 ++--
 utils/autotune/autotune.c       |   97 ++++++++++++++++-----------------------
 2 files changed, 44 insertions(+), 61 deletions(-)

diff --git a/doc/asciidoc/man1/autotune.adoc b/doc/asciidoc/man1/autotune.adoc
index efea67e..b244c96 100644
--- a/doc/asciidoc/man1/autotune.adoc
+++ b/doc/asciidoc/man1/autotune.adoc
@@ -97,10 +97,10 @@ activity can slip in, treading over a larger address space).
 Reset the gravity values to their factory defaults. These defaults
 are statically defined by the Xenomai platform code.
 
-*--nohog*::
-Disable load generation while auto-tuning. *autotune* runs a simple
-load generator internally in parallel to estimating the latency, in
-order to eliminate irregular delays which tend to appear on fully idle
+*--noload*::
+Disable load generation while auto-tuning. *autotune* runs a load
+generator internally in parallel to estimating the latency, in order
+to eliminate irregular delays which tend to appear on fully idle
 systems.  Therefore, keeping the load generation enabled most often
 leads to a more accurate estimation.
 
diff --git a/utils/autotune/autotune.c b/utils/autotune/autotune.c
index 1c13084..4a7ddb0 100644
--- a/utils/autotune/autotune.c
+++ b/utils/autotune/autotune.c
@@ -20,6 +20,7 @@
 #include <getopt.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <signal.h>
 #include <pthread.h>
 #include <limits.h>
 #include <time.h>
@@ -28,7 +29,7 @@
 
 static int tune_irqlat, tune_kernlat, tune_userlat;
 
-static int reset, nohog, quiet;
+static int reset, noload, quiet;
 
 static const struct option base_options[] = {
        {
@@ -63,9 +64,9 @@ static const struct option base_options[] = {
                .val = 1
        },
        {
-#define nohog_opt      5
-               .name = "nohog",
-               .flag = &nohog,
+#define noload_opt     5
+               .name = "noload",
+               .flag = &noload,
                .val = 1
        },
        {
@@ -107,35 +108,6 @@ static void *sampler_thread(void *arg)
        return NULL;
 }
 
-static void *hog_thread(void *arg)
-{
-       int fdi, fdo, count = 0;
-       ssize_t nbytes, ret;
-       char buf[512];
-
-       fdi = open("/dev/zero", O_RDONLY);
-       if (fdi < 0)
-               error(1, errno, "/dev/zero");
-
-       fdo = open("/dev/null", O_WRONLY);
-       if (fdi < 0)
-               error(1, errno, "/dev/null");
-
-       for (;;) {
-               nbytes = read(fdi, buf, sizeof(buf));
-               if (nbytes <= 0)
-                       error(1, EIO, "hog streaming");
-               if (nbytes > 0) {
-                       ret = write(fdo, buf, nbytes);
-                       (void)ret;
-               }
-               if ((++count % 1024) == 0)
-                       usleep(10000);
-       }
-
-       return NULL;
-}
-
 static void create_sampler(pthread_t *tid, int fd)
 {
        struct sched_param param;
@@ -157,25 +129,29 @@ static void create_sampler(pthread_t *tid, int fd)
        pthread_setname_np(*tid, "sampler");
 }
 
-static void create_hog(pthread_t *tid)
+static pid_t start_load(void)
 {
-       struct sched_param param;
-       pthread_attr_t attr;
+       char *period;
+       pid_t pid;
        int ret;
 
-       pthread_attr_init(&attr);
-       pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
-       pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
-       pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
-       param.sched_priority = 0;
-       pthread_attr_setschedparam(&attr, &param);
-       pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN * 8);
-       ret = pthread_create(tid, &attr, hog_thread, NULL);
-       if (ret)
-               error(1, ret, "hog thread");
+       ret = asprintf(&period, "%d", CONFIG_XENO_DEFAULT_PERIOD * 2 / 1000);
+       if (ret < 0)
+               error(1, ENOMEM, "start_load");
+               
+       switch (pid = vfork()) {
+       case -1:
+               error(1, errno, "vfork");
+       case 0:
+               execl(CONFIG_XENO_PREFIX "/bin/switchtest", "loadgen",
+                     "-Q", "-s", period, NULL);
+               _exit(99);
+               break;
+       }
 
-       pthread_attr_destroy(&attr);
-       pthread_setname_np(*tid, "hog");
+       free(period);
+
+       return pid;
 }
 
 static void usage(void)
@@ -186,7 +162,7 @@ static void usage(void)
        fprintf(stderr, "   --user              user scheduling latency\n");
        fprintf(stderr, "   --period            set the sampling period\n");
        fprintf(stderr, "   --reset             reset core timer gravity to 
factory defaults\n");
-       fprintf(stderr, "   --nohog             disable load generation\n");
+       fprintf(stderr, "   --noload            disable load generation\n");
        fprintf(stderr, "   --quiet             tame down verbosity\n");
        fprintf(stderr, "   --help              print this help\n\n");
        fprintf(stderr, "if no option is given, tune for all contexts using the 
default period.\n");
@@ -227,7 +203,8 @@ static void run_tuner(int fd, int op, int period, const 
char *type)
 int main(int argc, char *const argv[])
 {
        int fd, period, ret, c, lindex, tuned = 0;
-       pthread_t hog;
+       pid_t load_pid = -1;
+       time_t start;
 
        period = CONFIG_XENO_DEFAULT_PERIOD;
 
@@ -252,7 +229,7 @@ int main(int argc, char *const argv[])
                                error(1, EINVAL, "invalid sampling period 
(default %d)",
                                      CONFIG_XENO_DEFAULT_PERIOD);
                        break;
-               case nohog_opt:
+               case noload_opt:
                case quiet_opt:
                        break;
                case irq_opt:
@@ -280,13 +257,15 @@ int main(int argc, char *const argv[])
        }
 
        if (tune_irqlat || tune_kernlat || tune_userlat) {
-               if (!nohog)
-                       create_hog(&hog);
+               if (!noload)
+                       load_pid = start_load();
                if (!quiet)
-                       printf("Auto-tuning started, period=%d ns (may take a 
while)\n",
+                       printf("== auto-tuning started, period=%d ns (may take 
a while)\n",
                                period);
        } else
-               nohog = 1;
+               noload = 1;
+
+       time(&start);
 
        if (tune_irqlat)
                run_tuner(fd, AUTOTUNE_RTIOC_IRQ, period, "irq");
@@ -297,8 +276,12 @@ int main(int argc, char *const argv[])
        if (tune_userlat)
                run_tuner(fd, AUTOTUNE_RTIOC_USER, period, "user");
 
-       if (!nohog)
-               pthread_cancel(hog);
+       if (!quiet && (tune_userlat || tune_kernlat || tune_userlat))
+               printf("== auto-tuning completed after %ds\n",
+                      (int)(time(NULL) - start));
+
+       if (load_pid != -1)
+               __STD(kill(load_pid, SIGKILL));
 
        close(fd);
 


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

Reply via email to