changeset 10:f969335e80c1

Scheduling
author shivanidubey
date Thu, 20 Jun 2019 16:42:10 +0900
parents 3819f339c48a
children efd378a709cd
files src/proc.c src/usr/usertests.c
diffstat 2 files changed, 40 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/proc.c	Thu Jun 20 14:48:46 2019 +0900
+++ b/src/proc.c	Thu Jun 20 16:42:10 2019 +0900
@@ -340,20 +340,20 @@
 
 void scheduler(void)
 {
-
+    struct proc *p;
     for(;;){
         // Enable interrupts on this processor.
         sti();
 
         // Loop over process table looking for process to run.
         acquire(&ptable.lock);
-     
+    #if (0)      
         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.
-	struct proc *p; 
+	 
           p=&ptable.proc[highest_priority];
             switchuvm(p);
          
@@ -364,7 +364,27 @@
             // 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++){
+	      if(p->state != RUNNABLE) {
+                continue;
+	      }
 
+	      // Switch to chosen process.  It is the process's job
+	      // to release ptable.lock and then reacquire it
+	      // before jumping back to us.
+	      proc = p;
+	      switchuvm(p);
+
+	      p->state = RUNNING;
+
+	      swtch(&cpu->scheduler, proc->context);
+	      // Process is done running for now.
+	      // It should have changed its p->state before coming back.
+	      proc = 0;
+	    }	    
+        #endif 
         release(&ptable.lock);
     }
 }
--- a/src/usr/usertests.c	Thu Jun 20 14:48:46 2019 +0900
+++ b/src/usr/usertests.c	Thu Jun 20 16:42:10 2019 +0900
@@ -1600,6 +1600,22 @@
     randstate = randstate * 1664525 + 1013904223;
     return randstate;
 }
+//Priority Test
+void testpriority ()
+{
+  int pid;
+
+  pid = fork();
+  if(pid != 0)
+  {
+    if (getpriority()==10)
+      printf(1,"Okay\n"); 
+   setpriority(5);  
+   if (getpriority()==5) 
+     printf(1,"Okay\n");      
+  }
+  return;
+}
 
 int
 main(int argc, char *argv[])
@@ -1644,7 +1660,7 @@
     iref();
     forktest();
     bigdir(); // slow
-    
+    testpriority();
     exectest();
     
     exit();