Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify task queues locking mechanism #16477

Merged
merged 1 commit into from
Feb 7, 2020

Conversation

iskakaushik
Copy link
Contributor

@iskakaushik iskakaushik commented Feb 6, 2020

We now have one mutex guarding all accesses to
the underlying task heaps. This simplifies the more granular
but bug prone mechanism of having striped locks.

This also re-enables GPUThreadMerger tests that are currently
disabled due to their flaky nature. The scenario that gets fixed by this
change is as follows:

  1. Thread-1: We lock queue_meta_mutex_ and grab locks on queue_1 and release the meta mutex.
  2. Thread-1: We add an Observer on queues object.
  3. Thread-2: We lock queue_meta_mutex_ and grab locks on queue_2.
  4. Thread-2: We try to dispose all the pending tasks on queue_2 which calls erase on queues.

The above situation is not thread safe without having 1 lock.

Note: This increases the contention on one lock and could potentially be bad for perf. We are
explicitly making this trade-off towards reducing the complexity.

Fixes: flutter/flutter#49007

We now have one mutex guarding all accesses to
the underlying task heaps. This simplifies the more granular
but bug prone mechanism of having striped locks.

This also re-enables GPUThreadMerger tests that are currently
disabled due to their flaky nature.
@auto-assign auto-assign bot requested a review from cbracken February 6, 2020 21:10
@iskakaushik iskakaushik removed the request for review from cbracken February 6, 2020 21:10
@iskakaushik iskakaushik changed the title [WIP] Simplify task queues locking mechanism Simplify task queues locking mechanism Feb 6, 2020
Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on the hypothesis as to why this simplification leads to less flakiness? Also, a brief mention of the perf consequences of this change (essentially a global lock around all task queues) would be good. Overall, the simplification looks good and makes the code easier to reason about. So I am in favor of this change just for that reason. Also, replacing the operator[] with at is much needed.

Also, please link with flutter/flutter#49007.

@iskakaushik
Copy link
Contributor Author

@chinmaygarde i've updated the description elaborating my hypothesis. Let me know what you think.

@iskakaushik iskakaushik merged commit 5c70356 into flutter:master Feb 7, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 7, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 8, 2020
dnfield pushed a commit to flutter/flutter that referenced this pull request Feb 8, 2020
* c932214 Ensure fields of Rect and OffsetBase classes are optimized as non-null. (flutter/engine#16465)

* 5c70356 Simplify task queues locking mechanism (flutter/engine#16477)

* d589dde Fix text range logic for a11y (flutter/engine#16496)

* 1a4f4e3 Fix unused import in Android embedder (flutter/engine#16494)

* 964ae10 Disable ShellTest.WaitForFirstFrameTimeout on Fuchsia (flutter/engine#16495)

* 6158f03 Roll src/third_party/skia 87e3bef6f82f..9f3eef796f63 (7 commits) (flutter/engine#16493)
NoamDev pushed a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
We now have one mutex guarding all accesses to
the underlying task heaps. This simplifies the more granular
but bug prone mechanism of having striped locks.

This also re-enables GPUThreadMerger tests that are currently
disabled due to their flaky nature. The scenario that gets fixed by this
change is as follows:

1. Thread-1: We lock `queue_meta_mutex_` and grab locks on `queue_1` and release the meta mutex.
2. Thread-1: We add an Observer on `queues` object.
3. Thread-2: We lock `queue_meta_mutex_` and grab locks on `queue_2`.
4. Thread-2: We try to dispose all the pending tasks on `queue_2` which calls `erase` on `queues`.

The above situation is not thread safe without having 1 lock.

Note: This increases the contention on one lock and could potentially be bad for perf. We are
explicitly making this trade-off towards reducing the complexity.

Fixes: flutter/flutter#49007
NoamDev added a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GPU Thread Merger tests are flaky and have been disabled.
3 participants