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

Issue 2822035: Change chrome from statically enabling high resolution timers on windows... (Closed)

Created:
10 years, 5 months ago by Mike Belshe
Modified:
9 years, 5 months ago
CC:
chromium-reviews, cbentzel+watch_chromium.org, darin-cc_chromium.org, amit, brettw-cc_chromium.org
Visibility:
Public.

Description

Change chrome from statically enabling high resolution timers on windows to enabling them dynamically - only when the application really needs them. I am working on some test cases for this, and will add them. But wanted to send out the concept for review. In this implementation, I modify the message loop to detect when the application has requested high resolution timers. Note that there are multiple MessageLoops active in a single process. After a period of time, we simply shut it off again. We could have set a timer or kept a count of active timers, or any number of more complex algorithms. But I think this algorithm is very simple and good enough. If an application continues needing high resolution timers for more than 1s, we'll turn the high-resolution timers back on again. One last change - since we've implemented the clamp at 4ms, there isn't a lot of point to our use of 1ms for timeBeginPeriod. I've modified that to 2 (which is half of 4ms, our target minimal interval). BUG=46531 TEST=MessageLoop.HighResolutionTimers Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=51102

Patch Set 1 #

Patch Set 2 : '' #

Total comments: 12

Patch Set 3 : '' #

Total comments: 10

Patch Set 4 : '' #

Patch Set 5 : '' #

Patch Set 6 : '' #

Unified diffs Side-by-side diffs Delta from patch set Stats (+128 lines, -18 lines) Patch
M app/hi_res_timer_manager_win.cc View 3 1 chunk +1 line, -3 lines 0 comments Download
M base/message_loop.h View 1 2 3 4 2 chunks +18 lines, -0 lines 0 comments Download
M base/message_loop.cc View 1 2 3 1 chunk +26 lines, -0 lines 0 comments Download
M base/message_loop_unittest.cc View 5 1 chunk +29 lines, -0 lines 0 comments Download
M base/test/test_suite.h View 1 2 3 1 chunk +1 line, -2 lines 0 comments Download
M base/time.h View 1 2 3 2 chunks +28 lines, -3 lines 0 comments Download
M base/time_win.cc View 1 2 3 2 chunks +24 lines, -9 lines 0 comments Download
M chrome_frame/test/net/fake_external_tab.cc View 1 2 3 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 7 (0 generated)
Mike Belshe
Note: I'm happy to change the OS_WIN ifdef's. I did consider deliberately how to do ...
10 years, 5 months ago (2010-06-28 00:31:32 UTC) #1
jar (doing other things)
I'm not completely clear on the usage scenarios, but I'm suspicious about possible races. Adding ...
10 years, 5 months ago (2010-06-28 05:52:35 UTC) #2
Mike Belshe
http://codereview.chromium.org/2822035/diff/8001/9001 File base/message_loop.cc (right): http://codereview.chromium.org/2822035/diff/8001/9001#newcode292 base/message_loop.cc:292: delay_ms < Time::kMinLowResolutionThresholdMs; You're right, it should be anyone ...
10 years, 5 months ago (2010-06-28 18:14:46 UTC) #3
jar (doing other things)
I like the logic change. I had a few more thoughts and fears listed below. ...
10 years, 5 months ago (2010-06-29 00:37:05 UTC) #4
Mike Belshe
http://codereview.chromium.org/2822035/diff/4002/10 File base/message_loop.cc (right): http://codereview.chromium.org/2822035/diff/4002/10#newcode287 base/message_loop.cc:287: if (high_resolution_timer_expiration_.is_null()) { On 2010/06/29 00:37:05, jar wrote: > ...
10 years, 5 months ago (2010-06-29 01:53:30 UTC) #5
jar (doing other things)
I have some mild concerns, listed below, but expect that this is probably an excellent ...
10 years, 5 months ago (2010-06-29 04:19:56 UTC) #6
Mike Belshe
10 years, 5 months ago (2010-06-29 04:29:14 UTC) #7
Thanks, Jim!

