public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH][realtime] Use librttest arg parsing and init_pi_mutex
@ 2009-08-24 22:12 Darren Hart
  2009-08-25  9:58 ` Subrata Modak
  0 siblings, 1 reply; 2+ messages in thread
From: Darren Hart @ 2009-08-24 22:12 UTC (permalink / raw)
  To: ltp-list; +Cc: gowrishankar.m, Paul McKenney

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 <dvhltc@us.ibm.com>
Acked-by: Gowrishankar <gowrishankar.m@in.ibm.com>
CC: Paul McKenney <paulmck@linux.vnet.ibm.com>

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 <paulmck@us.ibm.com>
  *
  * 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
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-08-25  9:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-24 22:12 [LTP] [PATCH][realtime] Use librttest arg parsing and init_pi_mutex Darren Hart
2009-08-25  9:58 ` Subrata Modak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox