1
0
mirror of https://github.com/golang/go synced 2024-10-04 16:31:22 -06:00
Commit Graph

1768 Commits

Author SHA1 Message Date
Russ Cox
a2edc469a0 runtime: remove redundant 0x prefix in error print
%x already adds the prefix unconditionally

R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/51550043
2014-01-13 11:39:04 -05:00
Joel Sing
073bd0ba24 runtime/pprof: enable profiling test on openbsd
Profiling of multithreaded applications works correctly on OpenBSD
5.4-current, so enable the profiling test.

R=golang-codereviews, minux.ma
CC=golang-codereviews
https://golang.org/cl/50940043
2014-01-13 11:24:08 +11:00
Joel Sing
471763f657 runtime, syscall: update for openbsd system ABI break
Update Go so that it continues to work past the OpenBSD system ABI
break, with 64-bit time_t:

  http://www.openbsd.org/faq/current.html#20130813

Note: this makes OpenBSD 5.5 (currently 5.4-current) the minimum
supported release for Go.

Fixes #7049.

R=golang-codereviews, mikioh.mikioh
CC=golang-codereviews
https://golang.org/cl/13368046
2014-01-11 19:00:32 +11:00
Ian Lance Taylor
8da8b37674 runtime: fix 32-bit malloc for pointers >= 0x80000000
The spans array is allocated in runtime·mallocinit.  On a
32-bit system the number of entries in the spans array is
MaxArena32 / PageSize, which (2U << 30) / (1 << 12) == (1 << 19).
So we are allocating an array that can hold 19 bits for an
index that can hold 20 bits.  According to the comment in the
function, this is intentional: we only allocate enough spans
(and bitmaps) for a 2G arena, because allocating more would
probably be wasteful.

But since the span index is simply the upper 20 bits of the
memory address, this scheme only works if memory addresses are
limited to the low 2G of memory.  That would be OK if we were
careful to enforce it, but we're not.  What we are careful to
enforce, in functions like runtime·MHeap_SysAlloc, is that we
always return addresses between the heap's arena_start and
arena_start + MaxArena32.

We generally get away with it because we start allocating just
after the program end, so we only run into trouble with
programs that allocate a lot of memory, enough to get past
address 0x80000000.

This changes the code that computes a span index to subtract
arena_start on 32-bit systems just as we currently do on
64-bit systems.

R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/49460043
2014-01-09 15:00:00 -08:00
Rowan Worth
c4770b991b runtime: co-exist with NPTL's pthread_cancel.
NPTL uses SIGRTMIN (signal 32) to effect thread cancellation.
Go's runtime replaces NPTL's signal handler with its own, and
ends up aborting if a C library that ends up calling
pthread_cancel is used.

This patch prevents runtime from replacing NPTL's handler.

Fixes #6997.

R=golang-codereviews, iant, dvyukov
CC=golang-codereviews
https://golang.org/cl/47540043
2014-01-09 09:34:04 -08:00
Ian Lance Taylor
7e639c0229 runtime: change errorCString to a struct
This prevents callers from using reflect to create a new
instance of errorCString with an arbitrary value and calling
the Error method to examine arbitrary memory.

Fixes #7084.

R=golang-codereviews, minux.ma, bradfitz
CC=golang-codereviews
https://golang.org/cl/49600043
2014-01-08 21:40:33 -08:00
Keith Randall
e7d010a6a7 runtime: deallocate specials before deallocating the underlying object.
R=dvyukov
CC=golang-codereviews
https://golang.org/cl/48840043
2014-01-08 12:41:26 -08:00
Ian Lance Taylor
89c5d17878 runtime: handle gdb breakpoint in x86 traceback
This lets stack splits work correctly when running under gdb
when gdb has inserted a breakpoint somewhere on the call
stack.

Fixes #6834.

R=golang-codereviews, minux.ma
CC=golang-codereviews
https://golang.org/cl/48650043
2014-01-08 12:36:31 -08:00
Keith Randall
020b39c3f3 runtime: use special records hung off the MSpan to
record finalizers and heap profile info.  Enables
removing the special bit from the heap bitmap.  Also
provides a generic mechanism for annotating occasional
heap objects.

finalizers
        overhead      per obj
old	680 B	      80 B avg
new	16 B/span     48 B

profile
        overhead      per obj
old	32KB	      24 B + hash tables
new	16 B/span     24 B

R=cshapiro, khr, dvyukov, gobot
CC=golang-codereviews
https://golang.org/cl/13314053
2014-01-07 13:45:50 -08:00
Emil Hessman
aeeda707ff runtime: Fix panic when trying to stop CPU profiling with profiler turned off
Fixes #7063.

R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/47950043
2014-01-06 09:53:55 -08:00
Jeff Sickel
c136197ca8 runtime: plan 9 does have /dev/random
R=golang-codereviews, r, aram
CC=0intro, golang-codereviews, rsc
https://golang.org/cl/43420045
2014-01-04 10:53:22 -08:00
Keith Randall
f59ea4e58b runtime: Fix race detector checks to ignore KindNoPointers bit
when comparing kinds.

R=dvyukov, dave, khr
CC=golang-codereviews
https://golang.org/cl/41660045
2014-01-04 08:43:17 -08:00
David Symonds
8778760a7e runtime: increase attempt count for map iteration order test.
Some builders broke on this test; I'm guessing that was because
this test didn't try hard enough to find a different iteration order.

Update #6719

R=dave
CC=golang-codereviews
https://golang.org/cl/47300043
2014-01-03 10:41:56 +11:00
David Symonds
d4c66a35ba runtime: add a test for randomised map iteration order.
Technically the spec does not guarantee that the iteration order is random,
but it is a property that we have consciously pursued, and so it seems
right to verify that our implementation does indeed randomise.

Update #6719.

R=khr, bradfitz
CC=golang-codereviews
https://golang.org/cl/47010043
2014-01-03 10:10:54 +11:00
Keith Randall
1cc2ff8fc7 runtime: use readrange instead of read to check for races
on map keys and values which are now passed by reference.

R=dvyukov, khr
CC=golang-codereviews
https://golang.org/cl/43490044
2013-12-30 12:03:56 -08:00
Dave Cheney
d2fe44d568 runtime: load runtime.goarm as a byte, not a word
Fixes #6952.

runtime.asminit was incorrectly loading runtime.goarm as a word, not a uint8 which made it subject to alignment issues on arm5 platforms.

Alignment aside, this also meant that the top 3 bytes in R11 would have been garbage and could not be assumed to be setting up the FPU reliably.

R=iant, minux.ma
CC=golang-codereviews
https://golang.org/cl/46240043
2013-12-29 15:25:34 +11:00
Ian Lance Taylor
59583b09f3 runtime/cgo: include <signal.h> to fix build
R=golang-codereviews
TBR=dfc
CC=golang-codereviews
https://golang.org/cl/43120044
2013-12-24 08:24:32 -08:00
Ian Lance Taylor
699dbb60b7 runtime/cgo: always set signal mask before calling pthread_create
This was done correctly for most targets but was missing from
FreeBSD/ARM and Linux/ARM.

R=golang-codereviews, dave
CC=golang-codereviews
https://golang.org/cl/45180043
2013-12-24 08:08:15 -08:00
S.Çağlar Onur
41183d015d cgo/runtime: replace sigprocmask with pthread_sigmask.
sigprocmask use in a multithreaded environment is undefined so replace it with pthread_sigmask.

Fixes #6811.

R=jsing, iant
CC=golang-codereviews, golang-dev
https://golang.org/cl/30460043
2013-12-22 08:55:29 -08:00
Shenghou Ma
eb7ed0d626 runtime: fix build for OpenBSD
R=golang-dev
CC=golang-dev
https://golang.org/cl/38030045
2013-12-19 21:12:18 -05:00
Shenghou Ma
0097d30c97 runtime: unblock signals when we try to core dump
Fixes #6988.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/44070046
2013-12-19 20:45:05 -05:00
Keith Randall
cbc565a801 reflect: rewrite Value to separate out pointer vs. nonpointer info.
Needed for precise gc and copying stacks.

reflect.Value now takes 4 words instead of 3.

Still to do:
 - un-iword-ify channel ops.
 - un-iword-ify method receivers.

R=golang-dev, iant, rsc, khr
CC=golang-dev
https://golang.org/cl/43040043
2013-12-19 15:15:24 -08:00
Rémy Oudompheng
e6b023473e runtime: reduce delays in finalizer test.
The runtime tests are executed 4 times in all.bash
and there is currently a 5-second delay each time.

R=golang-dev, minux.ma, khr, bradfitz
CC=golang-dev
https://golang.org/cl/42450043
2013-12-19 21:37:44 +01:00
Alex Brainman
7f8a5057dd syscall: add NewCallbackCDecl again
Fixes #6338

R=golang-dev, kin.wilson.za, rsc
CC=golang-dev
https://golang.org/cl/36180044
2013-12-19 14:38:50 +11:00
Alex Brainman
f18e2a3271 runtime/pprof: skip tests that fail on windows-amd64-race builder
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/44180043
2013-12-19 14:15:57 +11:00
Keith Randall
2d20c0d625 runtime: mark objects in free lists as allocated and unscannable.
On the plus side, we don't need to change the bits when mallocing
pointerless objects.  On the other hand, we need to mark objects in the
free lists during GC.  But the free lists are small at GC time, so it
should be a net win.

benchmark                    old ns/op    new ns/op    delta
BenchmarkMalloc8                    40           33  -17.65%
BenchmarkMalloc16                   45           38  -15.72%
BenchmarkMallocTypeInfo8            58           59   +0.85%
BenchmarkMallocTypeInfo16           63           64   +1.10%

R=golang-dev, rsc, dvyukov
CC=cshapiro, golang-dev
https://golang.org/cl/41040043
2013-12-18 17:13:59 -08:00
Brad Fitzpatrick
8c6ef061e3 sync: add Pool type
Adds the Pool type and docs, and use it in fmt.
This is a temporary implementation, until Dmitry
makes it fast.

Uses the API proposal from Russ in http://goo.gl/cCKeb2 but
adds an optional New field, as used in fmt and elsewhere.
Almost all callers want that.

Update #4720

R=golang-dev, rsc, cshapiro, iant, r, dvyukov, khr
CC=golang-dev
https://golang.org/cl/41860043
2013-12-18 11:08:34 -08:00
Alex Brainman
ae9e4db07c runtime: skip broken TestRuntimeGogoBytes on windows
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/43730043
2013-12-18 14:17:47 +11:00
Keith Randall
deb554934c runtime, gc: call interface conversion routines by reference.
Part of getting rid of vararg C calls.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/23310043
2013-12-17 16:55:06 -08:00
Keith Randall
9aae6c1a8b runtime: don't store evacuate bit as low bit of hashtable overflow pointer.
Hash tables currently store an evacuated bit in the low bit
of the overflow pointer.  That's probably not sustainable in the
long term as GC wants correctly typed & aligned pointers.  It is
also a pain to move any of this code to Go in the current state.

This change moves the evacuated bit into the tophash entries.

Performance change is negligable.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/14412043
2013-12-17 15:23:31 -08:00
Brad Fitzpatrick
4b76a31c6d runtime: don't crash in SetFinalizer if sizeof *x is zero
And document it explicitly, even though it already said
it wasn't guaranteed.

Fixes #6857

R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/43580043
2013-12-17 14:18:58 -08:00
Russ Cox
a392cf4fd3 runtime: fix test
Was supposed to be in the nm CL.

TBR=r
CC=golang-dev
https://golang.org/cl/42870043
2013-12-16 12:59:30 -05:00
Russ Cox
bc135f6492 runtime: fix crash in runtime.GoroutineProfile
This is a possible Go 1.2.1 candidate.

Fixes #6946.

R=iant, r
CC=golang-dev
https://golang.org/cl/41640043
2013-12-13 15:44:57 -05:00
Carl Shapiro
c69402d82b runtime: remove outdated comment and related indentation
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/39810043
2013-12-10 11:17:43 -08:00
Carl Shapiro
f574726f16 runtime: check for signed zero in printfloat
Fixes #6899

R=golang-dev, r, cshapiro, iant, rsc
CC=golang-dev
https://golang.org/cl/38120043
2013-12-09 17:51:30 -08:00
Russ Cox
4230044bb8 runtime: remove non-extern decls of runtime.goarm
The linker is in charge of providing the one true declaration.

R=golang-dev, dave, r
CC=golang-dev
https://golang.org/cl/39560043
2013-12-09 19:35:07 -05:00
Anthony Martin
274a8e3f56 runtime: do not use memmove in the Plan 9 signal handler
Fixes a regression introduced in revision 4cb93e2900d0.

That revision changed runtime·memmove to use SSE MOVOU
instructions for sizes between 17 and 256 bytes. We were
using memmove to save a copy of the note string during
the note handler. The Plan 9 kernel does not allow the
use of floating point in note handlers (which includes
MOVOU since it touches the XMM registers).

Arguably, runtime·memmove should not be using MOVOU when
GO386=387 but that wouldn't help us on amd64. It's very
important that we guard against any future changes so we
use a simple copy loop instead.

This change is extracted from CL 9796043 (since that CL
is still being ironed out).

R=rsc
CC=golang-dev
https://golang.org/cl/34640045
2013-12-09 18:41:48 -05:00
Carl Shapiro
bc9691c465 cmd/gc, runtime: correct a misnomer regarding dead value maps
The funcdata symbol incorrectly named the dead value map the
dead pointer map.  The dead value map identifies all dead
values, including pointers and non-pointers, in a stack frame.
The purpose of this map is to allow the runtime to poison
locations of dead data to catch lost invariants.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/38670043
2013-12-09 14:45:10 -08:00
Russ Cox
7c17982f72 runtime: remove cross-function jump in vlop_arm.s
The new linker will disallow this on arm
(it is already disallowed on amd64 and 386)
in order to be able to lay out each function
separately.

The restriction is only for jumps into the middle
of a function; jumps to the beginning of a function
remain fine.

Prereq for linker cleanup (golang.org/s/go13linker).

R=iant, r, minux.ma
CC=golang-dev
https://golang.org/cl/35800043
2013-12-08 22:52:08 -05:00
Carl Shapiro
76c54c1193 runtime: add GODEBUG option for an electric fence like heap mode
When enabled this new debugging mode will allocate objects on
their own page and never recycle memory addresses.  This is an
essential tool to root cause a broad class of heap corruption.

R=golang-dev, dave, daniel.morsing, dvyukov, rsc, iant, cshapiro
CC=golang-dev
https://golang.org/cl/22060046
2013-12-06 14:40:45 -08:00
Carl Shapiro
f056daf075 cmd/5g, cmd/5l, cmd/6g, cmd/6l, cmd/8g, cmd/8l, cmd/gc, runtime: generate pointer maps by liveness analysis
This change allows the garbage collector to examine stack
slots that are determined as live and containing a pointer
value by the garbage collector.  This results in a mean
reduction of 65% in the number of stack slots scanned during
an invocation of "GOGC=1 all.bash".

Unfortunately, this does not yet allow garbage collection to
be precise for the stack slots computed as live.  Pointers
confound the determination of what definitions reach a given
instruction.  In general, this problem is not solvable without
runtime cost but some advanced cooperation from the compiler
might mitigate common cases.

R=golang-dev, rsc, cshapiro
CC=golang-dev
https://golang.org/cl/14430048
2013-12-05 17:35:22 -08:00
Carl Shapiro
48279bd567 runtime: add an allocation and free tracing for gc debugging
Output for an allocation and free (sweep) follows

MProf_Malloc(p=0xc2100210a0, size=0x50, type=0x0 <single object>)
        #0 0x46ee15 runtime.mallocgc /usr/local/google/home/cshapiro/go/src/pkg/runtime/malloc.goc:141
        #1 0x47004f runtime.settype_flush /usr/local/google/home/cshapiro/go/src/pkg/runtime/malloc.goc:612
        #2 0x45f92c gc /usr/local/google/home/cshapiro/go/src/pkg/runtime/mgc0.c:2071
        #3 0x45f89e mgc /usr/local/google/home/cshapiro/go/src/pkg/runtime/mgc0.c:2050
        #4 0x45258b runtime.mcall /usr/local/google/home/cshapiro/go/src/pkg/runtime/asm_amd64.s:179

MProf_Free(p=0xc2100210a0, size=0x50)
        #0 0x46ee15 runtime.mallocgc /usr/local/google/home/cshapiro/go/src/pkg/runtime/malloc.goc:141
        #1 0x47004f runtime.settype_flush /usr/local/google/home/cshapiro/go/src/pkg/runtime/malloc.goc:612
        #2 0x45f92c gc /usr/local/google/home/cshapiro/go/src/pkg/runtime/mgc0.c:2071
        #3 0x45f89e mgc /usr/local/google/home/cshapiro/go/src/pkg/runtime/mgc0.c:2050
        #4 0x45258b runtime.mcall /usr/local/google/home/cshapiro/go/src/pkg/runtime/asm_amd64.s:179

R=golang-dev, dvyukov, rsc, cshapiro
CC=golang-dev
https://golang.org/cl/21990045
2013-12-03 14:42:38 -08:00
Carl Shapiro
0368a7ceb6 runtime: move stack scanning into the parallel mark phase
This change reduces the cost of the stack scanning by frames.
It moves the stack scanning from the serial root enumeration
phase to the parallel tracing phase.  The output that follows
are timings for the issue 6482 benchmark

Baseline

BenchmarkGoroutineSelect	      50	 108027405 ns/op
BenchmarkGoroutineBlocking	      50	  89573332 ns/op
BenchmarkGoroutineForRange	      20	  95614116 ns/op
BenchmarkGoroutineIdle		      20	 122809512 ns/op

Stack scan by frames, non-parallel

BenchmarkGoroutineSelect	      20	 297138929 ns/op
BenchmarkGoroutineBlocking	      20	 301137599 ns/op
BenchmarkGoroutineForRange	      10	 312499469 ns/op
BenchmarkGoroutineIdle		      10	 209428876 ns/op

Stack scan by frames, parallel

BenchmarkGoroutineSelect	      20	 183938431 ns/op
BenchmarkGoroutineBlocking	      20	 170109999 ns/op
BenchmarkGoroutineForRange	      20	 179628882 ns/op
BenchmarkGoroutineIdle		      20	 157541498 ns/op

The remaining performance disparity is due to inefficiencies
in gentraceback and its callees.  The effect was isolated by
using a parallel stack scan where scanstack was modified to do
a conservative scan of the stack segments without gentraceback
followed by a call of gentrackback with a no-op callback.

The output that follows are the top-10 most frequent tops of
stacks as determined by the Linux perf record facility.

Baseline

+  25.19%  gc.test  gc.test            [.] runtime.xchg
+  19.00%  gc.test  gc.test            [.] scanblock
+   8.53%  gc.test  gc.test            [.] scanstack
+   8.46%  gc.test  gc.test            [.] flushptrbuf
+   5.08%  gc.test  gc.test            [.] procresize
+   3.57%  gc.test  gc.test            [.] runtime.chanrecv
+   2.94%  gc.test  gc.test            [.] dequeue
+   2.74%  gc.test  gc.test            [.] addroots
+   2.25%  gc.test  gc.test            [.] runtime.ready
+   1.33%  gc.test  gc.test            [.] runtime.cas64

Gentraceback

+  18.12%  gc.test  gc.test             [.] runtime.xchg
+  14.68%  gc.test  gc.test             [.] scanblock
+   8.20%  gc.test  gc.test             [.] runtime.gentraceback
+   7.38%  gc.test  gc.test             [.] flushptrbuf
+   6.84%  gc.test  gc.test             [.] scanstack
+   5.92%  gc.test  gc.test             [.] runtime.findfunc
+   3.62%  gc.test  gc.test             [.] procresize
+   3.15%  gc.test  gc.test             [.] readvarint
+   1.92%  gc.test  gc.test             [.] addroots
+   1.87%  gc.test  gc.test             [.] runtime.chanrecv

R=golang-dev, dvyukov, rsc
CC=golang-dev
https://golang.org/cl/17410043
2013-12-03 14:12:55 -08:00
Keith Randall
24699fb05c runtime: get rid of concatstring's vararg C argument.
Pass as a slice of strings instead.  For 2-5 strings, implement
dedicated routines so no slices are needed.

static call counts in the go binary:
 2 strings: 342 occurrences
 3 strings:  98
 4 strings:  30
 5 strings:  13
6+ strings:  14

