2010-10-18 10:32:55 -06:00
|
|
|
// Copyright 2010 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 "runtime.h"
|
2011-12-16 13:33:58 -07:00
|
|
|
#include "os_GOOS.h"
|
|
|
|
#include "arch_GOARCH.h"
|
2013-08-12 14:47:18 -06:00
|
|
|
#include "../../cmd/ld/textflag.h"
|
2010-10-18 10:32:55 -06:00
|
|
|
|
|
|
|
int8 *goos = "plan9";
|
2013-01-30 03:53:56 -07:00
|
|
|
extern SigTab runtime·sigtab[];
|
2012-05-04 04:48:34 -06:00
|
|
|
|
|
|
|
int32 runtime·postnote(int32, int8*);
|
2010-10-18 10:32:55 -06:00
|
|
|
|
2013-02-21 05:24:38 -07:00
|
|
|
// Called to initialize a new m (including the bootstrap m).
|
|
|
|
// Called on the parent thread (main thread in case of bootstrap), can allocate memory.
|
2010-10-18 10:32:55 -06:00
|
|
|
void
|
2013-02-21 05:24:38 -07:00
|
|
|
runtime·mpreinit(M *mp)
|
2010-10-18 10:32:55 -06:00
|
|
|
{
|
2013-01-30 03:53:56 -07:00
|
|
|
// Initialize stack and goroutine for note handling.
|
2013-02-21 05:24:38 -07:00
|
|
|
mp->gsignal = runtime·malg(32*1024);
|
2014-06-27 07:36:41 -06:00
|
|
|
mp->gsignal->m = mp;
|
2014-08-07 03:28:10 -06:00
|
|
|
mp->notesig = (int8*)runtime·mallocgc(ERRMAX*sizeof(int8), nil, 0);
|
2013-03-07 16:54:44 -07:00
|
|
|
|
|
|
|
// Initialize stack for handling strings from the
|
|
|
|
// errstr system call, as used in package syscall.
|
2014-08-07 03:28:10 -06:00
|
|
|
mp->errstr = (byte*)runtime·mallocgc(ERRMAX*sizeof(byte), nil, 0);
|
2013-02-21 05:24:38 -07:00
|
|
|
}
|
2013-01-30 03:53:56 -07:00
|
|
|
|
2013-02-21 05:24:38 -07:00
|
|
|
// Called to initialize a new m (including the bootstrap m).
|
|
|
|
// Called on the new thread, can not allocate memory.
|
|
|
|
void
|
|
|
|
runtime·minit(void)
|
|
|
|
{
|
2012-10-05 14:23:30 -06:00
|
|
|
// Mask all SSE floating-point exceptions
|
|
|
|
// when running on the 64-bit kernel.
|
|
|
|
runtime·setfpmasks();
|
2010-10-18 10:32:55 -06:00
|
|
|
}
|
|
|
|
|
2013-02-20 15:48:23 -07:00
|
|
|
// Called from dropm to undo the effect of an minit.
|
|
|
|
void
|
|
|
|
runtime·unminit(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-05 10:07:44 -06:00
|
|
|
static int32
|
|
|
|
getproccount(void)
|
|
|
|
{
|
|
|
|
int32 fd, i, n, ncpu;
|
|
|
|
byte buf[2048];
|
|
|
|
|
2013-03-12 12:03:16 -06:00
|
|
|
fd = runtime·open("/dev/sysstat", OREAD, 0);
|
2011-10-05 10:07:44 -06:00
|
|
|
if(fd < 0)
|
|
|
|
return 1;
|
|
|
|
ncpu = 0;
|
|
|
|
for(;;) {
|
|
|
|
n = runtime·read(fd, buf, sizeof buf);
|
|
|
|
if(n <= 0)
|
|
|
|
break;
|
|
|
|
for(i = 0; i < n; i++) {
|
|
|
|
if(buf[i] == '\n')
|
|
|
|
ncpu++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
runtime·close(fd);
|
|
|
|
return ncpu > 0 ? ncpu : 1;
|
|
|
|
}
|
|
|
|
|
2012-05-04 04:48:34 -06:00
|
|
|
static int32
|
|
|
|
getpid(void)
|
|
|
|
{
|
|
|
|
byte b[20], *c;
|
2012-05-16 16:09:28 -06:00
|
|
|
int32 fd;
|
2012-05-04 04:48:34 -06:00
|
|
|
|
|
|
|
runtime·memclr(b, sizeof(b));
|
2013-03-12 12:03:16 -06:00
|
|
|
fd = runtime·open("#c/pid", 0, 0);
|
2012-05-04 04:48:34 -06:00
|
|
|
if(fd >= 0) {
|
|
|
|
runtime·read(fd, b, sizeof(b));
|
|
|
|
runtime·close(fd);
|
|
|
|
}
|
|
|
|
c = b;
|
|
|
|
while(*c == ' ' || *c == '\t')
|
|
|
|
c++;
|
|
|
|
return runtime·atoi(c);
|
|
|
|
}
|
|
|
|
|
2010-10-18 10:32:55 -06:00
|
|
|
void
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·osinit(void)
|
2010-10-18 10:32:55 -06:00
|
|
|
{
|
2011-10-05 10:07:44 -06:00
|
|
|
runtime·ncpu = getproccount();
|
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 09:54:39 -06:00
|
|
|
g->m->procid = getpid();
|
2013-01-30 03:53:56 -07:00
|
|
|
runtime·notify(runtime·sigtramp);
|
2010-10-18 10:32:55 -06:00
|
|
|
}
|
|
|
|
|
2013-03-14 23:11:03 -06:00
|
|
|
void
|
|
|
|
runtime·crash(void)
|
|
|
|
{
|
|
|
|
runtime·notify(nil);
|
|
|
|
*(int32*)0 = 0;
|
|
|
|
}
|
|
|
|
|
2013-03-12 12:03:16 -06:00
|
|
|
void
|
|
|
|
runtime·get_random_data(byte **rnd, int32 *rnd_len)
|
|
|
|
{
|
2014-01-04 11:53:22 -07:00
|
|
|
static byte random_data[HashRandomBytes];
|
|
|
|
int32 fd;
|
|
|
|
|
|
|
|
fd = runtime·open("/dev/random", 0 /* O_RDONLY */, 0);
|
|
|
|
if(runtime·read(fd, random_data, HashRandomBytes) == HashRandomBytes) {
|
|
|
|
*rnd = random_data;
|
|
|
|
*rnd_len = HashRandomBytes;
|
|
|
|
} else {
|
|
|
|
*rnd = nil;
|
|
|
|
*rnd_len = 0;
|
|
|
|
}
|
|
|
|
runtime·close(fd);
|
2013-03-12 12:03:16 -06:00
|
|
|
}
|
|
|
|
|
2011-01-11 17:48:15 -07:00
|
|
|
void
|
|
|
|
runtime·goenvs(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-10-18 10:32:55 -06:00
|
|
|
void
|
os/signal: selective signal handling
Restore package os/signal, with new API:
Notify replaces Incoming, allowing clients
to ask for certain signals only. Also, signals
go to everyone who asks, not just one client.
This could plausibly move into package os now
that there are no magic side effects as a result
of the import.
Update runtime for new API: move common Unix
signal handling code into signal_unix.c.
(It's so easy to do this now that we don't have
to edit Makefiles!)
Tested on darwin,linux 386,amd64.
Fixes #1266.
R=r, dsymonds, bradfitz, iant, borman
CC=golang-dev
https://golang.org/cl/3749041
2012-02-13 11:52:37 -07:00
|
|
|
runtime·initsig(void)
|
2011-10-05 10:07:44 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-12 14:47:18 -06:00
|
|
|
#pragma textflag NOSPLIT
|
2011-10-05 10:07:44 -06:00
|
|
|
void
|
|
|
|
runtime·osyield(void)
|
2010-10-18 10:32:55 -06:00
|
|
|
{
|
2011-10-05 10:07:44 -06:00
|
|
|
runtime·sleep(0);
|
|
|
|
}
|
|
|
|
|
2013-08-12 14:47:18 -06:00
|
|
|
#pragma textflag NOSPLIT
|
2011-10-05 10:07:44 -06:00
|
|
|
void
|
|
|
|
runtime·usleep(uint32 µs)
|
|
|
|
{
|
|
|
|
uint32 ms;
|
|
|
|
|
|
|
|
ms = µs/1000;
|
|
|
|
if(ms == 0)
|
|
|
|
ms = 1;
|
|
|
|
runtime·sleep(ms);
|
2010-10-18 10:32:55 -06:00
|
|
|
}
|
|
|
|
|
liblink, runtime: preliminary support for plan9/amd64
A TLS slot is reserved by _rt0_.*_plan9 as an automatic and
its address (which is static on Plan 9) is saved in the
global _privates symbol. The startup linkage now is exactly
like that from Plan 9 libc, and the way we access g is
exactly as if we'd have used privalloc(2).
Aside from making the code more standard, this change
drastically simplifies it, both for 386 and for amd64, and
makes the Plan 9 code in liblink common for both 386 and
amd64.
The amd64 runtime code was cleared of nxm assumptions, and
now runs on the standard Plan 9 kernel.
Note handling fixes will follow in a separate CL.
LGTM=rsc
R=golang-codereviews, rsc, bradfitz, dave
CC=0intro, ality, golang-codereviews, jas, minux.ma, mischief
https://golang.org/cl/101510049
2014-07-02 05:04:10 -06:00
|
|
|
#pragma textflag NOSPLIT
|
|
|
|
int64
|
|
|
|
runtime·nanotime(void)
|
|
|
|
{
|
2014-07-09 04:33:42 -06:00
|
|
|
int64 ns, scratch;
|
|
|
|
|
|
|
|
ns = runtime·nsec(&scratch);
|
|
|
|
// TODO(aram): remove hack after I fix _nsec in the pc64 kernel.
|
|
|
|
if(ns == 0)
|
|
|
|
return scratch;
|
|
|
|
return ns;
|
liblink, runtime: preliminary support for plan9/amd64
A TLS slot is reserved by _rt0_.*_plan9 as an automatic and
its address (which is static on Plan 9) is saved in the
global _privates symbol. The startup linkage now is exactly
like that from Plan 9 libc, and the way we access g is
exactly as if we'd have used privalloc(2).
Aside from making the code more standard, this change
drastically simplifies it, both for 386 and for amd64, and
makes the Plan 9 code in liblink common for both 386 and
amd64.
The amd64 runtime code was cleared of nxm assumptions, and
now runs on the standard Plan 9 kernel.
Note handling fixes will follow in a separate CL.
LGTM=rsc
R=golang-codereviews, rsc, bradfitz, dave
CC=0intro, ality, golang-codereviews, jas, minux.ma, mischief
https://golang.org/cl/101510049
2014-07-02 05:04:10 -06:00
|
|
|
}
|
|
|
|
|
2011-12-12 14:12:22 -07:00
|
|
|
void
|
|
|
|
time·now(int64 sec, int32 nsec)
|
|
|
|
{
|
|
|
|
int64 ns;
|
|
|
|
|
|
|
|
ns = runtime·nanotime();
|
|
|
|
sec = ns / 1000000000LL;
|
|
|
|
nsec = ns - sec * 1000000000LL;
|
|
|
|
FLUSH(&sec);
|
|
|
|
FLUSH(&nsec);
|
|
|
|
}
|
|
|
|
|
2010-10-18 10:32:55 -06:00
|
|
|
void
|
2012-05-04 04:48:34 -06:00
|
|
|
runtime·itoa(int32 n, byte *p, uint32 len)
|
|
|
|
{
|
|
|
|
byte *q, c;
|
|
|
|
uint32 i;
|
|
|
|
|
|
|
|
if(len <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
runtime·memclr(p, len);
|
|
|
|
q = p;
|
|
|
|
|
|
|
|
if(n==0) {
|
|
|
|
*q++ = '0';
|
|
|
|
USED(q);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(n < 0) {
|
|
|
|
*q++ = '-';
|
|
|
|
p++;
|
|
|
|
n = -n;
|
|
|
|
}
|
|
|
|
for(i=0; n > 0 && i < len; i++) {
|
|
|
|
*q++ = '0' + (n%10);
|
|
|
|
n = n/10;
|
|
|
|
}
|
|
|
|
for(q--; q >= p; ) {
|
|
|
|
c = *p;
|
|
|
|
*p++ = *q;
|
|
|
|
*q-- = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-30 03:53:56 -07:00
|
|
|
runtime·goexitsall(int8 *status)
|
2012-05-04 04:48:34 -06:00
|
|
|
{
|
2014-03-13 10:00:12 -06:00
|
|
|
int8 buf[ERRMAX];
|
2012-12-18 09:30:29 -07:00
|
|
|
M *mp;
|
2012-05-04 04:48:34 -06:00
|
|
|
int32 pid;
|
|
|
|
|
2014-03-13 10:00:12 -06:00
|
|
|
runtime·snprintf((byte*)buf, sizeof buf, "go: exit %s", status);
|
2012-05-04 04:48:34 -06:00
|
|
|
pid = getpid();
|
2012-12-18 09:30:29 -07:00
|
|
|
for(mp=runtime·atomicloadp(&runtime·allm); mp; mp=mp->alllink)
|
|
|
|
if(mp->procid != pid)
|
2014-03-13 10:00:12 -06:00
|
|
|
runtime·postnote(mp->procid, buf);
|
2012-05-04 04:48:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
|
|
|
runtime·postnote(int32 pid, int8* msg)
|
|
|
|
{
|
2013-08-06 05:49:03 -06:00
|
|
|
int32 fd;
|
|
|
|
intgo len;
|
2011-06-10 01:23:54 -06:00
|
|
|
uint8 buf[128];
|
|
|
|
uint8 tmp[16];
|
|
|
|
uint8 *p, *q;
|
runtime: add timer support, use for package time
This looks like it is just moving some code from
time to runtime (and translating it to C), but the
runtime can do a better job managing the goroutines,
and it needs this functionality for its own maintenance
(for example, for the garbage collector to hand back
unused memory to the OS on a time delay).
Might as well have just one copy of the timer logic,
and runtime can't depend on time, so vice versa.
It also unifies Sleep, NewTicker, and NewTimer behind
one mechanism, so that there are no claims that one
is more efficient than another. (For example, today
people recommend using time.After instead of time.Sleep
to avoid blocking an OS thread.)
Fixes #1644.
Fixes #1731.
Fixes #2190.
R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov
CC=golang-dev
https://golang.org/cl/5334051
2011-11-09 13:17:05 -07:00
|
|
|
|
2011-06-10 01:23:54 -06:00
|
|
|
runtime·memclr(buf, sizeof buf);
|
|
|
|
|
2012-05-04 04:48:34 -06:00
|
|
|
/* build path string /proc/pid/note */
|
|
|
|
q = tmp;
|
2011-06-10 01:23:54 -06:00
|
|
|
p = buf;
|
2012-05-04 04:48:34 -06:00
|
|
|
runtime·itoa(pid, tmp, sizeof tmp);
|
2011-07-12 18:30:40 -06:00
|
|
|
runtime·memmove((void*)p, (void*)"/proc/", 6);
|
2012-05-04 04:48:34 -06:00
|
|
|
for(p += 6; *p++ = *q++; );
|
|
|
|
p--;
|
|
|
|
runtime·memmove((void*)p, (void*)"/note", 5);
|
runtime: add timer support, use for package time
This looks like it is just moving some code from
time to runtime (and translating it to C), but the
runtime can do a better job managing the goroutines,
and it needs this functionality for its own maintenance
(for example, for the garbage collector to hand back
unused memory to the OS on a time delay).
Might as well have just one copy of the timer logic,
and runtime can't depend on time, so vice versa.
It also unifies Sleep, NewTicker, and NewTimer behind
one mechanism, so that there are no claims that one
is more efficient than another. (For example, today
people recommend using time.After instead of time.Sleep
to avoid blocking an OS thread.)
Fixes #1644.
Fixes #1731.
Fixes #2190.
R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov
CC=golang-dev
https://golang.org/cl/5334051
2011-11-09 13:17:05 -07:00
|
|
|
|
2013-03-12 12:03:16 -06:00
|
|
|
fd = runtime·open((int8*)buf, OWRITE, 0);
|
2012-05-04 04:48:34 -06:00
|
|
|
if(fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
len = runtime·findnull((byte*)msg);
|
|
|
|
if(runtime·write(fd, msg, len) != len) {
|
|
|
|
runtime·close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
runtime·close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
runtime·exit(int32 e)
|
|
|
|
{
|
|
|
|
byte tmp[16];
|
2013-01-30 03:53:56 -07:00
|
|
|
int8 *status;
|
|
|
|
|
2012-05-04 04:48:34 -06:00
|
|
|
if(e == 0)
|
2013-01-30 03:53:56 -07:00
|
|
|
status = "";
|
2012-05-04 04:48:34 -06:00
|
|
|
else {
|
|
|
|
/* build error string */
|
|
|
|
runtime·itoa(e, tmp, sizeof tmp);
|
2013-01-30 03:53:56 -07:00
|
|
|
status = (int8*)tmp;
|
2012-05-04 04:48:34 -06:00
|
|
|
}
|
|
|
|
|
2013-01-30 03:53:56 -07:00
|
|
|
runtime·goexitsall(status);
|
|
|
|
runtime·exits(status);
|
2010-10-18 10:32:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-01 09:44:43 -07:00
|
|
|
runtime·newosproc(M *mp, void *stk)
|
2010-10-18 10:32:55 -06:00
|
|
|
{
|
2012-12-18 09:30:29 -07:00
|
|
|
mp->tls[0] = mp->id; // so 386 asm can find it
|
2010-10-18 10:32:55 -06:00
|
|
|
if(0){
|
2013-03-01 09:57:50 -07:00
|
|
|
runtime·printf("newosproc stk=%p m=%p g=%p rfork=%p id=%d/%d ostk=%p\n",
|
|
|
|
stk, mp, mp->g0, runtime·rfork, mp->id, (int32)mp->tls[0], &mp);
|
runtime: add timer support, use for package time
This looks like it is just moving some code from
time to runtime (and translating it to C), but the
runtime can do a better job managing the goroutines,
and it needs this functionality for its own maintenance
(for example, for the garbage collector to hand back
unused memory to the OS on a time delay).
Might as well have just one copy of the timer logic,
and runtime can't depend on time, so vice versa.
It also unifies Sleep, NewTicker, and NewTimer behind
one mechanism, so that there are no claims that one
is more efficient than another. (For example, today
people recommend using time.After instead of time.Sleep
to avoid blocking an OS thread.)
Fixes #1644.
Fixes #1731.
Fixes #2190.
R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov
CC=golang-dev
https://golang.org/cl/5334051
2011-11-09 13:17:05 -07:00
|
|
|
}
|
|
|
|
|
2013-03-01 09:44:43 -07:00
|
|
|
if(runtime·rfork(RFPROC|RFMEM|RFNOWAIT, stk, mp, mp->g0, runtime·mstart) < 0)
|
runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost
Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries. The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.
The symbols left alone are:
** known to cgo **
_cgo_free
_cgo_malloc
libcgo_thread_start
initcgo
ncgocall
** known to linker **
_rt0_$GOARCH
_rt0_$GOARCH_$GOOS
text
etext
data
end
pclntab
epclntab
symtab
esymtab
** known to C compiler **
_divv
_modv
_div64by32
etc (arch specific)
Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.
Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.
R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
2010-11-04 12:00:19 -06:00
|
|
|
runtime·throw("newosproc: rfork failed");
|
2010-10-18 10:32:55 -06:00
|
|
|
}
|
|
|
|
|
2011-11-02 07:42:01 -06:00
|
|
|
uintptr
|
|
|
|
runtime·semacreate(void)
|
2010-10-18 10:32:55 -06:00
|
|
|
{
|
2011-11-02 07:42:01 -06:00
|
|
|
return 1;
|
2010-10-18 10:32:55 -06:00
|
|
|
}
|
|
|
|
|
2013-08-12 14:47:18 -06:00
|
|
|
#pragma textflag NOSPLIT
|
runtime: add timer support, use for package time
This looks like it is just moving some code from
time to runtime (and translating it to C), but the
runtime can do a better job managing the goroutines,
and it needs this functionality for its own maintenance
(for example, for the garbage collector to hand back
unused memory to the OS on a time delay).
Might as well have just one copy of the timer logic,
and runtime can't depend on time, so vice versa.
It also unifies Sleep, NewTicker, and NewTimer behind
one mechanism, so that there are no claims that one
is more efficient than another. (For example, today
people recommend using time.After instead of time.Sleep
to avoid blocking an OS thread.)
Fixes #1644.
Fixes #1731.
Fixes #2190.
R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov
CC=golang-dev
https://golang.org/cl/5334051
2011-11-09 13:17:05 -07:00
|
|
|
int32
|
|
|
|
runtime·semasleep(int64 ns)
|
2010-10-18 10:32:55 -06:00
|
|
|
{
|
runtime: add timer support, use for package time
This looks like it is just moving some code from
time to runtime (and translating it to C), but the
runtime can do a better job managing the goroutines,
and it needs this functionality for its own maintenance
(for example, for the garbage collector to hand back
unused memory to the OS on a time delay).
Might as well have just one copy of the timer logic,
and runtime can't depend on time, so vice versa.
It also unifies Sleep, NewTicker, and NewTimer behind
one mechanism, so that there are no claims that one
is more efficient than another. (For example, today
people recommend using time.After instead of time.Sleep
to avoid blocking an OS thread.)
Fixes #1644.
Fixes #1731.
Fixes #2190.
R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov
CC=golang-dev
https://golang.org/cl/5334051
2011-11-09 13:17:05 -07:00
|
|
|
int32 ret;
|
|
|
|
int32 ms;
|
|
|
|
|
|
|
|
if(ns >= 0) {
|
2013-07-29 12:22:34 -06:00
|
|
|
ms = runtime·timediv(ns, 1000000, nil);
|
2014-04-09 22:36:20 -06:00
|
|
|
if(ms == 0)
|
|
|
|
ms = 1;
|
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 09:54:39 -06:00
|
|
|
ret = runtime·plan9_tsemacquire(&g->m->waitsemacount, ms);
|
runtime: add timer support, use for package time
This looks like it is just moving some code from
time to runtime (and translating it to C), but the
runtime can do a better job managing the goroutines,
and it needs this functionality for its own maintenance
(for example, for the garbage collector to hand back
unused memory to the OS on a time delay).
Might as well have just one copy of the timer logic,
and runtime can't depend on time, so vice versa.
It also unifies Sleep, NewTicker, and NewTimer behind
one mechanism, so that there are no claims that one
is more efficient than another. (For example, today
people recommend using time.After instead of time.Sleep
to avoid blocking an OS thread.)
Fixes #1644.
Fixes #1731.
Fixes #2190.
R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov
CC=golang-dev
https://golang.org/cl/5334051
2011-11-09 13:17:05 -07:00
|
|
|
if(ret == 1)
|
|
|
|
return 0; // success
|
|
|
|
return -1; // timeout or interrupted
|
|
|
|
}
|
|
|
|
|
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 09:54:39 -06:00
|
|
|
while(runtime·plan9_semacquire(&g->m->waitsemacount, 1) < 0) {
|
2012-05-16 16:09:28 -06:00
|
|
|
/* interrupted; try again (c.f. lock_sema.c) */
|
2011-11-02 07:42:01 -06:00
|
|
|
}
|
runtime: add timer support, use for package time
This looks like it is just moving some code from
time to runtime (and translating it to C), but the
runtime can do a better job managing the goroutines,
and it needs this functionality for its own maintenance
(for example, for the garbage collector to hand back
unused memory to the OS on a time delay).
Might as well have just one copy of the timer logic,
and runtime can't depend on time, so vice versa.
It also unifies Sleep, NewTicker, and NewTimer behind
one mechanism, so that there are no claims that one
is more efficient than another. (For example, today
people recommend using time.After instead of time.Sleep
to avoid blocking an OS thread.)
Fixes #1644.
Fixes #1731.
Fixes #2190.
R=golang-dev, r, hectorchu, iant, iant, jsing, alex.brainman, dvyukov
CC=golang-dev
https://golang.org/cl/5334051
2011-11-09 13:17:05 -07:00
|
|
|
return 0; // success
|
2010-10-18 10:32:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-11-02 07:42:01 -06:00
|
|
|
runtime·semawakeup(M *mp)
|
2010-10-18 10:32:55 -06:00
|
|
|
{
|
2011-11-02 07:42:01 -06:00
|
|
|
runtime·plan9_semrelease(&mp->waitsemacount, 1);
|
2010-10-18 10:32:55 -06:00
|
|
|
}
|
|
|
|
|
2014-03-13 10:00:12 -06:00
|
|
|
static int64
|
|
|
|
atolwhex(byte *p)
|
|
|
|
{
|
|
|
|
int64 n;
|
|
|
|
int32 f;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
f = 0;
|
|
|
|
while(*p == ' ' || *p == '\t')
|
|
|
|
p++;
|
|
|
|
if(*p == '-' || *p == '+') {
|
|
|
|
if(*p++ == '-')
|
|
|
|
f = 1;
|
|
|
|
while(*p == ' ' || *p == '\t')
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if(p[0] == '0' && p[1]) {
|
|
|
|
if(p[1] == 'x' || p[1] == 'X') {
|
|
|
|
p += 2;
|
|
|
|
for(;;) {
|
|
|
|
if('0' <= *p && *p <= '9')
|
|
|
|
n = n*16 + *p++ - '0';
|
|
|
|
else if('a' <= *p && *p <= 'f')
|
|
|
|
n = n*16 + *p++ - 'a' + 10;
|
|
|
|
else if('A' <= *p && *p <= 'F')
|
|
|
|
n = n*16 + *p++ - 'A' + 10;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
while('0' <= *p && *p <= '7')
|
|
|
|
n = n*8 + *p++ - '0';
|
|
|
|
} else
|
|
|
|
while('0' <= *p && *p <= '9')
|
|
|
|
n = n*10 + *p++ - '0';
|
|
|
|
if(f)
|
|
|
|
n = -n;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2011-07-25 22:52:46 -06:00
|
|
|
void
|
|
|
|
runtime·sigpanic(void)
|
|
|
|
{
|
2014-03-13 10:00:12 -06:00
|
|
|
byte *p;
|
|
|
|
|
2014-04-03 17:05:59 -06:00
|
|
|
if(!runtime·canpanic(g))
|
|
|
|
runtime·throw("unexpected signal during runtime execution");
|
|
|
|
|
2014-03-13 10:00:12 -06:00
|
|
|
switch(g->sig) {
|
|
|
|
case SIGRFAULT:
|
|
|
|
case SIGWFAULT:
|
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 09:54:39 -06:00
|
|
|
p = runtime·strstr((byte*)g->m->notesig, (byte*)"addr=")+5;
|
2014-03-13 10:00:12 -06:00
|
|
|
g->sigcode1 = atolwhex(p);
|
|
|
|
if(g->sigcode1 < 0x1000 || g->paniconfault) {
|
|
|
|
if(g->sigpc == 0)
|
|
|
|
runtime·panicstring("call of nil func value");
|
|
|
|
runtime·panicstring("invalid memory address or nil pointer dereference");
|
|
|
|
}
|
|
|
|
runtime·printf("unexpected fault address %p\n", g->sigcode1);
|
2013-01-30 03:53:56 -07:00
|
|
|
runtime·throw("fault");
|
2014-03-13 10:00:12 -06:00
|
|
|
break;
|
|
|
|
case SIGTRAP:
|
|
|
|
if(g->paniconfault)
|
|
|
|
runtime·panicstring("invalid memory address or nil pointer dereference");
|
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 09:54:39 -06:00
|
|
|
runtime·throw(g->m->notesig);
|
2014-03-13 10:00:12 -06:00
|
|
|
break;
|
|
|
|
case SIGINTDIV:
|
|
|
|
runtime·panicstring("integer divide by zero");
|
|
|
|
break;
|
|
|
|
case SIGFLOAT:
|
|
|
|
runtime·panicstring("floating point error");
|
|
|
|
break;
|
|
|
|
default:
|
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 09:54:39 -06:00
|
|
|
runtime·panicstring(g->m->notesig);
|
2014-03-13 10:00:12 -06:00
|
|
|
break;
|
|
|
|
}
|
2011-07-25 22:52:46 -06:00
|
|
|
}
|
2011-11-17 20:09:28 -07:00
|
|
|
|
|
|
|
int32
|
|
|
|
runtime·read(int32 fd, void *buf, int32 nbytes)
|
|
|
|
{
|
|
|
|
return runtime·pread(fd, buf, nbytes, -1LL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32
|
2014-05-31 02:09:48 -06:00
|
|
|
runtime·write(uintptr fd, void *buf, int32 nbytes)
|
2011-11-17 20:09:28 -07:00
|
|
|
{
|
2014-05-31 02:09:48 -06:00
|
|
|
return runtime·pwrite((int32)fd, buf, nbytes, -1LL);
|
2011-11-17 20:09:28 -07:00
|
|
|
}
|
2012-02-24 13:28:51 -07:00
|
|
|
|
|
|
|
uintptr
|
|
|
|
runtime·memlimit(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2012-02-28 14:18:24 -07:00
|
|
|
|
2013-08-29 13:36:59 -06:00
|
|
|
#pragma dataflag NOPTR
|
2012-03-12 13:55:18 -06:00
|
|
|
static int8 badsignal[] = "runtime: signal received on thread not created by Go.\n";
|
|
|
|
|
|
|
|
// This runs on a foreign stack, without an m or a g. No stack split.
|
2013-08-12 14:47:18 -06:00
|
|
|
#pragma textflag NOSPLIT
|
2012-03-12 13:55:18 -06:00
|
|
|
void
|
2013-07-11 14:39:39 -06:00
|
|
|
runtime·badsignal2(void)
|
2012-03-12 13:55:18 -06:00
|
|
|
{
|
|
|
|
runtime·pwrite(2, badsignal, sizeof badsignal - 1, -1LL);
|
2013-01-30 03:53:56 -07:00
|
|
|
runtime·exits(badsignal);
|
2012-03-12 13:55:18 -06:00
|
|
|
}
|