Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 2d228e1cde1e589047951309e9a9344e92cf15d1
      
https://github.com/WebKit/WebKit/commit/2d228e1cde1e589047951309e9a9344e92cf15d1
  Author: Alejandro G. Castro <[email protected]>
  Date:   2026-09-29 (Tue, 29 Sep 2026)

  Changed paths:
    M Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLGBM.cpp
    M Source/WebKit/Platform/IPC/IPCEvent.h
    M Source/WebKit/Platform/IPC/IPCSemaphore.h
    M Source/WebKit/Platform/IPC/StreamServerConnection.cpp
    M Source/WebKit/Platform/IPC/StreamServerConnection.h
    M Source/WebKit/Platform/IPC/unix/IPCSemaphoreUnix.cpp
    M Tools/TestWebKitAPI/Tests/IPC/StreamConnectionTests.cpp

  Log Message:
  -----------
  [WPE][GTK] Improve GPU process performance by avoiding a lot of wake-up calls 
when WebGL draws
https://bugs.webkit.org/show_bug.cgi?id=323327

Reviewed by Kimmo Kinnunen.

WebGL draw messages are not batched, so the GPU process drains the message
stream faster than the web process fills it and goes to sleep between
draws. Waking it again is an eventfd write on the client, and a poll, a read
and a scheduler round trip on the server, tens of thousands of times a second.
Mesa also defers submission until its command stream fills, so accumulated
draws only start at the frame sync point instead of overlapping the script
that follows them. Together these leave Aquarium 18% slower with the GPU
process than with WebGL in the web process.

We reimplemented the IPC::Semaphore on Linux following the suggestions after
trying other options to make it closer to Apple ports implementation. Now it
has become a token count in a page shared with the peer, carried by a memfd
so the existing file descriptor serialization is unchanged. A waiter polls
the count before parking on it with futex(2), and signal() issues FUTEX_WAKE 
only
when a waiter is actually parked, so a signal that arrives while the peer is
still polling costs two atomic operations and no system call at all.

The memfd is sealed against resizing, so a peer cannot shrink the page under a
mapping and turn the next access into a fault, and the receiving side checks the
seals before mapping a descriptor it did not create. The futex timeout uses the
kernel timespec layout, which is not the libc one on 32-bit targets with a
64-bit time_t.

Polling only pays off on a semaphore that gets signalled while its waiter is
still awake, so it is adaptive. Each semaphore keeps a local hint, polls while
polling keeps succeeding, stops when it does not, and retries once every 64
waits so that a semaphore which becomes busy starts polling again.

Separately, add StreamServerConnection::Client::didRunOutOfMessages(), called
when a connection runs out of messages after dispatching some in the same pass,
and use it in RemoteGraphicsContextGLGBM for a glFlush. When a pass stops at
the message limit, the buffer is checked once more, so a burst that ends
exactly on the limit is still reported in that pass instead of being missed by
the next, empty one.

This way the code is easier to maintain because the stream protocol is 
untouched.

Linux desktop and rpi4 are getting neutral or better results than with
GPUProcess off or current implementation.

Add test: Tools/TestWebKitAPI/Tests/IPC/StreamConnectionTests.cpp

* Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLGBM.cpp:
(WebKit::RemoteGraphicsContextGLGBM::didRunOutOfMessages):
* Source/WebKit/Platform/IPC/IPCEvent.h:
(IPC::createEventSignalPair):
* Source/WebKit/Platform/IPC/IPCSemaphore.h:
* Source/WebKit/Platform/IPC/StreamServerConnection.cpp:
(IPC::StreamServerConnection::dispatchStreamMessages):
* Source/WebKit/Platform/IPC/StreamServerConnection.h:
(IPC::StreamServerConnectionClient::didRunOutOfMessages):
* Source/WebKit/Platform/IPC/unix/IPCSemaphoreUnix.cpp:
(IPC::futexWakeOne):
(IPC::futexWaitWhileZero):
(IPC::mapSemaphoreState):
(IPC::tryDecrement):
(IPC::Semaphore::Semaphore):
(IPC::Semaphore::operator=):
(IPC::Semaphore::signal):
(IPC::Semaphore::waitImpl):
(IPC::Semaphore::wait):
(IPC::Semaphore::waitFor):
(IPC::Semaphore::destroy):
(IPC::Semaphore::~Semaphore):
(IPC::waitImpl): Deleted.
* Tools/TestWebKitAPI/Tests/IPC/StreamConnectionTests.cpp:
(TestWebKitAPI::TEST_F):
(TestWebKitAPI::TEST_P):

Canonical link: https://commits.webkit.org/322146@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to