]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: introduce notetsleepg function
authorDmitriy Vyukov <dvyukov@google.com>
Mon, 22 Jul 2013 19:02:27 +0000 (23:02 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Mon, 22 Jul 2013 19:02:27 +0000 (23:02 +0400)
notetsleepg is the same as notetsleep, but is called on user g.
It includes entersyscall/exitsyscall and will help to avoid
split stack functions in syscall status.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/11681043

src/pkg/runtime/cpuprof.c
src/pkg/runtime/lock_futex.c
src/pkg/runtime/lock_sema.c
src/pkg/runtime/mheap.c
src/pkg/runtime/runtime.h
src/pkg/runtime/sigqueue.goc
src/pkg/runtime/time.goc

index 6793e5d361a0174b571aaa9c9f103a3d76c5f677..ef3077339a260e21e3e321d2b8c07df44e6106f8 100644 (file)
@@ -358,9 +358,7 @@ getprofile(Profile *p)
                return ret;
 
        // Wait for new log.
-       runtime·entersyscallblock();
-       runtime·notesleep(&p->wait);
-       runtime·exitsyscall();
+       runtime·notetsleepg(&p->wait, -1);
        runtime·noteclear(&p->wait);
 
        n = p->handoff;
index 95d590bae96928c4288191e20b7357ecb0e07533..2265607000d909876da605b3f88275fcc174d255 100644 (file)
@@ -159,3 +159,16 @@ runtime·notetsleep(Note *n, int64 ns)
                runtime·setprof(true);
        return runtime·atomicload((uint32*)&n->key) != 0;
 }
+
+bool
+runtime·notetsleepg(Note *n, int64 ns)
+{
+       bool res;
+
+       if(g == m->g0)
+               runtime·throw("notetsleepg on g0");
+       runtime·entersyscallblock();
+       res = runtime·notetsleep(n, ns);
+       runtime·exitsyscall();
+       return res;
+}
index 069b8c1ad3887f7005752a9d9cb144f502fd64e8..da5d24a423ccaa0daa21528a22a927d974751b62 100644 (file)
@@ -231,3 +231,16 @@ runtime·notetsleep(Note *n, int64 ns)
                }
        }
 }
+
+bool
+runtime·notetsleepg(Note *n, int64 ns)
+{
+       bool res;
+
+       if(g == m->g0)
+               runtime·throw("notetsleepg on g0");
+       runtime·entersyscallblock();
+       res = runtime·notetsleep(n, ns);
+       runtime·exitsyscall();
+       return res;
+}
index e076d89f135a06162446b4c2d119d3481c48b424..6dd5fa9bf9b63d1a42d8f745037cccc98440cd8a 100644 (file)
@@ -460,9 +460,7 @@ runtime·MHeap_Scavenger(void)
        h = &runtime·mheap;
        for(k=0;; k++) {
                runtime·noteclear(&note);
-               runtime·entersyscallblock();
-               runtime·notetsleep(&note, tick);
-               runtime·exitsyscall();
+               runtime·notetsleepg(&note, tick);
 
                runtime·lock(h);
                now = runtime·nanotime();
@@ -474,9 +472,7 @@ runtime·MHeap_Scavenger(void)
                        runtime·noteclear(&note);
                        notep = &note;
                        runtime·newproc1(&forcegchelperv, (byte*)&notep, sizeof(notep), 0, runtime·MHeap_Scavenger);
-                       runtime·entersyscallblock();
-                       runtime·notesleep(&note);
-                       runtime·exitsyscall();
+                       runtime·notetsleepg(&note, -1);
                        if(runtime·debug.gctrace > 0)
                                runtime·printf("scvg%d: GC forced\n", k);
                        runtime·lock(h);
index f8d45ba819f06864bb458a6a128de5508e897a8e..244b54848946e0af8df3ac2903775c5bb58efb32 100644 (file)
@@ -905,11 +905,15 @@ void      runtime·unlock(Lock*);
  * wake up early, it must wait to call noteclear until it
  * can be sure that no other goroutine is calling
  * notewakeup.
+ *
+ * notesleep/notetsleep are generally called on g0,
+ * notetsleepg is similar to notetsleep but is called on user g.
  */
 void   runtime·noteclear(Note*);
 void   runtime·notesleep(Note*);
 void   runtime·notewakeup(Note*);
 bool   runtime·notetsleep(Note*, int64);  // false - timeout
+bool   runtime·notetsleepg(Note*, int64);  // false - timeout
 
 /*
  * low-level synchronization for implementing the above
index 9bfab3bfae0b04cb0c780407c753e56386d913c9..e430e2103d77227b0812c10370d84d6e737f5aca 100644 (file)
@@ -106,9 +106,7 @@ func signal_recv() (m uint32) {
                                new = HASWAITER;
                        if(runtime·cas(&sig.state, old, new)) {
                                if (new == HASWAITER) {
-                                       runtime·entersyscallblock();
-                                       runtime·notesleep(&sig);
-                                       runtime·exitsyscall();
+                                       runtime·notetsleepg(&sig, -1);
                                        runtime·noteclear(&sig);
                                }
                                break;
index be0c1f83d4c6860c7c49a779fa1897f9bafc4d25..4f20300ff11225fd2fe938a18dc86499e25540ae 100644 (file)
@@ -214,9 +214,7 @@ timerproc(void)
                timers.sleeping = true;
                runtime·noteclear(&timers.waitnote);
                runtime·unlock(&timers);
-               runtime·entersyscallblock();
-               runtime·notetsleep(&timers.waitnote, delta);
-               runtime·exitsyscall();
+               runtime·notetsleepg(&timers.waitnote, delta);
        }
 }