kernel: add pidalloc() and reuse pid once the counter wraps arround
This commit is contained in:
parent
0df8b0c63c
commit
2450b55c7b
4 changed files with 25 additions and 20 deletions
|
@ -768,7 +768,6 @@ extern char* eve;
|
||||||
extern char hostdomain[];
|
extern char hostdomain[];
|
||||||
extern uchar initcode[];
|
extern uchar initcode[];
|
||||||
extern Queue* kprintoq;
|
extern Queue* kprintoq;
|
||||||
extern Ref noteidalloc;
|
|
||||||
extern int nsyscall;
|
extern int nsyscall;
|
||||||
extern Palloc palloc;
|
extern Palloc palloc;
|
||||||
extern Queue* serialoq;
|
extern Queue* serialoq;
|
||||||
|
|
|
@ -214,6 +214,7 @@ ulong perfticks(void);
|
||||||
void pexit(char*, int);
|
void pexit(char*, int);
|
||||||
void pgrpcpy(Pgrp*, Pgrp*);
|
void pgrpcpy(Pgrp*, Pgrp*);
|
||||||
void pgrpnote(ulong, char*, long, int);
|
void pgrpnote(ulong, char*, long, int);
|
||||||
|
int pidalloc(Proc*);
|
||||||
void pio(Segment *, ulong, ulong, Page **);
|
void pio(Segment *, ulong, ulong, Page **);
|
||||||
#define poperror() up->nerrlab--
|
#define poperror() up->nerrlab--
|
||||||
void portcountpagerefs(ulong*, int);
|
void portcountpagerefs(ulong*, int);
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
int schedgain = 30; /* units in seconds */
|
int schedgain = 30; /* units in seconds */
|
||||||
int nrdy;
|
int nrdy;
|
||||||
Ref noteidalloc;
|
|
||||||
|
|
||||||
void updatecpu(Proc*);
|
void updatecpu(Proc*);
|
||||||
int reprioritize(Proc*);
|
int reprioritize(Proc*);
|
||||||
|
@ -19,8 +18,6 @@ long skipscheds;
|
||||||
long preempts;
|
long preempts;
|
||||||
ulong load;
|
ulong load;
|
||||||
|
|
||||||
static Ref pidalloc;
|
|
||||||
|
|
||||||
static struct Procalloc
|
static struct Procalloc
|
||||||
{
|
{
|
||||||
Lock;
|
Lock;
|
||||||
|
@ -56,8 +53,7 @@ char *statename[] =
|
||||||
"Waitrelease",
|
"Waitrelease",
|
||||||
};
|
};
|
||||||
|
|
||||||
static void pidhash(Proc*);
|
static void pidfree(Proc*);
|
||||||
static void pidunhash(Proc*);
|
|
||||||
static void rebalance(void);
|
static void rebalance(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -637,11 +633,7 @@ newproc(void)
|
||||||
p->nargs = 0;
|
p->nargs = 0;
|
||||||
p->setargs = 0;
|
p->setargs = 0;
|
||||||
memset(p->seg, 0, sizeof p->seg);
|
memset(p->seg, 0, sizeof p->seg);
|
||||||
p->pid = incref(&pidalloc);
|
p->noteid = pidalloc(p);
|
||||||
pidhash(p);
|
|
||||||
p->noteid = incref(¬eidalloc);
|
|
||||||
if(p->pid==0 || p->noteid==0)
|
|
||||||
panic("pidalloc");
|
|
||||||
if(p->kstack == 0)
|
if(p->kstack == 0)
|
||||||
p->kstack = smalloc(KSTACK);
|
p->kstack = smalloc(KSTACK);
|
||||||
|
|
||||||
|
@ -1182,7 +1174,7 @@ pexit(char *exitstr, int freemem)
|
||||||
qunlock(&up->seglock);
|
qunlock(&up->seglock);
|
||||||
|
|
||||||
lock(&up->exl); /* Prevent my children from leaving waits */
|
lock(&up->exl); /* Prevent my children from leaving waits */
|
||||||
pidunhash(up);
|
pidfree(up);
|
||||||
up->pid = 0;
|
up->pid = 0;
|
||||||
wakeup(&up->waitr);
|
wakeup(&up->waitr);
|
||||||
unlock(&up->exl);
|
unlock(&up->exl);
|
||||||
|
@ -1597,20 +1589,33 @@ accounttime(void)
|
||||||
m->load = (m->load*(HZ-1)+n)/HZ;
|
m->load = (m->load*(HZ-1)+n)/HZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
int
|
||||||
pidhash(Proc *p)
|
pidalloc(Proc *p)
|
||||||
{
|
{
|
||||||
int h;
|
static Ref ref;
|
||||||
|
int pid, h;
|
||||||
|
Proc *x;
|
||||||
|
|
||||||
h = p->pid % nelem(procalloc.ht);
|
|
||||||
lock(&procalloc);
|
lock(&procalloc);
|
||||||
p->pidhash = procalloc.ht[h];
|
Retry:
|
||||||
procalloc.ht[h] = p;
|
pid = incref(&ref) & 0x7FFFFFFF;
|
||||||
|
if(pid == 0)
|
||||||
|
goto Retry;
|
||||||
|
h = pid % nelem(procalloc.ht);
|
||||||
|
for(x = procalloc.ht[h]; x != nil; x = x->pidhash)
|
||||||
|
if(x->pid == pid)
|
||||||
|
goto Retry;
|
||||||
|
if(p){
|
||||||
|
p->pid = pid;
|
||||||
|
p->pidhash = procalloc.ht[h];
|
||||||
|
procalloc.ht[h] = p;
|
||||||
|
}
|
||||||
unlock(&procalloc);
|
unlock(&procalloc);
|
||||||
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pidunhash(Proc *p)
|
pidfree(Proc *p)
|
||||||
{
|
{
|
||||||
int h;
|
int h;
|
||||||
Proc **l;
|
Proc **l;
|
||||||
|
|
|
@ -78,7 +78,7 @@ sysrfork(ulong *arg)
|
||||||
closeegrp(oeg);
|
closeegrp(oeg);
|
||||||
}
|
}
|
||||||
if(flag & RFNOTEG)
|
if(flag & RFNOTEG)
|
||||||
up->noteid = incref(¬eidalloc);
|
up->noteid = pidalloc(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue