Use librttest arg parsing and init_pi_mutex This patch converts pthread_cond_many to use the librttest infrastructure for argument parsing and mutex initialization. The default behavior of the test changes from using a non-pi mutex to a pi mutex. This is because -p defaults to 1 in librttest. We could update run.sh with -p0, but I feel inside a realtime testsuite this test should be using PI mutexes anyway.
Signed-off-by: Darren Hart <[email protected]> Acked-by: Gowrishankar <[email protected]> CC: Paul McKenney <[email protected]> Index: realtime/perf/latency/pthread_cond_many.c =================================================================== --- realtime.orig/perf/latency/pthread_cond_many.c 2009-08-03 14:47:01.000000000 -0700 +++ realtime/perf/latency/pthread_cond_many.c 2009-08-03 14:51:01.000000000 -0700 @@ -24,12 +24,12 @@ * * USAGE: * Use run_auto.sh script in current directory to build and run test. - * Use "-j" to enable jvm simulator. * * AUTHOR * Paul E. McKenney <[email protected]> * * HISTORY + * librttest parsing, threading, and mutex initialization - Darren Hart * * *****************************************************************************/ @@ -46,10 +46,12 @@ #include <librttest.h> #include <libstats.h> #define PASS_US 100 -pthread_mutex_t child_mutex = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t child_mutex; volatile int *child_waiting = NULL; double endtime; pthread_cond_t *condlist = NULL; +int iterations = 0; +int nthreads = 0; int realtime = 0; int broadcast_flag = 0; unsigned long latency = 0; @@ -242,42 +244,68 @@ printf("Standard Deviation: %f\n", stats_stddev(&dat)); } -void -usage(char *progname) +void usage(void) { - fprintf(stderr, - "Usage: %s [--realtime] [--broadcast] iterations nthreads\n", - progname); - printf("currently options are not supported\n"); - exit(-1); + rt_help(); + printf("pthread_cond_many specific options:\n"); + printf(" -r,--realtime run with realtime priority\n"); + printf(" -b,--broadcast use cond_broadcast instead of cond_signal\n"); + printf(" -iITERATIONS iterations (required)\n"); + printf(" -nNTHREADS number of threads (required)\n"); + printf("deprecated unnamed arguments:\n"); + printf(" pthread_cond_many [options] iterations nthreads\n"); +} + +int parse_args(int c, char *v) +{ + int handled; + switch (c) { + case 'h': + usage(); + exit(0); + case 'a': + broadcast_flag = 1; + break; + case 'i': + iterations = atoi(v); + break; + case 'n': + nthreads = atoi(v); + break; + case 'r': + realtime = 1; + break; + default: + handled = 0; + break; + } + return handled; } int main(int argc, char *argv[]) { - int i = 1; - long iter; - long nthreads; + struct option longopts[] = { + {"broadcast", 0, NULL, 'a'}, + {"realtime", 0, NULL, 'r'}, + {NULL, 0, NULL, 0}, + }; setup(); - while (i < argc) { - if (strcmp(argv[i], "--realtime") == 0) { - realtime = 1; - i++; - } else if (strcmp(argv[i], "--broadcast") == 0) { - broadcast_flag = 1; - i++; - } else if (argv[i][0] == '-') { - usage(argv[0]); - } else { - break; - } - } - if (argc - i < 2) { - usage(argv[0]); + init_pi_mutex(&child_mutex); + rt_init_long("ahi:n:r", longopts, parse_args, argc, argv); + + /* Legacy command line arguments support, overrides getopt args. */ + if (optind < argc) + iterations = strtol(argv[optind++], NULL, 0); + if (optind < argc) + nthreads = strtol(argv[optind++], NULL, 0); + + /* Ensure we have the required arguments. */ + if (iterations == 0 || nthreads == 0) { + usage(); + exit(1); } - iter = strtol(argv[i], NULL, 0); - nthreads = strtol(argv[i + 1], NULL, 0); child_waiting = (int *)malloc(sizeof(*child_waiting) * nthreads); condlist = (pthread_cond_t *)malloc(sizeof(*condlist) * nthreads); @@ -285,7 +313,7 @@ fprintf(stderr, "Out of memory\n"); exit(-1); } - test_signal(iter, nthreads); + test_signal(iterations, nthreads); printf("\nCriteria: latencies < %d us\n", PASS_US); printf("Result: %s\n", fail ? "FAIL" : "PASS"); return 0; Index: realtime/perf/latency/run.sh =================================================================== --- realtime.orig/perf/latency/run.sh 2009-08-03 14:47:01.000000000 -0700 +++ realtime/perf/latency/run.sh 2009-08-03 14:47:33.000000000 -0700 @@ -35,11 +35,11 @@ rm -f $nthread.$iter.$nproc.*.out i=0 -./pthread_cond_many --realtime --broadcast $iter $nthread > $nthread.$iter.$nproc.$i.out & +./pthread_cond_many --realtime --broadcast -i $iter -n $nthread > $nthread.$iter.$nproc.$i.out & i=1 while test $i -lt $nproc do - ./pthread_cond_many --broadcast $iter $nthread > $nthread.$iter.$nproc.$i.out & + ./pthread_cond_many --broadcast -i $iter -n $nthread > $nthread.$iter.$nproc.$i.out & i=`expr $i + 1` done wait -- Darren Hart IBM Linux Technology Center Real-Time Linux Team ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
