Title: [283696] trunk/Source/WebKit
Revision
283696
Author
[email protected]
Date
2021-10-06 19:21:13 -0700 (Wed, 06 Oct 2021)

Log Message

Add a configurable wake up message hysteresis to IPC::StreamClientConnection
https://bugs.webkit.org/show_bug.cgi?id=231304

Reviewed by Simon Fraser.

Make it possible to avoid sending the wakeup message in StreamClientConnection, until some configurable number
of messages have been queued up. This allows us to avoid triggering excessive wakeups in the GPU Process when
using streaming IPC for display lists in the Canvas Lines subtest in MotionMark, which exercises sending a
massive, constant stream of cheap drawing commands to the GPUP.

By default, this hysteresis remains at 0, which means that we'll continue to immediately send GL commands to the
GPU Process when using GPU Process for WebGL. In a future patch, I intend on defaulting to a small hysteresis
(i.e. ~256) for 2D canvas and DOM rendering.

* Platform/IPC/StreamClientConnection.cpp:
(IPC::StreamClientConnection::wakeUpServer):
(IPC::StreamClientConnection::deferredWakeUpServer):
(IPC::StreamClientConnection::decrementRemainingMessageCountBeforeSendingWakeUp):
(IPC::StreamClientConnection::sendDeferredWakeUpMessageIfNeeded):
* Platform/IPC/StreamClientConnection.h:

Also mark StreamClientConnection with `WTF_MAKE_FAST_ALLOCATED`, so that we can wrap the client connection in a
`std::unique_ptr` in a future patch.

(IPC::StreamClientConnection::trySendStream):

When sending a normal (non-blocking) stream message, if the wakeup hysteresis count is non-zero, avoid
immediately signaling the semaphore and instead just set the hysteresis count to the client's specified count
(`m_wakeUpMessageHysteresis`).

(IPC::StreamClientConnection::trySendSyncStream):

When sending a sync message, we always want to immediately flush out any pending wakeup message regardless of
the current hysteresis, since we're waiting for the server to process a reply.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (283695 => 283696)


--- trunk/Source/WebKit/ChangeLog	2021-10-07 02:15:33 UTC (rev 283695)
+++ trunk/Source/WebKit/ChangeLog	2021-10-07 02:21:13 UTC (rev 283696)
@@ -1,5 +1,42 @@
 2021-10-06  Wenson Hsieh  <[email protected]>
 
+        Add a configurable wake up message hysteresis to IPC::StreamClientConnection
+        https://bugs.webkit.org/show_bug.cgi?id=231304
+
+        Reviewed by Simon Fraser.
+
+        Make it possible to avoid sending the wakeup message in StreamClientConnection, until some configurable number
+        of messages have been queued up. This allows us to avoid triggering excessive wakeups in the GPU Process when
+        using streaming IPC for display lists in the Canvas Lines subtest in MotionMark, which exercises sending a
+        massive, constant stream of cheap drawing commands to the GPUP.
+
+        By default, this hysteresis remains at 0, which means that we'll continue to immediately send GL commands to the
+        GPU Process when using GPU Process for WebGL. In a future patch, I intend on defaulting to a small hysteresis
+        (i.e. ~256) for 2D canvas and DOM rendering.
+
+        * Platform/IPC/StreamClientConnection.cpp:
+        (IPC::StreamClientConnection::wakeUpServer):
+        (IPC::StreamClientConnection::deferredWakeUpServer):
+        (IPC::StreamClientConnection::decrementRemainingMessageCountBeforeSendingWakeUp):
+        (IPC::StreamClientConnection::sendDeferredWakeUpMessageIfNeeded):
+        * Platform/IPC/StreamClientConnection.h:
+
+        Also mark StreamClientConnection with `WTF_MAKE_FAST_ALLOCATED`, so that we can wrap the client connection in a
+        `std::unique_ptr` in a future patch.
+
+        (IPC::StreamClientConnection::trySendStream):
+
+        When sending a normal (non-blocking) stream message, if the wakeup hysteresis count is non-zero, avoid
+        immediately signaling the semaphore and instead just set the hysteresis count to the client's specified count
+        (`m_wakeUpMessageHysteresis`).
+
+        (IPC::StreamClientConnection::trySendSyncStream):
+
+        When sending a sync message, we always want to immediately flush out any pending wakeup message regardless of
+        the current hysteresis, since we're waiting for the server to process a reply.
+
+2021-10-06  Wenson Hsieh  <[email protected]>
+
         Fix unified source-related build failures in RemoteSourceBufferProxy.cpp
         https://bugs.webkit.org/show_bug.cgi?id=231335
 

Modified: trunk/Source/WebKit/Platform/IPC/StreamClientConnection.cpp (283695 => 283696)


--- trunk/Source/WebKit/Platform/IPC/StreamClientConnection.cpp	2021-10-07 02:15:33 UTC (rev 283695)
+++ trunk/Source/WebKit/Platform/IPC/StreamClientConnection.cpp	2021-10-07 02:21:13 UTC (rev 283696)
@@ -46,8 +46,36 @@
 
 void StreamClientConnection::wakeUpServer()
 {
-    if (m_wakeUpSemaphore)
-        m_wakeUpSemaphore->signal();
+    if (!m_wakeUpSemaphore)
+        return;
+
+    m_wakeUpSemaphore->signal();
+    m_remainingMessageCountBeforeSendingWakeUp = 0;
 }
 
+void StreamClientConnection::deferredWakeUpServer()
+{
+    if (m_wakeUpMessageHysteresis)
+        m_remainingMessageCountBeforeSendingWakeUp = m_wakeUpMessageHysteresis;
+    else
+        wakeUpServer();
 }
+
+void StreamClientConnection::decrementRemainingMessageCountBeforeSendingWakeUp()
+{
+    if (!m_remainingMessageCountBeforeSendingWakeUp)
+        return;
+
+    if (!--m_remainingMessageCountBeforeSendingWakeUp)
+        wakeUpServer();
+}
+
+void StreamClientConnection::sendDeferredWakeUpMessageIfNeeded()
+{
+    if (!m_remainingMessageCountBeforeSendingWakeUp)
+        return;
+
+    wakeUpServer();
+}
+
+}

Modified: trunk/Source/WebKit/Platform/IPC/StreamClientConnection.h (283695 => 283696)


--- trunk/Source/WebKit/Platform/IPC/StreamClientConnection.h	2021-10-07 02:15:33 UTC (rev 283695)
+++ trunk/Source/WebKit/Platform/IPC/StreamClientConnection.h	2021-10-07 02:21:13 UTC (rev 283696)
@@ -47,6 +47,7 @@
 //
 // The StreamClientConnection trusts the StreamServerConnection.
 class StreamClientConnection final {
+    WTF_MAKE_FAST_ALLOCATED;
     WTF_MAKE_NONCOPYABLE(StreamClientConnection);
 public:
     StreamClientConnection(Connection&, size_t bufferSize);
@@ -54,6 +55,13 @@
     StreamConnectionBuffer& streamBuffer() { return m_buffer; }
     void setWakeUpSemaphore(IPC::Semaphore&&);
 
+    void setWakeUpMessageHysteresis(unsigned hysteresis)
+    {
+        ASSERT(!m_remainingMessageCountBeforeSendingWakeUp);
+        m_wakeUpMessageHysteresis = hysteresis;
+    }
+    void sendDeferredWakeUpMessageIfNeeded();
+
     template<typename T, typename U> bool send(T&& message, ObjectIdentifier<U> destinationID, Timeout);
 
     using SendSyncResult = Connection::SendSyncResult;
@@ -83,6 +91,8 @@
     };
     WakeUpServer release(size_t writeSize);
     void wakeUpServer();
+    void deferredWakeUpServer();
+    void decrementRemainingMessageCountBeforeSendingWakeUp();
 
     Span alignedSpan(size_t offset, size_t limit);
     size_t size(size_t offset, size_t limit);
@@ -103,6 +113,8 @@
     size_t m_clientOffset { 0 };
     StreamConnectionBuffer m_buffer;
     std::optional<Semaphore> m_wakeUpSemaphore;
+    unsigned m_remainingMessageCountBeforeSendingWakeUp { 0 };
+    unsigned m_wakeUpMessageHysteresis { 0 };
 };
 
 template<typename T, typename U>
@@ -131,7 +143,9 @@
     if (messageEncoder << message.arguments()) {
         auto wakeupResult = release(messageEncoder.size());
         if (wakeupResult == StreamClientConnection::WakeUpServer::Yes)
-            wakeUpServer();
+            deferredWakeUpServer();
+        else
+            decrementRemainingMessageCountBeforeSendingWakeUp();
         return true;
     }
     return false;
@@ -172,6 +186,8 @@
 
         if (wakeupResult == StreamClientConnection::WakeUpServer::Yes)
             wakeUpServer();
+        else
+            sendDeferredWakeUpMessageIfNeeded();
         if constexpr(T::isReplyStreamEncodable) {
             auto replySpan = tryAcquireAll(timeout);
             if (!replySpan)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to