Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Issue 2464233002: Experiment with redirecting all BrowserThreads (but UI/IO) to TaskScheduler (Closed)

Created:
4 years, 1 month ago by gab
Modified:
4 years ago
CC:
chromium-reviews, gab+watch_chromium.org, robliao+watch_chromium.org, jam, fdoray+watch_chromium.org, darin-cc_chromium.org, fdoray, robliao, danakj
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Experiment with redirecting all BrowserThreads (but UI/IO) to TaskScheduler This is part of the migration phase for TaskScheduler, design doc: https://docs.google.com/document/d/1S2AAeoo1xa_vsLbDYBsDHCqhrkfiMgoIPlyRi6kxa5k/edit Also generalizes BrowserThreadImpl away from the underlying thread's MessageLoop and id in favor of TaskRunners and BrowserThreadState. Cool side-effect: BrowserThreadImpl::StartWithOptions() no longer blocks on the underlying thread starting (it used to via GetThreadId()), it now takes a reference to its TaskRunner and lets the thread itself start on its own schedule :). This wasn't previously intended to block (BrowserThreadImpl::StartAndWaitForTesting() is supposed to be used for that) but had unintentionally regressed in http://crrev.com/408295 because GetThreadId() implicitly waits (http://crbug.com/672977). Another nice improvement is that ~BrowserThreadImpl() now cleans the BrowserThreadGlobals associated with it, this has the side-effect to force proper destruction order of TestBrowserThread in tests which brought forth a few precursor cleanups (https://crbug.com/653916#c24) which will from now on be enforced by this CL. When redirection is disabled, the logic should be the exact same as before. - Threads are brought up. - Tasks are posted to their MessageLoop (albeit through their TaskRunner now). - On shutdown, threads are joined one by one. When redirection is enabled, we try to mimic this logic. - Redirection TaskRunners are only live (|accepting_tasks|) for the same period that the matching thread would be. - On shutdown, we block on each TaskRunner's queue being flushed one-by-one in the same order as in the no-redirection case (this almost identical to real threads join % one slight difference documented in detail in BrowserThreadImpl::StopRedirectionOfThreadID()). BUG=653916, 672977 CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_chromium_tsan_rel_ng TEST= A) "out\Release\chrome.exe" Runs/shuts down the exact same as before. B) "out\Release\chrome.exe --force-fieldtrials=BrowserScheduler/Enabled/ --force-fieldtrial-params=BrowserScheduler.Enabled:Background/3;3;1;0;10000/BackgroundFileIO/3;3;1;0;10000/Foreground/3;3;1;0;10000/ForegroundFileIO/3;3;1;0;10000/RedirectSequencedWorkerPools/true/RedirectNonUINonIOBrowserThreads/true" Runs/shuts down smoothly and chrome://tracing confirms that redirected BrowserThreads are running on TaskSchedulerWorkers. Committed: https://crrev.com/3ee0e445ae07397a077eb3213fc46318af01b43e Cr-Commit-Position: refs/heads/master@{#439139}

Patch Set 1 #

Patch Set 2 : cleanup and put behind experiment #

Patch Set 3 : content->variations DEPS and some tweaks #

Patch Set 4 : replace ThreadTaskRunnerHandle usage with RunsTasksOnCurrentThread #

Patch Set 5 : Introduce BrowserThreadGlobals::states and rm BrowserThreadGlobals::threads/thread_ids :) #

Patch Set 6 : Cancel redirection on BrowserMainLoop shutdown #

Patch Set 7 : Synchronously flush redirected TaskRunners on shutdown. #

Patch Set 8 : Decline tasks posted after cancelling a redirection -- better shutdown simulation #

Patch Set 9 : Fix globals.states check edge case #

Patch Set 10 : rm content->variations DEPS, use ContentBrowserClient instead #

Patch Set 11 : Rely on Thread::using_external_message_loop_ instead of hard-coding BrowserThread::UI #

Total comments: 10

Patch Set 12 : Allow UNINITIALIZED as well as SHUTDOWN for other threads (happens in unit tests) #

Patch Set 13 : Add ResetGlobalsForTesting() and fix shutdown state in unittests #

Total comments: 1

Patch Set 14 : review:avi#36 #

