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

Issue 2887193002: Create a thread safe version of StatsCounters and use. (Closed)

Created:
3 years, 7 months ago by kschimpf
Modified:
3 years, 6 months ago
CC:
v8-reviews_googlegroups.com, wasm-v8_google.com
Target Ref:
refs/heads/master
Project:
v8
Visibility:
Public.

Description

Create a thread safe version of StatsCounters and use. Creates a new class StatsCounterThreadSafe to be used by counters that can be updated when compiling/decoding etc. are done using workers. Does this by using a mutex on all opreations. Also updates the StatsCounterThreadSafe constructor to force counter initialization, as well as method Reset(). In addition, whenever the method StatsTable::SetCounterFunction() is called (from the main thread), it forces counter initialization for all thread safe stats counters. BUG=v8:6361 Review-Url: https://codereview.chromium.org/2887193002 Cr-Commit-Position: refs/heads/master@{#45526} Committed: https://chromium.googlesource.com/v8/v8/+/fbbc0ff24328fe966cc9538976f693601f44e5d1

Patch Set 1 #

Patch Set 2 : Clean up nits. #

Patch Set 3 : Clean up code. #

Total comments: 2

Patch Set 4 : Make Counters a shared pointer, to allow workers to hold on to them. #

Patch Set 5 : Clean up nits. #

Total comments: 6

Patch Set 6 : Factor out base class StatsCounterBase #

Total comments: 2

Patch Set 7 : Replace NULL with nullptr. #

Total comments: 10

Patch Set 8 : fix nits of mtrofin #

Total comments: 12
Unified diffs Side-by-side diffs Delta from patch set Stats (+199 lines, -74 lines) Patch
M src/api.cc View 1 2 3 4 5 6 1 chunk +1 line, -3 lines 0 comments Download
M src/counters.h View 1 2 3 4 5 12 chunks +81 lines, -30 lines 4 comments Download
M src/counters.cc View 1 2 3 4 5 3 chunks +63 lines, -4 lines 0 comments Download
M src/isolate.h View 1 2 3 3 chunks +3 lines, -0 lines 0 comments Download
M src/isolate.cc View 1 2 3 4 5 6 2 chunks +11 lines, -4 lines 3 comments Download
M src/wasm/wasm-module.h View 1 2 3 4 5 6 7 1 chunk +2 lines, -1 line 0 comments Download
M src/wasm/wasm-module.cc View 1 2 3 4 5 6 7 21 chunks +38 lines, -32 lines 5 comments Download

Messages

