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

Issue 45700043: code review 45700043: runtime: remove locks from netpoll hotpaths (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 4 months ago by dvyukov
Modified:
10 years, 3 months ago
Reviewers:
rsc, mikio, iant
CC:
golang-codereviews, mikio, gobot, iant, rsc, khr
Visibility:
Public.

Description

runtime: remove locks from netpoll hotpaths Introduces two-phase goroutine parking mechanism -- prepare to park, commit park. This mechanism does not require backing mutex to protect wait predicate. Use it in netpoll. See comment in netpoll.goc for details. This slightly reduces contention between reader, writer and read/write io notifications; and just eliminates a bunch of mutex operations from hotpaths, thus making then faster. benchmark old ns/op new ns/op delta BenchmarkTCP4ConcurrentReadWrite 2109 1945 -7.78% BenchmarkTCP4ConcurrentReadWrite-2 1162 1113 -4.22% BenchmarkTCP4ConcurrentReadWrite-4 798 755 -5.39% BenchmarkTCP4ConcurrentReadWrite-8 803 748 -6.85% BenchmarkTCP4Persistent 9411 9240 -1.82% BenchmarkTCP4Persistent-2 5888 5813 -1.27% BenchmarkTCP4Persistent-4 4016 3968 -1.20% BenchmarkTCP4Persistent-8 3943 3857 -2.18%

Patch Set 1 #

Patch Set 2 : diff -r 176779a4ebed https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 3 : diff -r 176779a4ebed https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 4 : diff -r 176779a4ebed https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 5 : diff -r 176779a4ebed https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 6 : diff -r 9963a911bc14 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 7 : diff -r 9fd412c6b156 https://dvyukov%40google.com@code.google.com/p/go/ #

Total comments: 5

Patch Set 8 : diff -r d5dbdcc7f614 https://dvyukov%40google.com@code.google.com/p/go/ #

Total comments: 2

Patch Set 9 : diff -r 5b5a2d2d2563 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 10 : diff -r 5b5a2d2d2563 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 11 : diff -r 5b5a2d2d2563 https://dvyukov%40google.com@code.google.com/p/go/ #

Total comments: 9

Patch Set 12 : diff -r 60a0c4c04f5f https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 13 : diff -r 60a0c4c04f5f https://dvyukov%40google.com@code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+180 lines, -85 lines) Patch
M src/pkg/runtime/asm_386.s View 1 2 3 4 5 6 7 1 chunk +6 lines, -0 lines 0 comments Download
M src/pkg/runtime/asm_amd64.s View 1 2 3 4 5 6 7 8 1 chunk +6 lines, -0 lines 0 comments Download
M src/pkg/runtime/atomic_arm.c View 1 2 3 4 5 6 7 1 chunk +13 lines, -0 lines 0 comments Download
M src/pkg/runtime/chan.c View 1 2 3 4 5 6 7 8 9 10 11 6 chunks +13 lines, -5 lines 0 comments Download
M src/pkg/runtime/mgc0.c View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/runtime/netpoll.goc View 1 2 3 4 5 6 7 8 9 10 11 12 chunks +87 lines, -51 lines 0 comments Download
M src/pkg/runtime/proc.c View 1 2 3 4 5 6 7 8 9 10 11 2 chunks +26 lines, -4 lines 0 comments Download
M src/pkg/runtime/runtime.h View 1 2 3 4 5 6 7 8 9 10 11 3 chunks +23 lines, -19 lines 0 comments Download
M src/pkg/runtime/sema.goc View 1 3 chunks +3 lines, -3 lines 0 comments Download
M src/pkg/runtime/time.goc View 1 2 chunks +2 lines, -2 lines 0 comments Download

Messages

Total messages: 13
dvyukov
Hello golang-codereviews@googlegroups.com, I'd like you to review this change to https://dvyukov%40google.com@code.google.com/p/go/
10 years, 3 months ago (2013-12-31 10:55:43 UTC) #1
mikio
I'haven't tested yet but looks good. Please pick any one hotpath or fastpath in the ...
10 years, 3 months ago (2014-01-01 09:04:45 UTC) #2
dvyukov
PTAL I've also fixed a bug on windows, where I could lose IO notification and ...
10 years, 3 months ago (2014-01-01 13:25:20 UTC) #3
mikio
LGTM
10 years, 3 months ago (2014-01-02 10:03:28 UTC) #4
dvyukov
https://codereview.appspot.com/45700043/diff/140001/src/pkg/runtime/proc.c File src/pkg/runtime/proc.c (right): https://codereview.appspot.com/45700043/diff/140001/src/pkg/runtime/proc.c#newcode1345 src/pkg/runtime/proc.c:1345: static bool parkunlock(G *gp, void *lock) newline after bool, ...
10 years, 3 months ago (2014-01-04 13:42:58 UTC) #5
dvyukov
https://codereview.appspot.com/45700043/diff/140001/src/pkg/runtime/proc.c File src/pkg/runtime/proc.c (right): https://codereview.appspot.com/45700043/diff/140001/src/pkg/runtime/proc.c#newcode1345 src/pkg/runtime/proc.c:1345: static bool parkunlock(G *gp, void *lock) On 2014/01/04 13:42:59, ...
10 years, 3 months ago (2014-01-18 16:55:09 UTC) #6
dvyukov
anybody else?
10 years, 3 months ago (2014-01-18 17:00:47 UTC) #7
gobot
R=iant@golang.org (assigned by bradfitz@golang.org)
10 years, 3 months ago (2014-01-19 18:03:25 UTC) #8
rsc
Please remember that when you say "anybody else?" to golang-codereviews, no one can hear you.
10 years, 3 months ago (2014-01-22 03:51:49 UTC) #9
rsc
LGTM https://codereview.appspot.com/45700043/diff/200001/src/pkg/runtime/netpoll.goc File src/pkg/runtime/netpoll.goc (right): https://codereview.appspot.com/45700043/diff/200001/src/pkg/runtime/netpoll.goc#newcode348 src/pkg/runtime/netpoll.goc:348: return old > WAIT ? old : nil; ...
10 years, 3 months ago (2014-01-22 03:55:26 UTC) #10
iant
LGTM https://codereview.appspot.com/45700043/diff/200001/src/pkg/runtime/netpoll.goc File src/pkg/runtime/netpoll.goc (left): https://codereview.appspot.com/45700043/diff/200001/src/pkg/runtime/netpoll.goc#oldcode100 src/pkg/runtime/netpoll.goc:100: runtime·lock(pd); Not acquiring the lock here means that ...
10 years, 3 months ago (2014-01-22 05:32:12 UTC) #11
dvyukov
On Wed, Jan 22, 2014 at 7:51 AM, <rsc@golang.org> wrote: > Please remember that when ...
10 years, 3 months ago (2014-01-22 07:02:57 UTC) #12
dvyukov
10 years, 3 months ago (2014-01-22 07:28:40 UTC) #13
*** Submitted as https://code.google.com/p/go/source/detail?r=da649606c628 ***

runtime: remove locks from netpoll hotpaths
Introduces two-phase goroutine parking mechanism -- prepare to park, commit
park.
This mechanism does not require backing mutex to protect wait predicate.
Use it in netpoll. See comment in netpoll.goc for details.
This slightly reduces contention between reader, writer and read/write io
notifications;
and just eliminates a bunch of mutex operations from hotpaths, thus making then
faster.

benchmark                             old ns/op    new ns/op    delta
BenchmarkTCP4ConcurrentReadWrite           2109         1945   -7.78%
BenchmarkTCP4ConcurrentReadWrite-2         1162         1113   -4.22%
BenchmarkTCP4ConcurrentReadWrite-4          798          755   -5.39%
BenchmarkTCP4ConcurrentReadWrite-8          803          748   -6.85%
BenchmarkTCP4Persistent                    9411         9240   -1.82%
BenchmarkTCP4Persistent-2                  5888         5813   -1.27%
BenchmarkTCP4Persistent-4                  4016         3968   -1.20%
BenchmarkTCP4Persistent-8                  3943         3857   -2.18%

R=golang-codereviews, mikioh.mikioh, gobot, iant, rsc
CC=golang-codereviews, khr
https://codereview.appspot.com/45700043

https://codereview.appspot.com/45700043/diff/200001/src/pkg/runtime/netpoll.goc
File src/pkg/runtime/netpoll.goc (right):

https://codereview.appspot.com/45700043/diff/200001/src/pkg/runtime/netpoll.g...
src/pkg/runtime/netpoll.goc:27: //        the goroutine commits to park by
chaning the state to G pointer,
On 2014/01/22 05:32:13, iant wrote:
> s/chaning/changing/

Done.

https://codereview.appspot.com/45700043/diff/200001/src/pkg/runtime/netpoll.g...
src/pkg/runtime/netpoll.goc:41: // The following fields are manipulated w/o
locks.
On 2014/01/22 05:32:13, iant wrote:
> s/The following fields/rg and wg/
> 
> There are several following fields, it's not automatically clear that the
> comment ends at the blank line.

Agree, this was confusing.
I've added an extended comment describing how fields are protected.

https://codereview.appspot.com/45700043/diff/200001/src/pkg/runtime/netpoll.g...
src/pkg/runtime/netpoll.goc:127: err = checkerr(pd, mode);
On 2014/01/22 05:32:13, iant wrote:
> Here again closing and rd may be examined without a lock.

Added a comment to PollDesc.

https://codereview.appspot.com/45700043/diff/200001/src/pkg/runtime/netpoll.g...
src/pkg/runtime/netpoll.goc:348: return old > WAIT ? old : nil;
On 2014/01/22 03:55:27, rsc wrote:
> please do not use ? : operators.
> they almost always make the code difficult to follow.
> there is a reason they are not in go.
> 
> if(old > WAIT)
>     return old;
> return nil;

Done.
Sign in to reply to this message.

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