Bug 227791 - [GPU Process] Regulate the WebPage RenderingUpdates from the WebProcess to the GPUProcess
Summary: [GPU Process] Regulate the WebPage RenderingUpdates from the WebProcess to th...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Said Abou-Hallawa
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-07-07 23:18 PDT by Said Abou-Hallawa
Modified: 2021-07-27 03:13 PDT (History)
6 users (show)

See Also:


Attachments
Patch (4.93 KB, patch)
2021-07-07 23:59 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (4.92 KB, patch)
2021-07-08 00:20 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (20.70 KB, patch)
2021-07-15 01:33 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (22.33 KB, patch)
2021-07-15 13:29 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch for EWS (26.63 KB, patch)
2021-07-17 02:02 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch for EWS (24.54 KB, patch)
2021-07-18 02:07 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (25.74 KB, patch)
2021-07-18 23:35 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (21.16 KB, patch)
2021-07-19 11:52 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (39.82 KB, patch)
2021-07-20 02:14 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (40.06 KB, patch)
2021-07-21 20:26 PDT, Said Abou-Hallawa
no flags Details | Formatted Diff | Diff
Patch (40.22 KB, patch)
2021-07-26 12:40 PDT, Said Abou-Hallawa
simon.fraser: review+
Details | Formatted Diff | Diff
Patch (40.51 KB, patch)
2021-07-26 16:20 PDT, Said Abou-Hallawa
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (40.64 KB, patch)
2021-07-26 20:24 PDT, Said Abou-Hallawa
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Said Abou-Hallawa 2021-07-07 23:18:44 PDT
Although RemoteRenderingBackend::stopListeningForIPC() removes its m_workQueue from the connection WorkQueueMessageReceiver HashMap, m_workQueue can still process accumulated received messages. Removing WorkQueueMessageReceiver will call the destructor ~WorkQueueMessageReceiver but the m_queue of the deleted object can still be running. The reason is the lambda of the WorkQueue::dispatch() in WorkQueueMessageReceiverQueue::enqueueMessage() captures the receiver which is RemoteRenderingBackend as a Ref pointer. Because RemoteRenderingBackend holds the last reference to WorkQueue, m_workQueue can run even after RemoteRenderingBackend::stopListeningForIPC() is called.
Comment 1 Said Abou-Hallawa 2021-07-07 23:19:52 PDT
<rdar://78430639>
Comment 2 Said Abou-Hallawa 2021-07-07 23:59:06 PDT
Created attachment 433122 [details]
Patch
Comment 3 Said Abou-Hallawa 2021-07-08 00:20:27 PDT
Created attachment 433124 [details]
Patch
Comment 4 Simon Fraser (smfr) 2021-07-08 13:54:58 PDT
This does not fix the "navigating away from the page" case. What's the plan for that?
Comment 5 Simon Fraser (smfr) 2021-07-09 10:33:07 PDT
Comment on attachment 433124 [details]
Patch

r- pending an answer to the question
Comment 6 Said Abou-Hallawa 2021-07-15 01:33:32 PDT
Created attachment 433568 [details]
Patch

Patch for EWS
Comment 7 Said Abou-Hallawa 2021-07-15 13:29:33 PDT
Created attachment 433620 [details]
Patch

Patch for EWS
Comment 8 Said Abou-Hallawa 2021-07-17 02:02:52 PDT
Created attachment 433729 [details]
Patch for EWS
Comment 9 Said Abou-Hallawa 2021-07-18 02:07:14 PDT
Created attachment 433746 [details]
Patch for EWS
Comment 10 Said Abou-Hallawa 2021-07-18 23:35:10 PDT
Created attachment 433771 [details]
Patch
Comment 11 Sam Weinig 2021-07-19 09:38:35 PDT
Comment on attachment 433771 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433771&action=review

> Tools/WebKitTestRunner/TestOptions.cpp:124
> +            { "RenderingUpdateRegulateEnabled", false },

This should not be needed.
Comment 12 Sam Weinig 2021-07-19 09:38:37 PDT
Comment on attachment 433771 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433771&action=review

> Tools/WebKitTestRunner/TestOptions.cpp:124
> +            { "RenderingUpdateRegulateEnabled", false },

This should not be needed.
Comment 13 Said Abou-Hallawa 2021-07-19 11:52:30 PDT
Created attachment 433805 [details]
Patch
Comment 14 Simon Fraser (smfr) 2021-07-19 14:43:24 PDT
Comment on attachment 433805 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433805&action=review

> Source/WebCore/page/RenderingUpdateScheduler.h:70
> +    unsigned m_rescheduledRenderingUpdates { 0 };

m_rescheduledRenderingUpdateCount

Move it up before the bools to optimize padding.

> Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:293
> +    m_didFinalizeRenderingUpdateVersion = std::min(didFinalizeRenderingUpdateVersion, m_finalizeRenderingUpdateVersion);

Isn't it a bug if didFinalizeRenderingUpdateVersion and m_finalizeRenderingUpdateVersion are out of order?

> Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:158
> +    uint64_t m_finalizeRenderingUpdateVersion { 1 };
> +    uint64_t m_didFinalizeRenderingUpdateVersion { 1 };