Why?  C varags, bad for stack scanning and copying.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/36380043
2013-12-03 10:39:19 -08:00
Keith Randall
c0f2294577 runtime: fix race detector when map keys/values are passed by pointer.
Now that the map implementation is reading the keys and values from
arbitrary memory (instead of from stack slots), it needs to tell the
race detector when it does so.

Fixes #6875.

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/36360043
2013-12-02 18:03:25 -08:00
Keith Randall
c792bde9ef runtime: don't use ... formal argument to deferreturn.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/28860043
2013-12-02 13:07:15 -08:00
Keith Randall
3278dc158e runtime: pass key/value to map accessors by reference, not by value.
This change is part of the plan to get rid of all vararg C calls
which are a pain for getting exact stack scanning.

We allocate a chunk of zero memory to return a pointer to when a
map access doesn't find the key.  This is simpler than returning nil
and fixing things up in the caller.  Linker magic allocates a single
zero memory area that is shared by all (non-reflect-generated) map
types.

Passing things by reference gets rid of some copies, so it speeds
up code with big keys/values.

benchmark             old ns/op    new ns/op    delta
BenchmarkBigKeyMap           34           31   -8.48%
BenchmarkBigValMap           37           30  -18.62%
BenchmarkSmallKeyMap         26           23  -11.28%

R=golang-dev, dvyukov, khr, rsc
CC=golang-dev
https://golang.org/cl/14794043
2013-12-02 13:05:04 -08:00
Russ Cox
2c98a3bc2e cmd/5l, runtime: fix divide for profiling tracebacks on ARM
Two bugs:
1. The first iteration of the traceback always uses LR when provided,
which it is (only) during a profiling signal, but in fact LR is correct
only if the stack frame has not been allocated yet. Otherwise an
intervening call may have changed LR, and the saved copy in the stack
frame should be used. Fix in traceback_arm.c.

2. The division runtime call adds 8 bytes to the stack. In order to
keep the traceback routines happy, it must copy the saved LR into
the new 0(SP). Change

        SUB $8, SP

into

        MOVW    0(SP), R11 // r11 is temporary, for use by linker
        MOVW.W  R11, -8(SP)

to update SP and 0(SP) atomically, so that the traceback always
sees a saved LR at 0(SP).

Fixes #6681.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/19910044
2013-10-31 18:15:55 +00:00
Russ Cox
b88148b9a0 undo CL 19810043 / 352f3b7c9664
The CL causes misc/cgo/test to fail randomly.
I suspect that the problem is the use of a division instruction
in usleep, which can be called while trying to acquire an m
and therefore cannot store the denominator in m.
The solution to that would be to rewrite the code to use a
magic multiply instead of a divide, but now we're getting
pretty far off the original code.

Go back to the original in preparation for a different,
less efficient but simpler fix.

««« original CL description
cmd/5l, runtime: make ARM integer division profiler-friendly

The implementation of division constructed non-standard
stack frames that could not be handled by the traceback
routines.

CL 13239052 left the frames non-standard but fixed them
for the specific case of a divide-by-zero panic.
A profiling signal can arrive at any time, so that fix
is not sufficient.

Change the division to store the extra argument in the M struct
instead of in a new stack slot. That keeps the frames bog standard
at all times.

Also fix a related bug in the traceback code: when starting
a traceback, the LR register should be ignored if the current
function has already allocated its stack frame and saved the
original LR on the stack. The stack copy should be used, as the
LR register may have been modified.

Combined, these make the torture test from issue 6681 pass.

Fixes #6681.

R=golang-dev, r, josharian
CC=golang-dev
https://golang.org/cl/19810043
»»»

TBR=r
CC=golang-dev
https://golang.org/cl/20350043
2013-10-31 17:18:57 +00:00
Russ Cox
b0db472ea2 cmd/5l, runtime: make ARM integer division profiler-friendly
The implementation of division constructed non-standard
stack frames that could not be handled by the traceback
routines.

CL 13239052 left the frames non-standard but fixed them
for the specific case of a divide-by-zero panic.
A profiling signal can arrive at any time, so that fix
is not sufficient.

Change the division to store the extra argument in the M struct
instead of in a new stack slot. That keeps the frames bog standard
at all times.

Also fix a related bug in the traceback code: when starting
a traceback, the LR register should be ignored if the current
function has already allocated its stack frame and saved the
original LR on the stack. The stack copy should be used, as the
LR register may have been modified.

Combined, these make the torture test from issue 6681 pass.

Fixes #6681.

R=golang-dev, r, josharian
CC=golang-dev
https://golang.org/cl/19810043
2013-10-30 18:50:34 +00:00
Russ Cox
00a757fb74 runtime: relax preemption assertion during stack split
The case can happen when starttheworld is calling acquirep
to get things moving again and acquirep gets preempted.
The stack trace is in golang.org/issue/6644.

It is difficult to build a short test case for this, but
the person who reported issue 6644 confirms that this
solves the problem.

Fixes #6644.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/18740044
2013-10-28 19:40:40 -04:00
Dmitriy Vyukov
f6329700ae runtime: remove nomemprof
Nomemprof seems to be unneeded now, there is no recursion.
If the recursion will be re-introduced, it will break loudly by deadlocking.
Fixes #6566.

R=golang-dev, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/14695044
2013-10-18 10:45:19 +04:00
Ian Lance Taylor
88c448ba40 runtime: correct test for when to poll network
Fixes #6610.

R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/14793043
2013-10-17 11:57:48 -07:00
Ian Lance Taylor
667303f158 runtime: correct parameter name in MCentral_AllocList comment
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/14792043
2013-10-17 11:57:00 -07:00
Alex Brainman
9aee98def8 undo CL 14231047 / 2f4c2dde2756
undone because the change slows down profile collection
significantly and unpredictable at times (see comments
at https://golang.org/cl/14231047 for details)

««« original CL description
runtime: collect profiles even while on g0 stack

Fixes #6417

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/14231047
»»»

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/14535046
2013-10-15 14:37:43 -04:00
Alex Brainman
9a420b79d7 runtime/pprof: disable flaky TestGoroutineSwitch on windows
Update #6417

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/14604043
2013-10-15 13:00:06 +11:00
Keith Randall
139cc96a57 runtime: markfreed's error reports should be prefixed with "markfreed", not "markallocated".
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/14441055
2013-10-09 13:28:47 -07:00
Ian Lance Taylor
cb30917387 runtime/cgo: mark callback functions as NOSPLIT
R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/14448044
2013-10-09 08:44:47 -07:00
Carl Shapiro
254dc5fdbe cmd/go, runtime: express armv5t architecture constraint differently
Instead of adding an -march=armv5t flag to the gcc command
line, the same effect is obtained with an ".arch armv5t"
pseudo op in the assembly file that uses armv5t instructions.

R=golang-dev, iant, dave
CC=golang-dev
https://golang.org/cl/14511044
2013-10-08 10:40:51 -07:00
Keith Randall
869368a528 runtime: fix bug in maps at the intersection of iterators, growing, and NaN keys
If an iterator is started while a map is in the middle of a grow,
and the map has NaN keys, then those keys might get returned by
the iterator more than once.  This fix makes the evacuation decision
deterministic and repeatable for NaN keys so each one gets returned
only once.

R=golang-dev, r, khr, iant
CC=golang-dev
https://golang.org/cl/14367043
2013-10-04 13:54:03 -07:00
Keith Randall
15baf6b4ac runtime: remove 3 unused declarations.
R=golang-dev, cshapiro, iant
CC=golang-dev
https://golang.org/cl/14405043
2013-10-04 13:22:20 -07:00
Alex Brainman
4207897dcc runtime: collect profiles even while on g0 stack
Fixes #6417

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/14231047
2013-10-04 13:53:34 +10:00
Russ Cox
408238e20b runtime: change default stack segment size to 8 kB
Changing from 4 kB to 8 kB brings significant improvement
on a variety of the Go 1 benchmarks, on both amd64
and 386 systems.

Significant runtime reductions:

          amd64  386
GoParse    -14%  -1%
GobDecode  -12% -20%
GobEncode  -64%  -1%
JSONDecode  -9%  -4%
JSONEncode -15%  -5%
Template   -17% -14%

In the longer term, khr's new stacks will avoid needing to
make this decision at all, but for Go 1.2 this is a reasonable
stopgap that makes performance significantly better.

Demand paging should mean that if the second 4 kB is not
used, it will not be brought into memory, so the change
should not adversely affect resident set size.
The same argument could justify bumping as high as 64 kB
on 64-bit machines, but there are diminishing returns
after 8 kB, and using 8 kB limits the possible unintended
memory overheads we are not aware of.

Benchmark graphs at
http://swtch.com/~rsc/gostackamd64.html
http://swtch.com/~rsc/gostack386.html

Full data at
http://swtch.com/~rsc/gostack.zip

R=golang-dev, khr, dave, bradfitz, dvyukov
CC=golang-dev
https://golang.org/cl/14317043
2013-10-03 09:19:10 -04:00
Russ Cox
4216203bcf runtime: remove syscall.NewCallbackCDecl on Windows
It is not possible to use (there is no declaration in package syscall),
and no one seems to care.

Alex Brainman may bring this back properly for Go 1.3.

Fixes #6338.

R=golang-dev, r, alex.brainman
CC=golang-dev
https://golang.org/cl/14287043
2013-10-02 21:39:45 -04:00
Russ Cox
5f853d7d94 runtime: fix finalizer test on amd64
Not scanning the stack by frames means we are reintroducing
a few false positives into the collection. Run the finalizer registration
in its own goroutine so that stack is guaranteed to be out of
consideration in a later collection.

This is working around a regression from yesterday's tip, but
it's not a regression from Go 1.1.

R=golang-dev
TBR=golang-dev
CC=golang-dev
https://golang.org/cl/14290043
2013-10-02 12:30:49 -04:00
Russ Cox
c3dadca977 runtime: do not scan stack by frames during garbage collection
Walking the stack by frames is ~3x more expensive
than not, and since it didn't end up being precise,
there is not enough benefit to outweigh the cost.

This is the conservative choice: this CL makes the
stack scanning behavior the same as it was in Go 1.1.

Add benchmarks to package runtime so that we have
them when we re-enable this feature during the
Go 1.3 development.

benchmark                     old ns/op    new ns/op    delta
BenchmarkGoroutineSelect        3194909      1272092  -60.18%
BenchmarkGoroutineBlocking      3120282       866366  -72.23%
BenchmarkGoroutineForRange      3256179       939902  -71.13%
BenchmarkGoroutineIdle          2005571       482982  -75.92%

The Go 1 benchmarks, just to add more data.
As far as I can tell the changes are mainly noise.

benchmark                         old ns/op    new ns/op    delta
BenchmarkBinaryTree17            4409403046   4414734932   +0.12%
BenchmarkFannkuch11              3407708965   3378306120   -0.86%
BenchmarkFmtFprintfEmpty                100           99   -0.60%
BenchmarkFmtFprintfString               242          239   -1.24%
BenchmarkFmtFprintfInt                  204          206   +0.98%
BenchmarkFmtFprintfIntInt               320          316   -1.25%
BenchmarkFmtFprintfPrefixedInt          295          299   +1.36%
BenchmarkFmtFprintfFloat                442          435   -1.58%
BenchmarkFmtManyArgs                   1246         1216   -2.41%
BenchmarkGobDecode                 10186951     10051210   -1.33%
BenchmarkGobEncode                 16504381     16445650   -0.36%
BenchmarkGzip                     447030885    447056865   +0.01%
BenchmarkGunzip                   111056154    111696305   +0.58%
BenchmarkHTTPClientServer             89973        93040   +3.41%
BenchmarkJSONEncode                28174182     27933893   -0.85%
BenchmarkJSONDecode               106353777    110443817   +3.85%
BenchmarkMandelbrot200              4822289      4806083   -0.34%
BenchmarkGoParse                    6102436      6142734   +0.66%
BenchmarkRegexpMatchEasy0_32            133          132   -0.75%
BenchmarkRegexpMatchEasy0_1K            372          373   +0.27%
BenchmarkRegexpMatchEasy1_32            113          111   -1.77%
BenchmarkRegexpMatchEasy1_1K            964          940   -2.49%
BenchmarkRegexpMatchMedium_32           202          205   +1.49%
BenchmarkRegexpMatchMedium_1K         68862        68858   -0.01%
BenchmarkRegexpMatchHard_32            3480         3407   -2.10%
BenchmarkRegexpMatchHard_1K          108255       112614   +4.03%
BenchmarkRevcomp                  751393035    743929976   -0.99%
BenchmarkTemplate                 139637041    135402220   -3.03%
BenchmarkTimeParse                      479          475   -0.84%
BenchmarkTimeFormat                     460          466   +1.30%

benchmark                          old MB/s     new MB/s  speedup
BenchmarkGobDecode                    75.34        76.36    1.01x
BenchmarkGobEncode                    46.50        46.67    1.00x
BenchmarkGzip                         43.41        43.41    1.00x
BenchmarkGunzip                      174.73       173.73    0.99x
BenchmarkJSONEncode                   68.87        69.47    1.01x
BenchmarkJSONDecode                   18.25        17.57    0.96x
BenchmarkGoParse                       9.49         9.43    0.99x
BenchmarkRegexpMatchEasy0_32         239.58       241.74    1.01x
BenchmarkRegexpMatchEasy0_1K        2749.74      2738.00    1.00x
BenchmarkRegexpMatchEasy1_32         282.49       286.32    1.01x
BenchmarkRegexpMatchEasy1_1K        1062.00      1088.96    1.03x
BenchmarkRegexpMatchMedium_32          4.93         4.86    0.99x
BenchmarkRegexpMatchMedium_1K         14.87        14.87    1.00x
BenchmarkRegexpMatchHard_32            9.19         9.39    1.02x
BenchmarkRegexpMatchHard_1K            9.46         9.09    0.96x
BenchmarkRevcomp                     338.26       341.65    1.01x
BenchmarkTemplate                     13.90        14.33    1.03x

Fixes #6482.

R=golang-dev, dave, r
CC=golang-dev
https://golang.org/cl/14257043
2013-10-02 11:59:53 -04:00
Rob Pike
fa7791e922 all: fix some mistakes found by go tool vet .
R=golang-dev, iant, adg
CC=golang-dev
https://golang.org/cl/14000043
2013-09-27 10:09:15 +10:00
Dave Cheney
649a2a9be5 runtime, syscall: update freebsd/arm calling convention to match EABI
Fixes #6451.

There is still some breakages unrelated to the syscall change.

[root@beaglebone ~/go/src]# /root/go/pkg/tool/freebsd_arm/go_bootstrap version
go version devel freebsd/arm
a std@beaglebone ~/go/src]# /root/go/pkg/tool/freebsd_arm/go_bootstrap install -
fatal error: mark - finalizer inconsistency

