Add the functionality to merge and unmerge MessageLoopTaskQueues#9436
Add the functionality to merge and unmerge MessageLoopTaskQueues#9436iskakaushik merged 14 commits intoflutter:masterfrom
Conversation
This introduces a notion of a "owning" and "subsumed" queue ids. Owning queue will take care of the tasks submitted to both that and it's subsumed queue. - The tasks submitted still maintain the queue affinity - Same for the task observers - Also adds MergedQueuesRunner which grabs both the locks owner and subsumed queues in RAII fashion.
- Also use task queue id to verify if we are running in the same thread. - This is to enable merging the backed message loop task queues to enable dynamic thread merging in IOS.
.gitignore
Outdated
| .idea | ||
| pubspec.lock | ||
| .vscode/ | ||
| compile_commands.json |
There was a problem hiding this comment.
Compile commands should only end up in out/. This should not be necessary.
fml/merged_queues_runner.cc
Outdated
| public: | ||
| // TODO (kaushikiska): refactor mutexes out side of MessageLoopTaskQueues | ||
| // for better DI. | ||
| MergedQueuesRunner(MessageLoopTaskQueues* task_queues, |
There was a problem hiding this comment.
Since the queue can't ever be nullptr, use a reference for clarity.
fml/message_loop_task_queues.h
Outdated
| std::vector<TaskObservers> task_observers_; | ||
| std::vector<DelayedTaskQueue> delayed_tasks_; | ||
|
|
||
| static const size_t _kUnmerged = ULONG_MAX; |
There was a problem hiding this comment.
Moved this to a struct
fml/message_loop_task_queues.cc
Outdated
| std::mutex& t1 = GetMutex(owner, MutexType::kTasks); | ||
| std::mutex& t2 = GetMutex(subsumed, MutexType::kTasks); | ||
|
|
||
| std::scoped_lock(o1, o2, t1, t2); |
There was a problem hiding this comment.
This does not actually perform the lock. Please use a variable here.
There was a problem hiding this comment.
Apparently I also missed the scoped_lock in the other review. Just global search and replace this pattern in the codebase.
fml/message_loop_task_queues.cc
Outdated
| // delayed_tasks locks | ||
| std::mutex& t = GetMutex(owner, MutexType::kTasks); | ||
|
|
||
| std::scoped_lock(o, t); |
There was a problem hiding this comment.
This does not actually perform the lock. Please use a variable here.
fml/message_loop_task_queues.cc
Outdated
| std::mutex& o = GetMutex(owner, MutexType::kObservers); | ||
|
|
||
| // delayed_tasks locks | ||
| std::mutex& t = GetMutex(owner, MutexType::kTasks); |
There was a problem hiding this comment.
Not acquiring the subsumed lock will cause unsafe access to the tasks/observers heap in HasPendingTasksUnlocked(subsumed). Just acquire all four locks.
| invocations.emplace_back(std::move(top.GetTask())); | ||
| tasks.pop(); | ||
| delayed_tasks_[top_queue].pop(); | ||
| if (type == FlushType::kSingle) { |
There was a problem hiding this comment.
We no longer make use of this in the concurrent tasks queue. So lets just get rid of flush type with the default being multiple.
There was a problem hiding this comment.
Created this flutter/flutter#36083, will follow this up.
| } | ||
|
|
||
| const TaskQueueId owner_; | ||
| TaskQueueId subsumed_; |
There was a problem hiding this comment.
Lets make task queue ID a struct with a single member of size_t.
|
The approach looks good. Have highlighted the thread safety issue and some other improvements. |
chinmaygarde
left a comment
There was a problem hiding this comment.
LGTM with the one nit.
fml/message_loop_task_queues.h
Outdated
| operator int() const { return value_; } | ||
|
|
||
| private: | ||
| size_t value_; |
There was a problem hiding this comment.
Zero it out to kUnused here by default.
flutter/engine@919e353...76a91d3 git log 919e353..76a91d3 --no-merges --oneline 76a91d3 Roll src/third_party/skia 8590026dbf0d..563d044c0e76 (38 commits) (flutter/engine#9824) 8143845 Roll fuchsia/sdk/core/mac-amd64 from olF8ZjlM3lWSmWq8XyfXTKoPveuZtTcrGJINk_ERHhwC to pU_n3ahOhH6HJhE4vs5pUR8cg5U22TItP_Ds_N2OXPIC (flutter/engine#9820) 379028a Add the functionality to merge and unmerge MessageLoopTaskQueues (flutter/engine#9436) 8abe85b Revert "Roll src/third_party/dart 24725a8559..28f95fcd24 (32 commits)" (flutter/engine#9817) 96746bc Roll src/third_party/skia c3f28e3cf0d4..8590026dbf0d (2 commits) (flutter/engine#9805) 3652a68 Roll fuchsia/sdk/core/mac-amd64 from CDbRdGJ3bu-aWMCZqN5VzfQqIBwDGL2wfFodWABKdCIC to olF8ZjlM3lWSmWq8XyfXTKoPveuZtTcrGJINk_ERHhwC (flutter/engine#9803) 67d284d Roll src/third_party/dart 24725a8559..28f95fcd24 (32 commits) The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md If the roll is causing failures, please contact the current sheriff ([email protected]), and stop the roller if necessary.
flutter/engine@919e353...76a91d3 git log 919e353..76a91d3 --no-merges --oneline 76a91d3 Roll src/third_party/skia 8590026dbf0d..563d044c0e76 (38 commits) (flutter/engine#9824) 8143845 Roll fuchsia/sdk/core/mac-amd64 from olF8ZjlM3lWSmWq8XyfXTKoPveuZtTcrGJINk_ERHhwC to pU_n3ahOhH6HJhE4vs5pUR8cg5U22TItP_Ds_N2OXPIC (flutter/engine#9820) 379028a Add the functionality to merge and unmerge MessageLoopTaskQueues (flutter/engine#9436) 8abe85b Revert &flutter#34;Roll src/third_party/dart 24725a8559..28f95fcd24 (32 commits)&flutter#34; (flutter/engine#9817) 96746bc Roll src/third_party/skia c3f28e3cf0d4..8590026dbf0d (2 commits) (flutter/engine#9805) 3652a68 Roll fuchsia/sdk/core/mac-amd64 from CDbRdGJ3bu-aWMCZqN5VzfQqIBwDGL2wfFodWABKdCIC to olF8ZjlM3lWSmWq8XyfXTKoPveuZtTcrGJINk_ERHhwC (flutter/engine#9803) 67d284d Roll src/third_party/dart 24725a8559..28f95fcd24 (32 commits) The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md If the roll is causing failures, please contact the current sheriff ([email protected]), and stop the roller if necessary.
This introduces a notion of a "owning" and "subsumed" queue ids.
Owning queue will take care of the tasks submitted to both that and it's
subsumed queue.
The tasks submitted still maintain the queue affinity
Same for the task observers
Also adds MergedQueuesRunner which grabs both the locks owner
and subsumed queues in RAII fashion.