提交 604a888d 创建 作者: Frans Kaashoek's avatar Frans Kaashoek

Scalable pid allocation

上级 5a376f5f
......@@ -12,7 +12,6 @@ struct ptable ptables[NCPU];
struct runq runqs[NCPU];
static struct proc *initproc;
int nextpid = 1;
extern void forkret(void);
extern void trapret(void);
......@@ -23,6 +22,8 @@ pinit(void)
int i;
for (c = 0; c < NCPU; c++) {
ptables[c].nextpid = 1;
ptables[c].name[0] = (char) (c + '0');
safestrcpy(ptables[c].name+1, "ptable", MAXNAME-1);
initlock(&ptables[c].lock, ptables[c].name);
......@@ -48,6 +49,7 @@ allocproc(void)
{
struct proc *p;
char *sp;
int pid;
acquire(&ptable->lock);
for(p = ptable->proc; p < &ptable->proc[NPROC]; p++)
......@@ -57,8 +59,9 @@ allocproc(void)
return 0;
found:
pid = ptable->nextpid++;
p->state = EMBRYO;
p->pid = nextpid++; // XXX global var!
p->pid = (cpu->id & 0xFFFF) << 16 | (pid & 0xFFFF);
release(&ptable->lock);
// Allocate kernel stack if possible.
......
......@@ -72,8 +72,8 @@ struct cpu {
struct cpu *cpu;
struct proc *proc; // The currently-running process.
struct ptable *ptable; // The per-core proc table
struct kmem *kmem; // The per-core proc table
struct runq *runq; // The per-core proc table
struct kmem *kmem; // The per-core memory table
struct runq *runq; // The per-core runq
};
struct runq {
......@@ -87,6 +87,7 @@ struct ptable {
struct spinlock lock;
struct proc proc[NPROC];
struct proc *runq;
int nextpid;
};
struct condtab {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论