runtime stack:
runtime.throw(0x3e80ac)
        /root/go/src/pkg/runtime/panic.c:464 +0x5c
addfinroots(0x2)
        /root/go/src/pkg/runtime/mgc0.c:1501 +0x74
runtime.walkfintab(0x6c200)
        /root/go/src/pkg/runtime/mfinal.c:216 +0xa0
addroots()
        /root/go/src/pkg/runtime/mgc0.c:1561 +0x188
gc(0x50632f78)
        /root/go/src/pkg/runtime/mgc0.c:2098 +0x19c
mgc(0x306170a0)
        /root/go/src/pkg/runtime/mgc0.c:2049 +0x30
runtime.mcall(0x3e97b0)
        /root/go/src/pkg/runtime/asm_arm.s:165 +0x3c

goroutine 1 [garbage collection]:
runtime.gc(0x0)
        /root/go/src/pkg/runtime/mgc0.c:2020 +0x1a0 fp=0x50632f80
runtime.mallocgc(0x680, 0x1b1971, 0x1)
        /root/go/src/pkg/runtime/malloc.goc:143 +0x210 fp=0x50632fbc
----- stack segment boundary -----
cnew(0x1b1970, 0x640, 0x1)
        /root/go/src/pkg/runtime/malloc.goc:718 +0xc4 fp=0x50626110
runtime.cnewarray(0x1b1970, 0x640)
        /root/go/src/pkg/runtime/malloc.goc:731 +0x3c fp=0x50626120
makeslice1(0x1ac6d0, 0x500, 0x640, 0x50626190)
        /root/go/src/pkg/runtime/slice.c:57 +0x50 fp=0x5062612c
growslice1(0x1ac6d0, 0x30714a00, 0x500, 0x500, 0x501, ...)
        /root/go/src/pkg/runtime/slice.c:113 +0x8c fp=0x50626144
runtime.growslice(0x1ac6d0, 0x30714a00, 0x500, 0x500, 0x1, ...)
        /root/go/src/pkg/runtime/slice.c:80 +0x19c fp=0x50626174
go/build.(*importReader).readByte(0x3070d1b0, 0xb384e)
        /root/go/src/pkg/go/build/read.go:43 +0xbc fp=0x506261b4
go/build.(*importReader).peekByte(0x3070d1b0, 0x3070d101, 0x3070d180)
        /root/go/src/pkg/go/build/read.go:89 +0x210 fp=0x506261d0
go/build.readComments(0x203e2560, 0x306f79a8, 0x306f79a8, 0x203e2560, 0x306f79a8, ...)
        /root/go/src/pkg/go/build/read.go:194 +0x84 fp=0x506261f4
go/build.(*Context).matchFile(0x3e9730, 0x306209c0, 0x13, 0x306c42b4, 0x5, ...)
        /root/go/src/pkg/go/build/build.go:812 +0x74c fp=0x5062629c
go/build.(*Context).Import(0x3e9730, 0x1f95c8, 0x1, 0x30620960, 0x13, ...)
        /root/go/src/pkg/go/build/build.go:580 +0xd64 fp=0x506268dc
go/build.(*Context).ImportDir(0x3e9730, 0x30620960, 0x13, 0x0, 0x24d901, ...)
        /root/go/src/pkg/go/build/build.go:397 +0x5c fp=0x50626904
main.func·021(0x30620960, 0x13, 0x203e2200, 0x30680330, 0x0, ...)
        /root/go/src/cmd/go/main.go:521 +0x2cc fp=0x5062696c
path/filepath.walk(0x30620960, 0x13, 0x203e2200, 0x30680330, 0x50626ae8, ...)
        /root/go/src/pkg/path/filepath/path.go:341 +0x5c fp=0x506269d8
path/filepath.walk(0x3067e720, 0x11, 0x203e2200, 0x30680210, 0x50626ae8, ...)
        /root/go/src/pkg/path/filepath/path.go:359 +0x308 fp=0x50626a44
path/filepath.Walk(0x3067e720, 0x11, 0x50626ae8, 0x1f9728, 0x1)
        /root/go/src/pkg/path/filepath/path.go:380 +0xb4 fp=0x50626a68
main.matchPackages(0xbfffedea, 0x3, 0x1b1190, 0x3067e600, 0x10)
        /root/go/src/cmd/go/main.go:530 +0x2c0 fp=0x50626b1c
main.allPackages(0xbfffedea, 0x3, 0x1fadc8, 0x3, 0x1)
        /root/go/src/cmd/go/main.go:474 +0x34 fp=0x50626b70
main.importPathsNoDotExpansion(0x30620018, 0x1, 0x1, 0x0, 0xffffffff, ...)
        /root/go/src/cmd/go/main.go:305 +0x2f8 fp=0x50626c04
main.importPaths(0x30620018, 0x1, 0x1, 0x3, 0x0, ...)
        /root/go/src/cmd/go/main.go:315 +0x44 fp=0x50626c88
main.packagesAndErrors(0x30620018, 0x1, 0x1, 0x50626d60, 0x90f44, ...)
        /root/go/src/cmd/go/pkg.go:798 +0x1bc fp=0x50626d1c
main.packagesForBuild(0x30620018, 0x1, 0x1, 0x53490, 0x0, ...)
        /root/go/src/cmd/go/pkg.go:818 +0x44 fp=0x50626dac
main.runInstall(0x3e46e0, 0x30620018, 0x1, 0x1)
        /root/go/src/cmd/go/build.go:311 +0x48 fp=0x50626e60
main.main()
        /root/go/src/cmd/go/main.go:161 +0x518 fp=0x50626f8c
runtime.main()
        /root/go/src/pkg/runtime/proc.c:222 +0x100 fp=0x50626fc0
runtime.goexit()
        /root/go/src/pkg/runtime/proc.c:1396 fp=0x50626fc0

goroutine 3 [syscall]:
os/signal.loop()
        /root/go/src/pkg/os/signal/signal_unix.go:21 +0x24
created by os/signal.init·1
        /root/go/src/pkg/os/signal/signal_unix.go:27 +0x48

R=minux.ma, rsc
CC=golang-dev
https://golang.org/cl/13824044
2013-09-26 21:35:49 +10:00
Russ Cox
05ff4d7a1a runtime/pprof: fix profile parser in test
Fixes #6417.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13843043
2013-09-23 16:05:36 -04:00
Russ Cox
0fc9db7944 undo CL 13321048 / 9567c5da6e25
Makes build unnecessarily slower. Will fix the parser instead.

««« original CL description
runtime/pprof: run TestGoroutineSwitch for longer

Short test now takes about 0.5 second here.

Fixes #6417.

The failure was also seen on our builders.

R=golang-dev, minux.ma, r
CC=golang-dev
https://golang.org/cl/13321048
»»»

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/13720048
2013-09-23 15:58:35 -04:00
Dmitriy Vyukov
3ec600d0ca runtime/race: update runtime to r191161.
Fixes #6305.

R=golang-dev, dave, alex.brainman, r
CC=golang-dev
https://golang.org/cl/13359046
2013-09-22 10:56:06 -07:00
Alex Brainman
521dbbfef3 runtime/pprof: run TestGoroutineSwitch for longer
Short test now takes about 0.5 second here.

Fixes #6417.

The failure was also seen on our builders.

R=golang-dev, minux.ma, r
CC=golang-dev
https://golang.org/cl/13321048
2013-09-22 17:31:08 +10:00
Russ Cox
551ada4742 runtime: avoid allocation of internal panic values
If a fault happens in malloc, inevitably the next thing that happens
is a deadlock trying to allocate the panic value that says the fault
happened. Stop doing that, two ways.

First, reject panic in malloc just as we reject panic in garbage collection.

Second, runtime.panicstring was using an error implementation
backed by a Go string, so the interface held an allocated *string.
Since the actual errors are C strings, define a new error
implementation backed by a C char*, which needs no indirection
and therefore no allocation.

This second fix will avoid allocation for errors like nil panic derefs
or division by zero, so it is worth doing even though the first fix
should take care of faults during malloc.

Update #6419

R=golang-dev, dvyukov, dave
CC=golang-dev
https://golang.org/cl/13774043
2013-09-20 15:15:25 -04:00
Rémy Oudompheng
381b72a7a3 cmd/gc: cleanup SWITCH nodes after walk.
Keeping pointers from the pre-walk phase confuses
the race detection instrumentation.

Fixes #6418.

R=golang-dev, dvyukov, r
CC=golang-dev
https://golang.org/cl/13368057
2013-09-19 09:23:04 +02:00
Carl Shapiro
16d6b6c771 runtime: export PCDATA value reader
This interface is required to use the PCDATA interface
implemented in Go 1.2.  While initially entirely private, the
FUNCDATA side of the interface has been made public.  This
change completes the FUNCDATA/PCDATA interface.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/13735043
2013-09-16 19:03:19 -07:00
Rémy Oudompheng
045dbeaf05 cmd/gc, runtime: inline append in frontend.
A new transformation during walk turns append calls
into a combination of growslice and memmove.

benchmark                     old ns/op    new ns/op    delta
BenchmarkAppend                     141          141   +0.00%
BenchmarkAppend1Byte                 18           11  -39.56%
BenchmarkAppend4Bytes                19           10  -42.63%
BenchmarkAppend7Bytes                18           10  -42.16%
BenchmarkAppend8Bytes                18           10  -40.44%
BenchmarkAppend15Bytes               19           11  -41.67%
BenchmarkAppend16Bytes               19           11  -41.97%
BenchmarkAppend32Bytes               23           14  -38.82%
BenchmarkAppendStr1Byte              14           10  -23.78%
BenchmarkAppendStr4Bytes             14           11  -21.13%
BenchmarkAppendStr8Bytes             14           10  -25.17%
BenchmarkAppendStr16Bytes            19           11  -41.45%
BenchmarkAppendStr32Bytes            18           14  -19.44%
BenchmarkAppendSpecialCase           62           63   +1.77%

R=golang-dev, khr, cshapiro, rsc, dave
CC=golang-dev
https://golang.org/cl/12815046
2013-09-16 20:31:21 -04:00
Russ Cox
30ecb4cd05 build: disable precise collection of stack frames
The code for call site-specific pointer bitmaps was not ready in time,
but the zeroing required without it is too expensive to use by default.
We will have to wait for precise collection of stack frames until Go 1.3.

The precise collection can be re-enabled by

        GOEXPERIMENT=precisestack ./all.bash

but that will not be the default for a Go 1.2 build.

Fixes #6087.

R=golang-dev, jeremyjackins, dan.kortschak, r
CC=golang-dev
https://golang.org/cl/13677045
2013-09-16 20:26:10 -04:00
Russ Cox
70138a2108 runtime: fix uint64 division on 386
The uint64 divide function calls _mul64x32 to do a 64x32-bit multiply
and then compares the result against the 64-bit numerator.
If the result is bigger than the numerator, must use the slow path.

Unfortunately, the 64x32 produces a 96-bit product, and only the
low 64 bits were being used in the comparison. Return all 96 bits,
the bottom 64 via the original uint64* pointer, and the top 32
as the function's return value.

Fixes 386 build (broken by ARM division tests).

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13722044
2013-09-16 15:11:32 -04:00
Russ Cox
a70cbf1329 runtime: fix freebsd build
TBR=golang-dev
CC=golang-dev
https://golang.org/cl/13720044
2013-09-16 14:22:24 -04:00
Russ Cox
647eaed93b cmd/cgo: allow C.malloc(0) always
Because we can, and because it otherwise might crash
the program if we think we're out of memory.

Fixes #6390.

R=golang-dev, iant, minux.ma
CC=golang-dev
https://golang.org/cl/13345048
2013-09-16 14:04:55 -04:00
Russ Cox
b2794a1c2e runtime: make ARM integer div-by-zero traceback-friendly
The implementation of division in the 5 toolchain is a bit too magical.
Hide the magic from the traceback routines.

Also add a test for the results of the software divide routine.

Fixes #5805.

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/13239052
2013-09-16 14:04:45 -04:00
Russ Cox
555da73c56 runtime, syscall: work around FreeBSD/amd64 kernel bug
The kernel implementation of the fast system call path,
the one invoked by the SYSCALL instruction, is broken for
restarting system calls. A C program demonstrating this is below.

Change the system calls to use INT $0x80 instead, because
that (perhaps slightly slower) system call path actually works.

I filed http://www.freebsd.org/cgi/query-pr.cgi?pr=182161.

The C program demonstrating that it is FreeBSD's fault is below.
It reports the same "Bad address" failures from wait.

#include <sys/time.h>
#include <sys/signal.h>
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

static void handler(int);
static void* looper(void*);

int
main(void)
{
        int i;
        struct sigaction sa;
        pthread_cond_t cond;
        pthread_mutex_t mu;

        memset(&sa, 0, sizeof sa);
        sa.sa_handler = handler;
        sa.sa_flags = SA_RESTART;
        memset(&sa.sa_mask, 0xff, sizeof sa.sa_mask);
        sigaction(SIGCHLD, &sa, 0);

        for(i=0; i<2; i++)
                pthread_create(0, 0, looper, 0);

        pthread_mutex_init(&mu, 0);
        pthread_mutex_lock(&mu);
        pthread_cond_init(&cond, 0);
        for(;;)
                pthread_cond_wait(&cond, &mu);

        return 0;
}

static void
handler(int sig)
{
}

int
mywait4(int pid, int *stat, int options, struct rusage *rusage)
{
        int result;

        asm("movq %%rcx, %%r10; syscall"
                : "=a" (result)
                : "a" (7),
                  "D" (pid),
                  "S" (stat),
                  "d" (options),
                  "c" (rusage));
}

static void*
looper(void *v)
{
        int pid, stat, out;
        struct rusage rusage;

        for(;;) {
                if((pid = fork()) == 0)
                        _exit(0);
                out = mywait4(pid, &stat, 0, &rusage);
                if(out != pid) {
                        printf("wait4 returned %d\n", out);
                }
        }
}

Fixes #6372.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13582047
2013-09-16 14:04:32 -04:00
Russ Cox
6d68fc8eea runtime: fix CPU profiling on Windows
The test 'gp == m->curg' is not valid on Windows,
because the goroutine being profiled is not from the
current m.

TBR=golang-dev
CC=golang-dev
https://golang.org/cl/13718043
2013-09-15 12:05:24 -04:00
Russ Cox
439f9397fc runtime: avoid inconsistent goroutine state in profiler
Because profiling signals can arrive at any time, we must
handle the case where a profiling signal arrives halfway
through a goroutine switch. Luckily, although there is much
to think through, very little needs to change.

Fixes #6000.
Fixes #6015.

R=golang-dev, dvyukov
CC=golang-dev
https://golang.org/cl/13421048
2013-09-13 14:19:23 -04:00
Russ Cox
7276c02b41 runtime, cmd/gc, cmd/ld: ignore method wrappers in recover
Bug #1:

Issue 5406 identified an interesting case:
        defer iface.M()
may end up calling a wrapper that copies an indirect receiver
from the iface value and then calls the real M method. That's
two calls down, not just one, and so recover() == nil always
in the real M method, even during a panic.

[For the purposes of this entire discussion, a wrapper's
implementation is a function containing an ordinary call, not
the optimized tail call form that is somtimes possible. The
tail call does not create a second frame, so it is already
handled correctly.]

Fix this bug by introducing g->panicwrap, which counts the
number of bytes on current stack segment that are due to
wrapper calls that should not count against the recover
check. All wrapper functions must now adjust g->panicwrap up
on entry and back down on exit. This adds slightly to their
expense; on the x86 it is a single instruction at entry and
exit; on the ARM it is three. However, the alternative is to
make a call to recover depend on being able to walk the stack,
which I very much want to avoid. We have enough problems
walking the stack for garbage collection and profiling.
Also, if performance is critical in a specific case, it is already
faster to use a pointer receiver and avoid this kind of wrapper
entirely.

Bug #2:

