Commit 8f8d871c authored by Amir Hosein Kashani's avatar Amir Hosein Kashani

before testing 3.2

parent 616316e1
......@@ -324,6 +324,7 @@ scheduler(void)
{
struct proc *p;
struct cpu *c = mycpu();
struct proc *p1;
c->proc = 0;
for(;;){
......@@ -336,6 +337,23 @@ scheduler(void)
if(p->state != RUNNABLE)
continue;
//choose highest priority
struct proc* minimum = ptable.proc ;
for(p1 = ptable.proc ; p1 <&ptable.proc[NPROC];p1++){
if(p1->state != RUNNABLE){
continue;
}
if(minimum->calculatedPriority > (p1->calculatedPriority)){
minimum = p1;
}
}
minimum-> calculatedPriority += minimum ->priority;
//for controling larg int and destroy negative priority
if(minimum->calculatedPriority<0){
minimum->calculatedPriority = 0;
}
p = minimum;
// Switch to chosen process. It is the process's job
// to release ptable.lock and then reacquire it
// before jumping back to us.
......
......@@ -39,6 +39,7 @@ struct proc {
int usagepointer;
int usage[100];
int priority;
int calculatedPriority;
uint sz; // Size of process memory (bytes)
pde_t* pgdir; // Page table
char *kstack; // Bottom of kernel stack for this process
......
......@@ -105,6 +105,7 @@ extern int sys_write(void);
extern int sys_uptime(void);
extern int sys_getChildren(void);
extern int sys_getCount(void);
extern int sys_changePriority(void);
static int (*syscalls[])(void) = {
[SYS_fork] sys_fork,
......@@ -129,7 +130,8 @@ static int (*syscalls[])(void) = {
[SYS_mkdir] sys_mkdir,
[SYS_close] sys_close,
[SYS_getChildren] sys_getChildren,
[SYS_getCount] sys_getCount
[SYS_getCount] sys_getCount,
[SYS_changePriority] sys_changePriority
};
void
......
......@@ -22,3 +22,4 @@
#define SYS_close 21
#define SYS_getChildren 22
#define SYS_getCount 23
#define SYS_changePriority 24
......@@ -138,6 +138,20 @@ sys_getCount(int find){
return counter;
}
//3.2
int
changePriority(int newPriority){
argint(0,&newPriority);
if(newPriority > 5 || newPriority < 0){
return -1;
}
myproc()->calculatedPriority = newPriority;
myproc()->priority = newPriority ;
return 5;
}
......
......@@ -25,6 +25,7 @@ int sleep(int);
int uptime(void);
int getChildren(int);
int getCount(int);
int changePriority(int);
// ulib.c
int stat(const char*, struct stat*);
......
......@@ -31,3 +31,4 @@ SYSCALL(sleep)
SYSCALL(uptime)
SYSCALL(getChildren)
SYSCALL(getCount)
SYSCALL(changePriority)
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