pingpong, etc. programs

Saurabh Desai <[email protected]>
Newsgroups gmane.comp.lib.phil
Message-ID <[email protected]>
I found out why the pingpong and other programs like test_str03 (an NGPT
test 
program), etc. performed unstable and poor on a 4-way system using NPTL. 
The pthread_cond_broadcast wakes up 200+ threads and they all contend
for 
an internal condvar lock. And again they wait in kernel using futex. 
To verify this I tried adding this patch in the library and that made a
hugh difference.

Without this patch:
./pp -v -n 128 -i 1 -S 32768
256 threads initialised in 0s.10121ms
128 games completed in 53s.104041ms

With this patch:
./pp -v -n 128 -i 1 -S 32768
256 threads initialised in 0s.9894ms
128 games completed in 0s.5049ms

Again, I did this to confirm the problem area. I guess the right fix
also involves futexes related kernel changes.

- Saurabh

==================
--- pthread_cond_broadcast.c.orig       2003-04-30 16:56:22.764088584
-0500
+++ pthread_cond_broadcast.c    2003-04-30 16:56:32.206653096 -0500
@@ -68,7 +68,7 @@
 #endif

       /* Wake everybody.  */
-      lll_futex_wake (futex, INT_MAX);
+      lll_futex_wake (futex, 1);

       /* That's all.  */
       return 0;

--- pthread_cond_wait.c.orig    2003-04-30 17:15:58.114792440 -0500
+++ pthread_cond_wait.c 2003-04-30 17:16:05.540663536 -0500
@@ -101,7 +101,7 @@
 {
   struct _pthread_cleanup_buffer buffer;
   struct _condvar_cleanup_buffer cbuffer;
-  int err;
+  int err, futex_wakeup=0;

   /* Make sure we are along.  */
   lll_mutex_lock (cond->__data.__lock);
@@ -167,8 +167,12 @@
   /* Another thread woken up.  */
   ++cond->__data.__woken_seq;

+  if (val > cond->__data.__woken_seq)
+       futex_wakeup = 1;
   /* We are done with the condvar.  */
   lll_mutex_unlock (cond->__data.__lock);
+  if (futex_wakeup)
+       lll_futex_wake (futex, 1);

   /* The cancellation handling is back to normal, remove the handler. 
*/
   __pthread_cleanup_pop (&buffer, 0);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.