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

Add the functionality to merge and unmerge MessageLoopTaskQueues #9436

Merged
merged 14 commits into from
Jul 12, 2019

Conversation

iskakaushik
Copy link
Contributor

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.

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.
.gitignore Outdated
@@ -21,5 +21,6 @@ Thumbs.db
.idea
pubspec.lock
.vscode/
compile_commands.json
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

public:
// TODO (kaushikiska): refactor mutexes out side of MessageLoopTaskQueues
// for better DI.
MergedQueuesRunner(MessageLoopTaskQueues* task_queues,
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -104,6 +134,11 @@ class MessageLoopTaskQueues
std::vector<TaskObservers> task_observers_;
std::vector<DelayedTaskQueue> delayed_tasks_;

static const size_t _kUnmerged = ULONG_MAX;
Copy link
Member

Choose a reason for hiding this comment

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

Lets typedef size_t

Copy link
Contributor Author

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

std::mutex& t1 = GetMutex(owner, MutexType::kTasks);
std::mutex& t2 = GetMutex(subsumed, MutexType::kTasks);

std::scoped_lock(o1, o2, t1, t2);
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// delayed_tasks locks
std::mutex& t = GetMutex(owner, MutexType::kTasks);

std::scoped_lock(o, t);
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

std::mutex& o = GetMutex(owner, MutexType::kObservers);

// delayed_tasks locks
std::mutex& t = GetMutex(owner, MutexType::kTasks);
Copy link
Member

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.

Copy link
Contributor Author

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) {
Copy link
Member

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.

Copy link
Contributor Author

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_;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@chinmaygarde
Copy link
Member

The approach looks good. Have highlighted the thread safety issue and some other improvements.

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.

LGTM with the one nit.

operator int() const { return value_; }

private:
size_t value_;
Copy link
Member

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.

@iskakaushik iskakaushik merged commit 379028a into flutter:master Jul 12, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 15, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Jul 15, 2019
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 &#34;Roll src/third_party/dart 24725a8559..28f95fcd24 (32 commits)&#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.
johnsonmh pushed a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
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.
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.

3 participants