]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: replace centralized ncgocall counter with a distributed one
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 21 Jul 2011 15:29:08 +0000 (11:29 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 21 Jul 2011 15:29:08 +0000 (11:29 -0400)
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4809042

src/pkg/runtime/cgocall.c
src/pkg/runtime/proc.c
src/pkg/runtime/runtime.h

index 58f287e90664980cb8e7504c9bc051574065903c..829448b020f6f8759e150bc191a969f7f437afee 100644 (file)
@@ -83,7 +83,6 @@
 // callee-save registers for gcc and returns to GoF, which returns to f.
 
 void *initcgo; /* filled in by dynamic linker when Cgo is available */
-int64 ncgocall;
 
 static void unlockm(void);
 static void unwindm(void);
@@ -101,7 +100,7 @@ runtime·cgocall(void (*fn)(void*), void *arg)
        if(fn == 0)
                runtime·throw("cgocall nil");
 
-       ncgocall++;
+       m->ncgocall++;
 
        /*
         * Lock g to m to ensure we stay on the same stack if we do a
@@ -155,7 +154,11 @@ unlockm(void)
 void
 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);
 }
 
index 56c8f9bcf90f05cf23dca91aa1c95656cb5ed678..6416651ce564c3c1e8ee7fa0877d6fc28cdcfc3d 100644 (file)
@@ -278,7 +278,9 @@ mcommoninit(M *m)
        // Add to runtime·allm so garbage collector doesn't free m
        // when it is just in a register or thread-local storage.
        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->fastrand = 0x49f6428aUL + m->id;
index ef0cc00f94338a6ddeac7bf29f4563ac0ab93242..50c2b0eeca23064b698cd7aca1b84b305d8f34ae 100644 (file)
@@ -231,6 +231,7 @@ struct      M
        int32   dying;
        int32   profilehz;
        uint32  fastrand;
+       uint64  ncgocall;
        Note    havenextg;
        G*      nextg;
        M*      alllink;        // on allm