The old code, which did not consider the possibility of two
calls, already contained a check to see if the call had split
its stack and so the panic-created segment was one behind the
current segment. In the wrapper case, both of the two calls
might split their stacks, so the panic-created segment can be
two behind the current segment.

Fix this by propagating the Stktop.panic flag forward during
stack splits instead of looking backward during recover.

Fixes #5406.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13367052
2013-09-12 14:00:16 -04:00
Rémy Oudompheng
ff416a3f19 cmd/gc: inline copy in frontend to call memmove directly.
A new node type OSPTR is added to refer to the data pointer of
strings and slices in a simple way during walk(). It will be
useful for future work on simplification of slice arithmetic.

benchmark                  old ns/op    new ns/op    delta
BenchmarkCopy1Byte                 9            8  -13.98%
BenchmarkCopy2Byte                14            8  -40.49%
BenchmarkCopy4Byte                13            8  -35.04%
BenchmarkCopy8Byte                13            8  -37.10%
BenchmarkCopy12Byte               14           12  -15.38%
BenchmarkCopy16Byte               14           12  -17.24%
BenchmarkCopy32Byte               19           14  -27.32%
BenchmarkCopy128Byte              31           26  -15.29%
BenchmarkCopy1024Byte            100           92   -7.50%
BenchmarkCopy1String              10            7  -28.99%
BenchmarkCopy2String              10            7  -28.06%
BenchmarkCopy4String              10            8  -22.69%
BenchmarkCopy8String              10            8  -23.30%
BenchmarkCopy12String             11           11   -5.88%
BenchmarkCopy16String             11           11   -5.08%
BenchmarkCopy32String             15           14   -6.58%
BenchmarkCopy128String            28           25  -10.60%
BenchmarkCopy1024String           95           95   +0.53%

R=golang-dev, bradfitz, cshapiro, dave, daniel.morsing, rsc, khr, khr
CC=golang-dev
https://golang.org/cl/9101048
2013-09-12 00:15:28 +02:00
Russ Cox
ce9ddd0eee runtime: keep args and frame in struct Func
args is useful for printing tracebacks.

frame is not necessary anymore, but we might some day
get back to functions where the frame size does not vary
by program counter, and if so we'll need it. Avoid needing
to introduce a new struct format later by keeping it now.

Fixes #5907.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13632051
2013-09-11 14:18:52 -04:00
Russ Cox
ab38e2a498 runtime: show m stack during crash on m stack
The various throwing > 0 finish a change started
in a previous CL, which sets throwing = -1 to mean
"don't show the internals". That gets set during the
"all goroutines are asleep - deadlock!" crash, and it
should also be set during any other expected crash
that does not indicate a problem within the runtime.

Most runtime.throw do indicate a problem within the
runtime, however, so we should be able to enumerate
the ones that should be silent. The goroutine sleeping
deadlock is the only one I can think of.

Update #5139

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13662043
2013-09-11 12:00:37 -04:00
Russ Cox
fa4984d535 runtime: show runtime.panic frame in traceback
Otherwise, if panic starts running deferred functions,
the code that panicked appears to be calling those
functions directly, which is not the case and can be
confusing.

For example:

main.Two()
        /Users/rsc/x.go:12 +0x2a
runtime.panic(0x20dc0, 0x2100cc010)
        /Users/rsc/g/go/src/pkg/runtime/panic.c:248 +0x106
main.One()
        /Users/rsc/x.go:8 +0x55

This makes clear(er) that main.Two is being called during
a panic, not as a direct call from main.One.

Fixes #5832.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13302051
2013-09-11 11:59:19 -04:00
Russ Cox
397ba2cb4a cmd/cgo: replace C.malloc with our own wrapper
This allows us to make two changes:

1. Force the argument type to be size_t, even on broken
   systems that declare malloc to take a ulong.

2. Call runtime.throw if malloc fails.
   (That is, the program crashes; it does not panic.)

Fixes #3403.
Fixes #5926.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13413047
2013-09-11 11:30:08 -04:00
Alexis Imperial-Legrand
927b7ac327 runtime: explicit init of runtime-gdb helpers
If using other gdb python scripts loaded before Go's gdb-runtime.py
and that have a different init prototype:
Traceback (most recent call last):
  File "/usr/lib/go/src/pkg/runtime/runtime-gdb.py", line 446, in <module>
    k()
TypeError: __init__() takes exactly 3 arguments (1 given)

The problem is that gdb keeps all python scripts in the same namespace,
so vars() contains them. To avoid that, load helpers one by one.

R=iant, rsc
CC=gobot, golang-dev
https://golang.org/cl/9752044
2013-09-10 13:00:08 -04:00
Keith Randall
4487054751 runtime: clean up / align comment tabbing
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13336046
2013-09-10 09:02:22 -07:00
Russ Cox
6252b41981 runtime: remove OABI check from ARM startup
The code in question is trying to print a nice error message
when a Go EABI binary runs on an OABI machine.
Unfortunately, the only way to do that is to use
ARM Thumb instructions, which we otherwise don't use.

There exist ARM EABI machines that do not support Thumb.
We could run on them if not for this OABI check, so disable it.

Fixes #5685.

R=golang-dev, minux.ma
CC=golang-dev
https://golang.org/cl/13234050
2013-09-09 15:06:05 -04:00
Joel Sing
3b089179c4 runtime: unbreak build on dragonfly
Update dragonfly memory functions to work with new memory statistics.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13615043
2013-09-09 08:48:06 -07:00
Keith Randall
78338d8c66 runtime: Smhasher tests of our map hash function.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/13436045
2013-09-06 16:23:46 -07:00
Dmitriy Vyukov
a33ef8d11b runtime: account for all sys memory in MemStats
Currently lots of sys allocations are not accounted in any of XxxSys,
including GC bitmap, spans table, GC roots blocks, GC finalizer blocks,
iface table, netpoll descriptors and more. Up to ~20% can unaccounted.
This change introduces 2 new stats: GCSys and OtherSys for GC metadata
and all other misc allocations, respectively.
Also ensures that all XxxSys indeed sum up to Sys. All sys memory allocation
functions require the stat for accounting, so that it's impossible to miss something.
Also fix updating of mcache_sys/inuse, they were not updated after deallocation.

test/bench/garbage/parser before:
Sys		670064344
HeapSys		610271232
StackSys	65536
MSpanSys	14204928
MCacheSys	16384
BuckHashSys	1439992

after:
Sys		670064344
HeapSys		610271232
StackSys	65536
MSpanSys	14188544
MCacheSys	16384
BuckHashSys	3194304
GCSys		39198688
OtherSys	3129656

Fixes #5799.

R=rsc, dave, alex.brainman
CC=golang-dev
https://golang.org/cl/12946043
2013-09-06 16:55:40 -04:00
Anthony Martin
3548ab5ebb runtime: handle timer overflow in tsleep
Make sure we never pass a timer into timerproc with
a negative duration since it will cause other timers
to never expire.

Fixes #5321.

R=golang-dev, minux.ma, remyoudompheng, mikioh.mikioh, r, bradfitz, rsc, dvyukov
CC=golang-dev
https://golang.org/cl/9035047
2013-09-06 15:47:39 -04:00
Aulus Egnatius Varialus
2b44b36487 cgo: enable cgo on dragonfly
Enable cgo for dragonfly/386 and dragonfly/amd64.

R=golang-dev, jsing, iant, bradfitz
CC=golang-dev
https://golang.org/cl/13247046
2013-09-04 15:19:21 -07:00
Keith Randall
23f9751e83 runtime: clean up map code. Remove hashmap.h.
Use cnew/cnewarray instead of mallocgc.

R=golang-dev, dvyukov
CC=golang-dev
https://golang.org/cl/13396045
2013-08-31 14:09:34 -07:00
Joel Sing
465ba6b78c runtime, syscall: add support for dragonfly/386
Add runtime and syscall support for dragonfly/386.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13237051
2013-08-31 09:32:07 -07:00
Keith Randall
fb376021be runtime: record type information for hashtable internal structures.
Remove all hashtable-specific GC code.

Fixes bug 6119.

R=cshapiro, dvyukov, khr
CC=golang-dev
https://golang.org/cl/13078044
2013-08-31 09:09:50 -07:00
Keith Randall
32b770b2c0 runtime: jump to badmcall instead of calling it.
This replaces the mcall frame with the badmcall frame instead of
leaving the mcall frame on the stack and adding the badmcall frame.
Because mcall is no longer on the stack, traceback will now report what
called mcall, which is what we would like to see in this situation.

R=golang-dev, cshapiro
CC=golang-dev
https://golang.org/cl/13012044
2013-08-29 15:53:34 -07:00
Carl Shapiro
c51152f438 runtime: check bitmap word for allocated bit in markonly
When searching for an allocated bit, flushptrbuf would search
backward in the bitmap word containing the bit of pointer
being looked-up before searching the span.  This extra check
was not replicated in markonly which, instead, after not
finding an allocated bit for a pointer would directly look in
the span.

Using statistics generated from godoc, before this change span
lookups were, on average, more common than word lookups.  It
was common for markonly to consult spans for one third of its
pointer lookups.  With this change in place, what were
previously span lookups are overwhelmingly become by the word
lookups making the total number of span lookups a relatively
small fraction of the whole.

This change also introduces some statistics gathering about
lookups guarded by the CollectStats enum.

R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/13311043
2013-08-29 13:52:38 -07:00
Keith Randall
ed467db6d8 cmd/cc,runtime: change preprocessor to expand macros inside of
#pragma textflag and #pragma dataflag directives.
Update dataflag directives to use symbols instead of integer constants.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13310043
2013-08-29 12:36:59 -07:00
Rob Pike
7c7d22ac5f runtime: re-enable TestParForParallel
See how it flies. We'll disable it again if the underlying issue is not resolved.
See issue 4155 for details.

Fixes #4155.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13368045
2013-08-29 11:42:18 +10:00
Keith Randall
d0dd420a24 runtime: rename FlagNoPointers to FlagNoScan. Better represents
the use of the flag, especially for objects which actually do have
pointers but we don't want the GC to scan them.

R=golang-dev, cshapiro
CC=golang-dev
https://golang.org/cl/13181045
2013-08-23 17:28:47 -07:00
Joel Sing
ac00524beb runtime: add dragonfly/amd64 port
Go runtime support for dragonfly/amd64, largely based of the existing
FreeBSD runtime (with some clues from the varialus/godfly work).

