-
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
Define thread priority enum and set thread priority for all threads in Engine #30605
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
2963aaf
to
e24ee60
Compare
78321b4
to
af19259
Compare
I think this patch makes a lot of sense. I'll take a stab at reviewing it. A couple of suggestions though:
|
Thank you reviewed; |
About the number of priority, I create two trace file in here: https://github.com/JsouLiang/ThreadPriorityTrace, you can use Xcode instrument to see. |
3f66389
to
49f45a9
Compare
@chinmaygarde hey, the pr has any progress? |
@chinmaygarde is a bit overloaded, so asking @dnfield and @gaaclarke to review. /cc @iskakaushik FYI and to review if needed. |
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.
Just some quick notes. I'll finish the review later.
fml/thread.h
Outdated
const std::string& thread_name() const { return thread_name_; } | ||
|
||
/// Set current thread name | ||
virtual void SetCurrentThreadName(); |
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.
Why is this virtual? Maybe instead of making this a class, you want it to be an interface?
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.
Yes, I think the method in the ThreadConfigure class user can have their own implementation by the user.
fml/thread.h
Outdated
@@ -28,6 +74,8 @@ class Thread { | |||
|
|||
private: | |||
std::unique_ptr<std::thread> thread_; | |||
/// ThreadConfigure is used for setting thread configure some like `priority` | |||
std::unique_ptr<ThreadConfig> thread_config_; |
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.
There isn't a need to hold onto this variable is there?
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.
The ThreadConfig set Thread is in the Thread callback, If don't hold it , it may be released when use it.
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.
But it's only used in the constructor.
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.
(the lambda can just take ownership of it)
5976fb3
to
f4bf7fa
Compare
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.
Thanks, this is looking better. You didn't have to do the functor refactor but I appreciate it. If you want to clean it up further, using an std::function would be even cleaner.
auto mask = | ||
ThreadHost::Type::UI | ThreadHost::Type::RASTER | ThreadHost::Type::IO; | ||
|
||
PlatformAndroidThreadConfigSetter android_thread_config_setter; |
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 variable isn't used.
fml/thread.h
Outdated
ThreadPriority priority; | ||
}; | ||
|
||
class ThreadConfigSetter { |
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.
Please add a docstring.
shell/common/thread_host.h
Outdated
explicit ThreadHostConfig( | ||
const std::string& name_prefix, | ||
uint64_t mask, | ||
std::shared_ptr<ThreadConfigSetter> setter = |
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.
The constructors should actually take in a unique_ptr of the ThreadConfigSetter and graduate it to a shared_ptr.
shell/common/thread_host.h
Outdated
: ThreadHostConfig("", mask, setter) {} | ||
|
||
/// Check if need to create thread. | ||
bool isNeedThread(Type type) const { return type_mask & type; } |
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.
bool isNeedThread(Type type) const { return type_mask & type; } | |
bool isThreadNeeded(Type type) const { return type_mask & type; } |
fml/thread.h
Outdated
ThreadPriority priority; | ||
}; | ||
|
||
class ThreadConfigSetter { |
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.
nit: Now that you've factored this out, it would actually be cleaner as a std::function instead of a functor. That would eliminate your need for shared_ptr
.
9f3bf28
to
151ab6d
Compare
@gaaclarke hey, listen to your suggestions, I change the |
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.
Hey awesome. I like the looks of this now. I hope you feel it's an improvement too. We've split apart the idea of the data versus the operation to set the data which better highlights that that is what is different between each platform. We didn't have to muck around with virtual functions or inheritance. Thanks buddy!
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.
/cc @iskakaushik apropos of our discussion yesterday.
This pull request is not suitable for automatic merging in its current state.
|
This pull request is not suitable for automatic merging in its current state.
|
@gaaclarke I think your suggestion is very correct, thank you. |
* 2a8f388 Roll Skia from a424b619bc40 to ec0af1664478 (6 revisions) (flutter/engine#31352) * ba8f1c5 Add clang-analyzer-* and clang-diagnostic-* to .clang-tidy (flutter/engine#31291) * 1eafb40 Use H5vcc CanvasKit implementation if it is detected. (flutter/engine#31191) * 6d99e90 Roll Dart SDK from 55c93c732da9 to b7eea441d7d1 (4 revisions) (flutter/engine#31353) * 935b46a Roll Fuchsia Mac SDK from 5_CZ81mTD... to 5CmPcHTb1... (flutter/engine#31356) * 244bb25 Roll Skia from ec0af1664478 to 9cb74e90792d (4 revisions) (flutter/engine#31357) * b6b5759 Roll Skia from 9cb74e90792d to 81d4b5d5b45d (6 revisions) (flutter/engine#31360) * 0f6db11 Roll Skia from 81d4b5d5b45d to 1f813e4c7f6d (1 revision) (flutter/engine#31362) * 321a482 Fix AccessibilityBridge crash due to invalid access during ReplaceSemanticsObject (flutter/engine#31351) * 2cc3abb Manual roll of ICU (flutter/engine#31132) * c1e843d Roll Fuchsia Linux SDK from 4VEg4eRJS... to YGS2LvlDy... (flutter/engine#31364) * fe08734 Roll Dart SDK from b7eea441d7d1 to 7e3310bbe1ed (2 revisions) (flutter/engine#31365) * 2062e57 Add trackpad gesture PointerData types (flutter/engine#28571) * 24fe585 Roll Skia from 1f813e4c7f6d to 5a2135af5623 (1 revision) (flutter/engine#31366) * 11bf86a Migrate string encoding conversions to FML (flutter/engine#31334) * 6d9f479 Roll Skia from 5a2135af5623 to 21a92dff8fdc (3 revisions) (flutter/engine#31368) * 417a05e Roll Dart SDK from 7e3310bbe1ed to a9cfcc289ed4 (1 revision) (flutter/engine#31369) * b04ed63 Change link to felt documentation (flutter/engine#31312) * 3e7515a Roll Fuchsia Mac SDK from 5CmPcHTb1... to ZA5ZzabQM... (flutter/engine#31370) * 90effff Revert "Add trackpad gesture PointerData types (#28571)" (flutter/engine#31375) * 3764a8f Change support for VM service message from "The Dart VM Service is listening" to "The Dart VM service is listening" (flutter/engine#31361) * 3d629c5 Fix html gradient rendering (#97762) (flutter/engine#31355) * 963c449 [Android] Show deprecation warnings for Android tests (flutter/engine#31246) * 0be895c Roll Dart SDK from a9cfcc289ed4 to 0041431f5ec7 (1 revision) (flutter/engine#31372) * 18f2faf Roll Skia from 21a92dff8fdc to c5d3326d767d (7 revisions) (flutter/engine#31373) * 1b762d3 Roll Fuchsia Linux SDK from YGS2LvlDy... to yDo1mhBKz... (flutter/engine#31374) * 7b6a7b6 Roll Skia from c5d3326d767d to b6dfd97c5290 (10 revisions) (flutter/engine#31377) * f55b161 [a11y] Delegate UTF8ToUTF16 to FML (flutter/engine#31376) * d36d25f TextEditingDelta Support for the Web (flutter/engine#28527) * aa17186 [fml] Use common FML string encoding utils (flutter/engine#31378) * 97d9ec3 Renamed the scenario tests target to be generic emulator tests. (flutter/engine#28919) * 902717f Roll Skia from b6dfd97c5290 to e1e2a858205f (3 revisions) (flutter/engine#31380) * 877f820 Roll Dart SDK from 0041431f5ec7 to a15d19a0d914 (2 revisions) (flutter/engine#31381) * 2d16729 Roll Skia from e1e2a858205f to 74ce095463e1 (2 revisions) (flutter/engine#31383) * 8d3c0fb [web] PathRef: do not use == with doubles in assertions (flutter/engine#31382) * d1164c1 Move recipes to repository folders. (flutter/engine#31367) * e031e07 Roll Skia from 74ce095463e1 to 82d65d0487bd (1 revision) (flutter/engine#31384) * 5140a44 Define thread priority enum and set thread priority for all threads in Engine (flutter/engine#30605) * 1e46918 Roll Dart SDK from a15d19a0d914 to a3736d4e9b1b (1 revision) (flutter/engine#31397) * 8a28948 Roll Fuchsia Linux SDK from yDo1mhBKz... to UHV3HWM3d... (flutter/engine#31398) * ca86c79 Roll Fuchsia Mac SDK from ZA5ZzabQM... to jjxstNbgZ... (flutter/engine#31399)
* 2a8f388 Roll Skia from a424b619bc40 to ec0af1664478 (6 revisions) (flutter/engine#31352) * ba8f1c5 Add clang-analyzer-* and clang-diagnostic-* to .clang-tidy (flutter/engine#31291) * 1eafb40 Use H5vcc CanvasKit implementation if it is detected. (flutter/engine#31191) * 6d99e90 Roll Dart SDK from 55c93c732da9 to b7eea441d7d1 (4 revisions) (flutter/engine#31353) * 935b46a Roll Fuchsia Mac SDK from 5_CZ81mTD... to 5CmPcHTb1... (flutter/engine#31356) * 244bb25 Roll Skia from ec0af1664478 to 9cb74e90792d (4 revisions) (flutter/engine#31357) * b6b5759 Roll Skia from 9cb74e90792d to 81d4b5d5b45d (6 revisions) (flutter/engine#31360) * 0f6db11 Roll Skia from 81d4b5d5b45d to 1f813e4c7f6d (1 revision) (flutter/engine#31362) * 321a482 Fix AccessibilityBridge crash due to invalid access during ReplaceSemanticsObject (flutter/engine#31351) * 2cc3abb Manual roll of ICU (flutter/engine#31132) * c1e843d Roll Fuchsia Linux SDK from 4VEg4eRJS... to YGS2LvlDy... (flutter/engine#31364) * fe08734 Roll Dart SDK from b7eea441d7d1 to 7e3310bbe1ed (2 revisions) (flutter/engine#31365) * 2062e57 Add trackpad gesture PointerData types (flutter/engine#28571) * 24fe585 Roll Skia from 1f813e4c7f6d to 5a2135af5623 (1 revision) (flutter/engine#31366) * 11bf86a Migrate string encoding conversions to FML (flutter/engine#31334) * 6d9f479 Roll Skia from 5a2135af5623 to 21a92dff8fdc (3 revisions) (flutter/engine#31368) * 417a05e Roll Dart SDK from 7e3310bbe1ed to a9cfcc289ed4 (1 revision) (flutter/engine#31369) * b04ed63 Change link to felt documentation (flutter/engine#31312) * 3e7515a Roll Fuchsia Mac SDK from 5CmPcHTb1... to ZA5ZzabQM... (flutter/engine#31370) * 90effff Revert "Add trackpad gesture PointerData types (flutter#28571)" (flutter/engine#31375) * 3764a8f Change support for VM service message from "The Dart VM Service is listening" to "The Dart VM service is listening" (flutter/engine#31361) * 3d629c5 Fix html gradient rendering (flutter#97762) (flutter/engine#31355) * 963c449 [Android] Show deprecation warnings for Android tests (flutter/engine#31246) * 0be895c Roll Dart SDK from a9cfcc289ed4 to 0041431f5ec7 (1 revision) (flutter/engine#31372) * 18f2faf Roll Skia from 21a92dff8fdc to c5d3326d767d (7 revisions) (flutter/engine#31373) * 1b762d3 Roll Fuchsia Linux SDK from YGS2LvlDy... to yDo1mhBKz... (flutter/engine#31374) * 7b6a7b6 Roll Skia from c5d3326d767d to b6dfd97c5290 (10 revisions) (flutter/engine#31377) * f55b161 [a11y] Delegate UTF8ToUTF16 to FML (flutter/engine#31376) * d36d25f TextEditingDelta Support for the Web (flutter/engine#28527) * aa17186 [fml] Use common FML string encoding utils (flutter/engine#31378) * 97d9ec3 Renamed the scenario tests target to be generic emulator tests. (flutter/engine#28919) * 902717f Roll Skia from b6dfd97c5290 to e1e2a858205f (3 revisions) (flutter/engine#31380) * 877f820 Roll Dart SDK from 0041431f5ec7 to a15d19a0d914 (2 revisions) (flutter/engine#31381) * 2d16729 Roll Skia from e1e2a858205f to 74ce095463e1 (2 revisions) (flutter/engine#31383) * 8d3c0fb [web] PathRef: do not use == with doubles in assertions (flutter/engine#31382) * d1164c1 Move recipes to repository folders. (flutter/engine#31367) * e031e07 Roll Skia from 74ce095463e1 to 82d65d0487bd (1 revision) (flutter/engine#31384) * 5140a44 Define thread priority enum and set thread priority for all threads in Engine (flutter/engine#30605) * 1e46918 Roll Dart SDK from a15d19a0d914 to a3736d4e9b1b (1 revision) (flutter/engine#31397) * 8a28948 Roll Fuchsia Linux SDK from yDo1mhBKz... to UHV3HWM3d... (flutter/engine#31398) * ca86c79 Roll Fuchsia Mac SDK from ZA5ZzabQM... to jjxstNbgZ... (flutter/engine#31399)
Refactoring the
fml::Thread
,flutter::ThreadHost
which the aim is can set theThread Priority
.First: define the
ThreadConfig
which hold the thread priority and thread name and we can add another thread priorities in this class.Second:
fml::Thread
can create byThreadConfig
, we can set the thread name by ThreadConfig, for example:std::make_unique<fml::Thread>(ThreadConfig("com.flutter.ui", Thread::ThreadPriority::DISPLAY));
. In std::thread call-back we set the priorities:Third: : Cause to set the thread priority, we may be use the platform-api, so we can inherit the
ThreadConfig
in iOS or Android, and override theThreadConfig::SetCurrentThreadPriority
(ThreadConfig::SetCurrentThreadPriority
is do nothing)Finally: Cause of all the flutter thread are created by the
flutter::ThreadHost
, so i modify the flutter::ThreadHost constructor in order to i can through the ThreadConfig from platform-enginePre-launch Checklist
writing and running engine tests.
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.