<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[182028] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/182028">182028</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2015-03-26 15:20:45 -0700 (Thu, 26 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Darwin] Boost the web process QoS level while handling a synchronous IPC message.
&lt;https://webkit.org/b/142988&gt;
&lt;rdar://problem/20264346&gt;

Reviewed by Antti Koivisto and Anders Carlsson.

Add a mechanism for IPC::Connection to boost the main thread for the duration
of processing a synchronous message.

This fixes an issue where the UI process would block on a synchronous request
to the web process that was being carried out at a lower QoS level.

* Platform/IPC/Connection.cpp:
(IPC::Connection::Connection): Save the main thread's pthread_t while we have
a chance to retreive it.

(IPC::Connection::processIncomingMessage): Optionally boost the main thread when
processing an incoming message with the IsSyncMessage flag set.

* Platform/IPC/Connection.h:
(IPC::Connection::setShouldBoostMainThreadOnSyncMessage): Added. When this mode is
enabled, Connection will give a temporary QoS override to the main thread when
receiving a synchronous message. Ownership of the override is handed to the
MessageDecoder, which resets the main thread QoS in its destructor.

* Platform/IPC/MessageDecoder.cpp:
(IPC::MessageDecoder::~MessageDecoder): Remove any QoS override owned by this message.

* Platform/IPC/MessageDecoder.h:
(IPC::MessageDecoder::setQOSClassOverride): Added. Takes ownership of a QoS override
to make sure it stays in effect until this message has been dispatched.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeConnection): Set up main thread QoS boosting for the
web process's connection to the UI process.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformIPCConnectioncpp">trunk/Source/WebKit2/Platform/IPC/Connection.cpp</a></li>
<li><a href="#trunkSourceWebKit2PlatformIPCConnectionh">trunk/Source/WebKit2/Platform/IPC/Connection.h</a></li>
<li><a href="#trunkSourceWebKit2PlatformIPCMessageDecodercpp">trunk/Source/WebKit2/Platform/IPC/MessageDecoder.cpp</a></li>
<li><a href="#trunkSourceWebKit2PlatformIPCMessageDecoderh">trunk/Source/WebKit2/Platform/IPC/MessageDecoder.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebProcesscpp">trunk/Source/WebKit2/WebProcess/WebProcess.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (182027 => 182028)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-03-26 22:09:35 UTC (rev 182027)
+++ trunk/Source/WebKit2/ChangeLog        2015-03-26 22:20:45 UTC (rev 182028)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2015-03-26  Andreas Kling  &lt;akling@apple.com&gt;
+
+        [Darwin] Boost the web process QoS level while handling a synchronous IPC message.
+        &lt;https://webkit.org/b/142988&gt;
+        &lt;rdar://problem/20264346&gt;
+
+        Reviewed by Antti Koivisto and Anders Carlsson.
+
+        Add a mechanism for IPC::Connection to boost the main thread for the duration
+        of processing a synchronous message.
+
+        This fixes an issue where the UI process would block on a synchronous request
+        to the web process that was being carried out at a lower QoS level.
+
+        * Platform/IPC/Connection.cpp:
+        (IPC::Connection::Connection): Save the main thread's pthread_t while we have
+        a chance to retreive it.
+
+        (IPC::Connection::processIncomingMessage): Optionally boost the main thread when
+        processing an incoming message with the IsSyncMessage flag set.
+
+        * Platform/IPC/Connection.h:
+        (IPC::Connection::setShouldBoostMainThreadOnSyncMessage): Added. When this mode is
+        enabled, Connection will give a temporary QoS override to the main thread when
+        receiving a synchronous message. Ownership of the override is handed to the
+        MessageDecoder, which resets the main thread QoS in its destructor.
+
+        * Platform/IPC/MessageDecoder.cpp:
+        (IPC::MessageDecoder::~MessageDecoder): Remove any QoS override owned by this message.
+
+        * Platform/IPC/MessageDecoder.h:
+        (IPC::MessageDecoder::setQOSClassOverride): Added. Takes ownership of a QoS override
+        to make sure it stays in effect until this message has been dispatched.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeConnection): Set up main thread QoS boosting for the
+        web process's connection to the UI process.
+
</ins><span class="cx"> 2015-03-26  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Cursor doesn't change back to pointer when leaving Mail
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/Connection.cpp (182027 => 182028)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/Connection.cpp        2015-03-26 22:09:35 UTC (rev 182027)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.cpp        2015-03-26 22:20:45 UTC (rev 182028)
</span><span class="lines">@@ -256,6 +256,11 @@
</span><span class="cx">     ASSERT(m_client);
</span><span class="cx"> 
</span><span class="cx">     platformInitialize(identifier);
</span><ins>+
+#if HAVE(QOS_CLASSES)
+    ASSERT(pthread_main_np());
+    m_mainThread = pthread_self();
+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Connection::~Connection()
</span><span class="lines">@@ -680,6 +685,13 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+#if HAVE(QOS_CLASSES)
+    if (message-&gt;isSyncMessage() &amp;&amp; m_shouldBoostMainThreadOnSyncMessage) {
+        pthread_override_t override = pthread_override_qos_class_start_np(m_mainThread, QOS_CLASS_USER_INTERACTIVE, 0);
+        message-&gt;setQOSClassOverride(override);
+    }
+#endif
+
</ins><span class="cx">     // Check if this is a sync message or if it's a message that should be dispatched even when waiting for
</span><span class="cx">     // a sync reply. If it is, and we're waiting for a sync reply this message needs to be dispatched.
</span><span class="cx">     // If we don't we'll end up with a deadlock where both sync message senders are stuck waiting for a reply.
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/Connection.h (182027 => 182028)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/Connection.h        2015-03-26 22:09:35 UTC (rev 182027)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.h        2015-03-26 22:20:45 UTC (rev 182028)
</span><span class="lines">@@ -200,6 +200,10 @@
</span><span class="cx"> 
</span><span class="cx">     bool isValid() const { return m_client; }
</span><span class="cx"> 
</span><ins>+#if HAVE(QOS_CLASSES)
+    void setShouldBoostMainThreadOnSyncMessage(bool b) { m_shouldBoostMainThreadOnSyncMessage = b; }
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx">     Connection(Identifier, bool isServer, Client&amp;, WTF::RunLoop&amp; clientRunLoop);
</span><span class="cx">     void platformInitialize(Identifier);
</span><span class="lines">@@ -304,6 +308,11 @@
</span><span class="cx">     typedef HashMap&lt;uint64_t, SecondaryThreadPendingSyncReply*&gt; SecondaryThreadPendingSyncReplyMap;
</span><span class="cx">     SecondaryThreadPendingSyncReplyMap m_secondaryThreadPendingSyncReplyMap;
</span><span class="cx"> 
</span><ins>+#if HAVE(QOS_CLASSES)
+    pthread_t m_mainThread { 0 };
+    bool m_shouldBoostMainThreadOnSyncMessage { false };
+#endif
+
</ins><span class="cx"> #if OS(DARWIN)
</span><span class="cx">     // Called on the connection queue.
</span><span class="cx">     void receiveSourceEventHandler();
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCMessageDecodercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/MessageDecoder.cpp (182027 => 182028)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/MessageDecoder.cpp        2015-03-26 22:09:35 UTC (rev 182027)
+++ trunk/Source/WebKit2/Platform/IPC/MessageDecoder.cpp        2015-03-26 22:20:45 UTC (rev 182028)
</span><span class="lines">@@ -39,6 +39,10 @@
</span><span class="cx"> 
</span><span class="cx"> MessageDecoder::~MessageDecoder()
</span><span class="cx"> {
</span><ins>+#if HAVE(QOS_CLASSES)
+    if (m_qosClassOverride)
+        pthread_override_qos_class_end_np(m_qosClassOverride);
+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> MessageDecoder::MessageDecoder(const DataReference&amp; buffer, Vector&lt;Attachment&gt; attachments)
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCMessageDecoderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/MessageDecoder.h (182027 => 182028)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/MessageDecoder.h        2015-03-26 22:09:35 UTC (rev 182027)
+++ trunk/Source/WebKit2/Platform/IPC/MessageDecoder.h        2015-03-26 22:20:45 UTC (rev 182028)
</span><span class="lines">@@ -34,6 +34,10 @@
</span><span class="cx"> #include &lt;uuid/uuid.h&gt;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if HAVE(QOS_CLASSES)
+#include &lt;pthread/qos.h&gt;
+#endif
+
</ins><span class="cx"> namespace IPC {
</span><span class="cx"> 
</span><span class="cx"> class DataReference;
</span><span class="lines">@@ -55,6 +59,10 @@
</span><span class="cx">     void setImportanceAssertion(std::unique_ptr&lt;ImportanceAssertion&gt;);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if HAVE(QOS_CLASSES)
+    void setQOSClassOverride(pthread_override_t override) { m_qosClassOverride = override; }
+#endif
+
</ins><span class="cx"> #if HAVE(DTRACE)
</span><span class="cx">     void setMessageProcessingToken(std::unique_ptr&lt;MessageRecorder::MessageProcessingToken&gt; token) { m_processingToken = WTF::move(token); }
</span><span class="cx"> 
</span><span class="lines">@@ -76,6 +84,10 @@
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     std::unique_ptr&lt;ImportanceAssertion&gt; m_importanceAssertion;
</span><span class="cx"> #endif
</span><ins>+
+#if HAVE(QOS_CLASSES)
+    pthread_override_t m_qosClassOverride { nullptr };
+#endif
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace IPC
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (182027 => 182028)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2015-03-26 22:09:35 UTC (rev 182027)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2015-03-26 22:20:45 UTC (rev 182028)
</span><span class="lines">@@ -223,6 +223,10 @@
</span><span class="cx"> 
</span><span class="cx">     connection-&gt;setShouldExitOnSyncMessageSendFailure(true);
</span><span class="cx"> 
</span><ins>+#if HAVE(QOS_CLASSES)
+    connection-&gt;setShouldBoostMainThreadOnSyncMessage(true);
+#endif
+
</ins><span class="cx">     m_eventDispatcher-&gt;initializeConnection(connection);
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">     m_viewUpdateDispatcher-&gt;initializeConnection(connection);
</span></span></pre>
</div>
</div>

</body>
</html>