git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFT PATCH 0/2] win32: optimize emulation of condition variables

From
Paolo Bonzini <bonzini@gnu.org>
Date
Jun 7, 2010, 13:38 UTC
Message-ID
<1275917892-16437-1-git-send-email-bonzini@gnu.org>

I recently looked at git's condvar implementation for use in another project, and found a couple of simple optimization opportunities. We can drop the waiters_lock, and we can make broadcast asynchronous if it is waking up only one thread.

I made two simple tests:
- 1 thread sending a broadcast every 10 msec, 10 threads calling
  pthread_cond_wait every 100 msec.  Timings are (average of three runs):
  before     2.094 us/wait      4.015 us/broadcast
  after      2.064 us/wait      2.883 us/broadcast
  i.e. most broadcasts and waits hit the fast path, the few that don't
  likely avoid the rendez-vous after the patch.  In this case the
  waiters_lock is always hitting its own fast path.  The speedup is
  mostly in broadcast, and comes mostly from the second patch.
- 1 thread sending a broadcast every 100 msec, 10 threads calling
  pthread_cond_wait every 10 msec.  Timings are:
  before     17.59 us/wait      192.2 us/broadcast
  after      8.959 us/wait      141.1 us/broadcast
  i.e. most broadcasts hit the slow path, and there will be also high
  contention on waiters_lock after the broadcast.  In this case the
  speedup comes from avoiding locks in the first patch.

I have tested this patch quite thoroughly outside git, but not as part of it. So help with that would be appreciated.

Thanks,
Paolo
Paolo Bonzini (2):
  win32: optimize condition variable implementation
  win32: optimize pthread_cond_broadcast
 compat/win32/pthread.c |   71 +++++++++++++++++++++++++----------------------
 compat/win32/pthread.h |    1 -
 2 files changed, 38 insertions(+), 34 deletions(-)
Next: Paolo Bonzini
Message 1 of 9 in “win32: optimize emulation of condition variables”
  1. 0/2 win32: optimize emulation of condition variablesPaolo Bonzini, Jun 7, 2010
  2. 1/2 win32: optimize condition variable implementationPaolo Bonzini, Jun 7, 2010
  3. Johannes SixtJun 8, 2010
  4. Paolo BonziniJun 8, 2010
  5. 2/2 win32: optimize pthread_cond_broadcastPaolo Bonzini, Jun 7, 2010
  6. Johannes SixtJun 8, 2010
  7. Paolo BonziniJun 8, 2010
  8. Johannes SixtJun 8, 2010
  9. 3/2 fix race in win32 pthread_cond_signal causing spurious wakeupsPaolo Bonzini, Jun 13, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.