From: Michal Sojka Date: Wed, 11 Nov 2009 14:40:35 +0000 (+0100) Subject: Almost final version of fwp-timing and its running script X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/fwp.git/commitdiff_plain/9df24902dd56311d5d7a49053f3230c903cbd4d0 Almost final version of fwp-timing and its running script --- diff --git a/fwp/tests/timing/fwp-timing.c b/fwp/tests/timing/fwp-timing.c index 41a385d..941a8f3 100644 --- a/fwp/tests/timing/fwp-timing.c +++ b/fwp/tests/timing/fwp-timing.c @@ -22,6 +22,7 @@ #include #include #include +#include bool opt_verbose = false; bool opt_quiet = false; @@ -84,11 +85,11 @@ void set_rt_prio(int priority) static struct sched_param param; if ((maxpri = sched_get_priority_max(SCHED_FIFO)) == -1) { - fprintf(stderr, "warning: sched_get_priority_max failed"); + fprintf(stderr, "warning: sched_get_priority_max failed\n"); } if ((minpri = sched_get_priority_min(SCHED_FIFO)) == -1) { - fprintf(stderr, "warning: sched_get_priority_min failed"); + fprintf(stderr, "warning: sched_get_priority_min failed\n"); } if (priority > maxpri) { @@ -101,7 +102,7 @@ void set_rt_prio(int priority) param.sched_priority = priority; if (sched_setscheduler(0, SCHED_FIFO, ¶m) == -1) { - fprintf(stderr, "warning: sched_setscheduler failed"); + fprintf(stderr, "warning: sched_setscheduler failed\n"); } mlockall(MCL_CURRENT | MCL_FUTURE); @@ -115,10 +116,12 @@ struct stream_params { int number; int id; int count; + frsh_vres_id_t vres; + pthread_t thread; }; -int negotiate_contract(struct stream_params *p, frsh_vres_id_t *vres) +int negotiate_contract(struct stream_params *p) { frsh_contract_t contract; int ret; @@ -160,16 +163,14 @@ int negotiate_contract(struct stream_params *p, frsh_vres_id_t *vres) ret = fres_contract_add_fwp(contract, fwp); if (ret) PERROR_AND_EXIT(ret, "fres_contract_add_fwp"); - ret = frsh_contract_negotiate(&contract, vres); - if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate"); + ret = frsh_contract_negotiate(&contract, &p->vres); frsh_contract_destroy(&contract); - return 0; + return ret; } void create_endpoints(struct stream_params *p, - frsh_vres_id_t vres, frsh_send_endpoint_t *epsrc, frsh_receive_endpoint_t *epdst) { @@ -191,12 +192,13 @@ void create_endpoints(struct stream_params *p, epsrc); if (ret < 0) error(1, errno, "frsh_send_endpoint_create()"); - ret = frsh_send_endpoint_bind(vres, *epsrc); + ret = frsh_send_endpoint_bind(p->vres, *epsrc); if (ret != 0) error(1, errno, "frsh_send_endpoint_bind"); } static struct option long_opts[] = { + { "loglevel",required_argument, 0, 'l' }, { "period", required_argument, 0, 'p' }, { "budget", required_argument, 0, 'b' }, { "source", required_argument, 0, 's' }, @@ -213,6 +215,7 @@ static void usage(void) { printf("usage: fwp-timing [ options ]\n"); + printf(" -l, --loglevel |=,...\n"); printf(" -p, --period period in miliseconds\n"); printf(" -b, --budget how many bytes is sent in each period\n"); printf(" -s, --source source IP address\n"); @@ -231,7 +234,7 @@ int parse_opts(int *argc, char **argv[], struct stream_params *p) int ret; bool options_found = false; - while ((opt = getopt_long(*argc, *argv, "/ab:c:d:n:p:qs:v", long_opts, NULL)) != -1) { + while ((opt = getopt_long(*argc, *argv, "/ab:c:d:l:n:p:qs:v", long_opts, NULL)) != -1) { options_found = true; switch (opt) { case 'a': @@ -252,6 +255,9 @@ int parse_opts(int *argc, char **argv[], struct stream_params *p) exit(1); } break; + case 'l': + ul_log_domain_arg2levels(optarg); + break; case 'n': p->number = atoi(optarg); break; @@ -387,7 +393,6 @@ sem_t finished; void *sender(void *arg) { struct stream_params *p = arg; - frsh_vres_id_t vres; frsh_send_endpoint_t epsrc; struct receiver_params *rp; int ret; @@ -398,23 +403,16 @@ void *sender(void *arg) msg = malloc(p->budget); if (!msg) error(1, errno, "malloc msg"); - negotiate_contract(p, &vres); - rp = malloc(sizeof(*rp)); rp->budget = p->budget; rp->id = p->id; - - create_endpoints(p, vres, &epsrc, &rp->epdst); - + + create_endpoints(p, &epsrc, &rp->epdst); + set_rt_prio(50); ret = pthread_create(&receiver_id, NULL, receiver, rp); - if (signal(SIGTERM, stopper) == SIG_ERR) - error(1, errno, "Error in signal registration"); - if (signal(SIGINT, stopper) == SIG_ERR) - error(1, errno, "Signal handler registration error"); - struct timespec next_period; struct timespec tss; clock_gettime(CLOCK_MONOTONIC, &next_period); @@ -439,8 +437,7 @@ void *sender(void *arg) &next_period, NULL); } - frsh_contract_cancel(vres); - free(p); + sem_post(&finished); return NULL; } @@ -462,7 +459,10 @@ void print_stat(bool final) int main(int argc, char *argv[]) { int ret; + int i; int num = 0; + bool negotiation_failure = false; + struct stream_params sp = { .budget = 1024, .period_ms = 20, @@ -472,7 +472,14 @@ int main(int argc, char *argv[]) .number = 1, .count = -1, }; - struct stream_params *p = NULL; + struct stream_params *p[100]; + + memset(p, 0, sizeof(p)); + + if (signal(SIGTERM, stopper) == SIG_ERR) + error(1, errno, "Error in signal registration"); + if (signal(SIGINT, stopper) == SIG_ERR) + error(1, errno, "Signal handler registration error"); sem_init(&finished, 0, 0); @@ -482,19 +489,32 @@ int main(int argc, char *argv[]) do { ret = parse_opts(&argc, &argv, &sp); if (num == 0 || ret == 0) { - int i; for (i=0; iid = num; - pthread_create(&thread, NULL, sender, p); - num++; + p[num] = malloc(sizeof(*p[0])); + if (!p[num]) error(1, errno, "malloc"); + *p[num] = sp; + p[num]->id = num; + ret = negotiate_contract(p[num]); + if (!ret) + num++; + else { + PERROR_FRESCOR(ret, "frsh_contract_negotiate"); + free(p[num]); + negotiation_failure = true; + break; + } } } } while(ret == 0); + if (negotiation_failure) { + goto destroy; + } + + for (i=0; ithread, NULL, sender, p[i]); + } + while (!exit_flag && !opt_quiet) { int v; print_stat(false); @@ -504,9 +524,15 @@ int main(int argc, char *argv[]) usleep(100000); } - while (num--) - sem_wait(&finished); +destroy: + for (i=0; ithread, NULL); + frsh_contract_cancel(p[i]->vres); + free(p[i]); + } + stats.lost = stats.sent - stats.received; print_stat(true); return 0; diff --git a/fwp/tests/timing/fwp-timing.pl b/fwp/tests/timing/fwp-timing.pl new file mode 100755 index 0000000..36afde5 --- /dev/null +++ b/fwp/tests/timing/fwp-timing.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl -w + +$omk_rules_dir=qx' +old_pwd="" +while [ ! -e Makefile.rules ]; do + if [ "$old_pwd" = `pwd` ]; then + echo "Makefile.rules has not been found in this or parent directory" >&2; exit 1; + else + old_pwd=`pwd`; + cd -L .. 2>/dev/null; + fi; +done; +pwd'; +chomp $omk_rules_dir; + +sub catch_zap { + my $signame = shift; + die "Somebody sent me a SIG$signame"; +} +$SIG{INT} = \&catch_zap; +$SIG{TERM} = \&catch_zap; + +@srcdst = ( + "-s 192.168.1.10 -d 192.168.1.11", + "-s 192.168.1.11 -d 192.168.1.12", + "-s 192.168.1.12 -d 192.168.1.13", + "-s 192.168.1.13 -d 192.168.1.10", +); + +$max=10; +$max=$ARGV[0] if (scalar(@ARGV)); + +for($i=1; $i<=$max; $i++) { + $|++; # Autoflush + printf "%3d: ", $i; + $|--; + my @streams = (); + for ($j=0; $j<@srcdst; $j++) { + use integer; + my $n = ($i-1) / @srcdst + ((($j % @srcdst) <= (($i-1) % @srcdst)) ? 1 : 0); + $streams[$j] = $srcdst[$j]." -n $n" if ($n); + } + $cmd="$omk_rules_dir/_compiled/bin-tests/fwp-timing -l 2 -q -c 10 ".join(" -/ ", @streams); + #print "$cmd\n"; + $out=`$cmd`; + print $out; +} +