New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 821034 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Apr 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows , Mac
Pri: 1
Type: Bug-Regression

Blocked on:
issue 824716

Blocking:
issue 890978



Sign in to add a comment

BrowserThreadGlobals lock contention regression in 67.0.3365.0 (browser process IO thread startup)

Project Member Reported by wittman@chromium.org, Mar 12 2018

Issue description

Time spent waiting on the BrowserThreadGlobals lock in mojo::SimpleWatcher::Context::Notify() during browser process IO thread startup on 64-bit Chrome on Windows regressed by 37ms in 67.0.3365.0 Canary release. This now accounts for 1.1% of non-idle startup execution time on the thread.

No changes were detected to the functions on the mojo::SimpleWatcher::Context::Notify() call stack in this release, so the immediate cause of this regression was likely some change indirectly affecting this code.

Execution profile difference of Canary 67.0.3364.0 vs. 67.0.3365.0: https://uma.googleplex.com/p/chrome/callstacks?sid=de499992cc86c8cb5d8b3f6ecf6995a5

A similar but smaller regression is also seen on Mac:
https://uma.googleplex.com/p/chrome/callstacks?sid=85d272e1199d51429e67f6195791b99f
 

Comment 1 by roc...@chromium.org, Mar 12 2018

Cc: hanxi@chromium.org
Hmm. hanxi@ has certainly been changing startup behavior relevant to IO thread bringup, but its not clear to me how those changes would increase contention.

In the suspected regression range there's only https://chromium-review.googlesource.com/c/chromium/src/+/941264

Less recently there was https://chromium-review.googlesource.com/c/chromium/src/+/905424

Comment 2 by hanxi@chromium.org, Mar 12 2018

Yes, I did some work about startup, but my CLs don't in the change list:

1) First CL: Canary 66 66.0.3350.0, Dev 66 66.0.3352.3
https://chromiumdash.appspot.com/commit/066637cf13d873fa6ed71430e9e60de52ebc7d7d

2) Second CL: Canary 67 67.0.3368.0. See
https://chromiumdash.appspot.com/commit/89d93df220a35ef162d662c27cb3ea3d643c4fd9

Can you verify the range?
The regression range is correct; it's derived from measuring this code in the wild on 67.0.3364.0 and 67.0.3365.0 and computing the difference in execution time between the two releases. Looking at the profiles for 67.0.3366.0 and 67.0.3367.0 the regression remains in the following releases.

It's possible that the cause of this contention is from somewhere else and we're just seeing it most significantly on this call stack for some reason. We do see smaller regressions in calls to content::BrowserThread::GetCurrentThreadIdentifier() on the IO[1] and UI[2] threads due to contention on the same lock, for example.

Perhaps gab@ has some idea what might have increased contention on this lock.

[1] https://uma.googleplex.com/p/chrome/callstacks?sid=bce7adc9cc6ad83817686ea22fbe2aa1
[2] https://uma.googleplex.com/p/chrome/callstacks?sid=c5df0c34cccfffbb3fe7221230605bf6
One other thought: this could be the result of some change that caused this code path to be executed much more frequently. Are there any CLs in the regression range that could have done that?

Comment 5 by fdoray@chromium.org, Mar 14 2018

It's not the first time that content::BrowserThread::CurrentlyOn() shows up in profiling reports (UMA profiler or local ETW traces). 

Irrespectively of what caused this specific regression, I believe it should be made more efficient. Perhaps we could ensure that BrowserThreadGlobals is initialized when Chrome is still single-threaded, and make most accesses lock-free.

Comment 6 by gab@chromium.org, Mar 14 2018

Status: Started (was: Assigned)
I agree that the locking scheme here is overkill now that we only have UI/IO BrowserThreads, all it's there for now is shutdown and shutdown is much simpler than it used to be.

Thanks for filling Mike, love the sampling profiler data once again!

I'll fix this.

Comment 7 by gab@chromium.org, Mar 14 2018

Note however that posting a task will also require a lock, so fixing this might just push the problem a few stack frames down to the next lock. But at least it will be a per task runner lock rather than a global lock. Sampling profiler will let us know if this is a problem then :)

Comment 8 by gab@chromium.org, Mar 14 2018

As for why it regressed in M67, this might just be that more and more tasks are posted from TaskScheduler. Since the logic below (wrongfully) assumes that any thread that isn't a BrowserThread doesn't outlive BrowserThreads, it now grabs the lock on PostTasks from all threads except posting from UI->IO.

  bool target_thread_outlives_current =
      GetCurrentThreadIdentifier(&current_thread) &&
      current_thread >= identifier;

