Changeset 117478


Ignore:
Timestamp:
05/17/12 12:08:03 (2 years ago)
Author:
ggaren@apple.com
Message:

This is not a joke: 3.7X speedup from removing a call to sleep
https://bugs.webkit.org/show_bug.cgi?id=86702

Reviewed by Eric Seidel.

The speedup was on a GC benchmark, with a custom VM caching layer
not in TOT yet.

Instruments showed most GC threads spending the majority of their
time sleeping instead of doing useful work. Removing the call to
sleep sped up the benchmark.

  • wtf/TCSpinLock.h:

(TCMalloc_SlowLock): Since a spin lock is only ever held for a short
amount of time, don't sleep for a long amount of time waiting for it
to unlock -- yielding to the scheduler is sufficient.

If we find a case where someone is sitting on a spin lock for over 2ms,
we should fix the spin lock holder, not the spin lock.

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r117311 r117478  
     12012-05-16  Geoffrey Garen  <ggaren@apple.com> 
     2 
     3        This is not a joke: 3.7X speedup from removing a call to sleep 
     4        https://bugs.webkit.org/show_bug.cgi?id=86702 
     5 
     6        Reviewed by Eric Seidel. 
     7 
     8        The speedup was on a GC benchmark, with a custom VM caching layer 
     9        not in TOT yet. 
     10 
     11        Instruments showed most GC threads spending the majority of their 
     12        time sleeping instead of doing useful work. Removing the call to 
     13        sleep sped up the benchmark. 
     14 
     15        * wtf/TCSpinLock.h: 
     16        (TCMalloc_SlowLock): Since a spin lock is only ever held for a short 
     17        amount of time, don't sleep for a long amount of time waiting for it 
     18        to unlock -- yielding to the scheduler is sufficient. 
     19 
     20        If we find a case where someone is sitting on a spin lock for over 2ms, 
     21        we should fix the spin lock holder, not the spin lock. 
     22 
    1232012-05-16  Simon Fraser  <simon.fraser@apple.com> 
    224 
  • trunk/Source/WTF/wtf/TCSpinLock.h

    r113571 r117478  
    130130 
    131131static void TCMalloc_SlowLock(volatile unsigned int* lockword) { 
    132 // Yield immediately since fast path failed 
     132  while (true) { 
     133    // Yield immediately since fast path failed 
    133134#if OS(WINDOWS) 
    134   Sleep(0); 
    135 #else 
    136   sched_yield(); 
    137 #endif 
    138   while (true) { 
     135    Sleep(0); 
     136#else 
     137    sched_yield(); 
     138#endif 
     139 
    139140    int r; 
    140141#if COMPILER(GCC) 
     
    168169      return; 
    169170    } 
    170  
    171     // This code was adapted from the ptmalloc2 implementation of 
    172     // spinlocks which would sched_yield() upto 50 times before 
    173     // sleeping once for a few milliseconds.  Mike Burrows suggested 
    174     // just doing one sched_yield() outside the loop and always 
    175     // sleeping after that.  This change helped a great deal on the 
    176     // performance of spinlocks under high contention.  A test program 
    177     // with 10 threads on a dual Xeon (four virtual processors) went 
    178     // from taking 30 seconds to 16 seconds. 
    179  
    180     // Sleep for a few milliseconds 
    181 #if OS(WINDOWS) 
    182     Sleep(2); 
    183 #else 
    184     struct timespec tm; 
    185     tm.tv_sec = 0; 
    186     tm.tv_nsec = 2000001; 
    187     nanosleep(&tm, NULL); 
    188 #endif 
    189171  } 
    190172} 
Note: See TracChangeset for help on using the changeset viewer.