add some annoying lock loop prints -- let's see
if they ever fire. also fix race in delaystack. it was actually happening! that just goes to show that while i can reason very well about what can and cannot happen, i have no intuition at all for how likely they are.
This commit is contained in:
parent
af89fc108d
commit
a620761c92
1 changed files with 65 additions and 8 deletions
|
|
@ -1,5 +1,19 @@
|
||||||
#include "threadimpl.h"
|
#include "threadimpl.h"
|
||||||
|
|
||||||
|
static int
|
||||||
|
timefmt(Fmt *fmt)
|
||||||
|
{
|
||||||
|
static char *mon[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||||
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
||||||
|
vlong ns;
|
||||||
|
Tm tm;
|
||||||
|
ns = nsec();
|
||||||
|
tm = *localtime(time(0));
|
||||||
|
return fmtprint(fmt, "%s %2d %02d:%02d:%02d.%03d",
|
||||||
|
mon[tm.mon], tm.mday, tm.hour, tm.min, tm.sec,
|
||||||
|
(int)(ns%1000000000)/1000000);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* spin locks
|
* spin locks
|
||||||
*/
|
*/
|
||||||
|
|
@ -17,6 +31,8 @@ int
|
||||||
_threadlock(Lock *l, int block, ulong pc)
|
_threadlock(Lock *l, int block, ulong pc)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
static int first=1;
|
||||||
|
if(first) {first=0; fmtinstall('T', timefmt);}
|
||||||
|
|
||||||
USED(pc);
|
USED(pc);
|
||||||
|
|
||||||
|
|
@ -27,17 +43,48 @@ _threadlock(Lock *l, int block, ulong pc)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* a thousand times pretty fast */
|
/* a thousand times pretty fast */
|
||||||
for(i=0; i<1000; i++){
|
for(i=0; i<10*1000; i++){
|
||||||
if(!_tas(&l->held))
|
if(!_tas(&l->held))
|
||||||
return 1;
|
return 1;
|
||||||
sched_yield();
|
sched_yield();
|
||||||
}
|
}
|
||||||
/* now nice and slow */
|
/* now nice and slow */
|
||||||
|
for(i=0; i<10; i++){
|
||||||
|
if(!_tas(&l->held))
|
||||||
|
return 1;
|
||||||
|
usleep(1);
|
||||||
|
}
|
||||||
|
fprint(2, "%T lock loop %p from %lux\n", l, pc);
|
||||||
|
for(i=0; i<10; i++){
|
||||||
|
if(!_tas(&l->held))
|
||||||
|
return 1;
|
||||||
|
usleep(10);
|
||||||
|
}
|
||||||
|
fprint(2, "%T lock loop %p from %lux\n", l, pc);
|
||||||
|
for(i=0; i<10; i++){
|
||||||
|
if(!_tas(&l->held))
|
||||||
|
return 1;
|
||||||
|
usleep(100);
|
||||||
|
}
|
||||||
|
fprint(2, "%T lock loop %p from %lux\n", l, pc);
|
||||||
|
for(i=0; i<10; i++){
|
||||||
|
if(!_tas(&l->held))
|
||||||
|
return 1;
|
||||||
|
usleep(1000);
|
||||||
|
}
|
||||||
|
fprint(2, "%T lock loop %p from %lux\n", l, pc);
|
||||||
|
for(i=0; i<10; i++){
|
||||||
|
if(!_tas(&l->held))
|
||||||
|
return 1;
|
||||||
|
usleep(10*1000);
|
||||||
|
}
|
||||||
|
fprint(2, "%T lock loop %p from %lux\n", l, pc);
|
||||||
for(i=0; i<1000; i++){
|
for(i=0; i<1000; i++){
|
||||||
if(!_tas(&l->held))
|
if(!_tas(&l->held))
|
||||||
return 1;
|
return 1;
|
||||||
usleep(100*1000);
|
usleep(100*1000);
|
||||||
}
|
}
|
||||||
|
fprint(2, "%T lock loop %p from %lux\n", l, pc);
|
||||||
/* take your time */
|
/* take your time */
|
||||||
while(_tas(&l->held))
|
while(_tas(&l->held))
|
||||||
usleep(1000*1000);
|
usleep(1000*1000);
|
||||||
|
|
@ -120,17 +167,19 @@ struct Stackfree
|
||||||
{
|
{
|
||||||
Stackfree *next;
|
Stackfree *next;
|
||||||
int pid;
|
int pid;
|
||||||
|
int pid1;
|
||||||
};
|
};
|
||||||
static Lock stacklock;
|
static Lock stacklock;
|
||||||
static Stackfree *stackfree;
|
static Stackfree *stackfree;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
delayfreestack(uchar *stk)
|
delayfreestack(uchar *stk, int pid, int pid1)
|
||||||
{
|
{
|
||||||
Stackfree *sf;
|
Stackfree *sf;
|
||||||
|
|
||||||
sf = (Stackfree*)stk;
|
sf = (Stackfree*)stk;
|
||||||
sf->pid = getpid();
|
sf->pid = pid;
|
||||||
|
sf->pid1 = pid1;
|
||||||
lock(&stacklock);
|
lock(&stacklock);
|
||||||
sf->next = stackfree;
|
sf->next = stackfree;
|
||||||
stackfree = sf;
|
stackfree = sf;
|
||||||
|
|
@ -147,7 +196,8 @@ dofreestacks(void)
|
||||||
|
|
||||||
for(last=nil,sf=stackfree; sf; last=sf,sf=next){
|
for(last=nil,sf=stackfree; sf; last=sf,sf=next){
|
||||||
next = sf->next;
|
next = sf->next;
|
||||||
if(sf->pid >= 1 && kill(sf->pid, 0) < 0 && errno == ESRCH){
|
if(sf->pid >= 1 && kill(sf->pid, 0) < 0 && errno == ESRCH)
|
||||||
|
if(sf->pid1 >= 1 && kill(sf->pid1, 0) < 0 && errno == ESRCH){
|
||||||
free(sf);
|
free(sf);
|
||||||
if(last)
|
if(last)
|
||||||
last->next = next;
|
last->next = next;
|
||||||
|
|
@ -166,17 +216,20 @@ startprocfn(void *v)
|
||||||
uchar *stk;
|
uchar *stk;
|
||||||
void (*fn)(void*);
|
void (*fn)(void*);
|
||||||
Proc *p;
|
Proc *p;
|
||||||
|
int pid0, pid1;
|
||||||
|
|
||||||
a = (void**)v;
|
a = (void**)v;
|
||||||
fn = a[0];
|
fn = a[0];
|
||||||
p = a[1];
|
p = a[1];
|
||||||
stk = a[2];
|
stk = a[2];
|
||||||
|
pid0 = (int)a[4];
|
||||||
|
pid1 = getpid();
|
||||||
free(a);
|
free(a);
|
||||||
p->osprocid = getpid();
|
p->osprocid = pid1;
|
||||||
|
|
||||||
(*fn)(p);
|
(*fn)(p);
|
||||||
|
|
||||||
delayfreestack(stk);
|
delayfreestack(stk, pid0, pid1);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -191,9 +244,12 @@ static int
|
||||||
trampnowait(void *v)
|
trampnowait(void *v)
|
||||||
{
|
{
|
||||||
void **a;
|
void **a;
|
||||||
|
int *kidpid;
|
||||||
|
|
||||||
a = (void*)v;
|
a = (void*)v;
|
||||||
*(int*)a[3] = clone(startprocfn, a[2]+65536-512, CLONE_VM|CLONE_FILES, a);
|
kidpid = a[3];
|
||||||
|
a[4] = (void*)getpid();
|
||||||
|
*kidpid = clone(startprocfn, a[2]+65536-512, CLONE_VM|CLONE_FILES, a);
|
||||||
_exit(0);
|
_exit(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +262,7 @@ _procstart(Proc *p, void (*fn)(Proc*))
|
||||||
int pid, kidpid, status;
|
int pid, kidpid, status;
|
||||||
|
|
||||||
dofreestacks();
|
dofreestacks();
|
||||||
a = malloc(4*sizeof a[0]);
|
a = malloc(5*sizeof a[0]);
|
||||||
if(a == nil)
|
if(a == nil)
|
||||||
sysfatal("_procstart malloc: %r");
|
sysfatal("_procstart malloc: %r");
|
||||||
stk = malloc(65536);
|
stk = malloc(65536);
|
||||||
|
|
@ -353,3 +409,4 @@ _threadpexit(void)
|
||||||
{
|
{
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue