Title: [117478] trunk/Source/WTF
Revision
117478
Author
gga...@apple.com
Date
2012-05-17 12:08:03 -0700 (Thu, 17 May 2012)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (117477 => 117478)


--- trunk/Source/WTF/ChangeLog	2012-05-17 19:07:57 UTC (rev 117477)
+++ trunk/Source/WTF/ChangeLog	2012-05-17 19:08:03 UTC (rev 117478)
@@ -1,3 +1,25 @@
+2012-05-16  Geoffrey Garen  <gga...@apple.com>
+
+        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.
+
 2012-05-16  Simon Fraser  <simon.fra...@apple.com>
 
         Make things build with DUMP_HASHTABLE_STATS=1

Modified: trunk/Source/WTF/wtf/TCSpinLock.h (117477 => 117478)


--- trunk/Source/WTF/wtf/TCSpinLock.h	2012-05-17 19:07:57 UTC (rev 117477)
+++ trunk/Source/WTF/wtf/TCSpinLock.h	2012-05-17 19:08:03 UTC (rev 117478)
@@ -129,13 +129,14 @@
 #define SPINLOCK_INITIALIZER { 0 }
 
 static void TCMalloc_SlowLock(volatile unsigned int* lockword) {
-// Yield immediately since fast path failed
+  while (true) {
+    // Yield immediately since fast path failed
 #if OS(WINDOWS)
-  Sleep(0);
+    Sleep(0);
 #else
-  sched_yield();
+    sched_yield();
 #endif
-  while (true) {
+
     int r;
 #if COMPILER(GCC)
 #if CPU(X86) || CPU(X86_64)
@@ -167,25 +168,6 @@
     if (!r) {
       return;
     }
-
-    // This code was adapted from the ptmalloc2 implementation of
-    // spinlocks which would sched_yield() upto 50 times before
-    // sleeping once for a few milliseconds.  Mike Burrows suggested
-    // just doing one sched_yield() outside the loop and always
-    // sleeping after that.  This change helped a great deal on the
-    // performance of spinlocks under high contention.  A test program
-    // with 10 threads on a dual Xeon (four virtual processors) went
-    // from taking 30 seconds to 16 seconds.
-
-    // Sleep for a few milliseconds
-#if OS(WINDOWS)
-    Sleep(2);
-#else
-    struct timespec tm;
-    tm.tv_sec = 0;
-    tm.tv_nsec = 2000001;
-    nanosleep(&tm, NULL);
-#endif
   }
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to