aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2008-09-24 14:13:07 -0700
committerRuss Cox <rsc@golang.org>2008-09-24 14:13:07 -0700
commita61bb954977f2b8a6439943e2a580d21715ee825 (patch)
treeb7f0fbc0b5af922cb1e30d7855793758575377b3 /src/runtime
parent5f0a5e7a1335eb9e4e6b430a61a9bfb1d168df21 (diff)
downloadgo-a61bb954977f2b8a6439943e2a580d21715ee825.tar.xz
get rid of per-G Note, avoids per-G kernel semaphore on Mac.
2.14u 19.82s 22.17r 6.out 100000 # old 1.87u 0.43s 2.31r 6.out 100000 # new R=r OCL=15762 CL=15772
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/proc.c30
-rw-r--r--src/runtime/runtime.h2
2 files changed, 18 insertions, 14 deletions
diff --git a/src/runtime/proc.c b/src/runtime/proc.c
index 84f5a06ed6..4fdcd4ec29 100644
--- a/src/runtime/proc.c
+++ b/src/runtime/proc.c
@@ -285,24 +285,25 @@ gfget(void)
void
ready(G *g)
{
- // Wait for g to stop running (for example, it migh
- // have queued itself on a channel but not yet gotten
- // a chance to call sys·gosched and actually go to sleep).
- notesleep(&g->stopped);
-
lock(&sched);
readylocked(g);
unlock(&sched);
}
-// Mark g ready to run. Sched is already locked,
-// and g is known not to be running right now
-// (i.e., ready has slept on g->stopped or the g was
-// just allocated in sys·newproc).
+// Mark g ready to run. Sched is already locked.
+// G might be running already and about to stop.
+// The sched lock protects g->status from changing underfoot.
static void
readylocked(G *g)
{
M *m;
+
+ if(g->m){
+ // Running on another machine.
+ // Ready it when it stops.
+ g->readyonstop = 1;
+ return;
+ }
// Mark runnable.
if(g->status == Grunnable || g->status == Grunning)
@@ -382,7 +383,7 @@ scheduler(void)
// Just finished running m->curg.
gp = m->curg;
- gp->m = nil; // for debugger
+ gp->m = nil;
switch(gp->status){
case Grunnable:
case Gdead:
@@ -398,15 +399,18 @@ scheduler(void)
sys·exit(0);
break;
}
- notewakeup(&gp->stopped);
+ if(gp->readyonstop){
+ gp->readyonstop = 0;
+ readylocked(gp);
+ }
}
// Find (or wait for) g to run. Unlocks sched.
gp = nextgandunlock();
- noteclear(&gp->stopped);
+ gp->readyonstop = 0;
gp->status = Grunning;
m->curg = gp;
- gp->m = m; // for debugger
+ gp->m = m;
g = gp;
gogo(&gp->sched);
}
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h
index 411b6046bf..86afaaa7c2 100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -123,7 +123,7 @@ struct G
int32 goid;
int32 selgen; // valid sudog pointer
G* schedlink;
- Note stopped;
+ bool readyonstop;
M* m; // for debuggers
};
struct Mem