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

Issue 5334051: code review 5334051: runtime: add timer support, use for package time (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 1 month ago by rsc
Modified:
14 years, 1 month ago
Reviewers:
CC:
golang-dev, r, hector, iant, iant2, jsing, brainman, dvyukov
Visibility:
Public.

Description

runtime: add timer support, use for package time This looks like it is just moving some code from time to runtime (and translating it to C), but the runtime can do a better job managing the goroutines, and it needs this functionality for its own maintenance (for example, for the garbage collector to hand back unused memory to the OS on a time delay). Might as well have just one copy of the timer logic, and runtime can't depend on time, so vice versa. It also unifies Sleep, NewTicker, and NewTimer behind one mechanism, so that there are no claims that one is more efficient than another. (For example, today people recommend using time.After instead of time.Sleep to avoid blocking an OS thread.) Fixes issue 1644. Fixes issue 1731. Fixes issue 2190.

Patch Set 1 #

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

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

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

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

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

Total comments: 14

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

Total comments: 17

Patch Set 8 : diff -r 41fb9e7d3027 https://go.googlecode.com/hg #

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

Total comments: 8

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

Total comments: 2

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

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

Total comments: 3

Patch Set 13 : diff -r 9870fbad1533 https://go.googlecode.com/hg #

Unified diffs Side-by-side diffs Delta from patch set Stats (+661 lines, -389 lines) Patch
M src/pkg/runtime/darwin/os.h View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/runtime/darwin/thread.c View 1 3 chunks +15 lines, -5 lines 0 comments Download
M src/pkg/runtime/freebsd/thread.c View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +12 lines, -3 lines 0 comments Download
M src/pkg/runtime/linux/thread.c View 1 2 3 4 5 6 7 1 chunk +16 lines, -2 lines 0 comments Download
M src/pkg/runtime/lock_futex.c View 1 2 3 4 5 6 7 6 chunks +44 lines, -16 lines 0 comments Download
M src/pkg/runtime/lock_sema.c View 1 2 3 4 5 6 7 8 9 10 11 12 7 chunks +107 lines, -18 lines 0 comments Download
M src/pkg/runtime/openbsd/thread.c View 1 2 3 4 5 6 7 8 9 10 1 chunk +39 lines, -8 lines 0 comments Download
M src/pkg/runtime/plan9/thread.c View 1 2 3 4 5 6 7 4 chunks +39 lines, -6 lines 0 comments Download
M src/pkg/runtime/proc.c View 1 2 3 4 5 6 7 8 9 10 11 12 4 chunks +5 lines, -6 lines 0 comments Download
M src/pkg/runtime/runtime.h View 1 2 3 4 5 6 7 8 9 5 chunks +50 lines, -1 line 0 comments Download
M src/pkg/runtime/time.goc View 1 2 3 4 5 6 7 8 9 1 chunk +231 lines, -1 line 0 comments Download
M src/pkg/runtime/windows/thread.c View 1 2 3 4 5 6 7 8 9 2 chunks +19 lines, -4 lines 0 comments Download
M src/pkg/time/sleep.go View 1 2 3 4 5 6 7 2 chunks +53 lines, -143 lines 0 comments Download
M src/pkg/time/sys.go View 1 2 3 4 5 6 7 8 1 chunk +1 line, -22 lines 0 comments Download
M src/pkg/time/tick.go View 1 2 3 4 5 6 7 2 chunks +29 lines, -153 lines 0 comments Download

Messages

Total messages: 36
rsc
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg
14 years, 1 month ago (2011-11-04 19:52:03 UTC) #1
bradfitz
Nice. "Fixes Issue nnn"? I feel like there is at least one. On Fri, Nov ...
14 years, 1 month ago (2011-11-04 19:54:07 UTC) #2
rsc
On Fri, Nov 4, 2011 at 15:54, Brad Fitzpatrick <bradfitz@golang.org> wrote: > "Fixes Issue nnn"? ...
14 years, 1 month ago (2011-11-04 19:54:36 UTC) #3
r
LGTM but some comments wouldn't hurt. this is mysterious to most http://codereview.appspot.com/5334051/diff/8002/src/pkg/runtime/freebsd/thread.c File src/pkg/runtime/freebsd/thread.c (right): ...
14 years, 1 month ago (2011-11-04 21:00:14 UTC) #4
hector
http://codereview.appspot.com/5334051/diff/8002/src/pkg/runtime/windows/thread.c File src/pkg/runtime/windows/thread.c (right): http://codereview.appspot.com/5334051/diff/8002/src/pkg/runtime/windows/thread.c#newcode154 src/pkg/runtime/windows/thread.c:154: // Is it right on 64-bit machines, or is ...
14 years, 1 month ago (2011-11-04 21:13:44 UTC) #5
iant
FYI http://codereview.appspot.com/5334051/diff/8002/src/pkg/runtime/freebsd/thread.c File src/pkg/runtime/freebsd/thread.c (right): http://codereview.appspot.com/5334051/diff/8002/src/pkg/runtime/freebsd/thread.c#newcode17 src/pkg/runtime/freebsd/thread.c:17: uintptr sec; On 2011/11/04 21:00:14, r wrote: > ...
14 years, 1 month ago (2011-11-04 21:31:53 UTC) #6
iant
FYI http://codereview.appspot.com/5334051/diff/8002/src/pkg/runtime/darwin/thread.c File src/pkg/runtime/darwin/thread.c (right): http://codereview.appspot.com/5334051/diff/8002/src/pkg/runtime/darwin/thread.c#newcode347 src/pkg/runtime/darwin/thread.c:347: int32 This interface is a bit confusing. If ...
14 years, 1 month ago (2011-11-04 22:13:57 UTC) #7
rsc
On Fri, Nov 4, 2011 at 18:13, <iant@golang.org> wrote: > This adjustment is not particularly ...
14 years, 1 month ago (2011-11-04 22:19:20 UTC) #8
iant2
Russ Cox <rsc@golang.org> writes: > On Fri, Nov 4, 2011 at 18:13, <iant@golang.org> wrote: >> ...
14 years, 1 month ago (2011-11-04 22:27:43 UTC) #9
jsing
http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/openbsd/thread.c File src/pkg/runtime/openbsd/thread.c (right): http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/openbsd/thread.c#newcode77 src/pkg/runtime/openbsd/thread.c:77: runtime·thrsleep(&m->waitsemacount, ms, 0, &m->waitsemalock); This will not work as ...
14 years, 1 month ago (2011-11-05 06:30:03 UTC) #10
jsing
With this change I'm seeing the following on linux amd64: TEST FAIL crypto/blowfish make[1]: Entering ...
14 years, 1 month ago (2011-11-06 14:50:50 UTC) #11
jsing
http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/freebsd/thread.c File src/pkg/runtime/freebsd/thread.c (right): http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/freebsd/thread.c#newcode15 src/pkg/runtime/freebsd/thread.c:15: typedef struct Timespec Timespec; Any reason not to add ...
14 years, 1 month ago (2011-11-06 14:56:29 UTC) #12
brainman
Applied your change to 87b7bdc68d7f+. But this program (simplified http://code.google.com/p/go/issues/detail?id=2190): package main import ( "time" ...
14 years, 1 month ago (2011-11-07 01:44:57 UTC) #13
dvyukov
http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/time.goc File src/pkg/runtime/time.goc (right): http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/time.goc#newcode122 src/pkg/runtime/time.goc:122: runtime·newm(timerproc); timers.started = 1;
14 years, 1 month ago (2011-11-07 09:55:44 UTC) #14
dvyukov
http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/proc.c File src/pkg/runtime/proc.c (right): http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/proc.c#newcode725 src/pkg/runtime/proc.c:725: m->procfn(); I think as of now it will throw ...
14 years, 1 month ago (2011-11-07 10:35:02 UTC) #15
dvyukov
http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/lock_futex.c File src/pkg/runtime/lock_futex.c (right): http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/lock_futex.c#newcode106 src/pkg/runtime/lock_futex.c:106: runtime·notesleep(Note *n) notetsleep(n, -1)? http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/lock_sema.c File src/pkg/runtime/lock_sema.c (right): http://codereview.appspot.com/5334051/diff/5002/src/pkg/runtime/lock_sema.c#newcode115 ...
14 years, 1 month ago (2011-11-07 10:54:15 UTC) #16
dvyukov
Now it would be nice if we rewrite case now <-time.After(timeout): into runtime.selecttimeout(timeout, &now): Because ...
14 years, 1 month ago (2011-11-07 11:26:10 UTC) #17
rsc
On Mon, Nov 7, 2011 at 06:26, <dvyukov@google.com> wrote: > Now it would be nice ...
14 years, 1 month ago (2011-11-07 17:38:47 UTC) #18
rsc
On Sun, Nov 6, 2011 at 09:56, <jsing@google.com> wrote: > src/pkg/runtime/freebsd/thread.c:15: typedef struct Timespec Timespec; ...
14 years, 1 month ago (2011-11-07 20:40:18 UTC) #19
rsc
PTAL Thanks for the great feedback, everyone. I added comments to time.goc and the top ...
14 years, 1 month ago (2011-11-07 21:50:05 UTC) #20
hector
On 7 November 2011 21:50, Russ Cox <rsc@golang.org> wrote: > Alex pointed out that Windows ...
14 years, 1 month ago (2011-11-07 22:21:14 UTC) #21
rsc
On Mon, Nov 7, 2011 at 17:20, Hector Chu <hectorchu@gmail.com> wrote: > That was me ...
14 years, 1 month ago (2011-11-07 22:45:16 UTC) #22
hector
Ah I see, thanks for the explanation. I once lost a long message on a ...
14 years, 1 month ago (2011-11-07 23:00:25 UTC) #23
brainman
On 2011/11/07 21:50:05, rsc wrote: > PTAL > Now tests fail: $ cd $GOROOT/src/pkg/time $ ...
14 years, 1 month ago (2011-11-08 00:40:11 UTC) #24
brainman
http://codereview.appspot.com/5334051/diff/18003/src/pkg/runtime/lock_sema.c File src/pkg/runtime/lock_sema.c (right): http://codereview.appspot.com/5334051/diff/18003/src/pkg/runtime/lock_sema.c#newcode184 src/pkg/runtime/lock_sema.c:184: // Deadline hasn't arrived. Keep sleeping. I think you're ...
14 years, 1 month ago (2011-11-08 02:14:32 UTC) #25
dvyukov
On 2011/11/07 17:38:47, rsc wrote: > On Mon, Nov 7, 2011 at 06:26, <mailto:dvyukov@google.com> wrote: ...
14 years, 1 month ago (2011-11-08 08:24:24 UTC) #26
dvyukov
http://codereview.appspot.com/5334051/diff/18003/src/pkg/runtime/lock_sema.c File src/pkg/runtime/lock_sema.c (right): http://codereview.appspot.com/5334051/diff/18003/src/pkg/runtime/lock_sema.c#newcode120 src/pkg/runtime/lock_sema.c:120: m->waitsema = runtime·semacreate(); I am not sure a waiting ...
14 years, 1 month ago (2011-11-08 09:46:45 UTC) #27
dvyukov
http://codereview.appspot.com/5334051/diff/18003/src/pkg/runtime/lock_sema.c File src/pkg/runtime/lock_sema.c (right): http://codereview.appspot.com/5334051/diff/18003/src/pkg/runtime/lock_sema.c#newcode190 src/pkg/runtime/lock_sema.c:190: // try to grant us the semaphore when we ...
14 years, 1 month ago (2011-11-08 10:09:16 UTC) #28
rsc
On Mon, Nov 7, 2011 at 21:14, <alex.brainman@gmail.com> wrote: > ns = deadline - now; ...
14 years, 1 month ago (2011-11-08 13:47:22 UTC) #29
rsc
> http://codereview.appspot.com/5334051/diff/18003/src/pkg/runtime/lock_sema.c#newcode120 > src/pkg/runtime/lock_sema.c:120: m->waitsema = runtime·semacreate(); > I am not sure a waiting goroutine ...
14 years, 1 month ago (2011-11-08 13:55:28 UTC) #30
dvyukov
On 2011/11/08 13:55:28, rsc wrote: > http://codereview.appspot.com/5334051/diff/18003/src/pkg/runtime/time.goc#newcode137 > > src/pkg/runtime/time.goc:137: siftup(i); > > please surround ...
14 years, 1 month ago (2011-11-08 14:14:14 UTC) #31
jsing
With these changes all of the tests pass on OpenBSD/amd64 - I can review the ...
14 years, 1 month ago (2011-11-08 16:25:51 UTC) #32
dvyukov
LGTM
14 years, 1 month ago (2011-11-08 16:57:08 UTC) #33
brainman
On 2011/11/08 13:47:22, rsc wrote: > > ... Does that happen to fix your time ...
14 years, 1 month ago (2011-11-08 22:34:07 UTC) #34
iant
LGTM http://codereview.appspot.com/5334051/diff/27004/src/pkg/runtime/lock_sema.c File src/pkg/runtime/lock_sema.c (right): http://codereview.appspot.com/5334051/diff/27004/src/pkg/runtime/lock_sema.c#newcode15 src/pkg/runtime/lock_sema.c:15: // Sleep trying to acquire m->waitsema for at ...
14 years, 1 month ago (2011-11-08 22:48:14 UTC) #35
rsc
14 years, 1 month ago (2011-11-09 20:17:11 UTC) #36
*** Submitted as http://code.google.com/p/go/source/detail?r=784b29af787e ***

runtime: add timer support, use for package time

This looks like it is just moving some code from
time to runtime (and translating it to C), but the
runtime can do a better job managing the goroutines,
and it needs this functionality for its own maintenance
(for example, for the garbage collector to hand back
unused memory to the OS on a time delay).
Might as well have just one copy of the timer logic,
and runtime can't depend on time, so vice versa.

It also unifies Sleep, NewTicker, and NewTimer behind
one mechanism, so that there are no claims that one
is more efficient than another.  (For example, today
people recommend using time.After instead of time.Sleep
to avoid blocking an OS thread.)

Fixes issue 1644.
Fixes issue 1731.
Fixes issue 2190.

R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov
CC=golang-dev
http://codereview.appspot.com/5334051
Sign in to reply to this message.

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