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

Enforce consistent stack size for Flutter threads #49111

Merged
merged 2 commits into from
Jan 8, 2024

Conversation

knopp
Copy link
Member

@knopp knopp commented Dec 15, 2023

Fixes flutter/flutter#72156

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@knopp knopp force-pushed the consistent_stack_size branch 5 times, most recently from c806284 to ed63891 Compare December 16, 2023 19:09
pthread_t current_thread = pthread_self();
pthread_getname_np(current_thread, thread_name, 8);
pthread_getname_np(current_thread, thread_name, 16);
Copy link
Member Author

Choose a reason for hiding this comment

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

This fails with error 34 when buffer length is less than 16 bytes.

@knopp knopp changed the title WIP: Enforce consistent stack size for Flutter threads Enforce consistent stack size for Flutter threads Dec 16, 2023
@@ -63,10 +109,10 @@ static void MockThreadConfigSetter(const fml::Thread::ThreadConfig& config) {
int policy = SCHED_OTHER;
switch (config.priority) {
case fml::Thread::ThreadPriority::kDisplay:
param.sched_priority = 10;
param.sched_priority = clamp_priority(10, policy);
Copy link
Member Author

Choose a reason for hiding this comment

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

Should the value perhaps be sched_get_priority_min and sched_get_priority_max? The values are platform specific (i.e. on macOS the allowed range is 15-47 for SCHED_OTHER, on Linux it is 0-0 for SCHED_OTHER and for other policies it requires root).

I don't quite understand how these tests were passing at all on linux.

Copy link
Member Author

@knopp knopp Dec 16, 2023

Choose a reason for hiding this comment

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

Ouch, actually, I know how. pthread tests never actually ran at all- because of missing build_config.h include FLUTTER_PTHREAD_SUPPORTED was 0 all the time.

@chinmaygarde
Copy link
Member

This is only going to be sufficient for the root isolate. Should we consider this for all threads in the isolate thread pool?

@knopp
Copy link
Member Author

knopp commented Dec 18, 2023

This is only going to be sufficient for the root isolate. Should we consider this for all threads in the isolate thread pool?

Aren't non-root isolate threads created by Dart VM? If so the stack size there is already set to 1MB, bigger than the 512kb default.

The biggest problem with current stack size is dealing with deep widget hierarchy (i.e. we get stack overflow getting widget inspector snapshot on a moderately complex application). So this only concerns UI threads.

@chinmaygarde
Copy link
Member

If so the stack size there is already set to 1MB

Oh. I didn't realize this was already the case. Making the root isolate at least that big makes sense then.

@knopp knopp force-pushed the consistent_stack_size branch 3 times, most recently from d4314c6 to e483e52 Compare December 25, 2023 14:19
@chinmaygarde
Copy link
Member

Triage: There is consensus that this is a sound fix.

static int clamp_priority(int priority, int policy) {
int min = sched_get_priority_min(policy);
int max = sched_get_priority_max(policy);
if (priority < min) {
Copy link
Member

Choose a reason for hiding this comment

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

Can use std::clamp(priority, min, max) here

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess my head is stuck in c++ 14 :)

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 8, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jan 8, 2024
…141112)

flutter/engine@bbebee1...db564ff

2024-01-08 skia-flutter-autoroll@skia.org Roll Skia from 272281e56cdc to 4b7cab157b50 (1 revision) (flutter/engine#49594)
2024-01-08 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from I-3hiLjX2DDy6mu22... to 6z4cZ6HUidtgmhvdk... (flutter/engine#49592)
2024-01-08 matej.knopp@gmail.com Enforce consistent stack size for Flutter threads (flutter/engine#49111)
2024-01-08 skia-flutter-autoroll@skia.org Roll Skia from 384e08e5fbbe to 272281e56cdc (1 revision) (flutter/engine#49588)
2024-01-08 skia-flutter-autoroll@skia.org Roll Skia from e2621f417ff5 to 384e08e5fbbe (1 revision) (flutter/engine#49587)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from I-3hiLjX2DDy to 6z4cZ6HUidtg

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC rmistry@google.com,zra@google.com on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants