Commit e97d677b authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

runtime: introduce notetsleepg function

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
parent 9fe4a9ec
...@@ -358,9 +358,7 @@ getprofile(Profile *p) ...@@ -358,9 +358,7 @@ getprofile(Profile *p)
return ret; return ret;
// Wait for new log. // Wait for new log.
runtime·entersyscallblock(); runtime·notetsleepg(&p->wait, -1);
runtime·notesleep(&p->wait);
runtime·exitsyscall();
runtime·noteclear(&p->wait); runtime·noteclear(&p->wait);
n = p->handoff; n = p->handoff;
......
...@@ -159,3 +159,16 @@ runtime·notetsleep(Note *n, int64 ns) ...@@ -159,3 +159,16 @@ runtime·notetsleep(Note *n, int64 ns)
runtime·setprof(true); runtime·setprof(true);
return runtime·atomicload((uint32*)&n->key) != 0; 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;
}
...@@ -231,3 +231,16 @@ runtime·notetsleep(Note *n, int64 ns) ...@@ -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;
}
...@@ -460,9 +460,7 @@ runtime·MHeap_Scavenger(void) ...@@ -460,9 +460,7 @@ runtime·MHeap_Scavenger(void)
h = &runtime·mheap; h = &runtime·mheap;
for(k=0;; k++) { for(k=0;; k++) {
runtime·noteclear(&note); runtime·noteclear(&note);
runtime·entersyscallblock(); runtime·notetsleepg(&note, tick);
runtime·notetsleep(&note, tick);
runtime·exitsyscall();
runtime·lock(h); runtime·lock(h);
now = runtime·nanotime(); now = runtime·nanotime();
...@@ -474,9 +472,7 @@ runtime·MHeap_Scavenger(void) ...@@ -474,9 +472,7 @@ runtime·MHeap_Scavenger(void)
runtime·noteclear(&note); runtime·noteclear(&note);
notep = &note; notep = &note;
runtime·newproc1(&forcegchelperv, (byte*)&notep, sizeof(notep), 0, runtime·MHeap_Scavenger); runtime·newproc1(&forcegchelperv, (byte*)&notep, sizeof(notep), 0, runtime·MHeap_Scavenger);
runtime·entersyscallblock(); runtime·notetsleepg(&note, -1);
runtime·notesleep(&note);
runtime·exitsyscall();
if(runtime·debug.gctrace > 0) if(runtime·debug.gctrace > 0)
runtime·printf("scvg%d: GC forced\n", k); runtime·printf("scvg%d: GC forced\n", k);
runtime·lock(h); runtime·lock(h);
......
...@@ -905,11 +905,15 @@ void runtime·unlock(Lock*); ...@@ -905,11 +905,15 @@ void runtime·unlock(Lock*);
* wake up early, it must wait to call noteclear until it * wake up early, it must wait to call noteclear until it
* can be sure that no other goroutine is calling * can be sure that no other goroutine is calling
* notewakeup. * 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·noteclear(Note*);
void runtime·notesleep(Note*); void runtime·notesleep(Note*);
void runtime·notewakeup(Note*); void runtime·notewakeup(Note*);
bool runtime·notetsleep(Note*, int64); // false - timeout bool runtime·notetsleep(Note*, int64); // false - timeout
bool runtime·notetsleepg(Note*, int64); // false - timeout
/* /*
* low-level synchronization for implementing the above * low-level synchronization for implementing the above
......
...@@ -106,9 +106,7 @@ func signal_recv() (m uint32) { ...@@ -106,9 +106,7 @@ func signal_recv() (m uint32) {
new = HASWAITER; new = HASWAITER;
if(runtime·cas(&sig.state, old, new)) { if(runtime·cas(&sig.state, old, new)) {
if (new == HASWAITER) { if (new == HASWAITER) {
runtime·entersyscallblock(); runtime·notetsleepg(&sig, -1);
runtime·notesleep(&sig);
runtime·exitsyscall();
runtime·noteclear(&sig); runtime·noteclear(&sig);
} }
break; break;
......
...@@ -214,9 +214,7 @@ timerproc(void) ...@@ -214,9 +214,7 @@ timerproc(void)
timers.sleeping = true; timers.sleeping = true;
runtime·noteclear(&timers.waitnote); runtime·noteclear(&timers.waitnote);
runtime·unlock(&timers); runtime·unlock(&timers);
runtime·entersyscallblock(); runtime·notetsleepg(&timers.waitnote, delta);
runtime·notetsleep(&timers.waitnote, delta);
runtime·exitsyscall();
} }
} }
......
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