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

2211 Commits

Author SHA1 Message Date
Russ Cox
32ecf57d22 runtime: reject onM calls from gsignal stack
The implementation and use patterns of onM assume
that they run on either the m->curg or m->g0 stack.

Calling onM from m->gsignal has two problems:

(1) When not on g0, onM switches to g0 and then "back" to curg.
If we didn't start at curg, bad things happen.

(2) The use of scalararg/ptrarg to pass C arguments and results
assumes that there is only one onM call at a time.
If a gsignal starts running, it may have interrupted the
setup/teardown of the args for an onM on the curg or g0 stack.
Using scalararg/ptrarg itself would smash those.

We can fix (1) by remembering what g was running before the switch.

We can fix (2) by requiring that uses of onM that might happen
on a signal handling stack must save the old scalararg/ptrarg
and restore them after the call, instead of zeroing them.
The only sane way to do this is to introduce a separate
onM_signalsafe that omits the signal check, and then if you
see a call to onM_signalsafe you know the surrounding code
must preserve the old scalararg/ptrarg values.
(The implementation would be that onM_signalsafe just calls
fn if on the signal stack or else jumps to onM. It's not necessary
to have two whole copies of the function.)

(2) is not a problem if the caller and callee are both Go and
a closure is used instead of the scalararg/ptrarg slots.

For now, I think we can avoid calling onM from code executing
on gsignal stacks, so just reject it.

In the long term, (2) goes away (as do the scalararg/ptrarg slots)
once everything is in Go, and at that point fixing (1) would be
trivial and maybe worth doing just for regularity.

LGTM=iant
R=golang-codereviews, iant
CC=dvyukov, golang-codereviews, khr, r
https://golang.org/cl/135400043
2014-09-04 00:10:10 -04:00
Russ Cox
cb767247ca runtime: refactor/fix asmcgocall/asmcgocall_errno
Instead of making asmcgocall call asmcgocall_errno,
make both load args into registers and call a shared
assembly function.

On amd64, this costs 1 word in the asmcgocall_errno path
but saves 3 words in the asmcgocall path, and the latter
is what happens on critical nosplit paths on Windows.

On arm, this fixes build failures: asmcgocall was writing
the arguments for asmcgocall_errno into the wrong
place on the stack. Passing them in registers avoids the
decision entirely.

On 386, this isn't really needed, since the nosplit paths
have twice as many words to work with, but do it for consistency.

Update #8635
Fixes arm build (except GOARM=5).

TBR=iant
CC=golang-codereviews
https://golang.org/cl/134390043
2014-09-04 00:01:55 -04:00
Russ Cox
93805d711c runtime: give 2 words back in notetsleep_internal
I really hoped we could avoid this nonsense, but it appears not.

Should fix windows/amd64 build breakage.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/137120043
2014-09-03 23:10:15 -04:00
Russ Cox
5ea69978fd runtime: make entersyscall/exitsyscall safe for stack splits
It is fundamentally unsafe to grow the stack once someone
has made a call to syscall.Syscall. That function takes 6 uintptr
arguments, but depending on the call some are pointers.
In fact, some might be pointers to stack values, and we don't know which.
That makes it impossible to copy the stack somewhere else.
Since we want to delete all the stack splitting code, relying only
on stack copying, make sure that Syscall never needs to split the stack.

The only thing Syscall does is:
        call entersyscall
        make the system call
        call exitsyscall

As long as we make sure that entersyscall and exitsyscall
can live in the nosplit region, they won't ask for more stack.

Do this by making entersyscall and exitsyscall set up the
stack guard so that any call to a function with a split check
will cause a crash. Then move non-essential slow-path
work onto the m stack using onM and mark the rest of the
work nosplit. The linker will verify that the chain of nosplits
fits in the total nosplit budget.

LGTM=iant
R=golang-codereviews, iant
CC=dvyukov, golang-codereviews, khr, r
https://golang.org/cl/140950043
2014-09-03 17:42:35 -04:00
Russ Cox
97f8386af7 runtime: convert symtab.c into symtab.go
Because symtab.c was partially converted before,
the diffs are not terribly useful.

The earlier conversion was trying to refactor or
clean up the code in addition to doing the translation.
It also made a mistake by redefining Func to be something
users could overwrite.

I undid those changes, making symtab.go a more
literal line-for-line translation of symtab.c instead.

LGTM=josharian
R=golang-codereviews, dave, bradfitz, josharian
CC=golang-codereviews, iant, khr, r
https://golang.org/cl/140880043
2014-09-03 13:02:48 -04:00
Brad Fitzpatrick
4930a8d058 runtime: relax flaky GC pause test
We often saw GC pauses of 0 ns, not just on Windows.
Google Compute Engine timer granularity might suck
too.

LGTM=rsc
R=rsc, dvyukov
CC=golang-codereviews
https://golang.org/cl/140910043
2014-09-03 09:54:53 -07:00
Russ Cox
176c44699b runtime: remove guard against uninitialized forcegc.g
The race was in the old C code.
The new Go code does not have the race
and does not need the check.

LGTM=bradfitz, dvyukov
R=golang-codereviews, bradfitz, dvyukov
CC=golang-codereviews, rlh
https://golang.org/cl/140180043
2014-09-03 12:48:32 -04:00
Dmitriy Vyukov
467a6d28be runtime: adopt race detector for runtime written in Go
Ignore memory access on g0/gsignal.
See the issue for context and explanation.
Fixes #8627.

LGTM=khr
R=golang-codereviews, mdempsky, khr
CC=golang-codereviews, rsc
https://golang.org/cl/137070043
2014-09-03 20:47:30 +04:00
Rick Hudson
56bd176e1d runtime: Start and stop individual goroutines at gc safepoints
Code to bring goroutines to a gc safepoint one at a time,
do some work such as scanning, and restart the
goroutine, and then move on to the next goroutine.
Currently this code does not do much useful work
but this infrastructure will be critical to future
concurrent GC work.

Fixed comments reviewers.

LGTM=rsc
R=golang-codereviews, rsc, dvyukov
CC=golang-codereviews
https://golang.org/cl/131580043
2014-09-03 12:06:36 -04:00
Keith Randall
f44073785a runtime: deferproc/deferreturn in Go
LGTM=rsc
R=golang-codereviews, rsc, khr
CC=golang-codereviews
https://golang.org/cl/139900043
2014-09-03 08:49:43 -07:00
Russ Cox
54138e1ac3 cmd/cgo, runtime: write cgo stub wrappers in Go, not C
LGTM=alex.brainman, iant
R=golang-codereviews, alex.brainman, iant
CC=dvyukov, golang-codereviews, khr, r
https://golang.org/cl/139070043
2014-09-03 11:36:14 -04:00
Russ Cox
012ceed914 runtime: make onM and mcall take Go func values
This gives them correct types in Go and also makes it
possible to use them to run Go code on an m stack.

LGTM=iant
R=golang-codereviews, dave, iant
CC=dvyukov, golang-codereviews, khr, r
https://golang.org/cl/137970044
2014-09-03 11:35:22 -04:00
Russ Cox
7ba41e9972 runtime: convert a few traceback-related functions from proc.c to traceback.go
They were in proc.c mainly because there was no portable
traceback source file. As part of converting them to Go,
move to traceback.go.

In order to get access to the PC of _rt0_go,
rename to runtime.rt0_go.

LGTM=r
R=golang-codereviews, r
CC=dvyukov, golang-codereviews, iant, khr
https://golang.org/cl/139110043
2014-09-03 11:11:16 -04:00
Russ Cox
0e07f1c99f runtime: introduce, use funcPC to convert Go func to PC
This removes the ** unsafe hack.

Real bug fixed at chan.go:101.

LGTM=dave, r, iant
R=golang-codereviews, dave, r, iant
CC=dvyukov, golang-codereviews, khr
https://golang.org/cl/140870044
2014-09-03 11:10:38 -04:00
Alex Brainman
2c780a35b9 runtime: increase windows prof thread priority sooner
If system is busy burning cpu, it takes long time (about 300ms on
windows builders) to adjust prof thread priority. Once adjusted, prof
thread runs ahead of everyone else, but due to initial slowness, it
does not capture prof snapshots until start-up period is completed.

Change prof thread priority sooner, so it can start captures straight
away.

LGTM=dvyukov
R=golang-codereviews, dvyukov
CC=golang-codereviews
https://golang.org/cl/134360043
2014-09-03 14:17:04 +10:00
Russ Cox
9aa7d136f5 runtime: avoid race with forcegc helper
While we are here, give the gc helper a real function name
that will appear in stack traces.

LGTM=rlh
R=rlh
CC=dvyukov, golang-codereviews
https://golang.org/cl/133470043
2014-09-02 19:18:46 -04:00
David du Colombier
d8cbbe6802 runtime: don't allocate a new string in snprintf
This fixes the Plan 9 build.

Fix issue 8621.

LGTM=iant
R=rsc, mattn.jp, iant
CC=golang-codereviews
https://golang.org/cl/135280043
2014-09-03 00:56:50 +02:00
David du Colombier
b3f224b280 runtime: handle empty environment variables on Plan 9
LGTM=bradfitz, rsc
R=rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/137920044
2014-09-03 00:56:31 +02:00
Keith Randall
3306d119b0 runtime: unify fastrand1 and fastrand2
C and Go calling conventions are now compatible, so we
don't need two versions of this function.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/139080043
2014-09-02 14:33:33 -07:00
Keith Randall
1d8fa7fa5d runtime: convert select implementation to Go.
LGTM=rsc
R=golang-codereviews, bradfitz, iant, khr, rsc
CC=golang-codereviews
https://golang.org/cl/139020043
2014-09-02 14:13:29 -07:00
Russ Cox
fa2af441f1 runtime: convert traceback*.c to Go
The two converted files were nearly identical.
Instead of continuing that duplication, I merged them
into a single traceback.go.

Tested on arm, amd64, amd64p32, and 386.

LGTM=r
R=golang-codereviews, remyoudompheng, dave, r
CC=dvyukov, golang-codereviews, iant, khr
https://golang.org/cl/134200044
2014-09-02 15:12:53 -04:00
Keith Randall
6baf173b67 runtime: move reflect trampolines into thunk file.
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/133460043
2014-09-02 10:07:02 -07:00
Dmitriy Vyukov
60447c2d95 runtime: convert clearpools/registerPoolCleanup to Go
LGTM=bradfitz, rsc
R=golang-codereviews, bradfitz, rsc
CC=golang-codereviews, khr
https://golang.org/cl/133240043
2014-09-02 20:03:48 +04:00
Matthew Dempsky
ac49e6735b runtime: convert cpuprof from C to Go
LGTM=dvyukov, rsc
R=golang-codereviews, dvyukov, rsc
CC=golang-codereviews
https://golang.org/cl/132440043
2014-09-02 00:14:22 -04:00
Alex Brainman
a19e638db2 runtime/pprof: adjust cpuHogger so that tests pass on windows builders
LGTM=rsc
R=dvyukov, rsc
CC=golang-codereviews
https://golang.org/cl/140110043
2014-09-01 23:06:22 -04:00
David du Colombier
20d9cc4bb0 runtime: fix gogetenv on Plan 9
LGTM=rsc
R=rsc, ality
CC=golang-codereviews
https://golang.org/cl/137030043
2014-09-01 23:03:26 -04:00
Russ Cox
649c83530a runtime: fix race detector running Go code on g0 of non-main thread
It looks like this has just always been broken:
the race detector handles running Go code on g0 of the main thread
and on g0 of any extra threads created by non-Go code, but it does
not handle running Go code on g0 of non-main threads created by Go.
Handle that.

Should fix the race build failures on the dashboard.

We're running into this now because we are running more
and more Go code on g0.

TBR=dvyukov
CC=golang-codereviews
https://golang.org/cl/137910043
2014-09-01 21:55:57 -04:00
Russ Cox
a8c5e87b1e runtime: fix Stack
Fixes #8626.

LGTM=bradfitz
R=golang-codereviews
CC=bradfitz, golang-codereviews, iant, r
https://golang.org/cl/137050043
2014-09-01 19:42:22 -04:00
Russ Cox
548d0805f7 runtime: convert mprof.goc to mprof.go
The exported Go definitions appearing in mprof.go are
copied verbatim from debug.go.

The unexported Go funcs and types are new.
The C Bucket type used a union and was not a line-for-line translation.

LGTM=remyoudompheng
R=golang-codereviews, remyoudompheng
CC=dvyukov, golang-codereviews, iant, khr, r
https://golang.org/cl/137040043
2014-09-01 18:51:12 -04:00
Russ Cox
60be96217d runtime: fix windows build
#ifdef'ed out code wasn't updated for argp change.

TBR=iant
CC=golang-codereviews
https://golang.org/cl/139040043
2014-09-01 17:36:45 -04:00
Russ Cox
fa5f86281e runtime: change concatstring panic to gothrow
It was a throw originally; it was converted incorrectly.

LGTM=dave
R=khr, dave
CC=golang-codereviews
https://golang.org/cl/139000043
2014-09-01 17:25:26 -04:00
Russ Cox
f611ae1c75 runtime: include os_*.h in the generated Go structs
Adding the #include to defs.c makes it get processed
by cmd/dist, which writes out Go equivalent for all the
C data structures defined in defs.c.

This in turn makes it necessary to define the Plink type,
used in os_plan9.h, in os_plan9.go. Rename it to _Plink
to avoid being exported.

LGTM=0intro, iant
R=golang-codereviews, iant, 0intro
CC=golang-codereviews, r
https://golang.org/cl/132490043
2014-09-01 17:25:10 -04:00
Russ Cox
3de7ba1873 runtime: change PC, SP values in Stkframe, Panic, Defer from byte* to uintptr
uintptr is better when translating to Go,
and in a few places it's better in C too.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews, iant, khr
https://golang.org/cl/138980043
2014-09-01 10:05:16 -04:00
Dmitriy Vyukov
f16729781b runtime/race: better handling of atomic operations
This change fixes the last known false negative of the race detector --
detection of races between mutating atomic operations and non-atomic operations.
Race runtime already has functions for precise modelling of various atomic operations,
so this change just forwards all atomic ops to race runtime
instead of poor man modeling in sync/atomic package.
Performance is also improved -- full sync/atomic tests run in 60s instead of 85s now.

LGTM=khr
R=golang-codereviews, khr
CC=golang-codereviews, rsc
https://golang.org/cl/111310044
2014-09-01 08:04:33 -04:00
Russ Cox
933169febb runtime: remove old malloc test programs
These haven't been run in ages.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews, iant, khr, r
https://golang.org/cl/134170043
2014-09-01 00:40:28 -04:00
Russ Cox
4dba769b73 runtime: paste mprof.goc into mprof.go as comments
NO CODE CHANGES HERE

The first conversion was not complete.
This CL doesn't make any actual changes,
but it inserts the missing mprof.goc code
as comments so that the next CL will have
useful diffs.

To make the diffs a bit more useful, removed
all semicolons, ->, and runtime· prefixes as well.

Also corrected order of a few functions in mprof.go
to match original order in mprof.goc.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews, iant, khr, r
https://golang.org/cl/134200043
2014-09-01 00:06:26 -04:00
Ian Lance Taylor
a287567d3c runtime: fix Linux build
Make the definition of the EpollEvent data field consistent
across architectures, adapt the other use of it in
netpoll_epoll for the new definition, and use uint64 rather
than uintptr.

LGTM=dave
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/137890043
2014-08-30 18:15:55 -07:00
Russ Cox
86c4c4f00c cmd/cc: generate error if #pragma pack off does anything
We can't translate misaligned things to Go, so start rejecting them in C.

The only one in any build appears to be EpollEvent on linux/amd64.
Fix that.

LGTM=r
R=golang-codereviews, r, dvyukov
CC=golang-codereviews, iant
https://golang.org/cl/137020043
2014-08-30 14:54:09 -04:00
Russ Cox
50199d7b35 runtime: translate env*.c to Go
In an earlier CL I wrote a separate Go-only version, but that broke Plan 9,
because the Go-only version assumed a non-Plan 9 system.

Translate the real ones instead.