This is overly conservative nowadays.

Comment 9 by gab@chromium.org, Mar 14 2018

Err. #8 should say, except when posting from IO->UI.
Project Member

Comment 10 by bugdroid1@chromium.org, Mar 16 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/790754cf4c27c9e1b33613c4e1a48c80c82172ba

commit 790754cf4c27c9e1b33613c4e1a48c80c82172ba
Author: Gabriel Charette <gab@chromium.org>
Date: Fri Mar 16 21:32:59 2018

Fix IWYU for BrowserThread::

Missing includes are blocking a bigger upcoming change that
removes browser_thread.h from other places which tend to have a far
reach.

This removal was done by a script which adds browser_thread.h if
the file has "BrowserThread::" on a line which isn't a comment.

If the file is a header it also substracts the include from matching .cc
file if any.

If the file is a .cc it omits the include if it's already in the
matching .h

Minor exceptions :
 * files that already included test_browser_thread.h (not doing so
   broke DEPS as some tests are explicitly allowed to include
   test_browser_thread.h but no content/public)
 * chrome/renderer/chrome_content_renderer_client_browsertest.cc
   (because it violates DEPS already by using BrowserThread:: from
    content/renderer but this CL doesn't aim to fix tricky use cases)

TBR=jam@chromium.org

Bug:  815225 ,  821034 
Change-Id: I5274433918c85f26caaa5b99adb990f07222fb99
Reviewed-on: https://chromium-review.googlesource.com/967186
Reviewed-by: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543834}
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/android_webview/browser/aw_printing_message_filter.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/android_webview/browser/aw_printing_message_filter.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/apps/guest_view/web_view_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/browsing_data/browsing_data_local_storage_helper_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/browsing_data/counters/cache_counter_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/chrome_site_per_process_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/chromeos/accessibility/select_to_speak_event_rewriter.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/chromeos/arc/print/arc_print_service.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/chromeos/extensions/external_cache_impl.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/chromeos/extensions/file_manager/private_api_file_system.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/chromeos/extensions/wallpaper_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/chromeos/extensions/wallpaper_function_base.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/chromeos/login/login_utils_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/chromeos/login/signin/oauth2_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/devtools/device/devtools_android_bridge.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/devtools/device/devtools_device_discovery.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/devtools/devtools_sanity_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/devtools/devtools_ui_bindings.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/download/chrome_download_manager_delegate.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/download/download_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/download/download_commands.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/download/download_crx_util.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/download/notification/download_notification_interactive_uitest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/bookmarks/bookmarks_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/content_settings/content_settings_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/data_reduction_proxy/data_reduction_proxy_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/declarative_content/chrome_content_rules_registry.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/declarative_net_request/declarative_net_request_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/developer_private/entry_picker.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/downloads/downloads_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_connection.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/enterprise_device_attributes/enterprise_device_attributes_apitest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_apitest_nss.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/enterprise_platform_keys_private/enterprise_platform_keys_private_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/music_manager_private/music_manager_private_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/page_capture/page_capture_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/page_capture/page_capture_apitest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/platform_keys/platform_keys_test_base.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/processes/processes_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/streams_private/streams_private_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/sync_file_system/sync_file_system_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/virtual_keyboard_private/chrome_virtual_keyboard_delegate.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/web_request/web_request_apitest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/blacklist.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/blacklist_state_fetcher.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/content_verifier_hash_fetch_behavior_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/extension_messages_apitest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/extensions/extension_service.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/icon_loader_auralinux.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/icon_loader_chromeos.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/lifetime/browser_close_manager_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/media/router/mojo/media_router_desktop.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/metrics/thread_watcher_android.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/net/predictor_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/notifications/notification_platform_bridge_mac.mm
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/password_manager/password_manager_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/password_manager/password_manager_test_base.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/pdf/pdf_extension_test.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/plugins/plugin_info_host_impl.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/plugins/plugin_info_host_impl.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/predictors/loading_predictor.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/prerender/prerender_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/prerender/prerender_message_filter.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/prerender/prerender_message_filter.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/prerender/prerender_nostate_prefetch_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/printing/printing_message_filter.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/printing/printing_message_filter.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/renderer_context_menu/spelling_menu_observer.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/renderer_host/chrome_extension_message_filter.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/renderer_host/chrome_render_message_filter.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/renderer_host/site_per_process_text_input_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/safe_browsing/certificate_reporting_service_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/safe_browsing/chrome_password_protection_service.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/safe_browsing/download_protection/check_client_download_request.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/safe_browsing/download_protection/download_feedback_service.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/safe_browsing/download_protection/download_protection_service.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/safe_browsing/threat_details_unittest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/speech/tts_message_filter.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/ssl/chrome_expect_ct_reporter_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/ssl/security_state_tab_helper_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/ssl/ssl_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/ui/global_error/global_error_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/ui/views/location_bar/location_bar_view_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/ui/views/ssl_client_certificate_selector_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/ui/webui/media_router/media_router_dialog_controller_impl.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/components/guest_view/browser/guest_view_message_filter.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/components/guest_view/browser/guest_view_message_filter.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/accessibility/accessibility_ui.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/android/dialog_overlay_impl.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/android/java/gin_java_bridge_message_filter.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/background_fetch/background_fetch_delegate_proxy_unittest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/background_fetch/background_fetch_scheduler_unittest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/background_sync/background_sync_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/blob_storage/blob_dispatcher_host.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/browser_main_loop.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/browser_main_loop_unittest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/browser_plugin/browser_plugin_message_filter.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/browser_plugin/browser_plugin_message_filter.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/browser_process_sub_thread.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/browser_side_navigation_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/browsing_data/clear_site_data_throttle_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/cache_storage/cache_storage_dispatcher_host.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/compositor/gpu_process_transport_factory.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/compositor/viz_process_transport_factory.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/devtools/devtools_interceptor_controller.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/devtools/devtools_target_registry.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/devtools/protocol/storage_handler.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/devtools/render_frame_devtools_agent_host.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/dom_storage/dom_storage_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/dom_storage/dom_storage_context_wrapper.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/dom_storage/dom_storage_message_filter.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/download/download_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/download/drag_download_file_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/download/mhtml_generation_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/fileapi/fileapi_message_filter.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/frame_host/navigation_controller_impl_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/frame_host/navigation_handle_impl_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/frame_host/render_frame_message_filter_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/gpu/gpu_ipc_browsertests.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/gpu/in_process_gpu_thread_browsertests.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/indexed_db/database_impl.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/indexed_db/indexed_db_callbacks.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/indexed_db/indexed_db_callbacks.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/loader/cross_site_document_blocking_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/loader/prefetch_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/media/android/browser_surface_view_manager.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/message_port_provider.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/network_service_client.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/network_service_restart_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/clipboard_host_impl.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/media/audio_input_renderer_host.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/media/audio_renderer_host.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/media/peer_connection_tracker_host.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/media/video_capture_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/media/video_capture_host.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/pepper/pepper_renderer_connection.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/render_message_filter.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/render_message_filter.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/render_process_host_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/render_process_host_impl.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/render_process_host_impl.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/render_view_host_impl.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/render_widget_host_impl.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/render_widget_host_view_mac_unittest.mm
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/renderer_host/text_input_client_message_filter.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/security_exploit_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/service_worker/service_worker_dispatcher_host.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/service_worker/service_worker_provider_host.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/site_per_process_hit_test_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/site_per_process_mac_browsertest.mm
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/speech/speech_recognition_dispatcher_host.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/speech/speech_recognition_dispatcher_host.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/speech/speech_recognizer_impl.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/tracing/background_tracing_manager_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/web_contents/web_contents_impl.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/web_contents/web_contents_impl_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/web_contents/web_contents_view_aura_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/browser/web_package/web_package_request_handler_browsertest.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/public/browser/browser_thread.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/public/test/content_browser_test_utils.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/public/test/fake_speech_recognition_manager.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/public/test/test_frame_navigation_observer.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/shell/browser/layout_test/layout_test_message_filter.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/content/test/content_browser_test_utils_internal.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/extensions/browser/api/bluetooth/bluetooth_event_router.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/extensions/browser/api/bluetooth_low_energy/bluetooth_api_advertisement.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_connection.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/extensions/browser/api/bluetooth_low_energy/bluetooth_low_energy_notify_session.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/extensions/browser/api/bluetooth_socket/bluetooth_api_socket.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/extensions/browser/api/bluetooth_socket/bluetooth_socket_api.cc
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h
[modify] https://crrev.com/790754cf4c27c9e1b33613c4e1a48c80c82172ba/extensions/browser/api/bluetooth_socket/bluetooth_socket_event_dispat
Project Member

Comment 11 by bugdroid1@chromium.org, Mar 20 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/d260e9cf660f062b203692601cf9b6ccb27f3d1e

commit d260e9cf660f062b203692601cf9b6ccb27f3d1e
Author: Gabriel Charette <gab@chromium.org>
Date: Tue Mar 20 18:10:45 2018

Refactor BrowserThreadImpl, BrowserProcessSubThread, and BrowserMainLoop

This brings back the invariant that BrowserThread::IO isn't available
before BrowserMainLoop::CreateThreads(). This was broken to fix issue
729596 to bring up the thread earlier for ServiceManager but it is
important that code that posts to BrowserThread::IO statically have an
happens-after relationship to BrowserMainLoop::CreateThreads(). Exposing
it statically earlier put that invariant at risk.

Thankfully fixing  issue 815225  resulted in finally reaching the long
sought goal of only having BrowserThread::UI/IO. Now that the IO thread
is also kicked off before it's named statically, BrowserThreadImpl no
longer needs to be a base::Thread, hence this refactoring.

Before this CL:
 * BrowserThreadImpl was a base::Thread
   (could be a fake thread if SetMessageLoop was used)
 * BrowserProcessSubThread was a BrowserThreadImpl
   (performed a bit more initialization)
 * BrowserProcessSubThread was only used in production (in
   BrowserMainLoop)
 * BrowserThreadImpl was used for fake threads (BrowserMainLoop for
   BrowserThread::UI) and for testing (TestBrowserThread(Impl)).
 * BrowserThreadImpl overrode Init/Run/CleanUp() from base::Thread to
   perform some sanity checks as well as drive IOThread's Delegate (ref.
   BrowserThread::SetIOThreadDelegate())
 * BrowserProcessSubThread re-overrode Init/Run/CleanUp() to perform
   per-thread //content initialization (tests missed out on that per
   TestBrowserThread bypassing BrowserProcessSubThread by directly
   subclassing BrowserThreadImpl).