R=bradfitz
CC=golang-dev
https://golang.org/cl/13088044
2013-08-24 01:50:24 +10:00
Dmitriy Vyukov
dfdd1ba028 runtime: do not trigger GC on g0
GC acquires worldsema, which is a goroutine-level semaphore
which parks goroutines. g0 can not be parked.
Fixes #6193.

R=khr, khr
CC=golang-dev
https://golang.org/cl/12880045
2013-08-22 02:17:45 +04:00
Carl Shapiro
87fdb8fb9a undo CL 13010045 / 04f8101b46dd
Update the original change but do not read interface types in
the arguments area.  Once the arguments area is zeroed as the
locals area is we can safely read interface type values there
too.

««« original CL description
undo CL 12785045 / 71ce80dc4195

This has broken the 32-bit builds.

««« original CL description
cmd/gc, runtime: use type information to scan interface values

R=golang-dev, rsc, dvyukov
CC=golang-dev
https://golang.org/cl/12785045
»»»

R=khr, golang-dev, khr
CC=golang-dev
https://golang.org/cl/13010045
»»»

R=khr, khr
CC=golang-dev
https://golang.org/cl/13073045
2013-08-21 13:51:00 -07:00
Sokolov Yura
fcf6a7e5ce time: make timers heap 4-ary
This slightly improves performance when a lot of timers are present

$ misc/benchcmp ../old_timers_m.txt ../new_timers_m.txt
benchmark                           old ns/op    new ns/op    delta
BenchmarkAfterFunc                       6884         6605   -4.05%
BenchmarkAfterFunc-2                     4473         4144   -7.36%
BenchmarkAfterFunc-3                     8601         6185  -28.09%
BenchmarkAfterFunc-4                     9378         8773   -6.45%
BenchmarkAfter                           7237         7278   +0.57%
BenchmarkAfter-2                         4638         3923  -15.42%
BenchmarkAfter-3                         8751         6239  -28.71%
BenchmarkAfter-4                         9223         8737   -5.27%
BenchmarkStop                             603          496  -17.74%
BenchmarkStop-2                           795          577  -27.42%
BenchmarkStop-3                           982          680  -30.75%
BenchmarkStop-4                          1164          739  -36.51%
BenchmarkSimultaneousAfterFunc            657          593   -9.74%
BenchmarkSimultaneousAfterFunc-2          816          757   -7.23%
BenchmarkSimultaneousAfterFunc-3          844          830   -1.66%
BenchmarkSimultaneousAfterFunc-4          785          771   -1.78%
BenchmarkStartStop                        238          239   +0.42%
BenchmarkStartStop-2                      249          234   -6.02%
BenchmarkStartStop-3                      271          268   -1.11%
BenchmarkStartStop-4                      293          295   +0.68%

R=golang-dev, dvyukov, bradfitz, r
CC=golang-dev
https://golang.org/cl/13094043
2013-08-21 18:51:37 +04:00
Mikio Hara
e82614e5be runtime: integrated network pollster for freebsd/arm
Update #6146

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12927047
2013-08-20 16:57:30 +09:00
Carl Shapiro
ca2d32b46d undo CL 12785045 / 71ce80dc4195
This has broken the 32-bit builds.

««« original CL description
cmd/gc, runtime: use type information to scan interface values

R=golang-dev, rsc, dvyukov
CC=golang-dev
https://golang.org/cl/12785045
»»»

R=khr, golang-dev, khr
CC=golang-dev
https://golang.org/cl/13010045
2013-08-19 14:16:55 -07:00
Keith Randall
6401e0f83f runtime: don't run finalizers if we're still on the g0 stack.
R=golang-dev, rsc, dvyukov, khr
CC=golang-dev
https://golang.org/cl/11386044
2013-08-19 12:20:50 -07:00
Dmitriy Vyukov
d017f578d0 runtime: do not preempt race calls
In the crash stack trace race cgocall() calls endcgo(),
this means that m->racecall is wrong.
Indeed this can happen is a goroutine is rescheduled to another M
during race call.
Disable preemption for race calls.
Fixes #6155.

R=golang-dev, rsc, cshapiro
CC=golang-dev
https://golang.org/cl/12866045
2013-08-19 23:06:46 +04:00
Carl Shapiro
21ea5103a4 cmd/gc, runtime: use type information to scan interface values
R=golang-dev, rsc, dvyukov
CC=golang-dev
https://golang.org/cl/12785045
2013-08-19 10:19:59 -07:00
Mikio Hara
c4cdd35e6e runtime: integrated network pollster for netbsd/amd64,386,arm
Original CL by minux (9545044).

Update #6146

R=golang-dev, rsc
CC=golang-dev, minux.ma
https://golang.org/cl/12949045
2013-08-17 12:11:29 +09:00
Russ Cox
665feeedcb runtime: impose thread count limit
Actually working to stay within the limit could cause subtle deadlocks.
Crashing avoids the subtlety.

Fixes #4056.

R=golang-dev, r, dvyukov
CC=golang-dev
https://golang.org/cl/13037043
2013-08-16 22:25:26 -04:00
Dmitriy Vyukov
18f5ce8561 runtime/race: add output tests for different GORACE params
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/13065043
2013-08-16 21:54:04 +04:00
Dmitriy Vyukov
187b9c695f runtime: fix goroutine stack accounting
Fixes #6166.
Fixes #6168.

R=golang-dev, bradfitz, remyoudompheng
CC=golang-dev
https://golang.org/cl/12927045
2013-08-16 21:04:05 +04:00
Dmitriy Vyukov
fbf5fd5f1e runtime/race: update runtime to rev 188542
Fixes #6107.
race: output goroutine 1 as main goroutine

Fixes #6130.
race: option to abort program on first detected error

R=golang-dev, mikioh.mikioh
CC=golang-dev
https://golang.org/cl/12968044
2013-08-16 17:51:09 +04:00
Russ Cox
757e0de89f runtime: impose stack size limit
The goal is to stop only those programs that would keep
going and run the machine out of memory, but before they do that.
1 GB on 64-bit, 250 MB on 32-bit.
That seems implausibly large, and it can be adjusted.

Fixes #2556.
Fixes #4494.
Fixes #5173.

R=khr, r, dvyukov
CC=golang-dev
https://golang.org/cl/12541052
2013-08-15 22:34:06 -04:00
Russ Cox
08fdf00906 tests: remove two misuses of nil pointers
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12858044
2013-08-15 11:51:04 -04:00
Mikio Hara
ff86d222be runtime: fix wrong syscall numbers on freebsd/386, openbsd/386
R=golang-dev, jsing
CC=golang-dev
https://golang.org/cl/12876044
2013-08-15 23:22:55 +09:00
Dmitriy Vyukov
f195ae94ca runtime: remove old preemption checks
runtime.gcwaiting checks are not needed anymore

R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/12934043
2013-08-15 14:32:10 +04:00
Dmitriy Vyukov
67c79da857 runtime: fix plan9 build
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12986043
2013-08-15 14:24:28 +04:00
Carl Shapiro
3ec0427a07 cmd/go, runtime/cgo: explicitly target ARMv5T
The baseline architecture had been left to the GCC configured
default which can be more accomodating than the rest of the Go
toolchain.  This prevented instructions used by the 5g compiler,
like BLX, from being used in GCC compiled assembler code.

R=golang-dev, dave, rsc, elias.naur, cshapiro
CC=golang-dev
https://golang.org/cl/12954043
2013-08-14 15:21:53 -07:00
Dmitriy Vyukov
3bd0b0a80d runtime: fix SetBlockProfileRate
It doughtily misses all possible corner cases.
In particular on machines with <1GHz processors,
SetBlockProfileRate(1) disables profiling.
Fixes #6114.

R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/12936043
2013-08-15 00:20:36 +04:00
Russ Cox
5822e7848a runtime: make SetFinalizer(x, f) accept any f for which f(x) is valid
Originally the requirement was f(x) where f's argument is
exactly x's type.

CL 11858043 relaxed the requirement in a non-standard
way: f's argument must be exactly x's type or interface{}.

If we're going to relax the requirement, it should be done
in a way consistent with the rest of Go. This CL allows f's
argument to have any type for which x is assignable;
that's the same requirement the compiler would impose
if compiling f(x) directly.

Fixes #5368.

R=dvyukov, bradfitz, pieter
CC=golang-dev
https://golang.org/cl/12895043
2013-08-14 14:54:31 -04:00
Russ Cox
2560f8fe22 runtime/cgo: use old-style indirect call on arm
TBR=elias.naur
CC=golang-dev
https://golang.org/cl/12943043
2013-08-14 14:54:08 -04:00
Dmitriy Vyukov
dd50dac56c runtime: fix windows build
R=golang-dev
CC=golang-dev
https://golang.org/cl/12941043
2013-08-14 22:18:49 +04:00
Dmitriy Vyukov
4e76abbc60 runtime: implement SysUnused on windows
Fixes #5584.

R=golang-dev, chaishushan, alex.brainman
CC=golang-dev
https://golang.org/cl/12720043
2013-08-14 21:54:07 +04:00
Elias Naur
dc48e9516c runtime: Fix build on older ARM
The ARM external linking CL used BLX instructions in gcc assembler. Replace with BL to retain support on older ARM processors.

R=rsc
CC=golang-dev
https://golang.org/cl/12938043
2013-08-14 13:50:12 -04:00
Elias Naur
48c0d8b6e2 runtime: Fix netbsd/arm and freebsd/arm build
The ARM external linking CL left missed changes to sys_freebsd_arm.s and sys_netbsd_arm.s already done to sys_linux_arm.s.

R=rsc
CC=golang-dev
https://golang.org/cl/12842044
2013-08-14 13:18:32 -04:00
Elias Naur
45233734e2 runtime.cmd/ld: Add ARM external linking and implement -shared in terms of external linking
This CL is an aggregate of 10271047, 10499043, 9733044. Descriptions of each follow:

10499043
runtime,cmd/ld: Merge TLS symbols and teach 5l about ARM TLS

This CL prepares for external linking support to ARM.

The pseudo-symbols runtime.g and runtime.m are merged into a single
runtime.tlsgm symbol. When external linking, the offset of a thread local
variable is stored at a memory location instead of being embedded into a offset
of a ldr instruction. With a single runtime.tlsgm symbol for both g and m, only
one such offset is needed.

