Module: xenomai-3 Branch: master Commit: 403d78ae930551c2d98b3e456f3b9a0e53fd668f URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=403d78ae930551c2d98b3e456f3b9a0e53fd668f
Author: Philippe Gerum <r...@xenomai.org> Date: Tue Sep 30 17:09:40 2014 +0200 utils/autotune: update load generator Create additional load with domain migrations. --- doc/asciidoc/man1/autotune.adoc | 8 ++--- utils/autotune/autotune.c | 68 +++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 29 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..5a18310 100644 --- a/utils/autotune/autotune.c +++ b/utils/autotune/autotune.c @@ -24,11 +24,12 @@ #include <limits.h> #include <time.h> #include <error.h> +#include <sys/cobalt.h> #include <rtdm/autotune.h> 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,10 +108,11 @@ static void *sampler_thread(void *arg) return NULL; } -static void *hog_thread(void *arg) +static void *load_thread(void *arg) { - int fdi, fdo, count = 0; + int fdi, fdo, count = 0, wakelim; ssize_t nbytes, ret; + struct timespec rqt; char buf[512]; fdi = open("/dev/zero", O_RDONLY); @@ -121,16 +123,25 @@ static void *hog_thread(void *arg) if (fdi < 0) error(1, errno, "/dev/null"); + rqt.tv_sec = 0; + rqt.tv_nsec = CONFIG_XENO_DEFAULT_PERIOD * 2; + wakelim = 20000000 / rqt.tv_nsec; + for (;;) { + clock_nanosleep(CLOCK_MONOTONIC, 0, &rqt, NULL); + + if (++count % wakelim) { + cobalt_thread_relax(); + continue; + } + nbytes = read(fdi, buf, sizeof(buf)); if (nbytes <= 0) - error(1, EIO, "hog streaming"); + error(1, EIO, "load streaming"); if (nbytes > 0) { ret = write(fdo, buf, nbytes); (void)ret; } - if ((++count % 1024) == 0) - usleep(10000); } return NULL; @@ -157,7 +168,7 @@ static void create_sampler(pthread_t *tid, int fd) pthread_setname_np(*tid, "sampler"); } -static void create_hog(pthread_t *tid) +static void create_load(pthread_t *tid) { struct sched_param param; pthread_attr_t attr; @@ -166,16 +177,16 @@ static void create_hog(pthread_t *tid) 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_setschedpolicy(&attr, SCHED_FIFO); + param.sched_priority = 1; pthread_attr_setschedparam(&attr, ¶m); pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN * 8); - ret = pthread_create(tid, &attr, hog_thread, NULL); + ret = pthread_create(tid, &attr, load_thread, NULL); if (ret) - error(1, ret, "hog thread"); + error(1, ret, "load thread"); pthread_attr_destroy(&attr); - pthread_setname_np(*tid, "hog"); + pthread_setname_np(*tid, "loadgen"); } static void usage(void) @@ -186,7 +197,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 +238,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; + pthread_t load_pth; + time_t start; period = CONFIG_XENO_DEFAULT_PERIOD; @@ -252,7 +264,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 +292,15 @@ int main(int argc, char *const argv[]) } if (tune_irqlat || tune_kernlat || tune_userlat) { - if (!nohog) - create_hog(&hog); + if (!noload) + create_load(&load_pth); if (!quiet) - printf("Auto-tuning started, period=%d ns (may take a while)\n", - period); + 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 +311,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 (!noload) + pthread_cancel(load_pth); close(fd); _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git