With this CL:
 * BrowserThreadImpl is merely a scoped object that binds a provided
   SingleThreadTaskRunner to a BrowserThread::ID.
 * BrowserProcessSubThread is a base::Thread and performs all of the
   initialization and cleanup specific to //content (this means it now
   also manages BrowserThread::SetIOThreadDelegate())
 * BrowserProcessSubThread can be brought up early before being bound to
   a BrowserThread::ID (BrowserMainLoop handles that through
   BrowserProcessSubThread ::RegisterAsBrowserThread())

Unfortunate exceptions required for this CL:
 * IOThread::Init() (invoked through BrowserThreadDelegate) perfoms
   blocking operations this was previously performed before installed
   the ThreadRestrictions on BrowserThread::IO. But now that //content
   is initialized after bringing up the thread, a
   base::ScopedAllowBlocking is required in scope of IOThread::Init().
 * TestBrowserThread previously bypassing BrowserProcessSubThread by
   directly subclassing BrowserThreadImpl meant it wasn't subject to
   ThreadRestrictions (unfortunate becomes it denies allowance
   verification to product code running in unit tests). Adding it back
   causes DCHECKs, as such
   BrowserProcessSubThread::AllowBlockingForTesting was added to allow
   this CL to pass CQ.

Of note:
 * BrowserProcessSubThread is still written as though it supports many
   BrowserThread::IDs but in practice it's mostly always
   BrowserThread::IO (except in ThreadWatcherTest I think). This change
   was big enough that I didn't bother also breaking that
   generalization.
 * BrowserThreadImpl's constructor was made private to ensure only
   BrowserProcessSubThread and a few select callers get to drive it (to
   avoid previous missed initialization issues)
 * Atomics to manage BrowserThread::SetIOThreadDelegate were removed.
   Restriction was instead added that this only be called before
   initialization and after shutdown (this was already the case).

Follow-ups to this CL:
 * //ios duplicates this logic and will need to undergo the same change
   as a follow-up
 * Fixing ios will allow removal of base::Thread::SetMessageLoop hack :)
 * Removing BrowserThreadGlobals::lock_ to address  crbug.com/821034  will
   be much easier
 * BrowserThread post APIs should DCHECK rather than no-op if using a
   BrowserThread::ID before it's registered.