I think these should be a type defined as MonotonicObjectIdentifier<>.

Can one be named as "last completed" or something? This is closer to the naming we use for TransactionIDs.
Comment 15 Said Abou-Hallawa 2021-07-20 02:14:18 PDT
Created attachment 433861 [details]
Patch
Comment 16 Said Abou-Hallawa 2021-07-21 20:26:46 PDT
Created attachment 433985 [details]
Patch
Comment 17 Said Abou-Hallawa 2021-07-21 20:34:08 PDT
Comment on attachment 433805 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=433805&action=review

>> Source/WebCore/page/RenderingUpdateScheduler.h:70
>> +    unsigned m_rescheduledRenderingUpdates { 0 };
> 
> m_rescheduledRenderingUpdateCount
> 
> Move it up before the bools to optimize padding.

Done.

>> Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:293
>> +    m_didFinalizeRenderingUpdateVersion = std::min(didFinalizeRenderingUpdateVersion, m_finalizeRenderingUpdateVersion);
> 
> Isn't it a bug if didFinalizeRenderingUpdateVersion and m_finalizeRenderingUpdateVersion are out of order?

Yes it is a bug if we are the only who sends didFinalizeRenderingUpdateVersion larger than m_finalizeRenderingUpdateVersion. And this is why I added the debug ASSERT above. But if the argument of the IPC message RemoteRenderingBackendProxy::DidFinalizeRenderingUpdate was altered when sending it from GPUProcess to WebProcess, I thought we can protect ourselves from this underflow if we just use std::min().

     unsigned delayedRenderingUpdates() const { return m_finalizeRenderingUpdateVersion - m_didFinalizeRenderingUpdateVersion; }

>> Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:158
>> +    uint64_t m_didFinalizeRenderingUpdateVersion { 1 };
> 
> I think these should be a type defined as MonotonicObjectIdentifier<>.
> 
> Can one be named as "last completed" or something? This is closer to the naming we use for TransactionIDs.

Done.
Comment 18 Said Abou-Hallawa 2021-07-26 12:40:44 PDT
Created attachment 434227 [details]
Patch
Comment 19 Simon Fraser (smfr) 2021-07-26 14:49:59 PDT
Comment on attachment 434227 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=434227&action=review

> Source/WebCore/ChangeLog:12
> +        certain number of rescheduling.

reschedules

> Source/WebKit/Shared/MonotonicObjectIdentifier.h:129
> +template<typename T>
> +inline unsigned operator-(const MonotonicObjectIdentifier<T>& a, const MonotonicObjectIdentifier<T>& b)
> +{
> +    return a.toUInt64() - b.toUInt64();
> +}

I think this needs to return a signed Int64 value to avoid mistakes.

> Source/WebKit/WebProcess/WebPage/WebPage.h:402
> +    bool canTriggerRenderingUpdate(unsigned rescheduledRenderingUpdateCount) const;

canTriggerRenderingUpdate -> shouldTriggerRenderingUpdate
Comment 20 Chris Dumez 2021-07-26 14:52:36 PDT
Comment on attachment 434227 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=434227&action=review

> Source/WebKit/Shared/MonotonicObjectIdentifier.h:35
> +template<typename T> class MonotonicObjectIdentifier {

I think this could use a comment to explain its purpose and how it differs from ObjectIdentifier. Isn't an ObjectIdentifier monotonic? It definitely can only increment.
Comment 21 Said Abou-Hallawa 2021-07-26 16:20:14 PDT
Created attachment 434253 [details]
Patch
Comment 22 Said Abou-Hallawa 2021-07-26 18:35:05 PDT
Comment on attachment 434227 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=434227&action=review

>> Source/WebCore/ChangeLog:12
>> +        certain number of rescheduling.
> 
> reschedules

Fixed.

>> Source/WebKit/Shared/MonotonicObjectIdentifier.h:35
>> +template<typename T> class MonotonicObjectIdentifier {
> 
> I think this could use a comment to explain its purpose and how it differs from ObjectIdentifier. Isn't an ObjectIdentifier monotonic? It definitely can only increment.

I added a comment describing the difference between the two and a FIXME suggesting merging them.

>> Source/WebKit/Shared/MonotonicObjectIdentifier.h:129
>> +}
> 
> I think this needs to return a signed Int64 value to avoid mistakes.

Done. I added a Checked calculation to deal with the overflow.

>> Source/WebKit/WebProcess/WebPage/WebPage.h:402
>> +    bool canTriggerRenderingUpdate(unsigned rescheduledRenderingUpdateCount) const;
> 
> canTriggerRenderingUpdate -> shouldTriggerRenderingUpdate

Fixed.
Comment 23 EWS 2021-07-26 19:03:48 PDT
Tools/Scripts/svn-apply failed to apply attachment 434253 [details] to trunk.
Please resolve the conflicts and upload a new patch.
Comment 24 Said Abou-Hallawa 2021-07-26 20:24:12 PDT
Created attachment 434265 [details]
Patch
Comment 25 EWS 2021-07-26 21:43:04 PDT
Committed r280337 (239984@main): <https://commits.webkit.org/239984@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 434265 [details].