From ad0e0b5f8b4e3c01e6d8146b089d940faef3c244 Mon Sep 17 00:00:00 2001
From: Amir Hosein Kashani <amkkashani@gmail.com>
Date: Wed, 18 Dec 2019 03:41:58 -0800
Subject: [PATCH] add struct for timing

---
 getCountTest.c |  6 +++++-
 proc.c         |  8 ++++++++
 proc.h         | 10 ++++++++++
 syscall.c      |  4 +++-
 syscall.h      |  1 +
 sysproc.c      | 14 +++++++++++++-
 trap.c         |  2 +-
 user.h         |  1 +
 usys.S         |  1 +
 9 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/getCountTest.c b/getCountTest.c
index effa27b..ce81f54 100644
--- a/getCountTest.c
+++ b/getCountTest.c
@@ -10,5 +10,9 @@ main(int argc,char **argv)
   getChildren(a);	
   int result = getCount(22);
   printf(1,"--- %d ---",result);
-  exit();
+  //this code for test of 3.3
+  /*
+  changePolicy(1);
+  changePolicy(2);
+  exit();*/
 }
\ No newline at end of file
diff --git a/proc.c b/proc.c
index 139623d..662b9fb 100644
--- a/proc.c
+++ b/proc.c
@@ -111,6 +111,14 @@ found:
   p->context = (struct context*)sp;
   memset(p->context, 0, sizeof *p->context);
   p->context->eip = (uint)forkret;
+  
+
+  //kashaia
+  p->timeHandeler.creationTime = ticks;
+  p ->timeHandeler.runningTime =0;
+  p->timeHandeler.sleepingTime = 0 ;
+  p->timeHandeler.readyTime = 0;
+  
 
   return p;
 }
diff --git a/proc.h b/proc.h
index b873746..91e8b90 100644
--- a/proc.h
+++ b/proc.h
@@ -34,10 +34,20 @@ struct context {
   uint eip;
 };
 
+struct timeVariables{//this struct for 3.4
+  int creationTime;
+  int terminationTime; 
+  int sleepingTime; 
+  int readyTime; 
+  int runningTime;
+  }; 
+
+
 enum procstate { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
 
 // Per-process state
 struct proc {
+  struct timeVariables timeHandeler;
   int usagepointer;
   int usage[100];
   int priority;
diff --git a/syscall.c b/syscall.c
index 86bce39..9939139 100644
--- a/syscall.c
+++ b/syscall.c
@@ -106,6 +106,7 @@ extern int sys_uptime(void);
 extern int sys_getChildren(void);
 extern int sys_getCount(void);
 extern int sys_changePriority(void);
+extern int sys_changePolicy(void);
 
 static int (*syscalls[])(void) = {
 [SYS_fork]    sys_fork,
@@ -131,7 +132,8 @@ static int (*syscalls[])(void) = {
 [SYS_close]   sys_close,
 [SYS_getChildren]   sys_getChildren,
 [SYS_getCount]  sys_getCount,
-[SYS_changePriority]  sys_changePriority  
+[SYS_changePriority]  sys_changePriority,
+[SYS_changePolicy]  sys_changePolicy,
 };
 
 void
diff --git a/syscall.h b/syscall.h
index d2b05c0..d27631e 100644
--- a/syscall.h
+++ b/syscall.h
@@ -23,3 +23,4 @@
 #define SYS_getChildren  22
 #define SYS_getCount  23
 #define SYS_changePriority  24
+#define SYS_changePolicy 25
diff --git a/sysproc.c b/sysproc.c
index 8691996..26c7633 100644
--- a/sysproc.c
+++ b/sysproc.c
@@ -8,7 +8,7 @@
 #include "proc.h"
 
 int table[1200][256] ={0};
-
+extern int cpuMode;
 int
 sys_getpid(void)
 {
@@ -152,6 +152,18 @@ sys_changePriority(int newPriority){
   return 5;
 }
 
+//3.3
+int
+sys_changePolicy(int mode){
+  argint(0,&mode);
+  if(mode>2 || mode<0){
+    return -1;
+  }
+  cprintf("%d",cpuMode);
+  cpuMode = mode;
+  return 1;
+}
+
 
 
 
diff --git a/trap.c b/trap.c
index 2a10e6e..3ae7926 100644
--- a/trap.c
+++ b/trap.c
@@ -37,6 +37,7 @@ idtinit(void)
 void
 trap(struct trapframe *tf)
 {
+  
   if(tf->trapno == T_SYSCALL){
     if(myproc()->killed)
       exit();
@@ -46,7 +47,6 @@ trap(struct trapframe *tf)
       exit();
     return;
   }
-
   switch(tf->trapno){
   case T_IRQ0 + IRQ_TIMER:
     if(cpuid() == 0){
diff --git a/user.h b/user.h
index c97cb96..ff63755 100644
--- a/user.h
+++ b/user.h
@@ -26,6 +26,7 @@ int uptime(void);
 int getChildren(int);
 int getCount(int);
 int changePriority(int);
+int changePolicy(int);
 
 // ulib.c
 int stat(const char*, struct stat*);
diff --git a/usys.S b/usys.S
index 189f8f8..17d5c60 100644
--- a/usys.S
+++ b/usys.S
@@ -32,3 +32,4 @@ SYSCALL(uptime)
 SYSCALL(getChildren)
 SYSCALL(getCount)
 SYSCALL(changePriority)
+SYSCALL(changePolicy)
\ No newline at end of file
-- 
2.18.1