2010-12-08 14:10:00 -05:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
#include <pthread.h>
|
2015-09-29 21:24:13 -07:00
|
|
|
#include <errno.h>
|
2011-11-09 23:11:48 +03:00
|
|
|
#include <string.h> // strerror
|
2012-03-14 13:07:25 +09:00
|
|
|
#include <signal.h>
|
2015-09-29 21:24:13 -07:00
|
|
|
#include <stdlib.h>
|
2010-12-08 14:10:00 -05:00
|
|
|
#include "libcgo.h"
|
|
|
|
|
|
|
|
|
|
static void* threadentry(void*);
|
all: remove 'extern register M *m' from runtime
The runtime has historically held two dedicated values g (current goroutine)
and m (current thread) in 'extern register' slots (TLS on x86, real registers
backed by TLS on ARM).
This CL removes the extern register m; code now uses g->m.
On ARM, this frees up the register that formerly held m (R9).
This is important for NaCl, because NaCl ARM code cannot use R9 at all.
The Go 1 macrobenchmarks (those with per-op times >= 10 µs) are unaffected:
BenchmarkBinaryTree17 5491374955 5471024381 -0.37%
BenchmarkFannkuch11 4357101311 4275174828 -1.88%
BenchmarkGobDecode 11029957 11364184 +3.03%
BenchmarkGobEncode 6852205 6784822 -0.98%
BenchmarkGzip 650795967 650152275 -0.10%
BenchmarkGunzip 140962363 141041670 +0.06%
BenchmarkHTTPClientServer 71581 73081 +2.10%
BenchmarkJSONEncode 31928079 31913356 -0.05%
BenchmarkJSONDecode 117470065 113689916 -3.22%
BenchmarkMandelbrot200 6008923 5998712 -0.17%
BenchmarkGoParse 6310917 6327487 +0.26%
BenchmarkRegexpMatchMedium_1K 114568 114763 +0.17%
BenchmarkRegexpMatchHard_1K 168977 169244 +0.16%
BenchmarkRevcomp 935294971 914060918 -2.27%
BenchmarkTemplate 145917123 148186096 +1.55%
Minux previous reported larger variations, but these were caused by
run-to-run noise, not repeatable slowdowns.
Actual code changes by Minux.
I only did the docs and the benchmarking.
LGTM=dvyukov, iant, minux
R=minux, josharian, iant, dave, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/109050043
2014-06-26 11:54:39 -04:00
|
|
|
static void (*setg_gcc)(void*);
|
2010-12-08 14:10:00 -05:00
|
|
|
|
|
|
|
|
void
|
all: remove 'extern register M *m' from runtime
The runtime has historically held two dedicated values g (current goroutine)
and m (current thread) in 'extern register' slots (TLS on x86, real registers
backed by TLS on ARM).
This CL removes the extern register m; code now uses g->m.
On ARM, this frees up the register that formerly held m (R9).
This is important for NaCl, because NaCl ARM code cannot use R9 at all.
The Go 1 macrobenchmarks (those with per-op times >= 10 µs) are unaffected:
BenchmarkBinaryTree17 5491374955 5471024381 -0.37%
BenchmarkFannkuch11 4357101311 4275174828 -1.88%
BenchmarkGobDecode 11029957 11364184 +3.03%
BenchmarkGobEncode 6852205 6784822 -0.98%
BenchmarkGzip 650795967 650152275 -0.10%
BenchmarkGunzip 140962363 141041670 +0.06%
BenchmarkHTTPClientServer 71581 73081 +2.10%
BenchmarkJSONEncode 31928079 31913356 -0.05%
BenchmarkJSONDecode 117470065 113689916 -3.22%
BenchmarkMandelbrot200 6008923 5998712 -0.17%
BenchmarkGoParse 6310917 6327487 +0.26%
BenchmarkRegexpMatchMedium_1K 114568 114763 +0.17%
BenchmarkRegexpMatchHard_1K 168977 169244 +0.16%
BenchmarkRevcomp 935294971 914060918 -2.27%
BenchmarkTemplate 145917123 148186096 +1.55%
Minux previous reported larger variations, but these were caused by
run-to-run noise, not repeatable slowdowns.
Actual code changes by Minux.
I only did the docs and the benchmarking.
LGTM=dvyukov, iant, minux
R=minux, josharian, iant, dave, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/109050043
2014-06-26 11:54:39 -04:00
|
|
|
x_cgo_init(G* g, void (*setg)(void*))
|
2010-12-08 14:10:00 -05:00
|
|
|
{
|
2015-09-29 21:24:13 -07:00
|
|
|
pthread_attr_t *attr;
|
2011-11-09 23:11:48 +03:00
|
|
|
size_t size;
|
|
|
|
|
|
2015-09-29 21:24:13 -07:00
|
|
|
/* The memory sanitizer distributed with versions of clang
|
|
|
|
|
before 3.8 has a bug: if you call mmap before malloc, mmap
|
|
|
|
|
may return an address that is later overwritten by the msan
|
|
|
|
|
library. Avoid this problem by forcing a call to malloc
|
|
|
|
|
here, before we ever call malloc.
|
|
|
|
|
|
|
|
|
|
This is only required for the memory sanitizer, so it's
|
|
|
|
|
unfortunate that we always run it. It should be possible
|
|
|
|
|
to remove this when we no longer care about versions of
|
|
|
|
|
clang before 3.8. The test for this is
|
|
|
|
|
misc/cgo/testsanitizers.
|
|
|
|
|
|
|
|
|
|
GCC works hard to eliminate a seemingly unnecessary call to
|
|
|
|
|
malloc, so we actually use the memory we allocate. */
|
|
|
|
|
|
all: remove 'extern register M *m' from runtime
The runtime has historically held two dedicated values g (current goroutine)
and m (current thread) in 'extern register' slots (TLS on x86, real registers
backed by TLS on ARM).
This CL removes the extern register m; code now uses g->m.
On ARM, this frees up the register that formerly held m (R9).
This is important for NaCl, because NaCl ARM code cannot use R9 at all.
The Go 1 macrobenchmarks (those with per-op times >= 10 µs) are unaffected:
BenchmarkBinaryTree17 5491374955 5471024381 -0.37%
BenchmarkFannkuch11 4357101311 4275174828 -1.88%
BenchmarkGobDecode 11029957 11364184 +3.03%
BenchmarkGobEncode 6852205 6784822 -0.98%
BenchmarkGzip 650795967 650152275 -0.10%
BenchmarkGunzip 140962363 141041670 +0.06%
BenchmarkHTTPClientServer 71581 73081 +2.10%
BenchmarkJSONEncode 31928079 31913356 -0.05%
BenchmarkJSONDecode 117470065 113689916 -3.22%
BenchmarkMandelbrot200 6008923 5998712 -0.17%
BenchmarkGoParse 6310917 6327487 +0.26%
BenchmarkRegexpMatchMedium_1K 114568 114763 +0.17%
BenchmarkRegexpMatchHard_1K 168977 169244 +0.16%
BenchmarkRevcomp 935294971 914060918 -2.27%
BenchmarkTemplate 145917123 148186096 +1.55%
Minux previous reported larger variations, but these were caused by
run-to-run noise, not repeatable slowdowns.
Actual code changes by Minux.
I only did the docs and the benchmarking.
LGTM=dvyukov, iant, minux
R=minux, josharian, iant, dave, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/109050043
2014-06-26 11:54:39 -04:00
|
|
|
setg_gcc = setg;
|
2015-09-29 21:24:13 -07:00
|
|
|
attr = (pthread_attr_t*)malloc(sizeof *attr);
|
|
|
|
|
if (attr == NULL) {
|
|
|
|
|
fatalf("malloc failed: %s", strerror(errno));
|
|
|
|
|
}
|
|
|
|
|
pthread_attr_init(attr);
|
|
|
|
|
pthread_attr_getstacksize(attr, &size);
|
|
|
|
|
g->stacklo = (uintptr)&size - size + 4096;
|
|
|
|
|
pthread_attr_destroy(attr);
|
|
|
|
|
free(attr);
|
2010-12-08 14:10:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2013-02-28 16:24:38 -05:00
|
|
|
_cgo_sys_thread_start(ThreadStart *ts)
|
2010-12-08 14:10:00 -05:00
|
|
|
{
|
|
|
|
|
pthread_attr_t attr;
|
2012-03-14 13:07:25 +09:00
|
|
|
sigset_t ign, oset;
|
2010-12-08 14:10:00 -05:00
|
|
|
pthread_t p;
|
|
|
|
|
size_t size;
|
2011-06-28 12:04:50 -04:00
|
|
|
int err;
|
2010-12-08 14:10:00 -05:00
|
|
|
|
2012-03-14 13:07:25 +09:00
|
|
|
sigfillset(&ign);
|
2013-12-22 08:55:29 -08:00
|
|
|
pthread_sigmask(SIG_SETMASK, &ign, &oset);
|
2012-03-14 13:07:25 +09:00
|
|
|
|
2010-12-08 14:10:00 -05:00
|
|
|
pthread_attr_init(&attr);
|
|
|
|
|
pthread_attr_getstacksize(&attr, &size);
|
runtime: assume precisestack, copystack, StackCopyAlways, ScanStackByFrames
Commit to stack copying for stack growth.
We're carrying around a surprising amount of cruft from older schemes.
I am confident that precise stack scans and stack copying are here to stay.
Delete fallback code for when precise stack info is disabled.
Delete fallback code for when copying stacks is disabled.
Delete fallback code for when StackCopyAlways is disabled.
Delete Stktop chain - there is only one stack segment now.
Delete M.moreargp, M.moreargsize, M.moreframesize, M.cret.
Delete G.writenbuf (unrelated, just dead).
Delete runtime.lessstack, runtime.oldstack.
Delete many amd64 morestack variants.
Delete initialization of morestack frame/arg sizes (shortens split prologue!).
Replace G's stackguard/stackbase/stack0/stacksize/
syscallstack/syscallguard/forkstackguard with simple stack
bounds (lo, hi).
Update liblink, runtime/cgo for adjustments to G.
LGTM=khr
R=khr, bradfitz
CC=golang-codereviews, iant, r
https://golang.org/cl/137410043
2014-09-09 13:39:57 -04:00
|
|
|
// Leave stacklo=0 and set stackhi=size; mstack will do the rest.
|
|
|
|
|
ts->g->stackhi = size;
|
2011-06-28 12:04:50 -04:00
|
|
|
err = pthread_create(&p, &attr, threadentry, ts);
|
2012-03-14 13:07:25 +09:00
|
|
|
|
2013-12-22 08:55:29 -08:00
|
|
|
pthread_sigmask(SIG_SETMASK, &oset, nil);
|
2012-03-14 13:07:25 +09:00
|
|
|
|
2011-06-28 12:04:50 -04:00
|
|
|
if (err != 0) {
|
2014-07-03 21:04:48 -04:00
|
|
|
fatalf("pthread_create failed: %s", strerror(err));
|
2011-06-28 12:04:50 -04:00
|
|
|
}
|
2010-12-08 14:10:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void*
|
|
|
|
|
threadentry(void *v)
|
|
|
|
|
{
|
|
|
|
|
ThreadStart ts;
|
|
|
|
|
|
|
|
|
|
ts = *(ThreadStart*)v;
|
|
|
|
|
free(v);
|
|
|
|
|
|
|
|
|
|
/*
|
2013-03-25 18:14:02 -04:00
|
|
|
* Set specific keys.
|
2010-12-08 14:10:00 -05:00
|
|
|
*/
|
all: remove 'extern register M *m' from runtime
The runtime has historically held two dedicated values g (current goroutine)
and m (current thread) in 'extern register' slots (TLS on x86, real registers
backed by TLS on ARM).
This CL removes the extern register m; code now uses g->m.
On ARM, this frees up the register that formerly held m (R9).
This is important for NaCl, because NaCl ARM code cannot use R9 at all.
The Go 1 macrobenchmarks (those with per-op times >= 10 µs) are unaffected:
BenchmarkBinaryTree17 5491374955 5471024381 -0.37%
BenchmarkFannkuch11 4357101311 4275174828 -1.88%
BenchmarkGobDecode 11029957 11364184 +3.03%
BenchmarkGobEncode 6852205 6784822 -0.98%
BenchmarkGzip 650795967 650152275 -0.10%
BenchmarkGunzip 140962363 141041670 +0.06%
BenchmarkHTTPClientServer 71581 73081 +2.10%
BenchmarkJSONEncode 31928079 31913356 -0.05%
BenchmarkJSONDecode 117470065 113689916 -3.22%
BenchmarkMandelbrot200 6008923 5998712 -0.17%
BenchmarkGoParse 6310917 6327487 +0.26%
BenchmarkRegexpMatchMedium_1K 114568 114763 +0.17%
BenchmarkRegexpMatchHard_1K 168977 169244 +0.16%
BenchmarkRevcomp 935294971 914060918 -2.27%
BenchmarkTemplate 145917123 148186096 +1.55%
Minux previous reported larger variations, but these were caused by
run-to-run noise, not repeatable slowdowns.
Actual code changes by Minux.
I only did the docs and the benchmarking.
LGTM=dvyukov, iant, minux
R=minux, josharian, iant, dave, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/109050043
2014-06-26 11:54:39 -04:00
|
|
|
setg_gcc((void*)ts.g);
|
2013-03-25 18:14:02 -04:00
|
|
|
|
2010-12-08 14:10:00 -05:00
|
|
|
crosscall_amd64(ts.fn);
|
|
|
|
|
return nil;
|
|
|
|
|
}
|