@@ -24,4 +24,7 @@ uint32_t string_to_policy(const char *str);
pid_t gettid(void);
+long int parse_num(const char *str, int base, size_t *len);
+long int parse_time(const char *str);
+
#endif /* __RT_UTILS.H */
@@ -13,6 +13,7 @@
#include <sched.h>
#include <stdarg.h>
#include <errno.h>
+#include <ctype.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -320,3 +321,62 @@ pid_t gettid(void)
{
return syscall(SYS_gettid);
}
+
+long int parse_num(const char *str, int base, size_t *len)
+{
+ long int ret;
+ char *endptr;
+
+ errno = 0;
+ ret = strtol(str, &endptr, base);
+ if (errno)
+ return -errno;
+ if (ret < 0)
+ return -ERANGE;
+
+ if (len)
+ *len = endptr - str;
+
+ return ret;
+}
+
+/*
+ * Return time in seconds
+ */
+long int parse_time(const char *str)
+{
+ long int time;
+ size_t len;
+ int factor = 1;
+ char c, *buf;
+
+ len = strlen(str);
+ if (len < 1)
+ return -EINVAL;
+
+ c = tolower(str[len-1]);
+ switch (c) {
+ case 'd': factor *= 60 * 60 * 24; break;
+ case 'h': factor *= 60 * 60; break;
+ case 'm': factor *= 60; break;
+ case 's': break;
+ default:
+ if (isalpha(c))
+ return -EINVAL;
+ }
+
+ buf = strdup(str);
+ if (!buf)
+ return -ENOMEM;
+
+ if (factor > 1)
+ buf[len - 1] = '\0';
+
+ time = parse_num(buf, 10, &len);
+ free(buf);
+
+ if (time < 0)
+ return time;
+
+ return time * factor;
+}
@@ -252,6 +252,7 @@ static void display_help(void)
"-f TO --forcetimeout=TO force timeout of mq_timedreceive(), requires -T\n"
"-i INTV --interval=INTV base interval of thread in us default=1000\n"
"-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n"
+ "-r TIME --runtime=TIME execute the test for TIME\n"
"-p PRIO --prio=PRIO priority\n"
"-S --smp SMP testing: options -a -t and same priority\n"
" of all threads\n"
@@ -271,6 +272,7 @@ static int tracelimit;
static int priority;
static int num_threads = 1;
static int max_cycles;
+static int runtime;
static int interval = 1000;
static int distance = 500;
static int smp;
@@ -293,6 +295,7 @@ static void process_options (int argc, char *argv[])
{"forcetimeout", required_argument, NULL, 'f'},
{"interval", required_argument, NULL, 'i'},
{"loops", required_argument, NULL, 'l'},
+ {"runtime", required_argument, NULL, 'r'},
{"priority", required_argument, NULL, 'p'},
{"smp", no_argument, NULL, 'S'},
{"threads", optional_argument, NULL, 't'},
@@ -325,6 +328,7 @@ static void process_options (int argc, char *argv[])
case 'f': forcetimeout = atoi(optarg); break;
case 'i': interval = atoi(optarg); break;
case 'l': max_cycles = atoi(optarg); break;
+ case 'r': runtime = parse_time(optarg); break;
case 'p': priority = atoi(optarg); break;
case 'S':
smp = 1;
@@ -369,7 +373,10 @@ static void process_options (int argc, char *argv[])
if (forcetimeout && !timeout)
error = 1;
-
+
+ if (runtime < 0)
+ error = 1;
+
if (priority && smp)
sameprio = 1;
@@ -418,10 +425,15 @@ int main(int argc, char *argv[])
sigemptyset(&sigset);
sigaddset(&sigset, SIGTERM);
sigaddset(&sigset, SIGINT);
+ sigaddset(&sigset, SIGALRM);
pthread_sigmask(SIG_SETMASK, &sigset, NULL);
signal(SIGINT, sighand);
signal(SIGTERM, sighand);
+ signal(SIGALRM, sighand);
+
+ if (runtime)
+ alarm(runtime);
receiver = calloc(num_threads, sizeof(struct params));
sender = calloc(num_threads, sizeof(struct params));
@@ -173,6 +173,7 @@ static void display_help(void)
"-d DIST --distance=DIST distance of thread intervals in us default=500\n"
"-i INTV --interval=INTV base interval of thread in us default=1000\n"
"-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n"
+ "-r TIME --runtime=TIME execute test for TIME. Valid postfixes 's', 'm', 'h', 'd'\n"
"-p PRIO --prio=PRIO priority\n"
"-S --smp SMP testing: options -a -t and same priority\n"
" of all threads\n"
@@ -190,6 +191,7 @@ static int tracelimit;
static int priority;
static int num_threads = 1;
static int max_cycles;
+static int runtime;
static int interval = 1000;
static int distance = 500;
static int smp;
@@ -209,13 +211,14 @@ static void process_options (int argc, char *argv[])
{"distance", required_argument, NULL, 'd'},
{"interval", required_argument, NULL, 'i'},
{"loops", required_argument, NULL, 'l'},
+ {"runtime", required_argument, NULL, 'r'},
{"priority", required_argument, NULL, 'p'},
{"smp", no_argument, NULL, 'S'},
{"threads", optional_argument, NULL, 't'},
{"help", no_argument, NULL, '?'},
{NULL, 0, NULL, 0}
};
- int c = getopt_long (argc, argv, "a::b:d:i:l:p:St::",
+ int c = getopt_long (argc, argv, "a::b:d:i:l:r:p:St::",
long_options, &option_index);
if (c == -1)
break;
@@ -239,6 +242,7 @@ static void process_options (int argc, char *argv[])
case 'd': distance = atoi(optarg); break;
case 'i': interval = atoi(optarg); break;
case 'l': max_cycles = atoi(optarg); break;
+ case 'r': runtime = parse_time(optarg); break;
case 'p': priority = atoi(optarg); break;
case 'S':
smp = 1;
@@ -280,6 +284,9 @@ static void process_options (int argc, char *argv[])
if (num_threads < 1)
error = 1;
+ if (runtime < 0)
+ error = 1;
+
if (priority && smp)
sameprio = 1;
@@ -317,6 +324,10 @@ int main(int argc, char *argv[])
signal(SIGINT, sighand);
signal(SIGTERM, sighand);
+ signal(SIGALRM, sighand);
+
+ if (runtime)
+ alarm(runtime);
receiver = calloc(num_threads, sizeof(struct params));
sender = calloc(num_threads, sizeof(struct params));
@@ -208,6 +208,7 @@ static void display_help(void)
"signaltest <options>\n\n"
"-b USEC --breaktrace=USEC send break trace command when latency > USEC\n"
"-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n"
+ "-r TIME --runtime=TIME execute test for TIME. Valid postfixes 's', 'm', 'h', 'd'\n"
"-p PRIO --prio=PRIO priority of highest prio thread\n"
"-q --quiet print a summary only on exit\n"
"-t NUM --threads=NUM number of threads: default=2\n"
@@ -221,6 +222,7 @@ static void display_help(void)
static int priority;
static int num_threads = 2;
static int max_cycles;
+static int runtime;
static int verbose;
static int quiet;
static int lockall = 0;
@@ -235,6 +237,7 @@ static void process_options (int argc, char *argv[])
static struct option long_options[] = {
{"breaktrace", required_argument, NULL, 'b'},
{"loops", required_argument, NULL, 'l'},
+ {"runtime", required_argument, NULL, 'r'},
{"priority", required_argument, NULL, 'p'},
{"quiet", no_argument, NULL, 'q'},
{"threads", required_argument, NULL, 't'},
@@ -243,13 +246,14 @@ static void process_options (int argc, char *argv[])
{"help", no_argument, NULL, '?'},
{NULL, 0, NULL, 0}
};
- int c = getopt_long (argc, argv, "b:c:d:i:l:np:qrsmt:v",
+ int c = getopt_long (argc, argv, "b:c:d:i:l:r:np:qrsmt:v",
long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 'b': tracelimit = atoi(optarg); break;
case 'l': max_cycles = atoi(optarg); break;
+ case 'r': runtime = parse_time(optarg); break;
case 'p': priority = atoi(optarg); break;
case 'q': quiet = 1; break;
case 't': num_threads = atoi(optarg); break;
@@ -265,6 +269,9 @@ static void process_options (int argc, char *argv[])
if (num_threads < 2)
error = 1;
+ if (runtime < 0)
+ error = 1;
+
if (error)
display_help ();
}
@@ -340,6 +347,10 @@ int main(int argc, char **argv)
signal(SIGINT, sighand);
signal(SIGTERM, sighand);
+ signal(SIGALRM, sighand);
+
+ if (runtime)
+ alarm(runtime);
par = calloc(num_threads, sizeof(struct thread_param));
if (!par)
@@ -222,6 +222,7 @@ static void display_help(void)
"-f --fork fork new processes instead of creating threads\n"
"-i INTV --interval=INTV base interval of thread in us default=1000\n"
"-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n"
+ "-r TIME --runtime=TIME execute test for TIME. Valid postfixes 's', 'm', 'h', 'd'\n"
"-p PRIO --prio=PRIO priority\n"
"-t --threads one thread per available processor\n"
"-t [NUM] --threads=NUM number of threads:\n"
@@ -236,6 +237,7 @@ static int affinity;
static int priority;
static int num_threads = 1;
static int max_cycles;
+static int runtime;
static int interval = 1000;
static int distance = 500;
@@ -255,12 +257,13 @@ static void process_options (int argc, char *argv[])
{"fork", optional_argument, NULL, 'f'},
{"interval", required_argument, NULL, 'i'},
{"loops", required_argument, NULL, 'l'},
+ {"runtime", required_argument, NULL, 'r'},
{"priority", required_argument, NULL, 'p'},
{"threads", optional_argument, NULL, 't'},
{"help", no_argument, NULL, '?'},
{NULL, 0, NULL, 0}
};
- int c = getopt_long (argc, argv, "a::b:d:f::i:l:p:t::",
+ int c = getopt_long (argc, argv, "a::b:d:f::i:l:r:p:t::",
long_options, &option_index);
if (c == -1)
break;
@@ -291,6 +294,7 @@ static void process_options (int argc, char *argv[])
break;
case 'i': interval = atoi(optarg); break;
case 'l': max_cycles = atoi(optarg); break;
+ case 'r': runtime = parse_time(optarg); break;
case 'p': priority = atoi(optarg); break;
case 't':
if (optarg != NULL)
@@ -322,6 +326,9 @@ static void process_options (int argc, char *argv[])
if (priority < 0 || priority > 99)
error = 1;
+ if (runtime < 0)
+ error = 1;
+
tracelimit = thistracelimit;
}
if (error)
@@ -433,9 +440,13 @@ int main(int argc, char *argv[])
signal(SIGINT, sighand);
signal(SIGTERM, sighand);
+ signal(SIGALRM, sighand);
sigemptyset(&sigset);
pthread_sigmask(SIG_SETMASK, &sigset, NULL);
+ if (runtime)
+ alarm(runtime);
+
if (!mustfork && !wasforked) {
receiver = calloc(num_threads, sizeof(struct params));
sender = calloc(num_threads, sizeof(struct params));
@@ -578,6 +589,7 @@ int main(int argc, char *argv[])
sigemptyset(&sigset);
sigaddset(&sigset, SIGTERM);
sigaddset(&sigset, SIGINT);
+ sigaddset(&sigset, SIGALRM);
pthread_sigmask(SIG_SETMASK, &sigset, NULL);
nanosleep(&maindelay, NULL);
@@ -248,6 +248,7 @@ static void display_help(void)
"-f --fork fork new processes instead of creating threads\n"
"-i INTV --interval=INTV base interval of thread in us default=1000\n"
"-l LOOPS --loops=LOOPS number of loops: default=0(endless)\n"
+ "-r TIME --runtime=TIME execute the test for TIME\n"
"-p PRIO --prio=PRIO priority\n"
"-S --smp SMP testing: options -a -t and same priority\n"
" of all threads\n"
@@ -264,6 +265,7 @@ static int affinity;
static int priority;
static int num_threads = 1;
static int max_cycles;
+static int runtime;
static int interval = 1000;
static int distance = 500;
static int smp;
@@ -285,13 +287,14 @@ static void process_options (int argc, char *argv[])
{"fork", optional_argument, NULL, 'f'},
{"interval", required_argument, NULL, 'i'},
{"loops", required_argument, NULL, 'l'},
+ {"runtime", required_argument, NULL, 'r'},
{"priority", required_argument, NULL, 'p'},
{"smp", no_argument, NULL, 'S'},
{"threads", optional_argument, NULL, 't'},
{"help", no_argument, NULL, '?'},
{NULL, 0, NULL, 0}
};
- int c = getopt_long (argc, argv, "a::b:d:f::i:l:p:St::",
+ int c = getopt_long (argc, argv, "a::b:d:f::i:l:r:p:St::",
long_options, &option_index);
if (c == -1)
break;
@@ -326,6 +329,7 @@ static void process_options (int argc, char *argv[])
break;
case 'i': interval = atoi(optarg); break;
case 'l': max_cycles = atoi(optarg); break;
+ case 'r': runtime = parse_time(optarg); break;
case 'p': priority = atoi(optarg); break;
case 'S':
smp = 1;
@@ -486,10 +490,14 @@ int main(int argc, char *argv[])
signal(SIGINT, sighand);
signal(SIGTERM, sighand);
+ signal(SIGALRM, sighand);
sigemptyset(&sigset);
pthread_sigmask(SIG_SETMASK, &sigset, NULL);
+ if (runtime)
+ alarm(runtime);
+
if (!mustfork && !wasforked) {
receiver = calloc(num_threads, sizeof(struct params));
sender = calloc(num_threads, sizeof(struct params));
@@ -663,6 +671,7 @@ int main(int argc, char *argv[])
sigemptyset(&sigset);
sigaddset(&sigset, SIGTERM);
sigaddset(&sigset, SIGINT);
+ sigaddset(&sigset, SIGALRM);
pthread_sigmask(SIG_SETMASK, &sigset, NULL);
nanosleep(&maindelay, NULL);