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

Issue 4723042: code review 4723042: runtime: faster entersyscall, exitsyscall (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 9 months ago by rsc
Modified:
12 years, 9 months ago
Reviewers:
dvyukov
CC:
r, bradfitz, r2, iant, iant2, golang-dev
Visibility:
Public.

Description

runtime: faster entersyscall, exitsyscall Uses atomic memory accesses to avoid the need to acquire and release schedlock on fast paths. benchmark old ns/op new ns/op delta runtime_test.BenchmarkSyscall 73 31 -56.63% runtime_test.BenchmarkSyscall-2 538 74 -86.23% runtime_test.BenchmarkSyscall-3 508 103 -79.72% runtime_test.BenchmarkSyscall-4 721 97 -86.52% runtime_test.BenchmarkSyscallWork 920 873 -5.11% runtime_test.BenchmarkSyscallWork-2 516 481 -6.78% runtime_test.BenchmarkSyscallWork-3 550 343 -37.64% runtime_test.BenchmarkSyscallWork-4 632 263 -58.39% (Intel Core i7 L640 2.13 GHz-based Lenovo X201s) Reduced a less artificial server benchmark from 11.5r 12.0u 8.0s to 8.3r 9.1u 1.0s.

Patch Set 1 #

Patch Set 2 : diff -r 2131931a8b68 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 2131931a8b68 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 353a5cdb24e0 https://go.googlecode.com/hg/ #

Total comments: 16

Patch Set 5 : diff -r 9b990418626f https://go.googlecode.com/hg #

Patch Set 6 : diff -r 9b990418626f https://go.googlecode.com/hg #

Patch Set 7 : diff -r 9b990418626f https://go.googlecode.com/hg #

Total comments: 2

Patch Set 8 : diff -r 00f0d6062b5d https://go.googlecode.com/hg #

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

Total comments: 9

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

Unified diffs Side-by-side diffs Delta from patch set Stats (+857 lines, -100 lines) Patch
M src/pkg/runtime/export_test.go View 1 1 chunk +6 lines, -0 lines 0 comments Download
M src/pkg/runtime/proc.c View 1 2 3 4 5 6 7 8 9 32 chunks +295 lines, -100 lines 0 comments Download
A src/pkg/runtime/proc.p View 1 2 3 4 5 6 7 1 chunk +506 lines, -0 lines 0 comments Download
M src/pkg/runtime/proc_test.go View 1 2 1 chunk +50 lines, -0 lines 0 comments Download

Messages

Total messages: 23
rsc
Hello dvyukov, r (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
12 years, 9 months ago (2011-07-15 06:02:24 UTC) #1
r
nice speedups. not sure i get every nuance but mostly it seems a straight translation ...
12 years, 9 months ago (2011-07-15 06:28:59 UTC) #2
bradfitz
http://codereview.appspot.com/4723042/diff/6001/src/pkg/runtime/proc.c File src/pkg/runtime/proc.c (right): http://codereview.appspot.com/4723042/diff/6001/src/pkg/runtime/proc.c#newcode106 src/pkg/runtime/proc.c:106: // fields can be done (holding schedlock) without fear ...
12 years, 9 months ago (2011-07-15 07:29:39 UTC) #3
r2
On 15/07/2011, at 5:29 PM, bradfitz@golang.org wrote: > > http://codereview.appspot.com/4723042/diff/6001/src/pkg/runtime/proc.c > File src/pkg/runtime/proc.c (right): > ...
12 years, 9 months ago (2011-07-15 07:31:50 UTC) #4
rsc
On Fri, Jul 15, 2011 at 02:29, <r@golang.org> wrote: > nice speedups. not sure i ...
12 years, 9 months ago (2011-07-15 15:39:26 UTC) #5
dvyukov
http://codereview.appspot.com/4723042/diff/6001/src/pkg/runtime/proc.c File src/pkg/runtime/proc.c (right): http://codereview.appspot.com/4723042/diff/6001/src/pkg/runtime/proc.c#newcode70 src/pkg/runtime/proc.c:70: volatile uint32 atomic; // atomic scheduling word (see below) ...
12 years, 9 months ago (2011-07-18 11:35:08 UTC) #6
rsc
> http://codereview.appspot.com/4723042/diff/6001/src/pkg/runtime/proc.c#newcode70 > src/pkg/runtime/proc.c:70: volatile uint32 atomic; // atomic scheduling > word (see below) > ...
12 years, 9 months ago (2011-07-18 15:02:48 UTC) #7
rsc
Hello dvyukov@google.com, r@golang.org, bradfitz@golang.org, r@google.com (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 9 months ago (2011-07-18 16:04:43 UTC) #8
rsc
This version addresses the comments made except for the msyscall range problem. I sent a ...
12 years, 9 months ago (2011-07-18 16:09:42 UTC) #9
dvyukov
http://codereview.appspot.com/4723042/diff/11006/src/pkg/runtime/proc.c File src/pkg/runtime/proc.c (left): http://codereview.appspot.com/4723042/diff/11006/src/pkg/runtime/proc.c#oldcode624 src/pkg/runtime/proc.c:624: // entersyscall is going to return immediately after. Is ...
12 years, 9 months ago (2011-07-18 19:03:16 UTC) #10
rsc
http://codereview.appspot.com/4723042/diff/11006/src/pkg/runtime/proc.c File src/pkg/runtime/proc.c (left): http://codereview.appspot.com/4723042/diff/11006/src/pkg/runtime/proc.c#oldcode624 src/pkg/runtime/proc.c:624: // entersyscall is going to return immediately after. On ...
12 years, 9 months ago (2011-07-18 19:05:36 UTC) #11
dvyukov
On 2011/07/18 16:09:42, rsc wrote: > This version addresses the comments made > except for ...
12 years, 9 months ago (2011-07-18 19:09:24 UTC) #12
dvyukov
Other than that, looks good to me.
12 years, 9 months ago (2011-07-18 19:10:07 UTC) #13
rsc
>> This version addresses the comments made >> except for the msyscall range problem. >> ...
12 years, 9 months ago (2011-07-18 19:16:07 UTC) #14
rsc
Hello dvyukov@google.com, r@golang.org, bradfitz@golang.org, r@google.com (cc: golang-dev@googlegroups.com), Please take another look.
12 years, 9 months ago (2011-07-18 20:23:43 UTC) #15
rsc
This version is ready for review + submission. It removes the limit on the number ...
12 years, 9 months ago (2011-07-18 20:25:22 UTC) #16
iant
LGTM http://codereview.appspot.com/4723042/diff/7011/src/pkg/runtime/proc.c File src/pkg/runtime/proc.c (right): http://codereview.appspot.com/4723042/diff/7011/src/pkg/runtime/proc.c#newcode73 src/pkg/runtime/proc.c:73: int32 predawn; // running initialization, don't run new ...
12 years, 9 months ago (2011-07-18 21:51:42 UTC) #17
r
LGTM are the benchmark numbers still right after all those changes? http://codereview.appspot.com/4723042/diff/7011/src/pkg/runtime/proc.c File src/pkg/runtime/proc.c (right): ...
12 years, 9 months ago (2011-07-18 22:18:16 UTC) #18
iant2
r@golang.org writes: > http://codereview.appspot.com/4723042/diff/7011/src/pkg/runtime/proc.c > File src/pkg/runtime/proc.c (right): > > http://codereview.appspot.com/4723042/diff/7011/src/pkg/runtime/proc.c#newcode291 > src/pkg/runtime/proc.c:291: canaddmcpu(void) > ...
12 years, 9 months ago (2011-07-18 23:02:44 UTC) #19
rsc
canaddmcpu is consistent with cansemacquire, which already existed (and we had the same discussion then). ...
12 years, 9 months ago (2011-07-19 15:00:04 UTC) #20
rsc
> are the benchmark numbers still right after all those changes? i don't have the ...
12 years, 9 months ago (2011-07-19 15:00:32 UTC) #21
rsc
*** Submitted as http://code.google.com/p/go/source/detail?r=bc165ba3d931 *** runtime: faster entersyscall, exitsyscall Uses atomic memory accesses to avoid ...
12 years, 9 months ago (2011-07-19 15:01:19 UTC) #22
dvyukov
12 years, 9 months ago (2011-07-19 15:04:55 UTC) #23
http://codereview.appspot.com/4723042/diff/7011/src/pkg/runtime/proc.c
File src/pkg/runtime/proc.c (right):

http://codereview.appspot.com/4723042/diff/7011/src/pkg/runtime/proc.c#newcod...
src/pkg/runtime/proc.c:291: canaddmcpu(void)
On 2011/07/18 22:18:17, r wrote:
> i prefer 'can' over 'maybe'. 'can' to me means 'do it if you can'; 'maybe'
means
> 'for some unspecified reason, do this or not'. thus 'can' seems determined;
> 'maybe' seems arbitrary.
> 
> "can you do this?" "yes!"
> "maybe you can do this?"  "yeah, maybe. let me finish my drink first."

I am not a native speaker, by 'can' for me also implies predicate rather than
action. (cangget() && canaddmcpu()) look inconsistent because these 2 can's do
very different things. Maybe tryaddmcpu() (like trylock())?

Hummm... Now I see that comment above the function says "Try to increment mcpu. 
Report whether succeeded". I think if it's renamed to tryadd, the comment
becomes unnecessary.

http://codereview.appspot.com/4723042/diff/7011/src/pkg/runtime/proc.c#newcod...
src/pkg/runtime/proc.c:809: }
I think now it's logical to replace the CAS loop with:

v = xadd(&runtime·sched.atomic, -1<<mcpuShift);
if(!(atomic_gwaiting(v) || (atomic_waitstop(v) && atomic_mcpu(v)-1 <=
atomic_mcpumax(v))))
    return;

and remove the decrement from the critical section.

http://codereview.appspot.com/4723042/diff/7011/src/pkg/runtime/proc.c#newcod...
src/pkg/runtime/proc.c:868: }
Ditto.

It slightly/subtly changes the algorithm, but as far as I see it's still
correct. Verification with Promela won't do any harm of course.
Sign in to reply to this message.

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