mirror of
https://github.com/golang/go
synced 2024-11-22 00:04:41 -07:00
runtime: add comments for various functions in proc.c
R=rsc CC=golang-dev https://golang.org/cl/5357047
This commit is contained in:
parent
8649444002
commit
4ac425fcdd
@ -739,8 +739,6 @@ struct CgoThreadStart
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Kick off new m's as needed (up to mcpumax).
|
// Kick off new m's as needed (up to mcpumax).
|
||||||
// There are already `other' other cpus that will
|
|
||||||
// start looking for goroutines shortly.
|
|
||||||
// Sched is locked.
|
// Sched is locked.
|
||||||
static void
|
static void
|
||||||
matchmg(void)
|
matchmg(void)
|
||||||
@ -763,6 +761,7 @@ matchmg(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new m. It will start off with a call to runtime·mstart.
|
||||||
static M*
|
static M*
|
||||||
startm(void)
|
startm(void)
|
||||||
{
|
{
|
||||||
@ -995,6 +994,9 @@ runtime·exitsyscall(void)
|
|||||||
g->gcstack = nil;
|
g->gcstack = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called from runtime·lessstack when returning from a function which
|
||||||
|
// allocated a new stack segment. The function's return value is in
|
||||||
|
// m->cret.
|
||||||
void
|
void
|
||||||
runtime·oldstack(void)
|
runtime·oldstack(void)
|
||||||
{
|
{
|
||||||
@ -1026,6 +1028,11 @@ runtime·oldstack(void)
|
|||||||
runtime·gogo(&old.gobuf, m->cret);
|
runtime·gogo(&old.gobuf, m->cret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called from reflect·call or from runtime·morestack when a new
|
||||||
|
// stack segment is needed. Allocate a new stack big enough for
|
||||||
|
// m->moreframesize bytes, copy m->moreargsize bytes to the new frame,
|
||||||
|
// and then act as though runtime·lessstack called the function at
|
||||||
|
// m->morepc.
|
||||||
void
|
void
|
||||||
runtime·newstack(void)
|
runtime·newstack(void)
|
||||||
{
|
{
|
||||||
@ -1113,6 +1120,10 @@ runtime·newstack(void)
|
|||||||
*(int32*)345 = 123; // never return
|
*(int32*)345 = 123; // never return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hook used by runtime·malg to call runtime·stackalloc on the
|
||||||
|
// scheduler stack. This exists because runtime·stackalloc insists
|
||||||
|
// on being called on the scheduler stack, to avoid trying to grow
|
||||||
|
// the stack while allocating a new stack segment.
|
||||||
static void
|
static void
|
||||||
mstackalloc(G *gp)
|
mstackalloc(G *gp)
|
||||||
{
|
{
|
||||||
@ -1120,6 +1131,7 @@ mstackalloc(G *gp)
|
|||||||
runtime·gogo(&gp->sched, 0);
|
runtime·gogo(&gp->sched, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allocate a new g, with a stack big enough for stacksize bytes.
|
||||||
G*
|
G*
|
||||||
runtime·malg(int32 stacksize)
|
runtime·malg(int32 stacksize)
|
||||||
{
|
{
|
||||||
@ -1146,15 +1158,13 @@ runtime·malg(int32 stacksize)
|
|||||||
return newg;
|
return newg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Create a new g running fn with siz bytes of arguments.
|
||||||
* Newproc and deferproc need to be textflag 7
|
// Put it on the queue of g's waiting to run.
|
||||||
* (no possible stack split when nearing overflow)
|
// The compiler turns a go statement into a call to this.
|
||||||
* because they assume that the arguments to fn
|
// Cannot split the stack because it assumes that the arguments
|
||||||
* are available sequentially beginning at &arg0.
|
// are available sequentially after &fn; they would not be
|
||||||
* If a stack split happened, only the one word
|
// copied if a stack split occurred. It's OK for this to call
|
||||||
* arg0 would be copied. It's okay if any functions
|
// functions that split the stack.
|
||||||
* they call split the stack below the newproc frame.
|
|
||||||
*/
|
|
||||||
#pragma textflag 7
|
#pragma textflag 7
|
||||||
void
|
void
|
||||||
runtime·newproc(int32 siz, byte* fn, ...)
|
runtime·newproc(int32 siz, byte* fn, ...)
|
||||||
@ -1168,6 +1178,10 @@ runtime·newproc(int32 siz, byte* fn, ...)
|
|||||||
runtime·newproc1(fn, argp, siz, 0, runtime·getcallerpc(&siz));
|
runtime·newproc1(fn, argp, siz, 0, runtime·getcallerpc(&siz));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new g running fn with narg bytes of arguments starting
|
||||||
|
// at argp and returning nret bytes of results. callerpc is the
|
||||||
|
// address of the go statement that created this. The new g is put
|
||||||
|
// on the queue of g's waiting to run.
|
||||||
G*
|
G*
|
||||||
runtime·newproc1(byte *fn, byte *argp, int32 narg, int32 nret, void *callerpc)
|
runtime·newproc1(byte *fn, byte *argp, int32 narg, int32 nret, void *callerpc)
|
||||||
{
|
{
|
||||||
@ -1228,6 +1242,12 @@ runtime·newproc1(byte *fn, byte *argp, int32 narg, int32 nret, void *callerpc)
|
|||||||
//printf(" goid=%d\n", newg->goid);
|
//printf(" goid=%d\n", newg->goid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new deferred function fn with siz bytes of arguments.
|
||||||
|
// The compiler turns a defer 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.
|
||||||
#pragma textflag 7
|
#pragma textflag 7
|
||||||
uintptr
|
uintptr
|
||||||
runtime·deferproc(int32 siz, byte* fn, ...)
|
runtime·deferproc(int32 siz, byte* fn, ...)
|
||||||
@ -1256,6 +1276,16 @@ runtime·deferproc(int32 siz, byte* fn, ...)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run a deferred function if there is one.
|
||||||
|
// The compiler inserts a call to this at the end of any
|
||||||
|
// function which calls defer.
|
||||||
|
// If there is a deferred function, this will call runtime·jmpdefer,
|
||||||
|
// which will jump to the deferred function such that it appears
|
||||||
|
// to have been called by the caller of deferreturn at the point
|
||||||
|
// just before deferreturn was called. The effect is that deferreturn
|
||||||
|
// is called again and again until there are no more deferred functions.
|
||||||
|
// Cannot split the stack because we reuse the caller's frame to
|
||||||
|
// call the deferred function.
|
||||||
#pragma textflag 7
|
#pragma textflag 7
|
||||||
void
|
void
|
||||||
runtime·deferreturn(uintptr arg0)
|
runtime·deferreturn(uintptr arg0)
|
||||||
@ -1277,6 +1307,7 @@ runtime·deferreturn(uintptr arg0)
|
|||||||
runtime·jmpdefer(fn, argp);
|
runtime·jmpdefer(fn, argp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run all deferred functions for the current goroutine.
|
||||||
static void
|
static void
|
||||||
rundefer(void)
|
rundefer(void)
|
||||||
{
|
{
|
||||||
@ -1318,6 +1349,7 @@ unwindstack(G *gp, byte *sp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print all currently active panics. Used when crashing.
|
||||||
static void
|
static void
|
||||||
printpanics(Panic *p)
|
printpanics(Panic *p)
|
||||||
{
|
{
|
||||||
@ -1334,6 +1366,7 @@ printpanics(Panic *p)
|
|||||||
|
|
||||||
static void recovery(G*);
|
static void recovery(G*);
|
||||||
|
|
||||||
|
// The implementation of the predeclared function panic.
|
||||||
void
|
void
|
||||||
runtime·panic(Eface e)
|
runtime·panic(Eface e)
|
||||||
{
|
{
|
||||||
@ -1376,6 +1409,9 @@ runtime·panic(Eface e)
|
|||||||
runtime·dopanic(0);
|
runtime·dopanic(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unwind the stack after a deferred function calls recover
|
||||||
|
// after a panic. Then arrange to continue running as though
|
||||||
|
// the caller of the deferred function returned normally.
|
||||||
static void
|
static void
|
||||||
recovery(G *gp)
|
recovery(G *gp)
|
||||||
{
|
{
|
||||||
@ -1407,7 +1443,10 @@ recovery(G *gp)
|
|||||||
runtime·gogo(&gp->sched, 1);
|
runtime·gogo(&gp->sched, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma textflag 7 /* no split, or else g->stackguard is not the stack for fp */
|
// The implementation of the predeclared function recover.
|
||||||
|
// Cannot split the stack because it needs to reliably
|
||||||
|
// find the stack segment of its caller.
|
||||||
|
#pragma textflag 7
|
||||||
void
|
void
|
||||||
runtime·recover(byte *argp, Eface ret)
|
runtime·recover(byte *argp, Eface ret)
|
||||||
{
|
{
|
||||||
@ -1519,6 +1558,7 @@ runtime·Gosched(void)
|
|||||||
runtime·gosched();
|
runtime·gosched();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementation of runtime.GOMAXPROCS.
|
||||||
// delete when scheduler is stronger
|
// delete when scheduler is stronger
|
||||||
int32
|
int32
|
||||||
runtime·gomaxprocsfunc(int32 n)
|
runtime·gomaxprocsfunc(int32 n)
|
||||||
@ -1634,6 +1674,7 @@ static struct {
|
|||||||
uintptr pcbuf[100];
|
uintptr pcbuf[100];
|
||||||
} prof;
|
} prof;
|
||||||
|
|
||||||
|
// Called if we receive a SIGPROF signal.
|
||||||
void
|
void
|
||||||
runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp)
|
runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp)
|
||||||
{
|
{
|
||||||
@ -1653,6 +1694,7 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp)
|
|||||||
runtime·unlock(&prof);
|
runtime·unlock(&prof);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Arrange to call fn with a traceback hz times a second.
|
||||||
void
|
void
|
||||||
runtime·setcpuprofilerate(void (*fn)(uintptr*, int32), int32 hz)
|
runtime·setcpuprofilerate(void (*fn)(uintptr*, int32), int32 hz)
|
||||||
{
|
{
|
||||||
@ -1683,6 +1725,8 @@ runtime·setcpuprofilerate(void (*fn)(uintptr*, int32), int32 hz)
|
|||||||
|
|
||||||
void (*libcgo_setenv)(byte**);
|
void (*libcgo_setenv)(byte**);
|
||||||
|
|
||||||
|
// Update the C environment if cgo is loaded.
|
||||||
|
// Called from os.Setenv.
|
||||||
void
|
void
|
||||||
os·setenv_c(String k, String v)
|
os·setenv_c(String k, String v)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user