Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(142)

Issue 5140043: code review 5140043: runtime: unify mutex code across OSes (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 5 months ago by dvyukov
Modified:
13 years, 4 months ago
Reviewers:
CC:
rsc, jsing, hector, golang-dev
Visibility:
Public.

Description

runtime: unify mutex code across OSes The change introduces 2 generic mutex implementations (futex- and semaphore-based). Each OS chooses a suitable mutex implementation and implements few callbacks (e.g. futex wait/wake). The CL reduces code duplication, extends some optimizations available only on Linux/Windows to other OSes and provides ground for futher optimizations. Chan finalizers are finally eliminated. (Linux/amd64, 8 HT cores) benchmark old new BenchmarkChanContended 83.6 77.8 ns/op BenchmarkChanContended-2 341 328 ns/op BenchmarkChanContended-4 382 383 ns/op BenchmarkChanContended-8 390 374 ns/op BenchmarkChanContended-16 313 291 ns/op (Darwin/amd64, 2 cores) benchmark old new BenchmarkChanContended 159 172 ns/op BenchmarkChanContended-2 6735 263 ns/op BenchmarkChanContended-4 10384 255 ns/op BenchmarkChanCreation 1174 407 ns/op BenchmarkChanCreation-2 4007 254 ns/op BenchmarkChanCreation-4 4029 246 ns/op

Patch Set 1 #

Patch Set 2 : diff -r 3299d0ca626a https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 860daf1b0c94 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 860daf1b0c94 https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r 860daf1b0c94 https://go.googlecode.com/hg/ #

Patch Set 6 : diff -r 06199863489f https://go.googlecode.com/hg/ #

Patch Set 7 : diff -r 06199863489f https://go.googlecode.com/hg/ #

Patch Set 8 : diff -r 06199863489f https://go.googlecode.com/hg/ #

Patch Set 9 : diff -r 8c6f3c5bae77 https://go.googlecode.com/hg/ #

Patch Set 10 : diff -r e645ee53ce25 https://go.googlecode.com/hg/ #

Patch Set 11 : diff -r e645ee53ce25 https://go.googlecode.com/hg/ #

Patch Set 12 : diff -r e645ee53ce25 https://go.googlecode.com/hg/ #

Patch Set 13 : diff -r 3fe4f3f34e9b https://go.googlecode.com/hg/ #

Patch Set 14 : diff -r 3fe4f3f34e9b https://go.googlecode.com/hg/ #

Patch Set 15 : diff -r 3fe4f3f34e9b https://go.googlecode.com/hg/ #

Patch Set 16 : diff -r 3fe4f3f34e9b https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 17 : diff -r 3fe4f3f34e9b https://go.googlecode.com/hg/ #

Total comments: 1

Patch Set 18 : diff -r 3fe4f3f34e9b https://go.googlecode.com/hg/ #

Total comments: 1

Patch Set 19 : diff -r 3fe4f3f34e9b https://go.googlecode.com/hg/ #

Patch Set 20 : diff -r b50d362fe507 https://go.googlecode.com/hg/ #

Patch Set 21 : diff -r b50d362fe507 https://go.googlecode.com/hg/ #

Patch Set 22 : diff -r b50d362fe507 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+336 lines, -640 lines) Patch
M src/pkg/runtime/Makefile View 1 2 3 4 5 6 7 8 9 10 20 1 chunk +16 lines, -0 lines 0 comments Download
M src/pkg/runtime/chan.c View 1 2 2 chunks +0 lines, -10 lines 0 comments Download
M src/pkg/runtime/darwin/thread.c View 1 2 3 4 2 chunks +8 lines, -112 lines 0 comments Download
M src/pkg/runtime/freebsd/thread.c View 1 2 3 4 5 6 7 8 9 10 3 chunks +5 lines, -90 lines 0 comments Download
M src/pkg/runtime/linux/thread.c View 1 2 3 4 5 6 7 8 9 10 11 12 13 20 3 chunks +5 lines, -130 lines 0 comments Download
A src/pkg/runtime/lock_futex.c View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 chunk +118 lines, -0 lines 0 comments Download
A src/pkg/runtime/lock_sema.c View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 chunk +128 lines, -0 lines 0 comments Download
M src/pkg/runtime/openbsd/thread.c View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 1 chunk +27 lines, -110 lines 0 comments Download
M src/pkg/runtime/plan9/thread.c View 1 2 3 4 5 6 7 8 9 10 2 chunks +10 lines, -73 lines 0 comments Download
M src/pkg/runtime/runtime.h View 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 4 chunks +11 lines, -28 lines 0 comments Download
M src/pkg/runtime/windows/thread.c View 1 2 3 4 5 6 7 8 9 10 1 chunk +8 lines, -87 lines 0 comments Download

Messages