On 2010/06/29 04:19:56, jar wrote:
> I have some mild concerns, listed below, but expect that this is probably an
> excellent improvement over current status quo. and I know you're about to go
on
> vacation  ...soooo....
> 
> LGTM
> 
> One last thing you might comment on is how this acts during thread shutdown. 
I
> don't think I saw code in the message loop destructor.... but perchance by the
> time threads of this sort are shutting down, the whole process is soon to
> terminate, and that will handle restoring low-res timers.
> If you think this might be an issue, you're welcome to file a bug and deal
with
> it when you get back.

On process shutdown, the OS takes care of the rest.  I've verified this many
times, so I think it is okay.



> 
> http://codereview.chromium.org/2822035/diff/4002/10
> File base/message_loop.cc (right):
> 
> http://codereview.chromium.org/2822035/diff/4002/10#newcode287
> base/message_loop.cc:287: if (high_resolution_timer_expiration_.is_null()) {
> I don't know if it makes sense... but when the high-res timer is active, then
> I'm more concerned with being more efficient, perhaps because I *imagine* that
> the CPU will be stressed to so do all its work.  I don't know if we have per
> tests that really exercise this question... and I'm not (to be honest) sure of
> which case is better served by optimizing.
> 
> On 2010/06/29 01:53:30, Mike Belshe wrote:
> > On 2010/06/29 00:37:05, jar wrote:
> > > This logic will (when we regularly need hi-res) cycle in-and-out of hi-res
> > mode.
> > >  IMO, it would be nicer to stay in hi-res mode by extending the expiration
> > > whenever we need_high_res_timers, even if we already have an expiration.
> > > WDYT?
> > 
> > Of course, that is what I wanted to do.  But we're deep in the guts of the
> > message loop.  Doing something computationally cheap (which is what we have
> > here) seems preferable.
> > 
> > Also - I'm optimizing for the case where we don't need hi-res timers, which
is
> > the common case.
> > > 
> > > To be precise.... you might not need to extend it (with the costly call to
> > > Now()), but you could use a boolean recently_needed_hi_res that would be
> > checked
> > > when we finally contemplate exiting hi-res.
> > > 
> > 
> >
> 
> http://codereview.chromium.org/2822035/diff/4002/10#newcode303
> base/message_loop.cc:303: if (base::TimeTicks::Now() >
> high_resolution_timer_expiration_) {
> On 2010/06/29 01:53:30, Mike Belshe wrote:
> > On 2010/06/29 00:37:05, jar wrote:
> > > It *might* be nice to schedule an event to disable hi-res, or at least
> > consider
> > > disabling it, rather than polling each time we post a delayed task.  There
> is
> > a
> > > tiny chance that this polling would have a perf impact.
> > 
> > Scheduling a task adds a bunch of complexity, but the real question is the
> > lifecycle of the new task.  To keep it simple, I thought this approach is
far
> > better.  I've reduced the per-timer overhead to 1 check (
> > high_resolution_timer_expiration.is_null()) and that seems pretty cheap.
> > > 
> > > It is also interesting that we only disable hi-res when we schedule
another
> > > timer event.  Maybe this happens more than often enough on some
threads....
> > but
> > > a lightly used thread could leave hi-res enabled for a loooong time.
> > 
> > Our app simply doesn't work that way.  But yes, it is theoretically
possible.
> 
> I'm not sure if this is correct... but it is plausible that JS code could
> request a short interval, and then that main renderer thread *might* not have
to
> deal with any events fro a long while.  That *might* be a plausible example of
> this issue.  Then again, perhaps all such threads regularly have timer events
> for "other stuff."  I'm not sure (but you probably know this far better than I
> do).

The theory is possible.  But I don't see that happening in testing.

Powered by Google App Engine
This is Rietveld 408576698