Patch Set 15 : Extract dependencies: 2487073005 & 2484283005 #

Patch Set 16 : Adapt TestBrowserThread and TestBrowserThreadBundle #

Patch Set 17 : update dependencies #

Patch Set 18 : Handle unintentionally null MessageLoop* #

Patch Set 19 : fix DCHECK in ~BrowserThreadImpl #

Patch Set 20 : Rebase and re-consider threads RUNNING during their async initialization. #

Patch Set 21 : Rebase on https://codereview.chromium.org/2487343005/ and disallow null msg loop again #

Patch Set 22 : Extract unittest side-effects to https://codereview.chromium.org/2523093002/ #

Patch Set 23 : rebase on r434093 #

Patch Set 24 : rebase on https://codereview.chromium.org/2535043003/ #

Patch Set 25 : rebase on r434987 #

Patch Set 26 : update dependencies #

Patch Set 27 : rm TODO #

Total comments: 39

Patch Set 28 : update dependencies #

Patch Set 29 : update dependencies #

Patch Set 30 : rebase on r436155 #

Patch Set 31 : Add missing lock in BrowserThreadImpl::Init in DCHECK builds #

Patch Set 32 : rebase on r436331 #

Patch Set 33 : review:fdoray#80 #

Patch Set 34 : merge and fix compile/naming nit #

Patch Set 35 : rebase on https://codereview.chromium.org/2558943002 #

Patch Set 36 : Hold the lock while starting!!! #

Total comments: 17

Patch Set 37 : rebase on r437246 #

Patch Set 38 : review:robliao#130/fdoray#131 #

Patch Set 39 : fix compile #

Patch Set 40 : WaitUntilThreadStarted on Android?? #

Patch Set 41 : rebase on r437591 #

Patch Set 42 : update dependencies #

Patch Set 43 : rebase on r438560 #

Patch Set 44 : nice comment for forced WaitUntilThreadStarted() on Android #

Patch Set 45 : rebase on r438809 #

Patch Set 46 : remove WaitUntilThreadStarted on Android, makes Android test instrumentation hang, is previous issu… #

Unified diffs Side-by-side diffs Delta from patch set Stats (+377 lines, -109 lines) Patch
M chrome/browser/chrome_content_browser_client.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 1 chunk +1 line, -1 line 0 comments Download
M chrome/browser/chrome_content_browser_client.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 1 chunk +7 lines, -1 line 0 comments Download
M content/browser/browser_main_loop.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 2 chunks +4 lines, -1 line 0 comments Download
M content/browser/browser_main_loop.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 7 chunks +113 lines, -31 lines 0 comments Download
M content/browser/browser_thread_impl.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 2 chunks +20 lines, -1 line 0 comments Download
M content/browser/browser_thread_impl.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 19 chunks +184 lines, -62 lines 0 comments Download
M content/public/browser/content_browser_client.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 1 chunk +4 lines, -0 lines 0 comments Download
M content/public/browser/content_browser_client.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 1 chunk +4 lines, -0 lines 0 comments Download
M content/public/test/test_browser_thread.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 1 chunk +2 lines, -0 lines 0 comments Download
M content/public/test/test_browser_thread.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 1 chunk +23 lines, -4 lines 0 comments Download
M content/public/test/test_browser_thread_bundle.cc View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2 chunks +15 lines, -8 lines 0 comments Download

Messages

Total messages: 229 (209 generated)
gab
Avi PTAL, thanks!
4 years, 1 month ago (2016-11-08 15:51:14 UTC) #26
Avi (use Gerrit)
Oh boy. This looks reasonable (and fun) but can you get more eyes on this ...
4 years, 1 month ago (2016-11-08 16:16:15 UTC) #27
gab
On 2016/11/08 16:16:15, Avi wrote: > Oh boy. This looks reasonable (and fun) but can ...
4 years, 1 month ago (2016-11-08 20:40:45 UTC) #36
Avi (use Gerrit)
I'll OK things for content, but if you know other threads experts (content owners or ...
4 years, 1 month ago (2016-11-08 20:48:17 UTC) #37
gab
@fdoray/robliao PTAL at threading logic @danakj (optional -- I know you're swamped these days but ...
4 years ago (2016-11-29 19:56:51 UTC) #79
fdoray
https://codereview.chromium.org/2464233002/diff/580001/content/browser/browser_main_loop.cc File content/browser/browser_main_loop.cc (right): https://codereview.chromium.org/2464233002/diff/580001/content/browser/browser_main_loop.cc#newcode327 content/browser/browser_main_loop.cc:327: } else { You could avoid keeping SingleThreadTaskRunners references ...
4 years ago (2016-12-01 15:15:22 UTC) #80
gab
@fdoray, comments addressed PTAL. Also, FYI, with a few more precursor CLs landed I'm now ...
4 years ago (2016-12-07 19:15:27 UTC) #109
robliao
Looks reasonable. A few questions and comments. https://codereview.chromium.org/2464233002/diff/860002/content/browser/browser_main_loop.cc File content/browser/browser_main_loop.cc (right): https://codereview.chromium.org/2464233002/diff/860002/content/browser/browser_main_loop.cc#newcode928 content/browser/browser_main_loop.cc:928: TRACE_EVENT_BEGIN1("startup", Does ...
4 years ago (2016-12-08 01:57:17 UTC) #130
fdoray
lgtm w/ comments https://codereview.chromium.org/2464233002/diff/860002/content/browser/browser_main_loop.cc File content/browser/browser_main_loop.cc (right): https://codereview.chromium.org/2464233002/diff/860002/content/browser/browser_main_loop.cc#newcode928 content/browser/browser_main_loop.cc:928: TRACE_EVENT_BEGIN1("startup", On 2016/12/08 01:57:17, robliao wrote: ...
4 years ago (2016-12-08 14:51:46 UTC) #131
gab
Done PTAnL, thanks! https://codereview.chromium.org/2464233002/diff/580001/content/browser/browser_thread_impl.cc File content/browser/browser_thread_impl.cc (right): https://codereview.chromium.org/2464233002/diff/580001/content/browser/browser_thread_impl.cc#newcode647 content/browser/browser_thread_impl.cc:647: void BrowserThread::SetDelegate(ID identifier, On 2016/12/07 19:15:27, ...
4 years ago (2016-12-08 18:49:42 UTC) #144
robliao
lgtm https://codereview.chromium.org/2464233002/diff/860002/content/browser/browser_thread_impl.cc File content/browser/browser_thread_impl.cc (right): https://codereview.chromium.org/2464233002/diff/860002/content/browser/browser_thread_impl.cc#newcode411 content/browser/browser_thread_impl.cc:411: globals.states[identifier_] = BrowserThreadState::RUNNING; On 2016/12/08 18:49:41, gab wrote: ...
4 years ago (2016-12-14 20:38:13 UTC) #200
gab
Thanks, @avi for content (+jam who's had time to come back before everything this tripped ...
4 years ago (2016-12-14 20:53:11 UTC) #202
Avi (use Gerrit)
LGTM good luck
4 years ago (2016-12-14 21:32:13 UTC) #208
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2464233002/1070001
4 years ago (2016-12-14 21:51:41 UTC) #212
commit-bot: I haz the power
Try jobs failed on following builders: linux_android_rel_ng on master.tryserver.chromium.android (JOB_FAILED, https://build.chromium.org/p/tryserver.chromium.android/builders/linux_android_rel_ng/builds/199430)
4 years ago (2016-12-15 00:04:54 UTC) #215
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2464233002/1130001
4 years ago (2016-12-15 23:38:12 UTC) #220
commit-bot: I haz the power
Try jobs failed on following builders: linux_chromium_rel_ng on master.tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/linux_chromium_rel_ng/builds/357593)
4 years ago (2016-12-16 03:35:25 UTC) #222
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2464233002/1130001
4 years ago (2016-12-16 16:27:57 UTC) #224
commit-bot: I haz the power
Committed patchset #46 (id:1130001)
4 years ago (2016-12-16 17:43:48 UTC) #227
commit-bot: I haz the power
4 years ago (2016-12-16 17:46:32 UTC) #229
Message was sent while issue was closed.
Patchset 46 (id:??) landed as
https://crrev.com/3ee0e445ae07397a077eb3213fc46318af01b43e
Cr-Commit-Position: refs/heads/master@{#439139}

Powered by Google App Engine
This is Rietveld 408576698