summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2019-07-02 13:55:52 -0400
committerFrans Kaashoek <[email protected]>2019-07-02 13:55:52 -0400
commit37ac6f8f4fa9a7fc1ddcacc3a97b30c400e52123 (patch)
tree50cf4c917f94375057e08d31996c1dfa483597a8 /kernel
parentda51735980e500922bc108a3444b64ac9450032e (diff)
downloadxv6-labs-37ac6f8f4fa9a7fc1ddcacc3a97b30c400e52123.tar.gz
xv6-labs-37ac6f8f4fa9a7fc1ddcacc3a97b30c400e52123.tar.bz2
xv6-labs-37ac6f8f4fa9a7fc1ddcacc3a97b30c400e52123.zip
Don't start processes at the end of the proc table
Diffstat (limited to 'kernel')
-rw-r--r--kernel/proc.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/kernel/proc.c b/kernel/proc.c
index b5d929d..71d4146 100644
--- a/kernel/proc.c
+++ b/kernel/proc.c
@@ -372,12 +372,14 @@ wait(void)
}
// Loop over process table looking for process to run.
-struct proc *find_runnable() {
+struct proc *find_runnable(int start) {
struct proc *p;
acquire(&ptable.lock);
- for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) {
+ for(int i = start; i < start+NPROC; i++) {
+ p = &ptable.proc[i % NPROC];
acquire(&p->lock);
if(p->state == RUNNABLE) {
+ p->state = RUNNING;
release(&ptable.lock);
return p;
}
@@ -400,19 +402,19 @@ scheduler(void)
{
struct proc *p;
struct cpu *c = mycpu();
-
+ int next;
+
c->proc = 0;
for(;;){
// Enable interrupts on this processor.
intr_on();
- if((p = find_runnable()) != 0){
+ if((p = find_runnable(next)) != 0) {
+ next = (next + 1) & NPROC;
// Switch to chosen process. It is the process's job
// to release its lock and then reacquire it
// before jumping back to us.
c->proc = p;
- p->state = RUNNING;
-
swtch(&c->scheduler, &p->context);
// Process is done running for now.