Bug 220974

Summary: WebGL IPC should use shared memory for synchronous messages
Product: WebKit Reporter: Kimmo Kinnunen <kkinnunen>
Component: WebGLAssignee: Kimmo Kinnunen <kkinnunen>
Status: RESOLVED FIXED    
Severity: Normal CC: dino, ggaren, kbr, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 219641, 222305, 222546    
Bug Blocks: 217211, 222726, 222722    
Attachments:
Description Flags
Patch
none
rebase
none
rebase
none
rebase none

Kimmo Kinnunen
Reported 2021-01-26 05:54:13 PST
WebGL IPC should send synchronised messages through the shared memory. Also the replies should by default be written to the shared memory.
Attachments
Patch (75.71 KB, patch)
2021-03-03 03:31 PST, Kimmo Kinnunen
no flags
rebase (77.40 KB, patch)
2021-03-15 05:49 PDT, Kimmo Kinnunen
no flags
rebase (77.39 KB, patch)
2021-03-15 05:51 PDT, Kimmo Kinnunen
no flags
rebase (77.42 KB, patch)
2021-03-15 06:14 PDT, Kimmo Kinnunen
no flags
Radar WebKit Bug Importer
Comment 1 2021-02-02 05:55:13 PST
Kimmo Kinnunen
Comment 2 2021-03-03 03:31:47 PST
Geoffrey Garen
Comment 3 2021-03-10 14:14:01 PST
Comment on attachment 422055 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=422055&action=review Nice speedup! I think I may have spotted a small bug. Can you re-check EWS (and the small bug) before landing? > Source/WebKit/Platform/IPC/Connection.h:326 > + bool pushPendingSyncRequestID(uint64_t syncRequestID = 0); Can we remove the default 0 argument here? Feels like it might invite mistakes. Seems unused so far. > Source/WebKit/Platform/IPC/StreamClientConnection.h:284 > +#if PLATFORM(COCOA) > + ClientLimit clientLimit = sharedClientLimit().exchange(ClientLimit::clientIsWaitingTag, std::memory_order_acq_rel); > + ClientOffset clientOffset = sharedClientOffset().load(std::memory_order_acquire); > +#else > + ClientLimit clientLimit = sharedClientLimit().load(std::memory_order_acquire); > + ClientOffset clientOffset = sharedClientOffset().load(std::memory_order_acquire); > +#endif > + if (!clientLimit && (clientOffset == ClientOffset::serverIsSleepingTag || !clientOffset)) > + break; In the iteration where we break out of the loop, we temporarily set clientIsWaitingTag, but never wait on our semaphore. What happens if the server notices clientIsWaitingTag, and signals our semaphore, before we have a chance to clear clientIsWaitingTag? Does that put our semaphore out of balance? Perhaps it would be better to just do two loads (removing the cocoa-specific path), and only store clientIsWaitingTag right before we wait.
Kimmo Kinnunen
Comment 4 2021-03-15 05:49:51 PDT
Kimmo Kinnunen
Comment 5 2021-03-15 05:51:34 PDT
Kimmo Kinnunen
Comment 6 2021-03-15 06:11:56 PDT
Thanks for the review! (In reply to Geoffrey Garen from comment #3) > In the iteration where we break out of the loop, we temporarily set > clientIsWaitingTag, but never wait on our semaphore. What happens if the > server notices clientIsWaitingTag, and signals our semaphore, before we have > a chance to clear clientIsWaitingTag? Does that put our semaphore out of > balance? All the sites expect spurious wakeups from the semaphore waits. > Perhaps it would be better to just do two loads (removing the cocoa-specific > path), and only store clientIsWaitingTag right before we wait. That's what the code tries to avoid with the exchange. It is the race the wait structure always has. E.g. it would be as follows: for(;;) { clientOffset = sharedClientOffset.load(); clientLimit = sharedClientLimit.load(); if (!clientOffset && !clientLimit) break; // Race here: what if the server sets clientOffset = clientLimit = 0 here and goes on to wait // for next command from the client? sharedClientLimit.store(clientIsWaitingTag); wait(); // If the above happens, this waits forever. }
Kimmo Kinnunen
Comment 7 2021-03-15 06:14:51 PDT
EWS
Comment 8 2021-03-15 13:02:08 PDT
Committed r274433: <https://commits.webkit.org/r274433> All reviewed patches have been landed. Closing bug and clearing flags on attachment 423167 [details].
Geoffrey Garen
Comment 9 2021-03-16 13:59:35 PDT
> All the sites expect spurious wakeups from the semaphore waits. Got it. I hadn't noticed this before. Thanks!
Note You need to log in before you can comment on or make changes to this bug.