1
0
mirror of https://github.com/golang/go synced 2024-10-04 12:21:26 -06:00
go/src/pkg/runtime/os_plan9_386.c
Russ Cox 89f185fe8a 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

151 lines
3.5 KiB
C

// 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"
#include "defs_GOOS_GOARCH.h"
#include "os_GOOS.h"
#include "signals_GOOS.h"
void
runtime·dumpregs(Ureg *u)
{
runtime·printf("ax %x\n", u->ax);
runtime·printf("bx %x\n", u->bx);
runtime·printf("cx %x\n", u->cx);
runtime·printf("dx %x\n", u->dx);
runtime·printf("di %x\n", u->di);
runtime·printf("si %x\n", u->si);
runtime·printf("bp %x\n", u->bp);
runtime·printf("sp %x\n", u->sp);
runtime·printf("pc %x\n", u->pc);
runtime·printf("flags %x\n", u->flags);
runtime·printf("cs %x\n", u->cs);
runtime·printf("fs %x\n", u->fs);
runtime·printf("gs %x\n", u->gs);
}
int32
runtime·sighandler(void *v, int8 *note, G *gp)
{
uintptr *sp;
SigTab *t;
bool crash;
Ureg *ureg;
intgo len, n;
int32 sig, flags;
ureg = (Ureg*)v;
// The kernel will never pass us a nil note or ureg so we probably
// made a mistake somewhere in runtime·sigtramp.
if(ureg == nil || note == nil) {
runtime·printf("sighandler: ureg %p note %p\n", ureg, note);
goto Throw;
}
// Check that the note is no more than ERRMAX bytes (including
// the trailing NUL). We should never receive a longer note.
len = runtime·findnull((byte*)note);
if(len > ERRMAX-1) {
runtime·printf("sighandler: note is longer than ERRMAX\n");
goto Throw;
}
// See if the note matches one of the patterns in runtime·sigtab.
// Notes that do not match any pattern can be handled at a higher
// level by the program but will otherwise be ignored.
flags = SigNotify;
for(sig = 0; sig < nelem(runtime·sigtab); sig++) {
t = &runtime·sigtab[sig];
n = runtime·findnull((byte*)t->name);
if(len < n)
continue;
if(runtime·strncmp((byte*)note, (byte*)t->name, n) == 0) {
flags = t->flags;
break;
}
}
if(flags & SigGoExit)
runtime·exits(note+9); // Strip "go: exit " prefix.
if(flags & SigPanic) {
// Copy the error string from sigtramp's stack into m->notesig so
// we can reliably access it from the panic routines.
runtime·memmove(g->m->notesig, note, len+1);
gp->sig = sig;
gp->sigpc = ureg->pc;
// Only push runtime·sigpanic if PC != 0.
//
// If PC == 0, probably panicked because of a call to a nil func.
// Not pushing that onto SP will make the trace look like a call
// to runtime·sigpanic instead. (Otherwise the trace will end at
// runtime·sigpanic and we won't get to see who faulted).
if(ureg->pc != 0) {
sp = (uintptr*)ureg->sp;
*--sp = ureg->pc;
ureg->sp = (uint32)sp;
}
ureg->pc = (uintptr)runtime·sigpanic;
return NCONT;
}
if(flags & SigNotify) {
// TODO(ality): See if os/signal wants it.
//if(runtime·sigsend(...))
// return NCONT;
}
if(flags & SigKill)
goto Exit;
if(!(flags & SigThrow))
return NCONT;
Throw:
g->m->throwing = 1;
g->m->caughtsig = gp;
runtime·startpanic();
runtime·printf("%s\n", note);
runtime·printf("PC=%x\n", ureg->pc);
runtime·printf("\n");
if(runtime·gotraceback(&crash)) {
runtime·goroutineheader(gp);
runtime·traceback(ureg->pc, ureg->sp, 0, gp);
runtime·tracebackothers(gp);
runtime·printf("\n");
runtime·dumpregs(ureg);
}
if(crash)
runtime·crash();
Exit:
runtime·goexitsall(note);
runtime·exits(note);
return NDFLT; // not reached
}
void
runtime·sigenable(uint32 sig)
{
USED(sig);
}
void
runtime·sigdisable(uint32 sig)
{
USED(sig);
}
void
runtime·resetcpuprofiler(int32 hz)
{
// TODO: Enable profiling interrupts.
g->m->profilehz = hz;
}