The larger part of this CL moves TLS code from gcc compiled to internally
compiled. The TLS code now uses the modern MRC instruction, and 5l is taught
about TLS fallbacks in case the instruction is not available or appropriate.

10271047
This CL adds support for -linkmode external to 5l.

For 5l itself, use addrel to allow for D_CALL relocations to be handled by the
host linker. Of the cases listed in rsc's comment in issue 4069, only case 5 and
63 needed an update. One of the TODO: addrel cases was since replaced, and the
rest of the cases are either covered by indirection through addpool (cases with
LTO or LFROM flags) or stubs (case 74). The addpool cases are covered because
addpool emits AWORD instructions, which in turn are handled by case 11.

In the runtime, change the argv argument in the rt0* functions slightly to be a
pointer to the argv list, instead of relying on a particular location of argv.

9733044
The -shared flag to 6l outputs a shared library, implemented in Go
and callable from non-Go programs such as C.

The main part of this CL change the thread local storage model.
Go uses the fastest and least general mode, local exec. TLS data in shared
libraries normally requires at least the local dynamic mode, however, this CL
instead opts for using the initial exec mode. Initial exec mode is faster than
local dynamic mode and can be used in linux since the linker has reserved a
limited amount of TLS space for performance sensitive TLS code.

Initial exec mode requires an extra load from the GOT table to determine the
TLS offset. This penalty will not be paid if ld is not in -shared mode, since
TLS accesses will be reduced to local exec.

The elf sections .init_array and .rela.init_array are added to register the Go
runtime entry with cgo at library load time.

The "hidden" attribute is added to Cgo functions called from Go, since Go
does not generate call through the GOT table, and adding non-GOT relocations for
a global function is not supported by gcc. Cgo symbols don't need to be global
and avoiding the GOT table is also faster.

The changes to 8l are only removes code relevant to the old -shared mode where
internal linking was used.

This CL only address the low level linker work. It can be submitted by itself,
but to be useful, the runtime changes in CL 9738047 is also needed.

Design discussion at
https://groups.google.com/forum/?fromgroups#!topic/golang-nuts/zmjXkGrEx6Q

Fixes #5590.

R=rsc
CC=golang-dev
https://golang.org/cl/12871044
2013-08-14 15:38:54 +00:00
Dmitriy Vyukov
c92287686d runtime: improve block profiler support for channels
1. Handle select statements.
2. Handle chan close.
3. Show top frame in debug mode (chansend/chanrecv/selectgo).
Fixes #6049.

R=golang-dev, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/12694050
2013-08-14 13:56:01 +04:00
Russ Cox
1a09d70e23 runtime: fix build on arm
Do not use ? :
I cannot say this enough.

TBR=dvyukov
CC=golang-dev
https://golang.org/cl/12903043
2013-08-13 19:37:54 -04:00
Dmitriy Vyukov
4f2e382c9f runtime: dump scheduler state if GODEBUG=schedtrace is set
The schedtrace value sets dump period in milliseconds.
In default mode the trace looks as follows:
SCHED 0ms: gomaxprocs=4 idleprocs=0 threads=3 idlethreads=0 runqueue=0 [1 0 0 0]
SCHED 1001ms: gomaxprocs=4 idleprocs=3 threads=6 idlethreads=3 runqueue=0 [0 0 0 0]
SCHED 2008ms: gomaxprocs=4 idleprocs=1 threads=6 idlethreads=1 runqueue=0 [0 1 0 0]
If GODEBUG=scheddetail=1 is set as well, then the detailed trace is printed:
SCHED 0ms: gomaxprocs=4 idleprocs=0 threads=3 idlethreads=0 runqueue=0 singleproc=0 gcwaiting=1 mlocked=0 nmspinning=0 stopwait=0 sysmonwait=0
  P0: status=3 tick=1 m=0 runqsize=1/128 gfreecnt=0
  P1: status=3 tick=0 m=-1 runqsize=0/128 gfreecnt=0
  P2: status=3 tick=0 m=-1 runqsize=0/128 gfreecnt=0
  P3: status=3 tick=0 m=-1 runqsize=0/128 gfreecnt=0
  M2: p=-1 curg=-1 mallocing=0 throwing=0 gcing=0 locks=1 dying=0 helpgc=0 spinning=0 lockedg=-1
  M1: p=-1 curg=-1 mallocing=0 throwing=0 gcing=0 locks=1 dying=0 helpgc=0 spinning=0 lockedg=-1
  M0: p=0 curg=1 mallocing=0 throwing=0 gcing=0 locks=1 dying=0 helpgc=0 spinning=0 lockedg=1
  G1: status=2() m=0 lockedm=0
  G2: status=1() m=-1 lockedm=-1

R=golang-dev, raggi, rsc
CC=golang-dev
https://golang.org/cl/11435044
2013-08-14 00:30:55 +04:00
Keith Randall
74e78df107 undo CL 12840043 / 3b9f54db72a1
Breaks the build.  Old bucket arrays kept by iterators
still need to be scanned.

««« original CL description
runtime: tell GC not to scan internal hashmap structures.
We'll do it ourselves via hash_gciter, thanks.
Fixes bug 6119.

R=golang-dev, dvyukov, cookieo9, rsc
CC=golang-dev
https://golang.org/cl/12840043
»»»

R=golang-dev
CC=golang-dev
https://golang.org/cl/12884043
2013-08-13 12:59:39 -07:00
Keith Randall
0df438c683 runtime: tell GC not to scan internal hashmap structures.
We'll do it ourselves via hash_gciter, thanks.
Fixes bug 6119.

R=golang-dev, dvyukov, cookieo9, rsc
CC=golang-dev
https://golang.org/cl/12840043
2013-08-13 12:36:03 -07:00
Russ Cox
ba14974e07 undo CL 12787044 / ed695cdf962b
The NetBSD and OpenBSD failures are apparently real,
not due to the test bug fixed in 100b9fc0c46f.

««« original CL description
runtime/pprof: test netbsd and openbsd again

Maybe these will work now.

R=golang-dev, dvyukov, bradfitz
CC=golang-dev
https://golang.org/cl/12787044
»»»

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12873043
2013-08-13 23:33:49 +04:00
Dmitriy Vyukov
4961483e7d runtime: fix LockOSThread
Fixes #6100.

R=golang-dev, dave, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/12703045
2013-08-13 22:37:04 +04:00
Dmitriy Vyukov
f9066fe1c0 runtime: more reliable preemption
Currently it's possible that a goroutine
that periodically executes non-blocking
cgo/syscalls is never preempted.
This change splits scheduler and syscall
ticks to prevent such situation.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/12658045
2013-08-13 22:14:04 +04:00
Dmitriy Vyukov
cc4e6aad8e runtime: do no lose CPU profiling signals
Currently we lose lots of profiling signals.
Most notably, GC is not accounted at all.
But stack splits, scheduler, syscalls, etc are lost as well.
This creates seriously misleading profile.
With this change all profiling signals are accounted.
Now I see these additional entries that were previously absent:
161  29.7%  29.7%      164  30.3% syscall.Syscall
 12   2.2%  50.9%       12   2.2% scanblock
 11   2.0%  55.0%       11   2.0% markonly
 10   1.8%  58.9%       10   1.8% sweepspan
  2   0.4%  85.8%        2   0.4% runtime.newstack
It is still impossible to understand what causes stack splits,
but at least it's clear how many time is spent on them.
Update #2197.
Update #5659.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/12179043
2013-08-13 22:12:02 +04:00
Dmitriy Vyukov
1da1030b5d runtime: fix false deadlock crash
Fixes #6070.
Update #6055.

R=golang-dev, nightlyone, rsc
CC=golang-dev
https://golang.org/cl/12602043
2013-08-13 22:07:42 +04:00
Russ Cox
469250fb77 runtime/pprof: test netbsd and openbsd again
Maybe these will work now.

R=golang-dev, dvyukov, bradfitz
CC=golang-dev
https://golang.org/cl/12787044
2013-08-13 12:35:37 -04:00
Dmitriy Vyukov
71c6da39ce runtime/pprof: fix test
R=golang-dev, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/12790043
2013-08-13 12:18:29 -04:00
Dmitriy Vyukov
aaab946943 runtime: fix handling of network deadlines
Ensure that deadlines affect already issued IO.

R=golang-dev, mikioh.mikioh, bradfitz
CC=golang-dev
https://golang.org/cl/12847043
2013-08-13 19:11:42 +04:00
Dmitriy Vyukov
5a20b4a6a9 sync: faster Cond
The new version does not require any memory allocations and is 30-50% faster.
Also detect and painc if Cond is copied after first.

benchmark            old ns/op    new ns/op    delta
BenchmarkCond1             317          195  -38.49%
BenchmarkCond1-2           875          607  -30.63%
BenchmarkCond1-4          1116          548  -50.90%
BenchmarkCond1-8          1013          613  -39.49%
BenchmarkCond1-16          983          450  -54.22%
BenchmarkCond2             559          352  -37.03%
BenchmarkCond2-2          1916         1378  -28.08%
BenchmarkCond2-4          1518         1322  -12.91%
BenchmarkCond2-8          2313         1291  -44.19%
BenchmarkCond2-16         1885         1078  -42.81%
BenchmarkCond4            1070          614  -42.62%
BenchmarkCond4-2          4899         3047  -37.80%
BenchmarkCond4-4          3813         3006  -21.16%
BenchmarkCond4-8          3605         3045  -15.53%
BenchmarkCond4-16         4148         2637  -36.43%
BenchmarkCond8            2086         1264  -39.41%
BenchmarkCond8-2          9961         6736  -32.38%
BenchmarkCond8-4          8135         7689   -5.48%
BenchmarkCond8-8          9623         7517  -21.89%
BenchmarkCond8-16        11661         8093  -30.60%

R=sougou, rsc, bradfitz, r
CC=golang-dev
https://golang.org/cl/11573043
2013-08-13 14:45:36 +04:00
Dmitriy Vyukov
d1b66439f9 runtime: eliminate excessive notewakeup calls in timers
If the timer goroutine is wakeup by timeout,
other goroutines will still notewakeup because sleeping is still set.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12763043
2013-08-13 14:14:24 +04:00
Dmitriy Vyukov
e33e476e07 syscall: disable cpu profiling around fork
Fixes #5517.
Fixes #5659.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12183044
2013-08-13 13:01:30 +04:00