Total messages: 41 (22 generated)
kschimpf
Please review. Thanks.
3 years, 7 months ago (2017-05-18 17:56:16 UTC) #7
jochen (gone - plz use gerrit)
https://codereview.chromium.org/2887193002/diff/40001/src/wasm/wasm-module.cc File src/wasm/wasm-module.cc (left): https://codereview.chromium.org/2887193002/diff/40001/src/wasm/wasm-module.cc#oldcode83 src/wasm/wasm-module.cc:83: } that doesn't look safe - isolate still can't ...
3 years, 7 months ago (2017-05-18 20:32:45 UTC) #8
kschimpf
https://codereview.chromium.org/2887193002/diff/40001/src/wasm/wasm-module.cc File src/wasm/wasm-module.cc (left): https://codereview.chromium.org/2887193002/diff/40001/src/wasm/wasm-module.cc#oldcode83 src/wasm/wasm-module.cc:83: } On 2017/05/18 20:32:45, jochen wrote: > that doesn't ...
3 years, 7 months ago (2017-05-18 21:05:24 UTC) #9
jochen (gone - plz use gerrit)
On 2017/05/18 at 21:05:24, kschimpf wrote: > https://codereview.chromium.org/2887193002/diff/40001/src/wasm/wasm-module.cc > File src/wasm/wasm-module.cc (left): > > https://codereview.chromium.org/2887193002/diff/40001/src/wasm/wasm-module.cc#oldcode83 ...
3 years, 7 months ago (2017-05-18 21:23:55 UTC) #10
kschimpf
After looking at this some more, using isolate->counters() isn't any safer. All that method does ...
3 years, 7 months ago (2017-05-22 15:49:36 UTC) #11
kschimpf
Ready for another review. Thanks.
3 years, 7 months ago (2017-05-22 20:19:51 UTC) #16
jochen (gone - plz use gerrit)
it's a bit sad that we now have to take a mutex all the time ...
3 years, 7 months ago (2017-05-23 11:29:21 UTC) #17
kschimpf
Refactored out base class StatsCounterBase. Also added check in the thread safe version to do ...
3 years, 7 months ago (2017-05-23 16:53:08 UTC) #20
jochen (gone - plz use gerrit)
lgtm https://codereview.chromium.org/2887193002/diff/100001/src/isolate.cc File src/isolate.cc (right): https://codereview.chromium.org/2887193002/diff/100001/src/isolate.cc#newcode2640 src/isolate.cc:2640: if (counters_ != NULL) return false; nit. nullptr
3 years, 7 months ago (2017-05-24 19:41:07 UTC) #23
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/2887193002/120001
3 years, 7 months ago (2017-05-24 20:22:55 UTC) #26
commit-bot: I haz the power
Try jobs failed on following builders: v8_presubmit on master.tryserver.v8 (JOB_FAILED, http://build.chromium.org/p/tryserver.v8/builders/v8_presubmit/builds/41807)
3 years, 7 months ago (2017-05-24 20:25:49 UTC) #28
kschimpf
https://codereview.chromium.org/2887193002/diff/100001/src/isolate.cc File src/isolate.cc (right): https://codereview.chromium.org/2887193002/diff/100001/src/isolate.cc#newcode2640 src/isolate.cc:2640: if (counters_ != NULL) return false; On 2017/05/24 19:41:07, ...
3 years, 7 months ago (2017-05-24 20:26:09 UTC) #29
Mircea Trofin
LGTM with nits. https://codereview.chromium.org/2887193002/diff/120001/src/wasm/wasm-module.cc File src/wasm/wasm-module.cc (right): https://codereview.chromium.org/2887193002/diff/120001/src/wasm/wasm-module.cc#newcode59 src/wasm/wasm-module.cc:59: static void RecordStats(Isolate* isolate, Code* code, ...
3 years, 7 months ago (2017-05-24 20:37:20 UTC) #30
kschimpf
https://codereview.chromium.org/2887193002/diff/120001/src/wasm/wasm-module.cc File src/wasm/wasm-module.cc (right): https://codereview.chromium.org/2887193002/diff/120001/src/wasm/wasm-module.cc#newcode59 src/wasm/wasm-module.cc:59: static void RecordStats(Isolate* isolate, Code* code, Counters* counters) { ...
3 years, 7 months ago (2017-05-24 20:49:13 UTC) #31
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/2887193002/140001
3 years, 7 months ago (2017-05-24 20:49:36 UTC) #34
commit-bot: I haz the power
Committed patchset #8 (id:140001) as https://chromium.googlesource.com/v8/v8/+/fbbc0ff24328fe966cc9538976f693601f44e5d1
3 years, 7 months ago (2017-05-24 21:21:12 UTC) #37
Clemens Hammacher
https://codereview.chromium.org/2887193002/diff/140001/src/counters.h File src/counters.h (right): https://codereview.chromium.org/2887193002/diff/140001/src/counters.h#newcode107 src/counters.h:107: void IncrementLoc(int* loc) { (*loc)++; } Is there any ...
3 years, 6 months ago (2017-06-02 13:08:50 UTC) #39
kschimpf
https://codereview.chromium.org/2887193002/diff/140001/src/counters.h File src/counters.h (left): https://codereview.chromium.org/2887193002/diff/140001/src/counters.h#oldcode121 src/counters.h:121: void Increment(int value) { Here was the previous definition ...
3 years, 6 months ago (2017-06-02 15:01:02 UTC) #40
kschimpf
3 years, 6 months ago (2017-06-02 17:06:28 UTC) #41
Message was sent while issue was closed.
https://codereview.chromium.org/2887193002/diff/140001/src/counters.h
File src/counters.h (right):

https://codereview.chromium.org/2887193002/diff/140001/src/counters.h#newcode107
src/counters.h:107: void IncrementLoc(int* loc) { (*loc)++; }
On 2017/06/02 15:01:02, kschimpf wrote:
> On 2017/06/02 13:08:49, Clemens Hammacher wrote:
> > Is there any implementation where the semantics of {IncrementLoc(loc)} is
> > different from {IncrementLoc(loc, 1)}? If no, we should just set a default
> value
> > of 1 for the {int value} parameter.
> > (Also on all other occurences of this pattern)
> 
> I did this to follow the same pattern as the code it replaced. However, I'll
> look to see if it is unnecessary.

There are calls on "size" counters that increment counts by the size value.
Hence they are needed.

https://codereview.chromium.org/2887193002/diff/140001/src/isolate.cc
File src/isolate.cc (right):

https://codereview.chromium.org/2887193002/diff/140001/src/isolate.cc#newcode...
src/isolate.cc:2640: if (counters_ != nullptr) return false;
On 2017/06/02 15:01:02, kschimpf wrote:
> On 2017/06/02 13:08:49, Clemens Hammacher wrote:
> > This pattern is not safe in general. A thread observing that {counters_ !=
> > nullptr} is not guaranteed to also observe all other updates performed
inside
> > the locked scope below. This would at least require atomic updates of the
> > {counters_} field, or explicit memory barries.
> > 
> > Overall, I don't see why we need the mutex here in the first place. Is it
> > allowed to call this function from a background task?
> 
> I was probably too concerned about this, since the way code was previously
> written, it could be called on background threads. However, I agree that we
> probably could have presumed this. Now that the StatsTable of an Isolate has
> been moved to a field in the Counters class, we can make stronger assumptions
> (by not making this method public). Will fix as part of CL
> https://codereview.chromium.org/2918703002

Fixed in cl https://codereview.chromium.org/2919953003

https://codereview.chromium.org/2887193002/diff/140001/src/wasm/wasm-module.cc
File src/wasm/wasm-module.cc (right):

https://codereview.chromium.org/2887193002/diff/140001/src/wasm/wasm-module.c...
src/wasm/wasm-module.cc:357: Counters* counters_;
On 2017/06/02 15:01:02, kschimpf wrote:
> On 2017/06/02 13:08:50, Clemens Hammacher wrote:
> > Why is this field needed? {counters_shared_.get()} should be equally good.
> It's
> > just reading a field from our own shared_ptr instance, so no potential race
> > conditions here.
> 
> I was confusing the assignment operator with the get() method, where there is
a
> LOT of inline code. You appear to be correct that I should have used the get()
> method. Fixing in separate CL.

Fixed in CL https://codereview.chromium.org/2919953003

https://codereview.chromium.org/2887193002/diff/140001/src/wasm/wasm-module.c...
src/wasm/wasm-module.cc:1561: Counters* counters_;
On 2017/06/02 13:08:50, Clemens Hammacher wrote:
> Same here.

Fixed in CL https://codereview.chromium.org/2919953003

Powered by Google App Engine
This is Rietveld 408576698