From 6b6ebd9f0d7469d0e6a459d1524d14e76cd40e11 Mon Sep 17 00:00:00 2001 From: John Kacur Date: Fri, 9 May 2014 01:21:06 +0200 Subject: [PATCH 1/7] lib: Rework err_msg_n to output strerror after message Outputting the message first followed by the strerror makes the error messages more readable. Signed-off-by: John Kacur --- src/cyclictest/cyclictest.c | 4 ++-- src/lib/error.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index 4547831..01dfc75 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -669,7 +669,7 @@ static int raise_soft_prio(int policy, const struct sched_param *param) err = getrlimit(RLIMIT_RTPRIO, &rlim); if (err) { err = errno; - err_msg_n(err, "WARN: getrlimit failed\n"); + err_msg_n(err, "WARN: getrlimit failed"); return err; } @@ -681,7 +681,7 @@ static int raise_soft_prio(int policy, const struct sched_param *param) err = setrlimit(RLIMIT_RTPRIO, &rlim); if (err) { err = errno; - err_msg_n(err, "WARN: setrlimit failed\n"); + err_msg_n(err, "WARN: setrlimit failed"); /* return err; */ } } else { diff --git a/src/lib/error.c b/src/lib/error.c index 1b5de5d..5eb6352 100644 --- a/src/lib/error.c +++ b/src/lib/error.c @@ -79,8 +79,8 @@ void fatal(char *fmt, ...) void err_doit(int err, const char *fmt, va_list ap) { - if (err) - fprintf(stderr, "%s\n", strerror(err)); vfprintf(stderr, fmt, ap); + if (err) + fprintf(stderr, ": %s\n", strerror(err)); return; } From 245b19c5f69a00f36bb17adbaf0472a45ac06154 Mon Sep 17 00:00:00 2001 From: John Kacur Date: Fri, 9 May 2014 14:12:26 +0200 Subject: [PATCH 2/7] rt_numa.h: Suppress discards 'const' qualifier warning In rt-tests we try to use const where appropriate for read-only, but we need to tell the compiler we are intentionally discarding const when calling library functions that expect char * Signed-off-by: John Kacur --- src/cyclictest/rt_numa.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cyclictest/rt_numa.h b/src/cyclictest/rt_numa.h index e64c446..60a1437 100644 --- a/src/cyclictest/rt_numa.h +++ b/src/cyclictest/rt_numa.h @@ -101,7 +101,7 @@ static inline struct bitmask* rt_numa_parse_cpustring(const char* s, * libnuma do not have this function. A work around should be to run * your command with e.g. taskset -c 9-15 */ - return numa_parse_cpustring(s); + return numa_parse_cpustring((char *)s); #endif } From 4b430a76785d630e399e60466fdc66cec3a74805 Mon Sep 17 00:00:00 2001 From: John Kacur Date: Thu, 14 Aug 2014 16:03:07 +0200 Subject: [PATCH 3/7] cyclictest: Always print an err message if write of 0 to cpu-dma_latency fails In set_latency_target() there are some paths that don't print an error message even when a write of 0 to /dev/cpu_dma_latency fails. This patch does the following - always print an error message if the write to /dev/cpu_dma_latency fails - Fix the error check with the write call. (a return of 0 or -1 indicate problems - rename ret to err since this function is void and returns no value - use err_msg_n instead of printf (which also prints to stderr) Signed-off-by: John Kacur --- src/cyclictest/cyclictest.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index 01dfc75..64f1764 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -233,20 +233,30 @@ static int32_t latency_target_value = 0; static void set_latency_target(void) { struct stat s; - int ret; + int err; - if (stat("/dev/cpu_dma_latency", &s) == 0) { - latency_target_fd = open("/dev/cpu_dma_latency", O_RDWR); - if (latency_target_fd == -1) - return; - ret = write(latency_target_fd, &latency_target_value, 4); - if (ret == 0) { - printf("# error setting cpu_dma_latency to %d!: %s\n", latency_target_value, strerror(errno)); - close(latency_target_fd); - return; - } - printf("# /dev/cpu_dma_latency set to %dus\n", latency_target_value); + errno = 0; + err = stat("/dev/cpu_dma_latency", &s); + if (err == -1) { + err_msg_n(errno, "WARN: stat /dev/cpu_dma_latency failed"); + return; } + + errno = 0; + latency_target_fd = open("/dev/cpu_dma_latency", O_RDWR); + if (latency_target_fd == -1) { + err_msg_n(errno, "WARN: open /dev/cpu_dma_latency"); + return; + } + + errno = 0; + err = write(latency_target_fd, &latency_target_value, 4); + if (err < 1) { + err_msg_n(errno, "# error setting cpu_dma_latency to %d!", latency_target_value); + close(latency_target_fd); + return; + } + printf("# /dev/cpu_dma_latency set to %dus\n", latency_target_value); } From f0b2df877c67b2755c02835dfeb5eec6dd3d1d8c Mon Sep 17 00:00:00 2001 From: John Kacur Date: Thu, 14 Aug 2014 16:22:11 +0200 Subject: [PATCH 4/7] cyclictest: Change the output from function sighand() to stderr cyclictest can be run from other tools such as rteval in order to get current status on long runs, SIGUSR1 is sent to cyclictest and caught by function sighand() This creates difficulties for rteval when parsing cyclictest output, so change the output to stderr. Note, a RFC was sent out on Apr.15 2014 entitled "RFC: SIGUSR1 to stderr" to: RT cc: Carsten Emde , Thomas Gleixner , Clark Williams Since I didn't receive any replies, I'm assumin there are no objections Signed-off-by: John Kacur --- src/cyclictest/cyclictest.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index 64f1764..ad7890f 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -1569,11 +1569,11 @@ static void sighand(int sig) int oldquiet = quiet; quiet = 0; - printf("#---------------------------\n"); - printf("# cyclictest current status:\n"); + fprintf(stderr, "#---------------------------\n"); + fprintf(stderr, "# cyclictest current status:\n"); for (i = 0; i < num_threads; i++) - print_stat(stdout, parameters[i], i, 0, 0); - printf("#---------------------------\n"); + print_stat(stderr, parameters[i], i, 0, 0); + fprintf(stderr, "#---------------------------\n"); quiet = oldquiet; return; } From 72ce09a0fa3c7b2b8c55d1f54749acc4274d2693 Mon Sep 17 00:00:00 2001 From: John Kacur Date: Thu, 14 Aug 2014 17:01:05 +0200 Subject: [PATCH 5/7] cyclictest: Fix help for long options only At some point in the history of cyclictest, a number of short options were removed and changed to long only options. However the display_help was not updated to reflect this and indicates short options that no longer exist. Fix this. I also found a long option that wasn't listed at all and added that. Signed-off-by: John Kacur --- src/cyclictest/cyclictest.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index ad7890f..b45041e 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -1009,7 +1009,7 @@ static void display_help(int error) "-D --duration=t specify a length for the test run\n" " default is in seconds, but 'm', 'h', or 'd' maybe added\n" " to modify value to minutes, hours or days\n" - "-e --latency=PM_QOS write PM_QOS to /dev/cpu_dma_latency\n" + " --latency=PM_QOS write PM_QOS to /dev/cpu_dma_latency\n" "-E --event event tracing (used with -b)\n" "-f --ftrace function trace (when -b is active)\n" "-F --fifo= create a named pipe at path and write stats to it\n" @@ -1023,13 +1023,14 @@ static void display_help(int error) "-m --mlockall lock current and future memory allocations\n" "-M --refresh_on_max delay updating the screen until a new max latency is hit\n" "-n --nanosleep use clock_nanosleep\n" + " --notrace suppress tracing\n" "-N --nsecs print results in ns instead of us (default us)\n" "-o RED --oscope=RED oscilloscope mode, reduce verbose output by RED\n" "-O TOPT --traceopt=TOPT trace option\n" "-p PRIO --prio=PRIO priority of highest prio thread\n" "-P --preemptoff Preempt off tracing (used with -b)\n" "-q --quiet print only a summary on exit\n" - "-Q --priospread spread priority levels starting at specified value\n" + " --priospread spread priority levels starting at specified value\n" "-r --relative use relative timer instead of absolute\n" "-R --resolution check clock resolution, calling clock_gettime() many\n" " times. list of clock_gettime() values will be\n" @@ -1052,8 +1053,8 @@ static void display_help(int error) " format: n:c:v n=tasknum c=count v=value in us\n" "-w --wakeup task wakeup tracing (used with -b)\n" "-W --wakeuprt rt task wakeup tracing (used with -b)\n" - "-X --dbg_cyclictest print info useful for debugging cyclictest\n" - "-y POLI --policy=POLI policy of realtime thread, POLI may be fifo(default) or rr\n" + " --dbg_cyclictest print info useful for debugging cyclictest\n" + " --policy=POLI policy of realtime thread, POLI may be fifo(default) or rr\n" " format: --policy=fifo(default) or --policy=rr\n", tracers ); From dd01e7dab9a4eb7adf752d6fc7706b7ebe2b2f2c Mon Sep 17 00:00:00 2001 From: John Kacur Date: Thu, 14 Aug 2014 17:24:31 +0200 Subject: [PATCH 6/7] cyclictest: Add long option --laptop to preserve battery power Some people running cyclictest on laptops don't want to automatically take advantage of the trick that prevents the power management to transistion to high cstates, since it eats up their battery power. Allow them to suppress this feature with --laptop This will result in power latency results of course. Feature-requested-by: Joakim Hernberg Signed-off-by: John Kacur --- src/cyclictest/cyclictest.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index b45041e..a3e7b1d 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -186,6 +186,7 @@ static int use_fifo = 0; static pthread_t fifo_threadid; static int aligned = 0; static int offset = 0; +static int laptop = 0; static pthread_cond_t refresh_on_max_cond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t refresh_on_max_lock = PTHREAD_MUTEX_INITIALIZER; @@ -235,6 +236,11 @@ static void set_latency_target(void) struct stat s; int err; + if (laptop) { + warn("not setting cpu_dma_latency to save battery power\n"); + return; + } + errno = 0; err = stat("/dev/cpu_dma_latency", &s); if (err == -1) { @@ -1020,6 +1026,9 @@ static void display_help(int error) "-i INTV --interval=INTV base interval of thread in us default=1000\n" "-I --irqsoff Irqsoff tracing (used with -b)\n" "-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n" + " --laptop Save battery when running cyclictest\n" + " This will give you poorer realtime results\n" + " but will not drain your battery so quickly\n" "-m --mlockall lock current and future memory allocations\n" "-M --refresh_on_max delay updating the screen until a new max latency is hit\n" "-n --nanosleep use clock_nanosleep\n" @@ -1183,7 +1192,7 @@ enum option_values { OPT_QUIET, OPT_PRIOSPREAD, OPT_RELATIVE, OPT_RESOLUTION, OPT_SYSTEM, OPT_SMP, OPT_THREADS, OPT_TRACER, OPT_UNBUFFERED, OPT_NUMA, OPT_VERBOSE, OPT_WAKEUP, OPT_WAKEUPRT, OPT_DBGCYCLIC, OPT_POLICY, OPT_HELP, OPT_NUMOPTS, - OPT_ALIGNED, + OPT_ALIGNED, OPT_LAPTOP, }; /* Process commandline options */ @@ -1216,6 +1225,7 @@ static void process_options (int argc, char *argv[], int max_cpus) {"histofall", required_argument, NULL, OPT_HISTOFALL }, {"interval", required_argument, NULL, OPT_INTERVAL }, {"irqsoff", no_argument, NULL, OPT_IRQSOFF }, + {"laptop", no_argument, NULL, OPT_LAPTOP }, {"loops", required_argument, NULL, OPT_LOOPS }, {"mlockall", no_argument, NULL, OPT_MLOCKALL }, {"refresh_on_max", no_argument, NULL, OPT_REFRESH }, @@ -1445,6 +1455,8 @@ static void process_options (int argc, char *argv[], int max_cpus) handlepolicy(optarg); break; case OPT_DBGCYCLIC: ct_debug = 1; break; + case OPT_LAPTOP: + laptop = 1; break; } } From 863f1482220034de0a85f8150384931318325953 Mon Sep 17 00:00:00 2001 From: Joakim Hernberg Date: Thu, 14 Aug 2014 19:29:29 +0200 Subject: [PATCH 7/7] cyclictest: make affinity option only use number of online cpus When I boot my 8 core i7 laptop with the maxcpus=4 kernel boot flag, cyclictest -S runs 8 threads. This patch makes it only use the number of online cpus instead. Signed-off-by: Joakim Hernberg Signed-off-by: John Kacur --- src/cyclictest/cyclictest.c | 2 +- src/cyclictest/rt_numa.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index a3e7b1d..c727d54 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -1763,7 +1763,7 @@ int main(int argc, char **argv) sigset_t sigset; int signum = SIGALRM; int mode; - int max_cpus = sysconf(_SC_NPROCESSORS_CONF); + int max_cpus = sysconf(_SC_NPROCESSORS_ONLN); int i, ret = -1; int status; diff --git a/src/cyclictest/rt_numa.h b/src/cyclictest/rt_numa.h index 60a1437..06c9420 100644 --- a/src/cyclictest/rt_numa.h +++ b/src/cyclictest/rt_numa.h @@ -128,7 +128,7 @@ static int rt_numa_numa_node_of_cpu(int cpu) int max_node, max_cpus; max_node = numa_max_node(); - max_cpus = sysconf(_SC_NPROCESSORS_CONF); + max_cpus = sysconf(_SC_NPROCESSORS_ONLN); if (cpu > max_cpus) { errno = EINVAL;