Commit a61bb954 authored by Russ Cox's avatar Russ Cox

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
parent 5f0a5e7a
...@@ -285,24 +285,25 @@ gfget(void) ...@@ -285,24 +285,25 @@ gfget(void)
void void
ready(G *g) 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); lock(&sched);
readylocked(g); readylocked(g);
unlock(&sched); unlock(&sched);
} }
// Mark g ready to run. Sched is already locked, // Mark g ready to run. Sched is already locked.
// and g is known not to be running right now // G might be running already and about to stop.
// (i.e., ready has slept on g->stopped or the g was // The sched lock protects g->status from changing underfoot.
// just allocated in sys·newproc).
static void static void
readylocked(G *g) readylocked(G *g)
{ {
M *m; M *m;
if(g->m){
// Running on another machine.
// Ready it when it stops.
g->readyonstop = 1;
return;
}
// Mark runnable. // Mark runnable.
if(g->status == Grunnable || g->status == Grunning) if(g->status == Grunnable || g->status == Grunning)
...@@ -382,7 +383,7 @@ scheduler(void) ...@@ -382,7 +383,7 @@ scheduler(void)
// Just finished running m->curg. // Just finished running m->curg.
gp = m->curg; gp = m->curg;
gp->m = nil; // for debugger gp->m = nil;
switch(gp->status){ switch(gp->status){
case Grunnable: case Grunnable:
case Gdead: case Gdead:
...@@ -398,15 +399,18 @@ scheduler(void) ...@@ -398,15 +399,18 @@ scheduler(void)
sys·exit(0); sys·exit(0);
break; break;
} }
notewakeup(&gp->stopped); if(gp->readyonstop){
gp->readyonstop = 0;
readylocked(gp);
}
} }
// Find (or wait for) g to run. Unlocks sched. // Find (or wait for) g to run. Unlocks sched.
gp = nextgandunlock(); gp = nextgandunlock();
noteclear(&gp->stopped); gp->readyonstop = 0;
gp->status = Grunning; gp->status = Grunning;
m->curg = gp; m->curg = gp;
gp->m = m; // for debugger gp->m = m;
g = gp; g = gp;
gogo(&gp->sched); gogo(&gp->sched);
} }
......
...@@ -123,7 +123,7 @@ struct G ...@@ -123,7 +123,7 @@ struct G
int32 goid; int32 goid;
int32 selgen; // valid sudog pointer int32 selgen; // valid sudog pointer
G* schedlink; G* schedlink;
Note stopped; bool readyonstop;
M* m; // for debuggers M* m; // for debuggers
}; };
struct Mem struct Mem
......
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