Title: [165687] trunk/Source
Revision
165687
Author
msab...@apple.com
Date
2014-03-15 17:44:51 -0700 (Sat, 15 Mar 2014)

Log Message

It should be possible to adjust DFG and FTL compiler thread priorities
https://bugs.webkit.org/show_bug.cgi?id=130288

Reviewed by Filip Pizlo.

Added ability to change thread priorities relative to its current priority.
Created options to adjust the priority of the DFG and FTL compilation work thread
pools.  For two core systems, there might be three runnable threads, the main thread,
the DFG compilation thread and the FTL compilation thread.  With the same priority,
the scheduler is free to schedule whatever thread it wants.  By lowering the
compilation threads, the main thread can run.  Further tests may suggest better values
for the new options, priorityDeltaOfDFGCompilerThreads and priorityDeltaOfFTLCompilerThreads.

For a two-core device, this change has a net positive improvement of 1-3% across
SunSpider, Octane, Kraken and AsmBench.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (165686 => 165687)


--- trunk/Source/_javascript_Core/ChangeLog	2014-03-16 00:17:56 UTC (rev 165686)
+++ trunk/Source/_javascript_Core/ChangeLog	2014-03-16 00:44:51 UTC (rev 165687)
@@ -1,3 +1,31 @@
+2014-03-15  Michael Saboff  <msab...@apple.com>
+
+        It should be possible to adjust DFG and FTL compiler thread priorities
+        https://bugs.webkit.org/show_bug.cgi?id=130288
+
+        Reviewed by Filip Pizlo.
+
+        Added ability to change thread priorities relative to its current priority.
+        Created options to adjust the priority of the DFG and FTL compilation work thread
+        pools.  For two core systems, there might be three runnable threads, the main thread,
+        the DFG compilation thread and the FTL compilation thread.  With the same priority,
+        the scheduler is free to schedule whatever thread it wants.  By lowering the
+        compilation threads, the main thread can run.  Further tests may suggest better values
+        for the new options, priorityDeltaOfDFGCompilerThreads and priorityDeltaOfFTLCompilerThreads.
+
+        For a two-core device, this change has a net positive improvement of 1-3% across
+        SunSpider, Octane, Kraken and AsmBench.
+
+        * dfg/DFGWorklist.cpp:
+        (JSC::DFG::Worklist::finishCreation):
+        (JSC::DFG::Worklist::create):
+        (JSC::DFG::ensureGlobalDFGWorklist):
+        (JSC::DFG::ensureGlobalFTLWorklist):
+        * dfg/DFGWorklist.h:
+        * runtime/Options.cpp:
+        (JSC::computePriorityDeltaOfWorkerThreads):
+        * runtime/Options.h:
+
 2014-03-15  David Kilzer  <ddkil...@apple.com>
 
         [iOS] Define SYSTEM_VERSION_PREFIX consistently

Modified: trunk/Source/_javascript_Core/dfg/DFGWorklist.cpp (165686 => 165687)


--- trunk/Source/_javascript_Core/dfg/DFGWorklist.cpp	2014-03-16 00:17:56 UTC (rev 165686)
+++ trunk/Source/_javascript_Core/dfg/DFGWorklist.cpp	2014-03-16 00:44:51 UTC (rev 165687)
@@ -55,20 +55,22 @@
     ASSERT(!m_numberOfActiveThreads);
 }
 
-void Worklist::finishCreation(unsigned numberOfThreads)
+void Worklist::finishCreation(unsigned numberOfThreads, int relativePriority)
 {
     RELEASE_ASSERT(numberOfThreads);
     for (unsigned i = numberOfThreads; i--;) {
         std::unique_ptr<ThreadData> data = ""
         data->m_identifier = createThread(threadFunction, data.get(), "JSC Compilation Thread");
+        if (relativePriority)
+            changeThreadPriority(data->m_identifier, relativePriority);
         m_threads.append(std::move(data));
     }
 }
 
-PassRefPtr<Worklist> Worklist::create(unsigned numberOfThreads)
+PassRefPtr<Worklist> Worklist::create(unsigned numberOfThreads, int relativePriority)
 {
     RefPtr<Worklist> result = adoptRef(new Worklist());
-    result->finishCreation(numberOfThreads);
+    result->finishCreation(numberOfThreads, relativePriority);
     return result;
 }
 
@@ -321,7 +323,7 @@
 {
     static std::once_flag initializeGlobalWorklistOnceFlag;
     std::call_once(initializeGlobalWorklistOnceFlag, [] {
-        theGlobalDFGWorklist = Worklist::create(Options::numberOfDFGCompilerThreads()).leakRef();
+        theGlobalDFGWorklist = Worklist::create(Options::numberOfDFGCompilerThreads(), Options::priorityDeltaOfDFGCompilerThreads()).leakRef();
     });
     return theGlobalDFGWorklist;
 }
@@ -337,7 +339,7 @@
 {
     static std::once_flag initializeGlobalWorklistOnceFlag;
     std::call_once(initializeGlobalWorklistOnceFlag, [] {
-        theGlobalFTLWorklist = Worklist::create(Options::numberOfFTLCompilerThreads()).leakRef();
+        theGlobalFTLWorklist = Worklist::create(Options::numberOfFTLCompilerThreads(), Options::priorityDeltaOfFTLCompilerThreads()).leakRef();
     });
     return theGlobalFTLWorklist;
 }

Modified: trunk/Source/_javascript_Core/dfg/DFGWorklist.h (165686 => 165687)


--- trunk/Source/_javascript_Core/dfg/DFGWorklist.h	2014-03-16 00:17:56 UTC (rev 165686)
+++ trunk/Source/_javascript_Core/dfg/DFGWorklist.h	2014-03-16 00:44:51 UTC (rev 165687)
@@ -49,7 +49,7 @@
 
     ~Worklist();
     
-    static PassRefPtr<Worklist> create(unsigned numberOfThreads);
+    static PassRefPtr<Worklist> create(unsigned numberOfThreads, int relativePriority = 0);
     
     void enqueue(PassRefPtr<Plan>);
     
@@ -77,7 +77,7 @@
     
 private:
     Worklist();
-    void finishCreation(unsigned numberOfThreads);
+    void finishCreation(unsigned numberOfThreads, int);
     
     void runThread(ThreadData*);
     static void threadFunction(void* argument);

Modified: trunk/Source/_javascript_Core/runtime/Options.cpp (165686 => 165687)


--- trunk/Source/_javascript_Core/runtime/Options.cpp	2014-03-16 00:17:56 UTC (rev 165686)
+++ trunk/Source/_javascript_Core/runtime/Options.cpp	2014-03-16 00:44:51 UTC (rev 165687)
@@ -101,6 +101,14 @@
     return std::max(cpusToUse, minimum);
 }
 
+static int32_t computePriorityDeltaOfWorkerThreads(int32_t twoCorePriorityDelta, int32_t multiCorePriorityDelta)
+{
+    if (WTF::numberOfProcessorCores() <= 2)
+        return twoCorePriorityDelta;
+
+    return multiCorePriorityDelta;
+}
+
 static unsigned computeNumberOfGCMarkers(unsigned maxNumberOfGCMarkers)
 {
 #if ENABLE(PARALLEL_GC)

Modified: trunk/Source/_javascript_Core/runtime/Options.h (165686 => 165687)


--- trunk/Source/_javascript_Core/runtime/Options.h	2014-03-16 00:17:56 UTC (rev 165686)
+++ trunk/Source/_javascript_Core/runtime/Options.h	2014-03-16 00:44:51 UTC (rev 165687)
@@ -160,6 +160,8 @@
     v(bool, enableConcurrentJIT, true) \
     v(unsigned, numberOfDFGCompilerThreads, computeNumberOfWorkerThreads(2, 2) - 1) \
     v(unsigned, numberOfFTLCompilerThreads, computeNumberOfWorkerThreads(8, 2) - 1) \
+    v(int32, priorityDeltaOfDFGCompilerThreads, computePriorityDeltaOfWorkerThreads(-1, 0)) \
+    v(int32, priorityDeltaOfFTLCompilerThreads, computePriorityDeltaOfWorkerThreads(-2, 0)) \
     \
     v(bool, enableProfiler, false) \
     \

Modified: trunk/Source/WTF/ChangeLog (165686 => 165687)


--- trunk/Source/WTF/ChangeLog	2014-03-16 00:17:56 UTC (rev 165686)
+++ trunk/Source/WTF/ChangeLog	2014-03-16 00:44:51 UTC (rev 165687)
@@ -1,3 +1,27 @@
+2014-03-15  Michael Saboff  <msab...@apple.com>
+
+        It should be possible to adjust DFG and FTL compiler thread priorities
+        https://bugs.webkit.org/show_bug.cgi?id=130288
+
+        Reviewed by Filip Pizlo.
+
+        Added ability to change thread priorities relative to its current priority.
+        Created options to adjust the priority of the DFG and FTL compilation work thread
+        pools.  For two core systems, there might be three runnable threads, the main thread,
+        the DFG compilation thread and the FTL compilation thread.  With the same priority,
+        the scheduler is free to schedule whatever thread it wants.  By lowering the
+        compilation threads, the main thread can run.  Further tests may suggest better values
+        for the new options, priorityDeltaOfDFGCompilerThreads and priorityDeltaOfFTLCompilerThreads.
+
+        For a two-core device, this change has a net positive improvement of 1-3% across
+        SunSpider, Octane, Kraken and AsmBench.
+
+        * wtf/Threading.h:
+        * wtf/ThreadingPthreads.cpp:
+        (WTF::changeThreadPriority):
+        * wtf/ThreadingWin.cpp:
+        (WTF::changeThreadPriority):
+
 2014-03-15  David Kilzer  <ddkil...@apple.com>
 
         Fix undefined behavior in WTF::equal() in StringImpl.h for i386/x86_64

Modified: trunk/Source/WTF/wtf/Threading.h (165686 => 165687)


--- trunk/Source/WTF/wtf/Threading.h	2014-03-16 00:17:56 UTC (rev 165686)
+++ trunk/Source/WTF/wtf/Threading.h	2014-03-16 00:44:51 UTC (rev 165687)
@@ -89,6 +89,7 @@
 void initializeCurrentThreadInternal(const char* threadName);
 
 WTF_EXPORT_PRIVATE ThreadIdentifier currentThread();
+WTF_EXPORT_PRIVATE void changeThreadPriority(ThreadIdentifier, int);
 WTF_EXPORT_PRIVATE int waitForThreadCompletion(ThreadIdentifier);
 WTF_EXPORT_PRIVATE void detachThread(ThreadIdentifier);
 
@@ -97,6 +98,7 @@
 using WTF::ThreadIdentifier;
 using WTF::createThread;
 using WTF::currentThread;
+using WTF::changeThreadPriority;
 using WTF::detachThread;
 using WTF::waitForThreadCompletion;
 

Modified: trunk/Source/WTF/wtf/ThreadingPthreads.cpp (165686 => 165687)


--- trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2014-03-16 00:17:56 UTC (rev 165686)
+++ trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2014-03-16 00:44:51 UTC (rev 165687)
@@ -203,7 +203,30 @@
     ASSERT(id);
     ThreadIdentifierData::initialize(id);
 }