Bug:  815225 ,  821034 , 729596
Change-Id: If1038f23079df72203b1e95c7d26647f8824a726
Reviewed-on: https://chromium-review.googlesource.com/969104
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544440}
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/base/threading/thread.h
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/base/threading/thread_restrictions.h
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/chrome/browser/browser_process_impl_unittest.cc
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/browser/browser_main_loop.cc
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/browser/browser_main_loop.h
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/browser/browser_main_loop_unittest.cc
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/browser/browser_main_runner.cc
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/browser/browser_process_sub_thread.cc
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/browser/browser_process_sub_thread.h
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/browser/browser_thread_impl.cc
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/browser/browser_thread_impl.h
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/browser/browser_thread_unittest.cc
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/public/browser/browser_thread.h
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/public/browser/browser_thread_delegate.h
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/public/test/test_browser_thread.cc
[modify] https://crrev.com/d260e9cf660f062b203692601cf9b6ccb27f3d1e/content/public/test/test_browser_thread.h

Project Member

Comment 12 by bugdroid1@chromium.org, Mar 26 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/fa239c8c41939589490f62c39321b8c2504b2219

commit fa239c8c41939589490f62c39321b8c2504b2219
Author: Matt Falkenhagen <falken@chromium.org>
Date: Mon Mar 26 04:21:19 2018

Revert "Refactor BrowserThreadImpl, BrowserProcessSubThread, and BrowserMainLoop"

This reverts commit d260e9cf660f062b203692601cf9b6ccb27f3d1e.

Reason for revert: In Windows Canary versions since 67.0.3377.0, where this commit landed, IO thread hang reports have spiked dramatically. It is now the #1 browser crash report on Windows Canary at 33% of reports. I'm speculatively reverting this to see if the crash rate heals.

Original change's description:
> Refactor BrowserThreadImpl, BrowserProcessSubThread, and BrowserMainLoop
>
> This brings back the invariant that BrowserThread::IO isn't available
> before BrowserMainLoop::CreateThreads(). This was broken to fix issue
> 729596 to bring up the thread earlier for ServiceManager but it is
> important that code that posts to BrowserThread::IO statically have an
> happens-after relationship to BrowserMainLoop::CreateThreads(). Exposing
> it statically earlier put that invariant at risk.
>
> Thankfully fixing  issue 815225  resulted in finally reaching the long
> sought goal of only having BrowserThread::UI/IO. Now that the IO thread
> is also kicked off before it's named statically, BrowserThreadImpl no
> longer needs to be a base::Thread, hence this refactoring.
>
> Before this CL:
>  * BrowserThreadImpl was a base::Thread
>    (could be a fake thread if SetMessageLoop was used)
>  * BrowserProcessSubThread was a BrowserThreadImpl
>    (performed a bit more initialization)
>  * BrowserProcessSubThread was only used in production (in
>    BrowserMainLoop)
>  * BrowserThreadImpl was used for fake threads (BrowserMainLoop for
>    BrowserThread::UI) and for testing (TestBrowserThread(Impl)).
>  * BrowserThreadImpl overrode Init/Run/CleanUp() from base::Thread to
>    perform some sanity checks as well as drive IOThread's Delegate (ref.
>    BrowserThread::SetIOThreadDelegate())
>  * BrowserProcessSubThread re-overrode Init/Run/CleanUp() to perform
>    per-thread //content initialization (tests missed out on that per
>    TestBrowserThread bypassing BrowserProcessSubThread by directly
>    subclassing BrowserThreadImpl).
>
> With this CL:
>  * BrowserThreadImpl is merely a scoped object that binds a provided
>    SingleThreadTaskRunner to a BrowserThread::ID.
>  * BrowserProcessSubThread is a base::Thread and performs all of the
>    initialization and cleanup specific to //content (this means it now
>    also manages BrowserThread::SetIOThreadDelegate())
>  * BrowserProcessSubThread can be brought up early before being bound to
>    a BrowserThread::ID (BrowserMainLoop handles that through
>    BrowserProcessSubThread ::RegisterAsBrowserThread())
>
> Unfortunate exceptions required for this CL:
>  * IOThread::Init() (invoked through BrowserThreadDelegate) perfoms
>    blocking operations this was previously performed before installed
>    the ThreadRestrictions on BrowserThread::IO. But now that //content
>    is initialized after bringing up the thread, a
>    base::ScopedAllowBlocking is required in scope of IOThread::Init().
>  * TestBrowserThread previously bypassing BrowserProcessSubThread by
>    directly subclassing BrowserThreadImpl meant it wasn't subject to
>    ThreadRestrictions (unfortunate becomes it denies allowance
>    verification to product code running in unit tests). Adding it back
>    causes DCHECKs, as such
>    BrowserProcessSubThread::AllowBlockingForTesting was added to allow
>    this CL to pass CQ.
>
> Of note:
>  * BrowserProcessSubThread is still written as though it supports many
>    BrowserThread::IDs but in practice it's mostly always
>    BrowserThread::IO (except in ThreadWatcherTest I think). This change
>    was big enough that I didn't bother also breaking that
>    generalization.
>  * BrowserThreadImpl's constructor was made private to ensure only
>    BrowserProcessSubThread and a few select callers get to drive it (to
>    avoid previous missed initialization issues)
>  * Atomics to manage BrowserThread::SetIOThreadDelegate were removed.
>    Restriction was instead added that this only be called before
>    initialization and after shutdown (this was already the case).
>
> Follow-ups to this CL:
>  * //ios duplicates this logic and will need to undergo the same change
>    as a follow-up
>  * Fixing ios will allow removal of base::Thread::SetMessageLoop hack :)
>  * Removing BrowserThreadGlobals::lock_ to address  crbug.com/821034  will
>    be much easier
>  * BrowserThread post APIs should DCHECK rather than no-op if using a
>    BrowserThread::ID before it's registered.
>
> Bug:  815225 ,  821034 , 729596
> Change-Id: If1038f23079df72203b1e95c7d26647f8824a726
> Reviewed-on: https://chromium-review.googlesource.com/969104
> Reviewed-by: John Abd-El-Malek <jam@chromium.org>
> Commit-Queue: Gabriel Charette <gab@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#544440}

TBR=gab@chromium.org,jam@chromium.org
NOPRESUBMIT=true

# Not skipping CQ checks because original CL landed > 1 day ago.
# falken: Skipping presubmit to use deprecated ThreadResrictions::DisallowWaiting().

Bug:  815225 ,  821034 , 729596
Change-Id: I2be97c5d8183497c005ab397c871f625b034d850
Reviewed-on: https://chromium-review.googlesource.com/979752
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545725}
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/base/threading/thread.h
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/base/threading/thread_restrictions.h
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/chrome/browser/browser_process_impl_unittest.cc
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/browser/browser_main_loop.cc
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/browser/browser_main_loop.h
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/browser/browser_main_loop_unittest.cc
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/browser/browser_main_runner.cc
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/browser/browser_process_sub_thread.cc
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/browser/browser_process_sub_thread.h
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/browser/browser_thread_impl.cc
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/browser/browser_thread_impl.h
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/browser/browser_thread_unittest.cc
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/public/browser/browser_thread.h
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/public/browser/browser_thread_delegate.h
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/public/test/test_browser_thread.cc
[modify] https://crrev.com/fa239c8c41939589490f62c39321b8c2504b2219/content/public/test/test_browser_thread.h

Comment 13 by gab@chromium.org, Mar 26 2018

Blockedon: 824716
Project Member

Comment 14 by bugdroid1@chromium.org, Mar 27 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/8eb4dff9914d111cbce7cbc756b0c96030151762

commit 8eb4dff9914d111cbce7cbc756b0c96030151762
Author: Gabriel Charette <gab@chromium.org>
Date: Tue Mar 27 14:22:54 2018

Reland "Refactor BrowserThreadImpl, BrowserProcessSubThread, and BrowserMainLoop"

This is a reland of d260e9cf660f062b203692601cf9b6ccb27f3d1e

It was reverted because of crbug.com/824716, these weren't new crashes
but known crashes mislabeled as a fallout of this change.
http://cl/190471699 fixes the crash backend to not rely on
"content::BrowserThreadImpl::IOThreadRun" being in the signature.

Only diff in this CL is to use base::debug::Alias() in methods that we
don't want optimized (i.e. IOThreadRun) out as CHECK_GT was seen as
optimized out in some of the reported crashes (even though the same
pattern as before was used by this CL..?)

Original change's description:
> Refactor BrowserThreadImpl, BrowserProcessSubThread, and BrowserMainLoop
>
> This brings back the invariant that BrowserThread::IO isn't available
> before BrowserMainLoop::CreateThreads(). This was broken to fix issue
> 729596 to bring up the thread earlier for ServiceManager but it is
> important that code that posts to BrowserThread::IO statically have an
> happens-after relationship to BrowserMainLoop::CreateThreads(). Exposing
> it statically earlier put that invariant at risk.
>
> Thankfully fixing  issue 815225  resulted in finally reaching the long
> sought goal of only having BrowserThread::UI/IO. Now that the IO thread
> is also kicked off before it's named statically, BrowserThreadImpl no
> longer needs to be a base::Thread, hence this refactoring.
>
> Before this CL:
>  * BrowserThreadImpl was a base::Thread
>    (could be a fake thread if SetMessageLoop was used)
>  * BrowserProcessSubThread was a BrowserThreadImpl
>    (performed a bit more initialization)
>  * BrowserProcessSubThread was only used in production (in
>    BrowserMainLoop)
>  * BrowserThreadImpl was used for fake threads (BrowserMainLoop for
>    BrowserThread::UI) and for testing (TestBrowserThread(Impl)).
>  * BrowserThreadImpl overrode Init/Run/CleanUp() from base::Thread to
>    perform some sanity checks as well as drive IOThread's Delegate (ref.
>    BrowserThread::SetIOThreadDelegate())
>  * BrowserProcessSubThread re-overrode Init/Run/CleanUp() to perform
>    per-thread //content initialization (tests missed out on that per
>    TestBrowserThread bypassing BrowserProcessSubThread by directly
>    subclassing BrowserThreadImpl).
>
> With this CL:
>  * BrowserThreadImpl is merely a scoped object that binds a provided
>    SingleThreadTaskRunner to a BrowserThread::ID.
>  * BrowserProcessSubThread is a base::Thread and performs all of the
>    initialization and cleanup specific to //content (this means it now
>    also manages BrowserThread::SetIOThreadDelegate())
>  * BrowserProcessSubThread can be brought up early before being bound to
>    a BrowserThread::ID (BrowserMainLoop handles that through
>    BrowserProcessSubThread ::RegisterAsBrowserThread())
>
> Unfortunate exceptions required for this CL:
>  * IOThread::Init() (invoked through BrowserThreadDelegate) perfoms
>    blocking operations this was previously performed before installed
>    the ThreadRestrictions on BrowserThread::IO. But now that //content
>    is initialized after bringing up the thread, a
>    base::ScopedAllowBlocking is required in scope of IOThread::Init().
>  * TestBrowserThread previously bypassing BrowserProcessSubThread by
>    directly subclassing BrowserThreadImpl meant it wasn't subject to
>    ThreadRestrictions (unfortunate becomes it denies allowance
>    verification to product code running in unit tests). Adding it back
>    causes DCHECKs, as such
>    BrowserProcessSubThread::AllowBlockingForTesting was added to allow
>    this CL to pass CQ.
>
> Of note:
>  * BrowserProcessSubThread is still written as though it supports many
>    BrowserThread::IDs but in practice it's mostly always
>    BrowserThread::IO (except in ThreadWatcherTest I think). This change
>    was big enough that I didn't bother also breaking that
>    generalization.
>  * BrowserThreadImpl's constructor was made private to ensure only
>    BrowserProcessSubThread and a few select callers get to drive it (to
>    avoid previous missed initialization issues)
>  * Atomics to manage BrowserThread::SetIOThreadDelegate were removed.
>    Restriction was instead added that this only be called before
>    initialization and after shutdown (this was already the case).
>
> Follow-ups to this CL:
>  * //ios duplicates this logic and will need to undergo the same change
>    as a follow-up
>  * Fixing ios will allow removal of base::Thread::SetMessageLoop hack :)
>  * Removing BrowserThreadGlobals::lock_ to address  crbug.com/821034  will
>    be much easier
>  * BrowserThread post APIs should DCHECK rather than no-op if using a
>    BrowserThread::ID before it's registered.
>
> Bug:  815225 ,  821034 , 729596
> Change-Id: If1038f23079df72203b1e95c7d26647f8824a726
> Reviewed-on: https://chromium-review.googlesource.com/969104
> Reviewed-by: John Abd-El-Malek <jam@chromium.org>
> Commit-Queue: Gabriel Charette <gab@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#544440}

TBR=jam@chromium.org

Bug:  815225 ,  821034 , 729596, 824716
Change-Id: I9a180975c69a008f8519d1d3d44663aa58a74a92
Reviewed-on: https://chromium-review.googlesource.com/980793
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546104}
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/base/threading/thread.h
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/base/threading/thread_restrictions.h
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/chrome/browser/browser_process_impl_unittest.cc
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/browser/browser_main_loop.cc
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/browser/browser_main_loop.h
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/browser/browser_main_loop_unittest.cc
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/browser/browser_main_runner.cc
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/browser/browser_process_sub_thread.cc
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/browser/browser_process_sub_thread.h
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/browser/browser_thread_impl.cc
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/browser/browser_thread_impl.h
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/browser/browser_thread_unittest.cc
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/public/browser/browser_thread.h
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/public/browser/browser_thread_delegate.h
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/public/test/test_browser_thread.cc
[modify] https://crrev.com/8eb4dff9914d111cbce7cbc756b0c96030151762/content/public/test/test_browser_thread.h