Total messages: 21
dvyukov
Hello rsc@golang.org, jsing@google.com, hectorchu@gmail.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
13 years, 4 months ago (2011-10-26 16:47:55 UTC) #1
dvyukov
The futex implementation is basically old Linux mutex implementation. The sema implementation is based on ...
13 years, 4 months ago (2011-10-26 16:52:28 UTC) #2
dvyukov
On 2011/10/26 16:52:28, dvyukov wrote: > The futex implementation is basically old Linux mutex implementation. ...
13 years, 4 months ago (2011-10-26 18:18:26 UTC) #3
hector
Very nice. Some nice speedups across the board. Windows 7 x64 Pentium Dual-Core T4200 @ ...
13 years, 4 months ago (2011-10-26 19:45:09 UTC) #4
hector
runtime_test.BenchmarkChanCreation 536.0 486.0 9.3% runtime_test.BenchmarkChanCreation-2 556.0 502.0 9.7% runtime_test.BenchmarkChanCreation-3 534.0 502.0 6.0% runtime_test.BenchmarkChanCreation-4 530.0 502.0 ...
13 years, 4 months ago (2011-10-26 19:46:12 UTC) #5
hector
I re-ran the test suite to check the finalizer results: runtime_test.BenchmarkFinalizerRun 100000 2320 ns/op runtime_test.BenchmarkFinalizerRun-2 ...
13 years, 4 months ago (2011-10-26 19:46:41 UTC) #6
dvyukov
On 2011/10/26 19:46:41, hector wrote: Thanks, Hector! It's a good sign that it does not ...
13 years, 4 months ago (2011-10-27 07:56:50 UTC) #7
hector
On 27 October 2011 08:56, <dvyukov@google.com> wrote: > Do you run all the benchmarks with ...
13 years, 4 months ago (2011-10-27 08:00:26 UTC) #8
hector
http://codereview.appspot.com/5140043/diff/36001/src/pkg/runtime/lock_sema.c File src/pkg/runtime/lock_sema.c (right): http://codereview.appspot.com/5140043/diff/36001/src/pkg/runtime/lock_sema.c#newcode66 src/pkg/runtime/lock_sema.c:66: if((v&LOCKED) == 0) In this case can you avoid ...
13 years, 4 months ago (2011-10-27 08:14:55 UTC) #9
dvyukov
Hello rsc@golang.org, jsing@google.com, hectorchu@gmail.com (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 4 months ago (2011-10-27 08:39:40 UTC) #10
dvyukov
On 2011/10/27 08:14:55, hector wrote: > http://codereview.appspot.com/5140043/diff/36001/src/pkg/runtime/lock_sema.c > File src/pkg/runtime/lock_sema.c (right): > > http://codereview.appspot.com/5140043/diff/36001/src/pkg/runtime/lock_sema.c#newcode66 > ...
13 years, 4 months ago (2011-10-27 08:42:21 UTC) #11
hector
LGTM, though I wish there weren't so many waitsema* vars in M. http://codereview.appspot.com/5140043/diff/28014/src/pkg/runtime/runtime.h File src/pkg/runtime/runtime.h ...
13 years, 4 months ago (2011-10-27 10:31:25 UTC) #12
dvyukov
Hello rsc@golang.org, jsing@google.com, hectorchu@gmail.com (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 4 months ago (2011-10-27 10:36:20 UTC) #13
dvyukov
On 2011/10/27 10:31:25, hector wrote: > LGTM, though I wish there weren't so many waitsema* ...
13 years, 4 months ago (2011-10-27 10:40:14 UTC) #14
hector
Sorry Dmitry just one more thing I noticed, please see comments. I guess in future ...
13 years, 4 months ago (2011-10-27 13:26:08 UTC) #15
dvyukov
Hello rsc@golang.org, jsing@google.com, hectorchu@gmail.com (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 4 months ago (2011-10-27 13:37:12 UTC) #16
dvyukov
On 2011/10/27 13:26:08, hector wrote: > Sorry Dmitry just one more thing I noticed, please ...
13 years, 4 months ago (2011-10-27 14:26:42 UTC) #17
rsc
LGTM
13 years, 4 months ago (2011-10-31 16:25:38 UTC) #18
jsing
LGTM I've tested this under OpenBSD and have not found any issues - the generally ...
13 years, 4 months ago (2011-11-02 12:23:02 UTC) #19
dvyukov
On Wed, Nov 2, 2011 at 5:21 PM, Joel Sing <jsing@google.com> wrote: > I think ...
13 years, 4 months ago (2011-11-02 13:38:20 UTC) #20
dvyukov
13 years, 4 months ago (2011-11-02 13:42:06 UTC) #21
*** Submitted as http://code.google.com/p/go/source/detail?r=71dc491f16f9 ***

runtime: unify mutex code across OSes
The change introduces 2 generic mutex implementations
(futex- and semaphore-based). Each OS chooses a suitable mutex
implementation and implements few callbacks (e.g. futex wait/wake).
The CL reduces code duplication, extends some optimizations available
only on Linux/Windows to other OSes and provides ground
for futher optimizations. Chan finalizers are finally eliminated.

(Linux/amd64, 8 HT cores)
benchmark                      old      new
BenchmarkChanContended         83.6     77.8 ns/op
BenchmarkChanContended-2       341      328 ns/op
BenchmarkChanContended-4       382      383 ns/op
BenchmarkChanContended-8       390      374 ns/op
BenchmarkChanContended-16      313      291 ns/op

(Darwin/amd64, 2 cores)
benchmark                      old      new
BenchmarkChanContended         159      172 ns/op
BenchmarkChanContended-2       6735     263 ns/op
BenchmarkChanContended-4       10384    255 ns/op
BenchmarkChanCreation          1174     407 ns/op
BenchmarkChanCreation-2        4007     254 ns/op
BenchmarkChanCreation-4        4029     246 ns/op

R=rsc, jsing, hectorchu
CC=golang-dev
http://codereview.appspot.com/5140043
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b