Skip to content

Commit

Permalink
runtime: run newproc1 on M stack.
Browse files Browse the repository at this point in the history
This makes newproc invisible to the GC. This is a pretty simple change since parts of newproc already depends on being run on the M stack.

LGTM=dvyukov
R=golang-codereviews, dvyukov
CC=golang-codereviews, khr
https://golang.org/cl/129520043
  • Loading branch information
DanielMorsing committed Aug 23, 2014
1 parent d216567 commit 6ed58c2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
31 changes: 28 additions & 3 deletions src/pkg/runtime/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1861,13 +1861,31 @@ runtime·malg(int32 stacksize)
return newg;
}

static void
newproc_m(void)
{
byte *argp;
void *callerpc;
FuncVal *fn;
int32 siz;
G *spawng;

siz = g->m->scalararg[0];
callerpc = (void*)g->m->scalararg[1];
argp = g->m->ptrarg[0];
fn = (FuncVal*)g->m->ptrarg[1];

runtime·newproc1(fn, argp, siz, 0, callerpc);
g->m->ptrarg[0] = nil;
g->m->ptrarg[1] = nil;
}

// Create a new g running fn with siz bytes of arguments.
// Put it on the queue of g's waiting to run.
// The compiler turns a go statement into a call to this.
// Cannot split the stack because it assumes that the arguments
// are available sequentially after &fn; they would not be
// copied if a stack split occurred. It's OK for this to call
// functions that split the stack.
// copied if a stack split occurred.
#pragma textflag NOSPLIT
void
runtime·newproc(int32 siz, FuncVal* fn, ...)
Expand All @@ -1878,7 +1896,14 @@ runtime·newproc(int32 siz, FuncVal* fn, ...)
argp = (byte*)(&fn+2); // skip caller's saved LR
else
argp = (byte*)(&fn+1);
runtime·newproc1(fn, argp, siz, 0, runtime·getcallerpc(&siz));

g->m->locks++;
g->m->scalararg[0] = siz;
g->m->scalararg[1] = (uintptr)runtime·getcallerpc(&siz);
g->m->ptrarg[0] = argp;
g->m->ptrarg[1] = fn;
runtime·onM(newproc_m);
g->m->locks--;
}

// Create a new g running fn with narg bytes of arguments starting
Expand Down
8 changes: 7 additions & 1 deletion src/pkg/runtime/race.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ uintptr
runtime·racegostart(void *pc)
{
uintptr racectx;
G *spawng;

runtime·racecall(__tsan_go_start, g->racectx, &racectx, pc);
if(g->m->curg != nil)
spawng = g->m->curg;
else
spawng = g;

runtime·racecall(__tsan_go_start, spawng->racectx, &racectx, pc);
return racectx;
}

Expand Down

0 comments on commit 6ed58c2

Please sign in to comment.