Mercurial > hg > Members > shivanidubey > xv6
changeset 11:efd378a709cd
fix priority
author | shivanidubey |
---|---|
date | Thu, 20 Jun 2019 19:08:58 +0900 |
parents | f969335e80c1 |
children | 7d90b5bc0f75 |
files | src/proc.c src/tools/mkfs.c src/usr/Makefile src/usr/usertests.c |
diffstat | 4 files changed, 32 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/proc.c Thu Jun 20 16:42:10 2019 +0900 +++ b/src/proc.c Thu Jun 20 19:08:58 2019 +0900 @@ -315,18 +315,23 @@ int get_highest_priority_proc(void) { int highest_priority; - highest_priority=ptable.proc->priority; - struct proc *p; - for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ + int pid = 0; + int hpid = -1; + int rpid = 0; + + highest_priority=100; + struct proc *p; + for(p = ptable.proc; p < &ptable.proc[NPROC]; p++, pid++){ if(p->state != RUNNABLE) { continue; - } - if (highest_priority > p->priority) - { + } + rpid = pid; + if (highest_priority > p->priority) { highest_priority=p->priority; - } + hpid = pid; + } } - return highest_priority; + return hpid > 0?hpid:rpid; } //PAGEBREAK: 42 @@ -347,14 +352,15 @@ // Loop over process table looking for process to run. acquire(&ptable.lock); - #if (0) + #if (1) int highest_priority = get_highest_priority_proc(); // Switch to chosen process. It is the process's job // to release ptable.lock and then reacquire it // before jumping back to us. - - p=&ptable.proc[highest_priority]; + if (highest_priority >= 0) { + p = &ptable.proc[highest_priority]; + proc = p; switchuvm(p); p->state = RUNNING; @@ -364,9 +370,10 @@ // Process is done running for now. // It should have changed its p->state before coming back. proc = 0; + } #else - for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){ + for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) { if(p->state != RUNNABLE) { continue; }
--- a/src/tools/mkfs.c Thu Jun 20 16:42:10 2019 +0900 +++ b/src/tools/mkfs.c Thu Jun 20 19:08:58 2019 +0900 @@ -11,7 +11,7 @@ #include "stat.h" #include "param.h" -#define static_assert(a, b) do { switch (0) case 0: case (a): ; } while (0) +// #define static_assert(a, b) do { switch (0) case 0: case (a): ; } while (0) int nblocks = 985; int nlog = LOGSIZE;
--- a/src/usr/Makefile Thu Jun 20 16:42:10 2019 +0900 +++ b/src/usr/Makefile Thu Jun 20 19:08:58 2019 +0900 @@ -24,7 +24,8 @@ _zombie\ _hello\ _forktest\ - _check\ + +# _check\ all: $(FS_IMAGE)
--- a/src/usr/usertests.c Thu Jun 20 16:42:10 2019 +0900 +++ b/src/usr/usertests.c Thu Jun 20 19:08:58 2019 +0900 @@ -1606,13 +1606,16 @@ int pid; pid = fork(); - if(pid != 0) - { - if (getpriority()==10) + if (pid != 0) { + if (getpriority()==10) { printf(1,"Okay\n"); - setpriority(5); - if (getpriority()==5) - printf(1,"Okay\n"); + } else { + printf(1,"Bad\n"); + } + setpriority(5); + if (getpriority()==5) { + printf(1,"Okay\n"); + } } return; } @@ -1628,6 +1631,7 @@ } close(open("usertests.ran", O_CREATE)); + testpriority(); bigargtest(); bigwrite(); bigargtest(); @@ -1660,7 +1664,6 @@ iref(); forktest(); bigdir(); // slow - testpriority(); exectest(); exit();