Project Member

Comment 15 by bugdroid1@chromium.org, Mar 27 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/9ed29db5e854f3f4c08029fa6ca4088a52053045

commit 9ed29db5e854f3f4c08029fa6ca4088a52053045
Author: Gabriel Charette <gab@chromium.org>
Date: Tue Mar 27 19:48:00 2018

Make BrowserThreadImpl lock-less

Sampling profiler highlights high contention on this lock:
 crbug.com/821034 .

Initializing/tear down was already single-threaded (tear down had to be moved
from BrowserProcessSubThread::Cleanup() to ~BrowserProcessSubThread() to
enforce this with a ThreadChecker however). Add dchecks to confirm/enforce
this and remove the lock which is usuless on data structures that are now (as
of series of changes over the last year) read-only after startup.

Use atomics to protect reads across the RUNNING=>SHUTDOWN boundary.

Bug:  821034 
Change-Id: I7800048bff51ad79cb10ee89fd3a0a31534c393e
Reviewed-on: https://chromium-review.googlesource.com/973556
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546212}
[modify] https://crrev.com/9ed29db5e854f3f4c08029fa6ca4088a52053045/content/browser/browser_process_sub_thread.cc
[modify] https://crrev.com/9ed29db5e854f3f4c08029fa6ca4088a52053045/content/browser/browser_thread_impl.cc
[modify] https://crrev.com/9ed29db5e854f3f4c08029fa6ca4088a52053045/content/browser/browser_thread_impl.h

Comment 16 Deleted

Comment 17 by gab@chromium.org, Apr 12 2018

Removed BrowserThreadGlobals::lock_ in r546212 (first live in 67.0.3382.0).

Comparison of time spend in LockImpl::Lock on BrowserThread::IO during browser startup:
67.0.3381.0 : https://uma.googleplex.com/p/chrome/callstacks?sid=4123b774cdae0360a93ddeb4f00e0c01
67.0.3382.0 : https://uma.googleplex.com/p/chrome/callstacks?sid=c076a5e584d5d22700b7241705e0d1d7

Summary:

67.0.3381.0 :
 - 3.722% time spent in LockImpl::Lock
 - Major contributor = mojo::SimpleWatcher::Context::Notify
   - 1.112% time spent locking BrowserThreadGlobals::lock_
   - 0.2057% time spent locking IncomingTaskQueue::incoming_queue_lock_
 - Other major contributors are stuck on IncomingTaskQueue::incoming_queue_lock_
 - 1.238% spent in content::BrowserThread::CurrentlyOn (all on BrowserThreadGlobals::lock_)

67.0.3382.0 :
 - 3.390% time spent in LockImpl::Lock
 - Major contributor = mojo::SimpleWatcher::Context::Notify
   - 0% time spent locking BrowserThreadGlobals::lock_
   - 1.216% time spent locking IncomingTaskQueue::incoming_queue_lock_
 - Other major contributors are stuck on IncomingTaskQueue::incoming_queue_lock_
 - 0% spent in content::BrowserThread::CurrentlyOn (the method still exists but is now blazing fast)

So this fix highlights even stronger that the real issue is crbug.com/786597. The vast majority of the locking is spent waiting for the incoming_queue_lock_ and that's most likely because the lock is held too long because managing the delayed task queue is slow.

Getting rid of BrowserThreadGlobals::lock_ was a first step to healing the situation and helped speed up BrowserThread::CurrentlyOn() from an average of 34.3ms to an instant 0ms call, but for PostTask the Lock merely acted as a bottleneck before trying to obtain IncomingTaskQueue::incoming_queue_lock_, relieving that means we get to it faster but don't obtain it faster.

I'll be attacking issue 786597 next to heal that situation.

PS: Thanks once again to the Sampling Profiler for this awesome data :)!
Blocking: 890978
Turns out this was a prereq to  issue 890978  (which wasn't known at the time).

This hence means that iOS is still affected by  issue 890978  per this lock.

Sign in to add a comment