public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH][realtime] prio-wake: allow for optional locking prior to broadcast
@ 2009-08-24 22:14 Darren Hart
  2009-08-25  9:58 ` Subrata Modak
  0 siblings, 1 reply; 2+ messages in thread
From: Darren Hart @ 2009-08-24 22:14 UTC (permalink / raw)
  To: ltp-list; +Cc: Gowrishankar, Vernon Mauery


prio-wake: allow for optional locking prior to broadcast

Allow the user to decide if the mutex should be held prior to
calling pthread_cond_broadcast().  Default remains the same.
Tested with and without the argument as well as with both 0 and 1
passed to the argument. Values other than 0 and 1 will result in locking
the mutex.

Signed-off-by: Darren Hart <dvhltc@us.ibm.com>
Acked-By: Dinakar Guniguntala <dino@in.ibm.com>
Acked-by: Vernon Mauery <vernux@us.ibm.com>
Acked-by: Gowrishankar <gowrishankar.m@in.ibm.com>

---
 func/prio-wake/prio-wake.c |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

Index: realtime/func/prio-wake/prio-wake.c
===================================================================
--- realtime.orig/func/prio-wake/prio-wake.c
+++ realtime/func/prio-wake/prio-wake.c
@@ -56,6 +56,7 @@
 #include <librttest.h>
 volatile int running_threads = 0;
 static int rt_threads = 0;
+static int locked_broadcast = 1;
 static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
 static pthread_mutex_t mutex;
 static volatile nsec_t beginrun;
@@ -67,6 +68,8 @@ void usage(void)
         rt_help();
         printf("prio-wake specific options:\n");
         printf("  -n#           #: number of worker threads\n");
+        printf("  -l#           1:lock the mutex before broadcast, 0:don't\n");
+	printf("                defaults to 1\n");
 }
 
 int parse_args(int c, char *v)
@@ -80,6 +83,9 @@ int parse_args(int c, char *v)
                 case 'n':
                         rt_threads = atoi(v);
                         break;
+                case 'l':
+                        locked_broadcast = atoi(v);
+                        break;
                 default:
                         handled = 0;
                         break;
@@ -106,9 +112,11 @@ void *master_thread(void* arg)
 
 	printf("%08lld us: Master thread about to wake the workers\n", start/NS_PER_US);
 	/* start the children threads */
-	rc = pthread_mutex_lock(&mutex);
+	if (locked_broadcast)
+		rc = pthread_mutex_lock(&mutex);
 	rc = pthread_cond_broadcast(&cond);
-	rc = pthread_mutex_unlock(&mutex);
+	if (locked_broadcast)
+		rc = pthread_mutex_unlock(&mutex);
 
 	while (running_threads > 0)
 		sleep(1);
@@ -161,7 +169,7 @@ int main(int argc, char* argv[])
 	int i;
 	setup();
 
-        rt_init("hn:", parse_args, argc, argv);
+        rt_init("hn:l:", parse_args, argc, argv);
 
 	if (rt_threads == 0) {
 		numcpus = sysconf(_SC_NPROCESSORS_ONLN);
@@ -172,7 +180,9 @@ int main(int argc, char* argv[])
 	printf("\n-----------------------\n");
 	printf("Priority Ordered Wakeup\n");
 	printf("-----------------------\n");
-	printf("Worker Threads: %d\n\n", rt_threads);
+	printf("Worker Threads: %d\n", rt_threads);
+	printf("Calling pthread_cond_broadcast() with mutex: %s\n\n",
+	       locked_broadcast ? "LOCKED" : "UNLOCKED");
 
 	pri_boost = 3;
 
-- 
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

* Re: [LTP] [PATCH][realtime] prio-wake: allow for optional locking prior to broadcast
  2009-08-24 22:14 [LTP] [PATCH][realtime] prio-wake: allow for optional locking prior to broadcast Darren Hart
@ 2009-08-25  9:58 ` Subrata Modak
  0 siblings, 0 replies; 2+ messages in thread
From: Subrata Modak @ 2009-08-25  9:58 UTC (permalink / raw)
  To: Darren Hart; +Cc: Gowrishankar, ltp-list, Vernon Mauery

On Mon, 2009-08-24 at 15:14 -0700, Darren Hart wrote: 
> prio-wake: allow for optional locking prior to broadcast
> 
> Allow the user to decide if the mutex should be held prior to
> calling pthread_cond_broadcast().  Default remains the same.
> Tested with and without the argument as well as with both 0 and 1
> passed to the argument. Values other than 0 and 1 will result in locking
> the mutex.
> 
> Signed-off-by: Darren Hart <dvhltc@us.ibm.com>

Thanks.

Regards--
Subrata

> Acked-By: Dinakar Guniguntala <dino@in.ibm.com>
> Acked-by: Vernon Mauery <vernux@us.ibm.com>
> Acked-by: Gowrishankar <gowrishankar.m@in.ibm.com>
> 
> ---
>  func/prio-wake/prio-wake.c |   18 ++++++++++++++----
>  1 file changed, 14 insertions(+), 4 deletions(-)
> 
> Index: realtime/func/prio-wake/prio-wake.c
> ===================================================================
> --- realtime.orig/func/prio-wake/prio-wake.c
> +++ realtime/func/prio-wake/prio-wake.c
> @@ -56,6 +56,7 @@
>  #include <librttest.h>
>  volatile int running_threads = 0;
>  static int rt_threads = 0;
> +static int locked_broadcast = 1;
>  static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
>  static pthread_mutex_t mutex;
>  static volatile nsec_t beginrun;
> @@ -67,6 +68,8 @@ void usage(void)
>          rt_help();
>          printf("prio-wake specific options:\n");
>          printf("  -n#           #: number of worker threads\n");
> +        printf("  -l#           1:lock the mutex before broadcast, 0:don't\n");
> +	printf("                defaults to 1\n");
>  }
> 
>  int parse_args(int c, char *v)
> @@ -80,6 +83,9 @@ int parse_args(int c, char *v)
>                  case 'n':
>                          rt_threads = atoi(v);
>                          break;
> +                case 'l':
> +                        locked_broadcast = atoi(v);
> +                        break;
>                  default:
>                          handled = 0;
>                          break;
> @@ -106,9 +112,11 @@ void *master_thread(void* arg)
> 
>  	printf("%08lld us: Master thread about to wake the workers\n", start/NS_PER_US);
>  	/* start the children threads */
> -	rc = pthread_mutex_lock(&mutex);
> +	if (locked_broadcast)
> +		rc = pthread_mutex_lock(&mutex);
>  	rc = pthread_cond_broadcast(&cond);
> -	rc = pthread_mutex_unlock(&mutex);
> +	if (locked_broadcast)
> +		rc = pthread_mutex_unlock(&mutex);
> 
>  	while (running_threads > 0)
>  		sleep(1);
> @@ -161,7 +169,7 @@ int main(int argc, char* argv[])
>  	int i;
>  	setup();
> 
> -        rt_init("hn:", parse_args, argc, argv);
> +        rt_init("hn:l:", parse_args, argc, argv);
> 
>  	if (rt_threads == 0) {
>  		numcpus = sysconf(_SC_NPROCESSORS_ONLN);
> @@ -172,7 +180,9 @@ int main(int argc, char* argv[])
>  	printf("\n-----------------------\n");
>  	printf("Priority Ordered Wakeup\n");
>  	printf("-----------------------\n");
> -	printf("Worker Threads: %d\n\n", rt_threads);
> +	printf("Worker Threads: %d\n", rt_threads);
> +	printf("Calling pthread_cond_broadcast() with mutex: %s\n\n",
> +	       locked_broadcast ? "LOCKED" : "UNLOCKED");
> 
>  	pri_boost = 3;
> 


------------------------------------------------------------------------------
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:14 [LTP] [PATCH][realtime] prio-wake: allow for optional locking prior to broadcast 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