LGTM=r
R=golang-codereviews, r
CC=0intro, golang-codereviews, iant, khr
https://golang.org/cl/140050044
2014-08-30 14:53:47 -04:00
Dmitriy Vyukov
2fd62a42b4 runtime/pprof: make CPU profiling tests more robust
Under the race detector most of the samples go into race runtime,
because of that freebsd race builder constantly fails on this test.

LGTM=bradfitz, rsc
R=golang-codereviews, bradfitz, rsc
CC=golang-codereviews, minux
https://golang.org/cl/133370043
2014-08-30 22:38:54 +04:00
Russ Cox
7006aafdcd runtime: preallocate panic errors for index and slice
This avoids allocating at the panic sites.

LGTM=r, khr
R=golang-codereviews, r, khr
CC=dvyukov, golang-codereviews, iant, khr
https://golang.org/cl/136020043
2014-08-30 14:18:41 -04:00
Keith Randall
47d6af2f68 runtime: convert chanrecv to Go
LGTM=rsc, dvyukov
R=golang-codereviews, bradfitz, rsc, dvyukov
CC=golang-codereviews
https://golang.org/cl/136980044
2014-08-30 11:03:28 -07:00
Matthew Dempsky
b70bc22cd0 runtime: retry fix openbsd build
Tested on linux/amd64 too this time.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=dave, golang-codereviews, iant, rsc
https://golang.org/cl/140050043
2014-08-29 23:13:17 -07:00
Russ Cox
397bdb216f runtime: increase nosplit area to 192
In CL 131450043, which raised it to 160,
I'd raise it to 192 if necessary.
Apparently it is necessary on windows/amd64.

One note for those concerned about the growth:
in the old segmented stack world, we wasted this much
space at the bottom of every stack segment.
In the new contiguous stack world, each goroutine has
only one stack segment, so we only waste this much space
once per goroutine. So even raising the limit further might
still be a net savings.

Fixes windows/amd64 build.

TBR=r
CC=golang-codereviews
https://golang.org/cl/132480043
2014-08-30 00:56:52 -04:00
Russ Cox
0316dafda2 runtime: rename SysAlloc to sysAlloc for Go
Renaming the C SysAlloc will let Go define a prototype without exporting it.
For use in cpuprof.goc's translation to Go.

LGTM=mdempsky
R=golang-codereviews, mdempsky
CC=golang-codereviews, iant
https://golang.org/cl/140060043
2014-08-30 00:54:40 -04:00
Dmitriy Vyukov
d4df63c3e8 runtime: convert type algorithms to Go
Actually it mostly deletes code -- alg.print and alg.copy go away.
There was only one usage of alg.print for debug purposes.
Alg.copy is used in chan.goc, but Keith replaces them with
memcopy during conversion, so alg.copy is not needed as well.
Converting them would be significant amount of work
for no visible benefit.

LGTM=crawshaw, rsc, khr
R=golang-codereviews, crawshaw, khr
CC=golang-codereviews, rsc
https://golang.org/cl/139930044
2014-08-30 08:40:56 +04:00
Russ Cox
1a976f1576 undo CL 135230043 / 60812bad3769
broke api check everywhere

««« original CL description
runtime: fix openbsd build

LGTM=iant
R=iant, minux
CC=golang-codereviews, jsing
https://golang.org/cl/135230043

»»»

TBR=mdempsky
CC=golang-codereviews
https://golang.org/cl/137010043
2014-08-30 00:16:07 -04:00
Matthew Dempsky
2758cb75f0 runtime: fix openbsd build
LGTM=iant
R=iant, minux
CC=golang-codereviews, jsing
https://golang.org/cl/135230043
2014-08-29 20:51:26 -07:00
Ian Lance Taylor
0b9e472300 runtime: rename Sigaltstack to SigaltstackT
Avoids a conflict between the type and function sigaltstack.

LGTM=crawshaw
R=rsc, crawshaw
CC=golang-codereviews
https://golang.org/cl/138920043
2014-08-29 16:11:05 -07:00
Russ Cox
858c57f5bd runtime: make allp a static array
It is anyway, just an allocated one.
Giving it a sized type makes Go access nicer.

LGTM=iant
R=dvyukov, iant
CC=golang-codereviews
https://golang.org/cl/139960043
2014-08-29 16:41:08 -04:00