Commit ad0e0b5f authored by Amir Hosein Kashani's avatar Amir Hosein Kashani

add struct for timing

parent c9a111a5
...@@ -10,5 +10,9 @@ main(int argc,char **argv) ...@@ -10,5 +10,9 @@ main(int argc,char **argv)
getChildren(a); getChildren(a);
int result = getCount(22); int result = getCount(22);
printf(1,"--- %d ---",result); printf(1,"--- %d ---",result);
exit(); //this code for test of 3.3
/*
changePolicy(1);
changePolicy(2);
exit();*/
} }
\ No newline at end of file
...@@ -111,6 +111,14 @@ found: ...@@ -111,6 +111,14 @@ found:
p->context = (struct context*)sp; p->context = (struct context*)sp;
memset(p->context, 0, sizeof *p->context); memset(p->context, 0, sizeof *p->context);
p->context->eip = (uint)forkret; p->context->eip = (uint)forkret;
//kashaia
p->timeHandeler.creationTime = ticks;
p ->timeHandeler.runningTime =0;
p->timeHandeler.sleepingTime = 0 ;
p->timeHandeler.readyTime = 0;
return p; return p;
} }
......
...@@ -34,10 +34,20 @@ struct context { ...@@ -34,10 +34,20 @@ struct context {
uint eip; 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 }; enum procstate { UNUSED, EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
// Per-process state // Per-process state
struct proc { struct proc {
struct timeVariables timeHandeler;
int usagepointer; int usagepointer;
int usage[100]; int usage[100];
int priority; int priority;
......
...@@ -106,6 +106,7 @@ extern int sys_uptime(void); ...@@ -106,6 +106,7 @@ extern int sys_uptime(void);
extern int sys_getChildren(void); extern int sys_getChildren(void);
extern int sys_getCount(void); extern int sys_getCount(void);
extern int sys_changePriority(void); extern int sys_changePriority(void);
extern int sys_changePolicy(void);
static int (*syscalls[])(void) = { static int (*syscalls[])(void) = {
[SYS_fork] sys_fork, [SYS_fork] sys_fork,
...@@ -131,7 +132,8 @@ static int (*syscalls[])(void) = { ...@@ -131,7 +132,8 @@ static int (*syscalls[])(void) = {
[SYS_close] sys_close, [SYS_close] sys_close,
[SYS_getChildren] sys_getChildren, [SYS_getChildren] sys_getChildren,
[SYS_getCount] sys_getCount, [SYS_getCount] sys_getCount,
[SYS_changePriority] sys_changePriority [SYS_changePriority] sys_changePriority,
[SYS_changePolicy] sys_changePolicy,
}; };
void void
......
...@@ -23,3 +23,4 @@ ...@@ -23,3 +23,4 @@
#define SYS_getChildren 22 #define SYS_getChildren 22
#define SYS_getCount 23 #define SYS_getCount 23
#define SYS_changePriority 24 #define SYS_changePriority 24
#define SYS_changePolicy 25
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "proc.h" #include "proc.h"
int table[1200][256] ={0}; int table[1200][256] ={0};
extern int cpuMode;
int int
sys_getpid(void) sys_getpid(void)
{ {
...@@ -152,6 +152,18 @@ sys_changePriority(int newPriority){ ...@@ -152,6 +152,18 @@ sys_changePriority(int newPriority){
return 5; 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;
}
......
...@@ -37,6 +37,7 @@ idtinit(void) ...@@ -37,6 +37,7 @@ idtinit(void)
void void
trap(struct trapframe *tf) trap(struct trapframe *tf)
{ {
if(tf->trapno == T_SYSCALL){ if(tf->trapno == T_SYSCALL){
if(myproc()->killed) if(myproc()->killed)
exit(); exit();
...@@ -46,7 +47,6 @@ trap(struct trapframe *tf) ...@@ -46,7 +47,6 @@ trap(struct trapframe *tf)
exit(); exit();
return; return;
} }
switch(tf->trapno){ switch(tf->trapno){
case T_IRQ0 + IRQ_TIMER: case T_IRQ0 + IRQ_TIMER:
if(cpuid() == 0){ if(cpuid() == 0){
......
...@@ -26,6 +26,7 @@ int uptime(void); ...@@ -26,6 +26,7 @@ int uptime(void);
int getChildren(int); int getChildren(int);
int getCount(int); int getCount(int);
int changePriority(int); int changePriority(int);
int changePolicy(int);
// ulib.c // ulib.c
int stat(const char*, struct stat*); int stat(const char*, struct stat*);
......
...@@ -32,3 +32,4 @@ SYSCALL(uptime) ...@@ -32,3 +32,4 @@ SYSCALL(uptime)
SYSCALL(getChildren) SYSCALL(getChildren)
SYSCALL(getCount) SYSCALL(getCount)
SYSCALL(changePriority) SYSCALL(changePriority)
SYSCALL(changePolicy)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment