Title: [211482] trunk/Source
Revision
211482
Author
akl...@apple.com
Date
2017-02-01 06:55:00 -0800 (Wed, 01 Feb 2017)

Log Message

Implement the alwaysRunsAtBackgroundPriority WK2 setting using thread QoS.
<https://webkit.org/b/167387>
<rdar://problem/29711409>

Reviewed by Antti Koivisto.

Source/bmalloc:

Support changing the QoS level of the scavenger thread asynchronously through
a request variable. This is not the most elegant thing in the world, but since
threads are only allowed to change their own QoS class, our options are limited.

* bmalloc/Heap.cpp:
(bmalloc::Heap::concurrentScavenge):
* bmalloc/Heap.h:
(bmalloc::Heap::takeRequestedScavengerThreadQOSClass):
(bmalloc::Heap::setScavengerThreadQOSClass):
* bmalloc/bmalloc.h:
(bmalloc::api::setScavengerThreadQOSClass):

Source/WebKit2:

Remove the old ProcessThrottlerClient implementation of alwaysRunsAtBackgroundPriority
and replace it with WTF::setGlobalMaxQOSClass().

If the setting is enabled, it's passed over to each WK2 child process along with its
bootstrap parameter, and we notify WTF in XPCServiceInitializer(), before anything
too threading related happens.

* Platform/IPC/Connection.cpp:
(IPC::Connection::processIncomingMessage):
* Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h:
(WebKit::XPCServiceInitializer):
* Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm:
(WebKit::XPCServiceInitializerDelegate::getExtraInitializationData):
* UIProcess/API/APIProcessPoolConfiguration.h:
* UIProcess/ChildProcessProxy.cpp:
(WebKit::ChildProcessProxy::ChildProcessProxy):
(WebKit::ChildProcessProxy::getLaunchOptions):
* UIProcess/ChildProcessProxy.h:
* UIProcess/Databases/DatabaseProcessProxy.cpp:
(WebKit::DatabaseProcessProxy::DatabaseProcessProxy):
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::NetworkProcessProxy):
(WebKit::NetworkProcessProxy::alwaysRunsAtBackgroundPriority): Deleted.
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/ProcessThrottler.cpp:
(WebKit::ProcessThrottler::assertionState):
* UIProcess/ProcessThrottlerClient.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::WebProcessProxy):
(WebKit::WebProcessProxy::alwaysRunsAtBackgroundPriority): Deleted.
* UIProcess/WebProcessProxy.h:

Source/WTF:

Add a new mechanism for overriding the max thread QoS level globally:

    void setGlobalMaxQOSClass(qos_class_t)
    qos_class_t adjustedQOSClass(qos_class_t)

The QoS cap applies to all newly created threads, threads that try to override
their QoS class manually, and also passed down to bmalloc.

* wtf/Threading.cpp:
(WTF::setCurrentThreadIsUserInteractive):
(WTF::setCurrentThreadIsUserInitiated):
(WTF::setGlobalMaxQOSClass):
(WTF::adjustedQOSClass):
* wtf/Threading.h:
* wtf/ThreadingPthreads.cpp:
(WTF::createThreadInternal):
* wtf/cocoa/WorkQueueCocoa.cpp:
(WTF::dispatchQOSClass):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (211481 => 211482)


--- trunk/Source/WTF/ChangeLog	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WTF/ChangeLog	2017-02-01 14:55:00 UTC (rev 211482)
@@ -1,3 +1,30 @@
+2017-02-01  Andreas Kling  <akl...@apple.com>
+
+        Implement the alwaysRunsAtBackgroundPriority WK2 setting using thread QoS.
+        <https://webkit.org/b/167387>
+        <rdar://problem/29711409>
+
+        Reviewed by Antti Koivisto.
+
+        Add a new mechanism for overriding the max thread QoS level globally:
+
+            void setGlobalMaxQOSClass(qos_class_t)
+            qos_class_t adjustedQOSClass(qos_class_t)
+
+        The QoS cap applies to all newly created threads, threads that try to override
+        their QoS class manually, and also passed down to bmalloc.
+
+        * wtf/Threading.cpp:
+        (WTF::setCurrentThreadIsUserInteractive):
+        (WTF::setCurrentThreadIsUserInitiated):
+        (WTF::setGlobalMaxQOSClass):
+        (WTF::adjustedQOSClass):
+        * wtf/Threading.h:
+        * wtf/ThreadingPthreads.cpp:
+        (WTF::createThreadInternal):
+        * wtf/cocoa/WorkQueueCocoa.cpp:
+        (WTF::dispatchQOSClass):
+
 2017-01-31  Antti Koivisto  <an...@apple.com>
 
         Teach cache coders to encode time_points

Modified: trunk/Source/WTF/wtf/Threading.cpp (211481 => 211482)


--- trunk/Source/WTF/wtf/Threading.cpp	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WTF/wtf/Threading.cpp	2017-02-01 14:55:00 UTC (rev 211482)
@@ -31,6 +31,10 @@
 #include <cstring>
 #include <wtf/text/StringView.h>
 
+#if HAVE(QOS_CLASSES)
+#include <bmalloc/bmalloc.h>
+#endif
+
 namespace WTF {
 
 struct NewThreadContext {
@@ -110,7 +114,7 @@
 #if HAVE(QOS_CLASSES)
     ASSERT(relativePriority <= 0);
     ASSERT(relativePriority >= QOS_MIN_RELATIVE_PRIORITY);
-    pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, relativePriority);
+    pthread_set_qos_class_self_np(adjustedQOSClass(QOS_CLASS_USER_INTERACTIVE), relativePriority);
 #else
     UNUSED_PARAM(relativePriority);
 #endif
@@ -121,10 +125,27 @@
 #if HAVE(QOS_CLASSES)
     ASSERT(relativePriority <= 0);
     ASSERT(relativePriority >= QOS_MIN_RELATIVE_PRIORITY);
-    pthread_set_qos_class_self_np(QOS_CLASS_USER_INITIATED, relativePriority);
+    pthread_set_qos_class_self_np(adjustedQOSClass(QOS_CLASS_USER_INITIATED), relativePriority);
 #else
     UNUSED_PARAM(relativePriority);
 #endif
 }
 
+#if HAVE(QOS_CLASSES)
+static qos_class_t globalMaxQOSclass { QOS_CLASS_UNSPECIFIED };
+
+void setGlobalMaxQOSClass(qos_class_t maxClass)
+{
+    bmalloc::api::setScavengerThreadQOSClass(maxClass);
+    globalMaxQOSclass = maxClass;
+}
+
+qos_class_t adjustedQOSClass(qos_class_t originalClass)
+{
+    if (globalMaxQOSclass != QOS_CLASS_UNSPECIFIED)
+        return std::min(originalClass, globalMaxQOSclass);
+    return originalClass;
+}
+#endif
+
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/Threading.h (211481 => 211482)


--- trunk/Source/WTF/wtf/Threading.h	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WTF/wtf/Threading.h	2017-02-01 14:55:00 UTC (rev 211482)
@@ -79,6 +79,11 @@
 
 const char* normalizeThreadName(const char* threadName);
 
+#if HAVE(QOS_CLASSES)
+WTF_EXPORT_PRIVATE void setGlobalMaxQOSClass(qos_class_t);
+WTF_EXPORT_PRIVATE qos_class_t adjustedQOSClass(qos_class_t);
+#endif
+
 } // namespace WTF
 
 using WTF::ThreadIdentifier;
@@ -88,4 +93,9 @@
 using WTF::detachThread;
 using WTF::waitForThreadCompletion;
 
+#if HAVE(QOS_CLASSES)
+using WTF::setGlobalMaxQOSClass;
+using WTF::adjustedQOSClass;
+#endif
+
 #endif // Threading_h

Modified: trunk/Source/WTF/wtf/ThreadingPthreads.cpp (211481 => 211482)


--- trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2017-02-01 14:55:00 UTC (rev 211482)
@@ -176,7 +176,7 @@
     pthread_attr_t attr;
     pthread_attr_init(&attr);
 #if HAVE(QOS_CLASSES)
-    pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INITIATED, 0);
+    pthread_attr_set_qos_class_np(&attr, adjustedQOSClass(QOS_CLASS_USER_INITIATED), 0);
 #endif
     int error = pthread_create(&threadHandle, &attr, wtfThreadEntryPoint, invocation.get());
     pthread_attr_destroy(&attr);

