This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Encouraging the kernel(?) to more efficiently wake my threads


Hi,

I understand this libc mailing list might not be the place for this
question.  I spent an hour  trying to find a "pthreads" mailing list
but could not.  If this is the incorrect place to post, please advice
a more appropriate place (if you are able) and I will happily go away.

I have a c++ pthreads application running on the 3.0.6-gentoo kernel
on a quad-core machine without "Intel Hyper Threading".  My
application is attempting to run 5 threads on these 4 CPUs.  The
application spends all of its time doing this:

Mama Thread (1 of these)
 a) Release 4 Baby threads to do some work (signal 4 semaphores)
 b) do some prep work for the next cycle
 c) Wait for the 5 baby threads to complete (wait on 4 semaphores)
 d) goto (a)

Baby thread (4 of these)
 e) Wait for mama to tell them to work (semaphore)
 f) do the work
 g) tell mama work is done (semaphore)
 h) goto (e)

After noticing some "underutilization" in top, I added some
timing/profiling information by writing out gettimeofdata during the
run.  What I found was this:

In picture form:
  http://img7.imageshack.us/img7/5435/threadsi.png

In text form:
i) Step (a) asks the OS to run 4 additional threads.  These four
threads plus the mama thread is 5 -- one more than the number of CPUs
I have.
j) Three baby threads are started and one remains sleeping/unloved
k) When one of the baby threads completes, the remaining unloved baby
thread is started
l) (k) happens after (b) is completed
m) After (b) completes and before (k) happens, a CPU on my system is unused

Question: What can I do to encourage the OS to wake up the unloved
baby thread after (b) [or time "3" in the image]?

Thank you,

Chris


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]