1
0
mirror of https://github.com/golang/go synced 2024-11-08 01:46:14 -07:00
Commit Graph

3346 Commits

Author SHA1 Message Date
Austin Clements
9300d223a3 runtime: document philosophy behind runtime atomic usage
Based on Dmitry Vyukov's comments in CL 65210.

Change-Id: I5dce7286b0d180cd43cad3aaf70f537fafcda588
Reviewed-on: https://go-review.googlesource.com/123275
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2018-07-11 20:21:32 +00:00
Joel Sing
8ec35ab66a runtime: correct new thread stack for openbsd MAP_STACK
OpenBSD 6.4 will require the stack pointer to be pointing at an area that is
marked as MAP_STACK when entering and exiting syscalls. Adjust the stack pointer
used for a new thread such that it points within the stack, not at the top of
it (i.e. outside).

Fixes #26142

Change-Id: I905bd8e5be3dfc325392e7ac490fb56a7c71b3aa
Reviewed-on: https://go-review.googlesource.com/122735
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-07-11 17:58:23 +00:00
Kamil Rytarowski
f5921d48f1 runtime/cgo: Add initial NetBSD Thread Sanitizer support
Recognize NetBSD in:
 - go/internal/work/init.go
 - race.bash
 - runtime/race/race.go

Add __ps_strings symbol in runtime/cgo/netbsd.go as this is
used internally in the TSan library for NetBSD and used for
ReExec().

Tested on NetBSD/amd64 v. 8.99.12.

Around 98% tests are passing for the ./race.bash target.

Updates #19273

Change-Id: Ic0e48d2fb159a7868aab5e17156eeaca1225e513
GitHub-Last-Rev: d6e082707b
GitHub-Pull-Request: golang/go#24322
Reviewed-on: https://go-review.googlesource.com/99835
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-10 23:14:31 +00:00
Alberto Donizetti
34619d5d13 runtime/trace: comment newlines to restore correct doc summary
Fixes #26309

Change-Id: I0e0b61b885817e514aa46e299b00833f16e98b2a
Reviewed-on: https://go-review.googlesource.com/122898
Reviewed-by: Айнар Гарипов <gugl.zadolbal@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-10 14:26:23 +00:00
Ian Lance Taylor
fb59bccef3 runtime: clarify SetFinalizer docs
Fixes #24480

Change-Id: I7db721fb71a17f07472ec7f216478e7887435639
Reviewed-on: https://go-review.googlesource.com/122557
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-09 23:40:50 +00:00
Ian Lance Taylor
9b7a8aaaf3 runtime: only run TestMemStats sanity tests once
Fixes #22696

Change-Id: Ibe4628f71d64a2b36b655ea69710a925924b12a3
Reviewed-on: https://go-review.googlesource.com/122586
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2018-07-09 17:48:35 +00:00
Ian Lance Taylor
b56e24782f runtime: scale timeout in TestStackGrowth
Updates #19381

Change-Id: I62b8b0cd7170941af77281eb3aada3802623ec27
Reviewed-on: https://go-review.googlesource.com/122587
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-09 02:18:16 +00:00
Austin Clements
d82256ac11 runtime: skip TestG0StackOverflow on Android
This test is skipped on Linux and should be skipped on Android for the
same reason.

Change-Id: I753c4788d935bd58874554b455c0d5be2315b794
Reviewed-on: https://go-review.googlesource.com/122585
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-08 19:59:58 +00:00
Austin Clements
5cb1b1773f runtime: fix TestAbort on non-x86 arches
CL 122515 tightened TestAbort to look for breakpoint exceptions and
not just general signal crashes, but this only applies on x86 arches.
On non-x86 arches we use a nil pointer dereference to abort, so the
test is now failing.

This CL re-loosens TestAbort on non-x86 arches to only expect a signal
traceback.

Should fix the build on linux/arm, linux/arm64, linux/ppc64, and
linux/s390x.

Change-Id: I1065341180ab5ab4da63b406c641dcde93c9490b
Reviewed-on: https://go-review.googlesource.com/122580
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-08 19:25:13 +00:00
David du Colombier
b001ffb864 runtime: fix TestAbort on Plan 9
Since CL 122515, TestAbort is failing on Plan 9
because there is no SIGTRAP signal on Plan 9,
but a note containing the "sys: breakpoint" string.

This change fixes the TestAbort test by handling
the Plan 9 case.

Fixes #26265.

Change-Id: I2fae00130bcee1cf946d8cc9d147a77f951be390
Reviewed-on: https://go-review.googlesource.com/122464
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2018-07-08 04:14:45 +00:00
Austin Clements
78561c4ae9 runtime: handle g0 stack overflows gracefully
Currently, if the runtime overflows the g0 stack on Windows, it leads
to an infinite recursion:

1. Something overflows the g0 stack bounds and calls morestack.

2. morestack determines it's on the g0 stack and hence cannot grow the
stack, so it calls badmorestackg0 (which prints "fatal: morestack on
g0") followed by abort.

3. abort performs an INT $3, which turns into a Windows
_EXCEPTION_BREAKPOINT exception.

4. This enters the Windows sigtramp, which ensures we're on the g0
stack and calls exceptionhandler.

5. exceptionhandler has a stack check prologue, so it determines that
it's out of stack and calls morestack.

6. goto 2

Fix this by making the exception handler avoid stack checks until it
has ruled out an abort and by blowing away the stack bounds in
lastcontinuehandler before we print the final fatal traceback (which
itself involves a lot of stack bounds checks).

Fixes #21382.

Change-Id: Ie66e91f708e18d131d97f22b43f9ac26f3aece5a
Reviewed-on: https://go-review.googlesource.com/120857
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-07-07 14:44:11 +00:00
Austin Clements
d6b56bb301 runtime: account for guard zone in Windows stack size
Windows includes an 8K guard in system-allocated thread stacks, which
we currently don't account for when setting the g0 stack bounds. As a
result, if we do overflow the g0 stack bounds, we'll get a
STATUS_GUARD_PAGE_VIOLATION exception, which we're not expecting.

Fix the g0 stack bounds to include a total of 16K of slop to account
for this 8K guard.

Updates #21382.

Change-Id: Ia89b741b1413328e4681a237f5a7ee645531fe16
Reviewed-on: https://go-review.googlesource.com/122516
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-07-07 14:44:09 +00:00
Austin Clements
7001ac5394 runtime: fix abort handling on Windows
On Windows, the IP recorded in the breakpoint exception caused by
runtime.abort is actually one byte after the INT3, unlike on UNIX
OSes. Account for this in isgoexception.

It turns out TestAbort was "passing" on Windows anyway because abort
still caused a fatal panic, just not the one we were expecting. This
CL tightens this test to check that the runtime specifically reports a
breakpoint exception.

Fixing this is related to #21382, since we use runtime.abort in
reporting g0 stack overflows, and it's important that we detect this
and not try to handle it.

Change-Id: I66120944d138eb80f839346b157a3759c1019e34
Reviewed-on: https://go-review.googlesource.com/122515
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
2018-07-07 14:44:07 +00:00
Nikhil Benesch
5929ead6fb runtime: support capturing C backtrace from signal handler on darwin/amd64
The implementation is mostly copied from the commit that added
linux/amd64 support for this feature (https://golang.org/cl/17761).

Change-Id: I3f482167620a7a3daf50a48087f8849a30d713bd
Reviewed-on: https://go-review.googlesource.com/102438
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-07-04 00:18:48 +00:00
Nikhil Benesch
0e0cd70ecf runtime: document when cgo traceback function is called
Fixes #24518.

Change-Id: I99c79c5a2ab9dbe7f0d257c263da9d2b5d1d55c4
Reviewed-on: https://go-review.googlesource.com/121917
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-03 04:16:23 +00:00
Austin Clements
99e9be8043 runtime: query thread stack size from OS on Windows
Currently, on Windows, the thread stack size is set or assumed in many
different places. In non-cgo binaries, both the Go linker and the
runtime have a copy of the stack size, the Go linker sets the size of
the main thread stack, and the runtime sets the size of other thread
stacks. In cgo binaries, the external linker sets the main thread
stack size, the runtime assumes the size of the main thread stack will
be the same as used by the Go linker, and the cgo entry code assumes
the same.

Furthermore, users can change the main thread stack size using
editbin, so the runtime doesn't even really know what size it is, and
user C code can create threads with unknown thread stack sizes, which
we also assume have the same default stack size.

This is all a mess.

Fix the corner cases of this and the duplication of knowledge between
the linker and the runtime by querying the OS for the stack bounds
during thread setup. Furthermore, we unify all of this into just
runtime.minit for both cgo and non-cgo binaries and for the main
thread, other runtime-created threads, and C-created threads.

Updates #20975.

Change-Id: I45dbee2b5ea2ae721a85a27680737ff046f9d464
Reviewed-on: https://go-review.googlesource.com/120336
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-02 15:18:26 +00:00
Austin Clements
52e782a2d6 runtime: initialize g0 stack bounds on Windows to full stack
Currently, we allocate 1MB or 2MB thread stacks on Windows, but in
non-cgo binaries still set the g0 stack bounds assuming only 64k is
available. While this is fine in pure Go binaries, a non-cgo Go binary
on Windows can use the syscall package to call arbitrary DLLs, which
may call back into Go. If a DLL function uses more than 64k of stack
and then calls back into Go, the Go runtime will believe that it's out
of stack space and crash.

Fix this by plumbing the correct stack size into the g0 stacks of
non-cgo binaries. Cgo binaries already use the correct size because
their g0 stack sizes are set by a different code path.

Fixes #20975.

Change-Id: Id6fb559cfe1e1ea0dfac56d4654865c20dccf68d
Reviewed-on: https://go-review.googlesource.com/120195
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-02 15:18:24 +00:00
Austin Clements
9daa35edf0 runtime: tidy OpenBSD sysctl code
The OpenBSD sysctl code has been copy-pasted three times now. Abstract
it.

Change-Id: Ia5558927f0bc2b218b5af425dab368b5485d266c
Reviewed-on: https://go-review.googlesource.com/121775
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-07-02 14:44:21 +00:00
cch123
5110d19fc2 runtime: fix typo in mapextra comment
Change-Id: Idbd8a1b5bfeb1c23c86cef0697cf0380900e95f3
GitHub-Last-Rev: a8c2b27046
GitHub-Pull-Request: golang/go#26175
Reviewed-on: https://go-review.googlesource.com/121821
Reviewed-by: Keith Randall <khr@golang.org>
2018-07-02 06:08:26 +00:00
Ian Lance Taylor
f43aa1df70 runtime: throw if the runtime panics with out of bounds index
If the runtime code panics due to a bad index or slice expression,
then throw instead of panicing. This will skip calls to recover and dump
the entire runtime stack trace. The runtime should never panic due to
an out of bounds index, and this will help with debugging if it does.

For #24991
Updates #25201

Change-Id: I85a9feded8f0de914ee1558425931853223c0514
Reviewed-on: https://go-review.googlesource.com/121515
Reviewed-by: Austin Clements <austin@google.com>
2018-06-29 21:29:17 +00:00
Austin Clements
955cc07dde runtime: remap stack spans with MAP_STACK on OpenBSD
OpenBSD 6.4 is going to start requiring that the SP points to memory
that was mapped with MAP_STACK on system call entry, traps, and when
switching to the alternate signal stack [1]. Currently, Go doesn't map
any memory MAP_STACK, so the kernel quickly kills Go processes.

Fix this by remapping the memory that backs stack spans with
MAP_STACK, and re-remapping it without MAP_STACK when it's returned to
the heap.

[1] http://openbsd-archive.7691.n7.nabble.com/stack-register-checking-td338238.html

Fixes #26142.

Change-Id: I656eb84385a22833445d49328bb304f8cdd0e225
Reviewed-on: https://go-review.googlesource.com/121657
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2018-06-29 21:27:23 +00:00
Vladimir Kuzmin
b080abf656 cmd/compile: map delete should clear value always
Map delete must clear value every time because
newly added map optimizations of compound-assignment
operators (CL #91557) rely on this behavior of map delete.

It slows down map delete operation for non-reference types:

name                   old time/op    new time/op    delta
MapDelete/Int32/100      23.9ns ± 2%    27.8ns ± 4%  +16.04%  (p=0.000 n=20+20)
MapDelete/Int32/1000     21.5ns ± 2%    25.2ns ± 2%  +17.06%  (p=0.000 n=20+19)
MapDelete/Int32/10000    24.2ns ± 6%    27.2ns ± 5%  +12.39%  (p=0.000 n=19+19)
MapDelete/Int64/100      24.2ns ± 4%    27.7ns ± 2%  +14.55%  (p=0.000 n=20+20)
MapDelete/Int64/1000     22.1ns ± 2%    24.8ns ± 2%  +12.36%  (p=0.000 n=10+20)

Fixes #25936

Change-Id: I8499b790cb5bb019938161b3e50f3243d9bbb79c
Reviewed-on: https://go-review.googlesource.com/120255
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
2018-06-26 01:57:01 +00:00
Jeremy Jackins
444e7ddb27 runtime/trace: reword the trace package summary
Reword the package summary to be a little easier to read.

Change-Id: I84a9301a02e228b46165410a429548b3774762d5
GitHub-Last-Rev: 1342c7219f
GitHub-Pull-Request: golang/go#26052
Reviewed-on: https://go-review.googlesource.com/120795
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-25 19:11:01 +00:00
Nikhil Benesch
6fdbed0543 runtime: respect timeout in semasleep on Darwin
semasleep on Darwin was refactored in https://golang.org/cl/118736 to
use the pthread_cond_timedwait function from libc. The new code
incorrectly assumed that pthread_cond_timedwait took a timeout relative
to the current time, when it in fact it takes a timeout specified in
absolute time. semasleep thus specified a timeout well in the past,
causing it to immediately exceed the timeout and spin hot. This was the
source of a large performance hit to CockroachDB (#26019).

Adjust semasleep to instead call pthread_cond_timedwait_relative_np,
which properly interprets its timeout parameter as relative to the
current time.

pthread_cond_timedwait_relative_np is non-portable, but using
pthread_cond_timedwait correctly would require two calls to
gettimeofday: one in the runtime package to convert the relative timeout
to absolute time, then another in the pthread library to convert back to
a relative offset [0], as the Darwin kernel expects a relative offset.

[0]: https://opensource.apple.com/source/libpthread/libpthread-301.30.1/src/pthread_cond.c.auto.html

Fix #26019.

Change-Id: I1a8c2429f79513b43d2b256365cd9166d235af8b
Reviewed-on: https://go-review.googlesource.com/120635
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-25 02:22:05 +00:00
Zhou Peng
b8d4d0218b runtime: fix comments style typo
Code comments should have a space between comments characters and
actual words.

Change-Id: I6274baf1fc09b37a32ec6c69ddbb8edca9eb5469
Reviewed-on: https://go-review.googlesource.com/120475
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-22 13:21:28 +00:00
Austin Clements
4991bc6257 runtime: avoid recursive panic on bad lock count
Currently, if lock or unlock calls throw because the g.m.lock count is
corrupted, we're unlikely to get a stack trace because startpanic_m
will itself attempt to acquire a lock, causing a recursive failure.

Avoid this by forcing the g.m.locks count to a sane value if it's
currently bad.

This might be enough to get a stack trace from #25128.

Change-Id: I52d7bd4717ffae94a821f4249585f3eb6cd5aa41
Reviewed-on: https://go-review.googlesource.com/120416
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-22 00:28:25 +00:00
Wei Xiao
0a7ac93c27 cmd/compile: improve atomic add intrinsics with ARMv8.1 new instruction
ARMv8.1 has added new instruction (LDADDAL) for atomic memory operations. This
CL improves existing atomic add intrinsics with the new instruction. Since the
new instruction is only guaranteed to be present after ARMv8.1, we guard its
usage with a conditional on CPU feature.

Performance result on ARMv8.1 machine:
name        old time/op  new time/op  delta
Xadd-224    1.05µs ± 6%  0.02µs ± 4%  -98.06%  (p=0.000 n=10+8)
Xadd64-224  1.05µs ± 3%  0.02µs ±13%  -98.10%  (p=0.000 n=9+10)
[Geo mean]  1.05µs       0.02µs       -98.08%

Performance result on ARMv8.0 machine:
name        old time/op  new time/op  delta
Xadd-46      538ns ± 1%   541ns ± 1%  +0.62%  (p=0.000 n=9+9)
Xadd64-46    505ns ± 1%   508ns ± 0%  +0.48%  (p=0.003 n=9+8)
[Geo mean]   521ns        524ns       +0.55%

Change-Id: If4b5d8d0e2d6f84fe1492a4f5de0789910ad0ee9
Reviewed-on: https://go-review.googlesource.com/81877
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-06-21 14:52:43 +00:00
David Carlier
65d55a13a9 runtime: fix FreeBSDNumCPU test
num cpu unit test fixes for FreeBSD.
cpuset -g can possibly output more
data than expected.

Fixes #25924

Change-Id: Iec45a919df68648759331da7cd1fa3b9f3ca4241
GitHub-Last-Rev: 4cc275b519
GitHub-Pull-Request: golang/go#25931
Reviewed-on: https://go-review.googlesource.com/119376
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-19 22:19:28 +00:00
Carlos Eduardo Seo
1caa06299c runtime: implement procyield properly for ppc64x
The procyield() function should yield the processor as in other
architectures. On ppc64x, this is achieved by setting the Program
Priority Register to 'low priority' prior to the spin loop, and
setting it back to 'medium-low priority' afterwards.

benchmark                          old ns/op     new ns/op     delta
BenchmarkMakeChan/Byte-8           87.7          86.6          -1.25%
BenchmarkMakeChan/Int-8            107           106           -0.93%
BenchmarkMakeChan/Ptr-8            201           204           +1.49%
BenchmarkMakeChan/Struct/0-8       78.2          79.7          +1.92%
BenchmarkMakeChan/Struct/32-8      196           200           +2.04%
BenchmarkMakeChan/Struct/40-8      236           230           -2.54%
BenchmarkChanNonblocking-8         8.64          8.85          +2.43%
BenchmarkChanUncontended-8         5577          5598          +0.38%
BenchmarkChanContended-8           66106         51529         -22.05%
BenchmarkChanSync-8                451           441           -2.22%
BenchmarkChanSyncWork-8            9155          9170          +0.16%
BenchmarkChanProdCons0-8           1585          1083          -31.67%
BenchmarkChanProdCons10-8          1094          838           -23.40%
BenchmarkChanProdCons100-8         831           657           -20.94%
BenchmarkChanProdConsWork0-8       1471          941           -36.03%
BenchmarkChanProdConsWork10-8      1033          721           -30.20%
BenchmarkChanProdConsWork100-8     730           511           -30.00%
BenchmarkChanCreation-8            135           128           -5.19%
BenchmarkChanSem-8                 602           463           -23.09%
BenchmarkChanPopular-8             3017466       2188441       -27.47%

Fixes #25625

Change-Id: Iacb1c888d3c066902152b8367500348fb631c5f9
Reviewed-on: https://go-review.googlesource.com/115376
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-19 16:39:52 +00:00
Heschi Kreinick
c99300229d runtime: fix lldb test after DWARF compression
Most (all?) released versions of lldb don't support compressed DWARF.
For now, skip the test if lldb can't find where to put the breakpoint.

This is the best I could think of -- there is no explicit error that I
can find that indicates it couldn't load the DWARF.

Fixes #25925.

Change-Id: Ib8fa486a04940cee5959ba7aab7bdbbaa3b2974e
Reviewed-on: https://go-review.googlesource.com/119535
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2018-06-18 23:20:57 +00:00
Heschi Kreinick
17a4e0475d runtime: skip gdb tests on mips after DWARF compression
DWARF compression appears to break GDB on mips for reasons unknown. Skip
the GDB tests there.

Fixes #25939.

Change-Id: Id76860d3a2ff8055999ac12ea891c37565bb6685
Reviewed-on: https://go-review.googlesource.com/119539
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2018-06-18 22:03:17 +00:00
Hana Kim
88b442f5c0 runtime/pprof: fix incorrect assumption in TestMapping
TestMapping assumed that there was only one mapping entry corresponding
to /exe/main, but that is not always true.
This CL changes the test logic to examine whether all referenced mappings
are symbolized. Based on the result, the test determines whether the
corresponding mapping entries' HasFunctions fields to be true or false.

I initially attempted to create two mappings for referenced locations
(one for symbolized and another for unsymbolized) as described in the
TODO in proto.go as part of fixing this bug. But that change requires
non-trivial modification in the upstream profile package so I decided
to just fix the test for now.

Fixes #25891

Change-Id: Id27a5b07bb5b59e133755a0f863bf56c0a4f7f2b
Reviewed-on: https://go-review.googlesource.com/119455
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-18 19:09:37 +00:00
Elias Naur
cdffe9b1e3 runtime: move semaphore ops from system calls to libc calls on iOS
Change-Id: I1c7a12497c47dd166cc41230d6e5e005edcbc848
Reviewed-on: https://go-review.googlesource.com/118819
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2018-06-16 00:58:45 +00:00
Keith Randall
5b5473c6bf runtime: move semaphore ops from system calls to libc calls on Darwin
This CL removes the last of the direct system calls in the runtime package.
This is the last CL for 1.11.

Use libcCall instead of asmcgocall in a few places I accidentally used
the wrong one.

For 1.12, we need to think about whether/how the syscall package
should be moved over to libc.

Update #17490

Change-Id: I4f0bd9cd6023f662f2e29588266fdfae5233898f
Reviewed-on: https://go-review.googlesource.com/118736
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-16 00:58:37 +00:00
Richard Musiol
c12399fffb all: enable vet/all for js/wasm and fix vet issues
This commit enables vet/all for the js/wasm architecture. It got
skipped initially because the codebase did not fully compile yet
for js/wasm, which made vet/all fail.

startTimer and stopTimer are not needed in the syscall package.
Removed their assembly code since their Go stubs were already gone.

Change-Id: Icaeb6d903876e51ceb1edff7631f715a98c28696
Reviewed-on: https://go-review.googlesource.com/118657
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-15 00:05:22 +00:00
Richard Musiol
e083dc6307 runtime, sycall/js: add support for callbacks from JavaScript
This commit adds support for JavaScript callbacks back into
WebAssembly. This is experimental API, just like the rest of the
syscall/js package. The time package now also uses this mechanism
to properly support timers without resorting to a busy loop.

JavaScript code can call into the same entry point multiple times.
The new RUN register is used to keep track of the program's
run state. Possible values are: starting, running, paused and exited.
If no goroutine is ready any more, the scheduler can put the
program into the "paused" state and the WebAssembly code will
stop running. When a callback occurs, the JavaScript code puts
the callback data into a queue and then calls into WebAssembly
to allow the Go code to continue running.

Updates #18892
Updates #25506

Change-Id: Ib8701cfa0536d10d69bd541c85b0e2a754eb54fb
Reviewed-on: https://go-review.googlesource.com/114197
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-14 21:50:53 +00:00
Alberto Donizetti
70c3bf27de runtime/pprof: use testenv.GoToolPath in TestMapping
The TestMapping test invokes the go tool in an exec.Command by
directly hard-coding a "go" string for the command. This can cause
test failures on systems where the "go" command points to an old
toolchain where the test is not supposed to work.

Use testenv.GoToolPath instead.

Also call 'go run' directly on the mappingtest/main.go file instead of
go-running the directory.

Change-Id: Ib91877c021209cbf4da50a561737d7a9d42c6adc
Reviewed-on: https://go-review.googlesource.com/118662
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-14 13:45:55 +00:00
Elias Naur
c824f540d9 runtime: move iOS kevent calls to libc
Change-Id: Ie97c9c9163f5af7b4768c34faac726e21627aa79
Reviewed-on: https://go-review.googlesource.com/118660
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2018-06-13 18:27:23 +00:00
Keith Randall
72c29fc8cd runtime: move darwin kevent calls to libc
kqueue, kevent, closeonexec, setitimer, with sysctl and fcntl helpers.

TODO:arm,arm64

Change-Id: I9386f377186d6ac7cb99064c524a67e0c8282eba
Reviewed-on: https://go-review.googlesource.com/118561
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
2018-06-13 18:27:15 +00:00
Hana Kim
537fb06c5d runtime/pprof: skip TestMapping if CGO is not available
The test requires cgo

Change-Id: I1bffee5f187afcf4b7e27516451c56ddfc263a26
Reviewed-on: https://go-review.googlesource.com/118638
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-13 18:06:14 +00:00
Hana Kim
7b2f55d89f runtime/pprof: set HasFunctions of mapping entries
The pprof tool utilizes attributes of mapping entries
such as HasFunctions to determine whether the profile
includes necessary symbol information.
If none of the attributes is set, pprof tool tries to
read the corresponding binary to use for local symbolization.
If the binary doesn't exist, it prints out error messages.

Go runtime generated profiles without any of the attributes
set so the pprof tool always printed out the error messages.
The error messages became more obvious with the new
terminal support that uses red color for error messages.

Go runtime can symbolize all Go symbols and generate
self-contained profile for pure Go program. Thus, there
is no reason for the pprof tool to look for the copy of
the binary. So, this CL sets one of the attributes
(HasFunctions) true if all PCs in samples look fully
symbolized.

For non-pure Go program, however, it's possible that
symbolization of non-Go PCs is incomplete. In this case,
we need to leave the attributes all false so pprof can attempt
to symbolize using the local copy of the binary if available.
It's hard to determine whether a mapping includes non-Go
code. Instead, this CL checks PCs from collected samples.
If unsuccessful symbolization is observed, it skips setting
the HasFunctions attribute.

Fixes #25743

Change-Id: I5108be45bbc37ab486d145fa03e7ce37d88fad50
Reviewed-on: https://go-review.googlesource.com/118275
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-13 14:04:38 +00:00
Richard Musiol
be36bd996e runtime/internal/sys: rename Wasm to WASM
This commit changes sys.Wasm to sys.WASM, as requested on
https://groups.google.com/forum/#!topic/golang-dev/VquDxlhjPkg

Change-Id: I30a208c34576a8bb49b9beb524203d71df8fdf1c
Reviewed-on: https://go-review.googlesource.com/118395
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-12 22:09:45 +00:00
Elias Naur
021c39d7a3 runtime: use libc for signal functions on iOS
Also:
 - Add extra SystemStack space for darwin/arm64 just
like for darwin/arm.
 - Removed redundant stack alignment; the arm64 hardware enforces
 the 16 byte alignment.
 - Save and restore the g registers at library initialization.
 - Zero g registers since libpreinit can call libc functions
 that in turn use asmcgocall. asmcgocall requires an initialized g.
 - Change asmcgocall to work even if no g is set. The change mimics
 amd64.

Change-Id: I1b8c63b07cfec23b909c0d215b50dc229f8adbc8
Reviewed-on: https://go-review.googlesource.com/117176
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2018-06-12 17:05:46 +00:00
Keith Randall
ec989337c5 runtime: use libc's signal functions on Darwin
sigaction, sigprocmask, sigaltstack, and raiseproc.

Fix bug in mstart_stub where we weren't saving callee-saved registers,
so if an m finished the pthread library calling mstart_stub would
sometimes fail.

Update #17490
Update #22805

Change-Id: Ie297ede0997910aa956834e49e85711b90cdfaa7
Reviewed-on: https://go-review.googlesource.com/116875
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-12 17:05:39 +00:00
Elias Naur
f027d1a878 runtime: convert a darwin/arm64 syscall to libc
Change-Id: I5704a07375fc672ac70c1f4e8df6f4fff760b4bf
Reviewed-on: https://go-review.googlesource.com/118117
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2018-06-12 15:29:51 +00:00
Iskander Sharipov
f864d89ef7 runtime: remove TODO notes suggesting jump tables
For memmove/memclr using jump tables only reduces overall
function performance for both amd64 and 386.

Benchmarks for 32-bit memclr:

	name            old time/op    new time/op    delta
	Memclr/5-8        8.01ns ± 0%    8.94ns ± 2%  +11.59%  (p=0.000 n=9+9)
	Memclr/16-8       9.05ns ± 0%    9.49ns ± 0%   +4.81%  (p=0.000 n=8+8)
	Memclr/64-8       9.15ns ± 0%    9.49ns ± 0%   +3.76%  (p=0.000 n=9+10)
	Memclr/256-8      16.6ns ± 0%    16.6ns ± 0%     ~     (p=1.140 n=10+9)
	Memclr/4096-8      179ns ± 0%     166ns ± 0%   -7.26%  (p=0.000 n=9+8)
	Memclr/65536-8    3.36µs ± 1%    3.31µs ± 1%   -1.48%  (p=0.000 n=10+9)
	Memclr/1M-8       59.5µs ± 3%    60.5µs ± 2%   +1.67%  (p=0.009 n=10+10)
	Memclr/4M-8        239µs ± 3%     245µs ± 0%   +2.49%  (p=0.004 n=10+8)
	Memclr/8M-8        618µs ± 2%     614µs ± 1%     ~     (p=0.315 n=10+8)
	Memclr/16M-8      1.49ms ± 2%    1.47ms ± 1%   -1.11%  (p=0.029 n=10+10)
	Memclr/64M-8      7.06ms ± 1%    7.05ms ± 0%     ~     (p=0.573 n=10+8)
	[Geo mean]        3.36µs         3.39µs        +1.14%

For less predictable data, like loop iteration dependant sizes,
branch table still shows 2-5% worse results.
It also makes code slightly more complicated.

This CL removes TODO note that directly suggest trying this
optimization out. That encourages people to spend their time
in a quite hopeless endeavour.

The code used to implement branch table used a 32/64-entry table
with pointers to TEXT blocks that implemented every associated
label work. Most last entries point to "loop" code that is
a fallthrough for all other sizes that do not map into specialized
routines. The only inefficiency is extra MOVL/MOVQ required
to fetch table pointer itself as MOVL $sym<>(SB)(AX*4) is not valid
in Go asm (it works in other assemblers):

	TEXT ·memclrNew(SB), NOSPLIT, $0-8
        	MOVL    ptr+0(FP), DI
        	MOVL    n+4(FP), BX
        	// Handle 0 separately.
        	TESTL   BX, BX
        	JEQ     _0
        	LEAL    -1(BX), CX // n-1
        	BSRL    CX, CX
		// AX or X0 zeroed inside every text block.
       		MOVL    $memclrTable<>(SB), AX
        	JMP     (AX)(CX*4)
	_0:
        	RET

Change-Id: I4f706931b8127f85a8439b95834d5c2485a5d1bf
Reviewed-on: https://go-review.googlesource.com/115678
Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2018-06-11 22:09:04 +00:00
Lynn Boger
9e9ff565cd runtime/race: implement race detector for ppc64le
This adds the support to enable the race detector for ppc64le.

Added runtime/race_ppc64le.s to manage the calls from Go to the
LLVM tsan functions, mostly converting from the Go ABI to the
PPC64 ABI expected by Clang generated code.

Changed racewalk.go to call racefuncenterfp instead of racefuncenter
on ppc64le to allow the caller pc to be obtained in the asm code
before calling the tsan version.

Changed the set up code for racecallbackthunk so it doesn't use
the autogenerated save and restore of the link register since that
sequence uses registers inconsistent with the normal ppc64 ABI.

Made various changes to recognize that race is supported for
ppc64le.

Ensured that tls_g is updated and accessible from race_linux_ppc64le.s
so that the race ctx can be obtained and passed to tsan functions.

This enables the race tests for ppc64le in cmd/dist/test.go and
increases the timeout when running the benchmarks with the -race
option to avoid timing out.

Updates #24354, #23731

Change-Id: Ib97dc7ac313e6313c836dc7d2fb698f9d8fba3ef
Reviewed-on: https://go-review.googlesource.com/107935
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-11 17:45:36 +00:00
Lynn Boger
30a63ecee3 runtime: restore r2 when restoring state from gobuf in gogo on ppc64x
When using plugins with goroutines calling cgo, we hit a case where
an intermittent SIGSEGV occurs when referencing an address that is based
on r2 (TOC address). When the failure can be generated in gdb, the
contents of r2 is wrong even though the value in the current stack's
slot for r2 is correct. So that means it somehow switched to start
running the code in this function without passing through the beginning
of the function which had the correct value of r2 and stored it there.

It was noted that in runtime.gogo when the state is restored from
gobuf, r2 is not restored from its slot on the stack. Adding the
instruction to restore r2 prevents the SIGSEGV.

This adds a testcase under testplugin which reproduces the problem if
the program is run multiple times. The team who reported this problem
has verified it fixes the issue on their larger, more complex
application.

Fixes #25756

Change-Id: I6028b6f1f8775d5c23f4ebb57ae273330a28eb8f
Reviewed-on: https://go-review.googlesource.com/117515
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-11 12:13:11 +00:00
philhofer
afae876b31 runtime: fix pprof livelock on arm
On 32-bit architectures without native 64-bit atomic instructions,
64-bit atomics are emulated using spinlocks. However,
the sigprof handling code expects to be able to perform
64-bit atomic operations in signal handlers. Spinning on an
acquired spinlock in a signal handler leads to a livelock.
This is issue #20146.

The original fix for #20146 did not include arm in
the list of architectures that need to work around portability
issues in the sigprof handler code. The unit test designed to
catch this issue does not fail on arm builds because arm uses
striped spinlocks, and thus the livelock takes many minutes
to reproduce. This is issue #24260. (This patch doesn't completely
fix #24260 on go1.10.2 due to issue #25785, which is probably
related to the arm cas kernel helpers. Those have been removed
at tip.)

With this patch applied, I was able to run the reproducer for
issue #24260 for more than 90 minutes without reproducing the
livelock. Without this patch, the livelock took as little as
8 minutes to reproduce.

Fixes #20146
Updates #24260

Change-Id: I64bf53a14d53c4932367d919ac55e17c99d87484
Reviewed-on: https://go-review.googlesource.com/117057
Run-TryBot: Philip Hofer <phofer@umich.edu>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2018-06-08 17:07:53 +00:00
cch123
cf901a7240 runtime: fix typo in runqput comment
Change-Id: Idd88a1d9420545e3e326f8e3b57a38d8c7515555
GitHub-Last-Rev: 59528f5522
GitHub-Pull-Request: golang/go#25779
Reviewed-on: https://go-review.googlesource.com/116935
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-07 14:58:07 +00:00