Modified: trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp (211481 => 211482)


--- trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WTF/wtf/cocoa/WorkQueueCocoa.cpp	2017-02-01 14:55:00 UTC (rev 211482)
@@ -49,15 +49,15 @@
 {
     switch (qos) {
     case WorkQueue::QOS::UserInteractive:
-        return QOS_CLASS_USER_INTERACTIVE;
+        return adjustedQOSClass(QOS_CLASS_USER_INTERACTIVE);
     case WorkQueue::QOS::UserInitiated:
-        return QOS_CLASS_USER_INITIATED;
+        return adjustedQOSClass(QOS_CLASS_USER_INITIATED);
     case WorkQueue::QOS::Default:
-        return QOS_CLASS_DEFAULT;
+        return adjustedQOSClass(QOS_CLASS_DEFAULT);
     case WorkQueue::QOS::Utility:
-        return QOS_CLASS_UTILITY;
+        return adjustedQOSClass(QOS_CLASS_UTILITY);
     case WorkQueue::QOS::Background:
-        return QOS_CLASS_BACKGROUND;
+        return adjustedQOSClass(QOS_CLASS_BACKGROUND);
     }
 }
 #else

Modified: trunk/Source/WebKit2/ChangeLog (211481 => 211482)


--- trunk/Source/WebKit2/ChangeLog	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/ChangeLog	2017-02-01 14:55:00 UTC (rev 211482)
@@ -1,3 +1,43 @@
+2017-02-01  Andreas Kling  <akl...@apple.com>
+
+        Implement the alwaysRunsAtBackgroundPriority WK2 setting using thread QoS.
+        <https://webkit.org/b/167387>
+        <rdar://problem/29711409>
+
+        Reviewed by Antti Koivisto.
+
+        Remove the old ProcessThrottlerClient implementation of alwaysRunsAtBackgroundPriority
+        and replace it with WTF::setGlobalMaxQOSClass().
+
+        If the setting is enabled, it's passed over to each WK2 child process along with its
+        bootstrap parameter, and we notify WTF in XPCServiceInitializer(), before anything
+        too threading related happens.
+
+        * Platform/IPC/Connection.cpp:
+        (IPC::Connection::processIncomingMessage):
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h:
+        (WebKit::XPCServiceInitializer):
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm:
+        (WebKit::XPCServiceInitializerDelegate::getExtraInitializationData):
+        * UIProcess/API/APIProcessPoolConfiguration.h:
+        * UIProcess/ChildProcessProxy.cpp:
+        (WebKit::ChildProcessProxy::ChildProcessProxy):
+        (WebKit::ChildProcessProxy::getLaunchOptions):
+        * UIProcess/ChildProcessProxy.h:
+        * UIProcess/Databases/DatabaseProcessProxy.cpp:
+        (WebKit::DatabaseProcessProxy::DatabaseProcessProxy):
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::NetworkProcessProxy):
+        (WebKit::NetworkProcessProxy::alwaysRunsAtBackgroundPriority): Deleted.
+        * UIProcess/Network/NetworkProcessProxy.h:
+        * UIProcess/ProcessThrottler.cpp:
+        (WebKit::ProcessThrottler::assertionState):
+        * UIProcess/ProcessThrottlerClient.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::WebProcessProxy):
+        (WebKit::WebProcessProxy::alwaysRunsAtBackgroundPriority): Deleted.
+        * UIProcess/WebProcessProxy.h:
+
 2017-02-01  Tomas Popela  <tpop...@redhat.com>
 
         [GTK] Add an API to add a custom tab into the print dialog

Modified: trunk/Source/WebKit2/Platform/IPC/Connection.cpp (211481 => 211482)


--- trunk/Source/WebKit2/Platform/IPC/Connection.cpp	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.cpp	2017-02-01 14:55:00 UTC (rev 211482)
@@ -671,7 +671,7 @@
 
 #if HAVE(QOS_CLASSES)
     if (message->isSyncMessage() && m_shouldBoostMainThreadOnSyncMessage) {
-        pthread_override_t override = pthread_override_qos_class_start_np(m_mainThread, QOS_CLASS_USER_INTERACTIVE, 0);
+        pthread_override_t override = pthread_override_qos_class_start_np(m_mainThread, adjustedQOSClass(QOS_CLASS_USER_INTERACTIVE), 0);
         message->setQOSClassOverride(override);
     }
 #endif

Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h (211481 => 211482)


--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h	2017-02-01 14:55:00 UTC (rev 211482)
@@ -101,6 +101,11 @@
     voucher_replace_default_voucher();
 #endif
 
+#if HAVE(QOS_CLASSES)
+    if (parameters.extraInitializationData.contains(ASCIILiteral("always-runs-at-background-priority")))
+        setGlobalMaxQOSClass(QOS_CLASS_UTILITY);
+#endif
+
     XPCServiceType::singleton().initialize(parameters);
 }
 

Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm (211481 => 211482)


--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm	2017-02-01 14:55:00 UTC (rev 211482)
@@ -103,6 +103,10 @@
             extraInitializationData.add(ASCIILiteral("user-directory-suffix"), userDirectorySuffix);
     }
 
+    String alwaysRunsAtBackgroundPriority = xpc_dictionary_get_string(extraDataInitializationDataObject, "always-runs-at-background-priority");
+    if (!alwaysRunsAtBackgroundPriority.isEmpty())
+        extraInitializationData.add(ASCIILiteral("always-runs-at-background-priority"), alwaysRunsAtBackgroundPriority);
+
     return true;
 }
 

Modified: trunk/Source/WebKit2/UIProcess/ChildProcessProxy.cpp (211481 => 211482)


--- trunk/Source/WebKit2/UIProcess/ChildProcessProxy.cpp	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/UIProcess/ChildProcessProxy.cpp	2017-02-01 14:55:00 UTC (rev 211482)
@@ -31,7 +31,8 @@
 
 namespace WebKit {
 
-ChildProcessProxy::ChildProcessProxy()
+ChildProcessProxy::ChildProcessProxy(bool alwaysRunsAtBackgroundPriority)
+    : m_alwaysRunsAtBackgroundPriority(alwaysRunsAtBackgroundPriority)
 {
 }
 
@@ -51,6 +52,9 @@
     if (const char* userDirectorySuffix = getenv("DIRHELPER_USER_DIR_SUFFIX"))
         launchOptions.extraInitializationData.add(ASCIILiteral("user-directory-suffix"), userDirectorySuffix);
 
+    if (m_alwaysRunsAtBackgroundPriority)
+        launchOptions.extraInitializationData.add(ASCIILiteral("always-runs-at-background-priority"), "true");
+
 #if ENABLE(DEVELOPER_MODE) && (PLATFORM(GTK) || PLATFORM(EFL))
     const char* varname;
     switch (launchOptions.processType) {

Modified: trunk/Source/WebKit2/UIProcess/ChildProcessProxy.h (211481 => 211482)


--- trunk/Source/WebKit2/UIProcess/ChildProcessProxy.h	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/UIProcess/ChildProcessProxy.h	2017-02-01 14:55:00 UTC (rev 211482)
@@ -36,8 +36,10 @@
 class ChildProcessProxy : ProcessLauncher::Client, public IPC::Connection::Client, public ThreadSafeRefCounted<ChildProcessProxy> {
     WTF_MAKE_NONCOPYABLE(ChildProcessProxy);
 
+protected:
+    explicit ChildProcessProxy(bool alwaysRunsAtBackgroundPriority = false);
+
 public:
-    ChildProcessProxy();
     virtual ~ChildProcessProxy();
 
     void connect();
@@ -93,6 +95,7 @@
     RefPtr<ProcessLauncher> m_processLauncher;
     RefPtr<IPC::Connection> m_connection;
     IPC::MessageReceiverMap m_messageReceiverMap;
+    bool m_alwaysRunsAtBackgroundPriority { false };
 };
 
 template<typename T>

Modified: trunk/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.cpp (211481 => 211482)


--- trunk/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.cpp	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.cpp	2017-02-01 14:55:00 UTC (rev 211482)
@@ -52,7 +52,8 @@
 }
 
 DatabaseProcessProxy::DatabaseProcessProxy(WebProcessPool* processPool)
-    : m_processPool(processPool)
+    : ChildProcessProxy(processPool->alwaysRunsAtBackgroundPriority())
+    , m_processPool(processPool)
     , m_numPendingConnectionRequests(0)
 {
     connect();

Modified: trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp (211481 => 211482)


--- trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.cpp	2017-02-01 14:55:00 UTC (rev 211482)
@@ -65,7 +65,8 @@
 }
 
 NetworkProcessProxy::NetworkProcessProxy(WebProcessPool& processPool)
-    : m_processPool(processPool)
+    : ChildProcessProxy(processPool.alwaysRunsAtBackgroundPriority())
+    , m_processPool(processPool)
     , m_numPendingConnectionRequests(0)
     , m_customProtocolManagerProxy(this, processPool)
     , m_throttler(*this)
@@ -387,11 +388,6 @@
         send(Messages::NetworkProcess::ProcessDidResume(), 0);
 }
 
