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

Scalable pid allocation

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