Web process main thread priority is lower than some network process threads.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jun 2014 19:03:04 +0000 (19:03 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Jun 2014 19:03:04 +0000 (19:03 +0000)
<https://webkit.org/b/133987>
<rdar://problem/17330300>

Source/WebKit2:
Mark the main thread as "user initiated" in process entry.

Reviewed by Maciej Stachowiak.

* Shared/ChildProcess.cpp:
(WebKit::ChildProcess::initialize):

Source/WTF:
Bring all of our threads to the appropriate priority level by opting in to the
threading QoS APIs. By marking them "user initiated", they still yield to UI
interaction, but take priority over background tasks.

Reviewed by Maciej Stachowiak.

* wtf/Platform.h:
* wtf/Threading.cpp:
(WTF::setCurrentThreadIsUserInitiated):
* wtf/Threading.h:
* wtf/ThreadingPthreads.cpp:
(WTF::createThreadInternal):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@170065 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WTF/wtf/Threading.cpp
Source/WTF/wtf/Threading.h
Source/WTF/wtf/ThreadingPthreads.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/ChildProcess.cpp

index 0674cf4..e4ab724 100644 (file)
@@ -1,3 +1,22 @@
+2014-06-17  Andreas Kling  <akling@apple.com>
+
+        Web process main thread priority is lower than some network process threads.
+        <https://webkit.org/b/133987>
+        <rdar://problem/17330300>
+
+        Bring all of our threads to the appropriate priority level by opting in to the
+        threading QoS APIs. By marking them "user initiated", they still yield to UI
+        interaction, but take priority over background tasks.
+
+        Reviewed by Maciej Stachowiak.
+
+        * wtf/Platform.h:
+        * wtf/Threading.cpp:
+        (WTF::setCurrentThreadIsUserInitiated):
+        * wtf/Threading.h:
+        * wtf/ThreadingPthreads.cpp:
+        (WTF::createThreadInternal):
+
 2014-06-17  Alex Christensen  <achristensen@webkit.org>
 
         Enable css jit for armv7 on iOS.
index 2e9a575..ba1efda 100644 (file)
 #endif
 
 #ifndef HAVE_QOS_CLASSES
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+#if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000)
 #define HAVE_QOS_CLASSES 1
 #endif
 #endif
index 2721b10..c8d996b 100644 (file)
@@ -91,6 +91,13 @@ void setCurrentThreadIsUserInteractive()
 #endif
 }
 
+void setCurrentThreadIsUserInitiated()
+{
+#if HAVE(QOS_CLASSES)
+    pthread_set_qos_class_self_np(QOS_CLASS_USER_INITIATED, 0);
+#endif
+}
+
 #if PLATFORM(MAC) || PLATFORM(WIN)
 
 // For ABI compatibility with Safari on Mac / Windows: Safari uses the private
index ffbe714..366dfbb 100644 (file)
@@ -84,6 +84,8 @@ WTF_EXPORT_PRIVATE ThreadIdentifier createThread(ThreadFunction, void*, const ch
 // Mark the current thread as requiring UI responsiveness.
 WTF_EXPORT_PRIVATE void setCurrentThreadIsUserInteractive();
 
+WTF_EXPORT_PRIVATE void setCurrentThreadIsUserInitiated();
+
 // Internal platform-specific createThread implementation.
 ThreadIdentifier createThreadInternal(ThreadFunction, void*, const char* threadName);
 
index 925a73f..6192915 100644 (file)
@@ -175,7 +175,14 @@ ThreadIdentifier createThreadInternal(ThreadFunction entryPoint, void* data, con
 {
     auto invocation = std::make_unique<ThreadFunctionInvocation>(entryPoint, data);
     pthread_t threadHandle;
-    if (pthread_create(&threadHandle, 0, wtfThreadEntryPoint, invocation.get())) {
+    pthread_attr_t attr;
+    pthread_attr_init(&attr);
+#if HAVE(QOS_CLASSES)
+    pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INITIATED, 0);
+#endif
+    int error = pthread_create(&threadHandle, &attr, wtfThreadEntryPoint, invocation.get());
+    pthread_attr_destroy(&attr);
+    if (error) {
         LOG_ERROR("Failed to create pthread at entry point %p with data %p", wtfThreadEntryPoint, invocation.get());
         return 0;
     }
index fc2f8ae..a16343c 100644 (file)
@@ -1,3 +1,16 @@
+2014-06-17  Andreas Kling  <akling@apple.com>
+
+        Web process main thread priority is lower than some network process threads.
+        <https://webkit.org/b/133987>
+        <rdar://problem/17330300>
+
+        Mark the main thread as "user initiated" in process entry.
+
+        Reviewed by Maciej Stachowiak.
+
+        * Shared/ChildProcess.cpp:
+        (WebKit::ChildProcess::initialize):
+
 2014-06-17  Anders Carlsson  <andersca@apple.com>
 
         Add SPI to get the NSURLRequest from a WKNavigationResponse
index d5693e9..dad43cd 100644 (file)
@@ -61,6 +61,8 @@ void ChildProcess::initialize(const ChildProcessInitializationParameters& parame
 {
     platformInitialize();
 
+    WTF::setCurrentThreadIsUserInitiated();
+
     initializeProcess(parameters);
     initializeProcessName(parameters);