-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Add the functionality to merge and unmerge MessageLoopTaskQueues #9436
Add the functionality to merge and unmerge MessageLoopTaskQueues #9436
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
@@ -21,5 +21,6 @@ Thumbs.db | |||
.idea | |||
pubspec.lock | |||
.vscode/ | |||
compile_commands.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compile commands should only end up in out/
. This should not be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the queue can't ever be nullptr, use a reference for clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
fml/message_loop_task_queues.h
Outdated
@@ -104,6 +134,11 @@ class MessageLoopTaskQueues | |||
std::vector<TaskObservers> task_observers_; | |||
std::vector<DelayedTaskQueue> delayed_tasks_; | |||
|
|||
static const size_t _kUnmerged = ULONG_MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets typedef size_t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not actually perform the lock. Please use a variable here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently I also missed the scoped_lock in the other review. Just global search and replace this pattern in the codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not actually perform the lock. Please use a variable here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not acquiring the subsumed lock will cause unsafe access to the tasks/observers heap in HasPendingTasksUnlocked(subsumed)
. Just acquire all four locks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if (top.GetTargetTime() > now) { | ||
break; | ||
} | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created this flutter/flutter#36083, will follow this up.
} | ||
|
||
const TaskQueueId owner_; | ||
TaskQueueId subsumed_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets make task queue ID a struct with a single member of size_t
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
The approach looks good. Have highlighted the thread safety issue and some other improvements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.