Commit d6ed1b70 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov Committed by Russ Cox

runtime: replace centralized ncgocall counter with a distributed one

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4809042
parent 6c46afdf
...@@ -83,7 +83,6 @@ ...@@ -83,7 +83,6 @@
// callee-save registers for gcc and returns to GoF, which returns to f. // callee-save registers for gcc and returns to GoF, which returns to f.
void *initcgo; /* filled in by dynamic linker when Cgo is available */ void *initcgo; /* filled in by dynamic linker when Cgo is available */
int64 ncgocall;
static void unlockm(void); static void unlockm(void);
static void unwindm(void); static void unwindm(void);
...@@ -101,7 +100,7 @@ runtime·cgocall(void (*fn)(void*), void *arg) ...@@ -101,7 +100,7 @@ runtime·cgocall(void (*fn)(void*), void *arg)
if(fn == 0) if(fn == 0)
runtime·throw("cgocall nil"); runtime·throw("cgocall nil");
ncgocall++; m->ncgocall++;
/* /*
* Lock g to m to ensure we stay on the same stack if we do a * Lock g to m to ensure we stay on the same stack if we do a
...@@ -155,7 +154,11 @@ unlockm(void) ...@@ -155,7 +154,11 @@ unlockm(void)
void void
runtime·Cgocalls(int64 ret) runtime·Cgocalls(int64 ret)
{ {
ret = ncgocall; M *m;
ret = 0;
for(m=runtime·atomicloadp(&runtime·allm); m; m=m->alllink)
ret += m->ncgocall;
FLUSH(&ret); FLUSH(&ret);
} }
......
...@@ -278,7 +278,9 @@ mcommoninit(M *m) ...@@ -278,7 +278,9 @@ mcommoninit(M *m)
// Add to runtime·allm so garbage collector doesn't free m // Add to runtime·allm so garbage collector doesn't free m
// when it is just in a register or thread-local storage. // when it is just in a register or thread-local storage.
m->alllink = runtime·allm; m->alllink = runtime·allm;
runtime·allm = m; // runtime·Cgocalls() iterates over allm w/o schedlock,
// so we need to publish it safely.
runtime·atomicstorep(&runtime·allm, m);
m->id = runtime·sched.mcount++; m->id = runtime·sched.mcount++;
m->fastrand = 0x49f6428aUL + m->id; m->fastrand = 0x49f6428aUL + m->id;
......
...@@ -231,6 +231,7 @@ struct M ...@@ -231,6 +231,7 @@ struct M
int32 dying; int32 dying;
int32 profilehz; int32 profilehz;
uint32 fastrand; uint32 fastrand;
uint64 ncgocall;
Note havenextg; Note havenextg;
G* nextg; G* nextg;
M* alllink; // on allm M* alllink; // on allm
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment