From 6ed58c296280575cc817d614bee0b19744e1ee55 Mon Sep 17 00:00:00 2001 From: Daniel Morsing Date: Sat, 23 Aug 2014 15:42:30 +0100 Subject: [PATCH] runtime: run newproc1 on M stack. 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 --- src/pkg/runtime/proc.c | 31 ++++++++++++++++++++++++++++--- src/pkg/runtime/race.c | 8 +++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index df85042340..dbe47d2af7 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -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, ...) @@ -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 diff --git a/src/pkg/runtime/race.c b/src/pkg/runtime/race.c index fa04a39310..6a4d2803c1 100644 --- a/src/pkg/runtime/race.c +++ b/src/pkg/runtime/race.c @@ -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; } -- 2.48.1