+    
+void changeThreadPriority(ThreadIdentifier threadID, int delta)
+{
+    pthread_t pthreadHandle;
+    ASSERT(threadID);
 
+    {
+        // We don't want to lock across the call to join, since that can block our thread and cause deadlock.
+        MutexLocker locker(threadMapMutex());
+        pthreadHandle = pthreadHandleForIdentifierWithLockAlreadyHeld(threadID);
+        ASSERT(pthreadHandle);
+    }
+
+    int policy;
+    struct sched_param param;
+
+    if (pthread_getschedparam(pthread_self(), &policy, &param))
+        return;
+
+    param.sched_priority += delta;
+
+    pthread_setschedparam(pthread_self(), policy, &param);
+}
+    
 int waitForThreadCompletion(ThreadIdentifier threadID)
 {
     pthread_t pthreadHandle;

Modified: trunk/Source/WTF/wtf/ThreadingWin.cpp (165686 => 165687)


--- trunk/Source/WTF/wtf/ThreadingWin.cpp	2014-03-16 00:17:56 UTC (rev 165686)
+++ trunk/Source/WTF/wtf/ThreadingWin.cpp	2014-03-16 00:44:51 UTC (rev 165687)
@@ -246,6 +246,17 @@
     return threadID;
 }
 
+void changeThreadPriority(ThreadIdentifier threadID, int delta)
+{
+    ASSERT(threadID);
+
+    HANDLE threadHandle = threadHandleForIdentifier(threadID);
+    if (!threadHandle)
+        LOG_ERROR("ThreadIdentifier %u does not correspond to an active thread", threadID);
+
+    SetThreadPriority(threadHandle, THREAD_PRIORITY_NORMAL + delta);
+}
+
 int waitForThreadCompletion(ThreadIdentifier threadID)
 {
     ASSERT(threadID);

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (165686 => 165687)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2014-03-16 00:17:56 UTC (rev 165686)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2014-03-16 00:44:51 UTC (rev 165687)
@@ -1952,8 +1952,8 @@
 		1A5B1C5318987EDF004FCF9B /* WebDocumentLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebDocumentLoader.h; sourceTree = "<group>"; };
 		1A5E4DA312D3BD3D0099A2BB /* TextCheckerState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCheckerState.h; sourceTree = "<group>"; };
 		1A60224918C16B0800C3E8C9 /* VisitedLinkProvider.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = VisitedLinkProvider.messages.in; sourceTree = "<group>"; };
-		1A60224A18C16B9F00C3E8C9 /* VisitedLinkProviderMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VisitedLinkProviderMessageReceiver.cpp; path = VisitedLinkProviderMessageReceiver.cpp; sourceTree = "<group>"; };
-		1A60224B18C16B9F00C3E8C9 /* VisitedLinkProviderMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VisitedLinkProviderMessages.h; path = VisitedLinkProviderMessages.h; sourceTree = "<group>"; };
+		1A60224A18C16B9F00C3E8C9 /* VisitedLinkProviderMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VisitedLinkProviderMessageReceiver.cpp; sourceTree = "<group>"; };
+		1A60224B18C16B9F00C3E8C9 /* VisitedLinkProviderMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VisitedLinkProviderMessages.h; sourceTree = "<group>"; };
 		1A6420E212DCE2FF00CAAE2C /* ShareableBitmap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShareableBitmap.cpp; sourceTree = "<group>"; };
 		1A6420E312DCE2FF00CAAE2C /* ShareableBitmap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShareableBitmap.h; sourceTree = "<group>"; };
 		1A64228A12DD024700CAAE2C /* DrawingArea.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DrawingArea.messages.in; sourceTree = "<group>"; };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to