-bool NetworkProcessProxy::alwaysRunsAtBackgroundPriority()
-{
-    return m_processPool.alwaysRunsAtBackgroundPriority();
-}
-
 void NetworkProcessProxy::processReadyToSuspend()
 {
     m_throttler.processReadyToSuspend();

Modified: trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h (211481 => 211482)


--- trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h	2017-02-01 14:55:00 UTC (rev 211482)
@@ -93,7 +93,6 @@
     void sendPrepareToSuspend() override;
     void sendCancelPrepareToSuspend() override;
     void sendProcessDidResume() override;
-    bool alwaysRunsAtBackgroundPriority() override;
     void didSetAssertionState(AssertionState) override;
 
     // IPC::Connection::Client

Modified: trunk/Source/WebKit2/UIProcess/ProcessThrottler.cpp (211481 => 211482)


--- trunk/Source/WebKit2/UIProcess/ProcessThrottler.cpp	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/UIProcess/ProcessThrottler.cpp	2017-02-01 14:55:00 UTC (rev 211482)
@@ -47,7 +47,7 @@
     ASSERT(!m_suspendTimer.isActive());
     
     if (m_foregroundCounter.value())
-        return m_process.alwaysRunsAtBackgroundPriority() ? AssertionState::Background : AssertionState::Foreground;
+        return AssertionState::Foreground;
     if (m_backgroundCounter.value())
         return AssertionState::Background;
     return AssertionState::Suspended;

Modified: trunk/Source/WebKit2/UIProcess/ProcessThrottlerClient.h (211481 => 211482)


--- trunk/Source/WebKit2/UIProcess/ProcessThrottlerClient.h	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/UIProcess/ProcessThrottlerClient.h	2017-02-01 14:55:00 UTC (rev 211482)
@@ -38,7 +38,6 @@
     virtual void sendPrepareToSuspend() = 0;
     virtual void sendCancelPrepareToSuspend() = 0;
     virtual void sendProcessDidResume() = 0;
-    virtual bool alwaysRunsAtBackgroundPriority() = 0;
     virtual void didSetAssertionState(AssertionState) = 0;
 };
 

Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp (211481 => 211482)


--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2017-02-01 14:55:00 UTC (rev 211482)
@@ -94,7 +94,8 @@
 }
 
 WebProcessProxy::WebProcessProxy(WebProcessPool& processPool)
-    : m_responsivenessTimer(*this)
+    : ChildProcessProxy(processPool.alwaysRunsAtBackgroundPriority())
+    , m_responsivenessTimer(*this)
     , m_processPool(processPool)
     , m_mayHaveUniversalFileReadSandboxExtension(false)
     , m_numberOfTimesSuddenTerminationWasDisabled(0)
@@ -923,11 +924,6 @@
         send(Messages::WebProcess::ProcessDidResume(), 0);
 }
 
-bool WebProcessProxy::alwaysRunsAtBackgroundPriority()
-{
-    return m_processPool->alwaysRunsAtBackgroundPriority();
-}
-
 void WebProcessProxy::processReadyToSuspend()
 {
     m_throttler.processReadyToSuspend();

Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.h (211481 => 211482)


--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.h	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.h	2017-02-01 14:55:00 UTC (rev 211482)
@@ -207,7 +207,6 @@
     void sendPrepareToSuspend() override;
     void sendCancelPrepareToSuspend() override;
     void sendProcessDidResume() override;
-    bool alwaysRunsAtBackgroundPriority() override;
     void didSetAssertionState(AssertionState) override;
 
     // ProcessLauncher::Client

Modified: trunk/Source/bmalloc/ChangeLog (211481 => 211482)


--- trunk/Source/bmalloc/ChangeLog	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/bmalloc/ChangeLog	2017-02-01 14:55:00 UTC (rev 211482)
@@ -1,3 +1,23 @@
+2017-02-01  Andreas Kling  <akl...@apple.com>
+
+        Implement the alwaysRunsAtBackgroundPriority WK2 setting using thread QoS.
+        <https://webkit.org/b/167387>
+        <rdar://problem/29711409>
+
+        Reviewed by Antti Koivisto.
+
+        Support changing the QoS level of the scavenger thread asynchronously through
+        a request variable. This is not the most elegant thing in the world, but since
+        threads are only allowed to change their own QoS class, our options are limited.
+
+        * bmalloc/Heap.cpp:
+        (bmalloc::Heap::concurrentScavenge):
+        * bmalloc/Heap.h:
+        (bmalloc::Heap::takeRequestedScavengerThreadQOSClass):
+        (bmalloc::Heap::setScavengerThreadQOSClass):
+        * bmalloc/bmalloc.h:
+        (bmalloc::api::setScavengerThreadQOSClass):
+
 2017-01-13  Geoffrey Garen  <gga...@apple.com>
 
         bmalloc: Use a separate zone when using system malloc

Modified: trunk/Source/bmalloc/bmalloc/Heap.cpp (211481 => 211482)


--- trunk/Source/bmalloc/bmalloc/Heap.cpp	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/bmalloc/bmalloc/Heap.cpp	2017-02-01 14:55:00 UTC (rev 211482)
@@ -109,6 +109,12 @@
 void Heap::concurrentScavenge()
 {
     std::unique_lock<StaticMutex> lock(PerProcess<Heap>::mutex());
+
+#if BOS(DARWIN)
+    if (auto requestedQOSClass = PerProcess<Heap>::getFastCase()->takeRequestedScavengerThreadQOSClass())
+        pthread_set_qos_class_self_np(requestedQOSClass, 0);
+#endif
+
     scavenge(lock, scavengeSleepDuration);
 }
 

Modified: trunk/Source/bmalloc/bmalloc/Heap.h (211481 => 211482)


--- trunk/Source/bmalloc/bmalloc/Heap.h	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/bmalloc/bmalloc/Heap.h	2017-02-01 14:55:00 UTC (rev 211482)
@@ -68,6 +68,11 @@
 
     void scavenge(std::unique_lock<StaticMutex>&, std::chrono::milliseconds sleepDuration);
 
+#if BOS(DARWIN)
+    qos_class_t takeRequestedScavengerThreadQOSClass() { return std::exchange(m_requestedScavengerThreadQOSClass, QOS_CLASS_UNSPECIFIED); }
+    void setScavengerThreadQOSClass(qos_class_t overrideClass) { m_requestedScavengerThreadQOSClass = overrideClass; }
+#endif
+
 private:
     struct LargeObjectHash {
         static unsigned hash(void* key)
@@ -120,6 +125,10 @@
     DebugHeap* m_debugHeap;
 
     VMHeap m_vmHeap;
+
+#if BOS(DARWIN)
+    qos_class_t m_requestedScavengerThreadQOSClass { QOS_CLASS_UNSPECIFIED };
+#endif
 };
 
 inline void Heap::allocateSmallBumpRanges(

Modified: trunk/Source/bmalloc/bmalloc/bmalloc.h (211481 => 211482)


--- trunk/Source/bmalloc/bmalloc/bmalloc.h	2017-02-01 14:14:36 UTC (rev 211481)
+++ trunk/Source/bmalloc/bmalloc/bmalloc.h	2017-02-01 14:55:00 UTC (rev 211482)
@@ -85,5 +85,13 @@
     return !PerProcess<Heap>::getFastCase()->debugHeap();
 }
 
+#if BOS(DARWIN)
+inline void setScavengerThreadQOSClass(qos_class_t overrideClass)
+{
+    std::unique_lock<StaticMutex> lock(PerProcess<Heap>::mutex());
+    PerProcess<Heap>::getFastCase()->setScavengerThreadQOSClass(overrideClass);
+}
+#endif
+
 } // namespace api
 } // namespace bmalloc
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to