C 如何在xv6中实现优先级调度程序?
在xv6中实现优先级调度算法 但我无法理解如何处理这方面的日程安排。 我能够使用此代码设置优先级C 如何在xv6中实现优先级调度程序?,c,scheduling,xv6,C,Scheduling,Xv6,在xv6中实现优先级调度算法 但我无法理解如何处理这方面的日程安排。 我能够使用此代码设置优先级 int set_priority(int pid,int priority) { struct proc *p; //acquire(&ptable.lock); //cprintf("Set Priority - %d \n",priority); for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
int
set_priority(int pid,int priority)
{
struct proc *p;
//acquire(&ptable.lock);
//cprintf("Set Priority - %d \n",priority);
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
if((p->pid == pid) || (p->parent->pid == pid)){
p->priority = priority;
return 0;
}
}
//release(&ptable.lock);
return -1;
}
int
设置优先级(整数pid,整数优先级)
{
结构程序*p;
//获取(&ptable.lock);
//cprintf(“设置优先级-%d\n”,优先级);
对于(p=ptable.proc;p<&ptable.proc[NPROC];p++){
如果((p->pid==pid)|(p->parent->pid==pid)){
p->优先级=优先级;
返回0;
}
}
//释放(&ptable.lock);
返回-1;
}
首先,您需要在struct proc
中添加一个字段(优先级)
struct proc{
//
....
int priority; // priority of the process
}
其次,您现在可以在proc.c
中编写自己的调度程序
void scheduler(void){
for(;;){
//add your own priority scheduler here.
}
}