问题描述
现在,似乎在每次单击滴答声后,正在运行的进程都被抢占并被迫屈服于处理器,我已经彻底研究了代码库,以下是处理抢占的唯一相关代码(请参见 trap.c ):
Right now it seems that on every click tick, the running process is preempted and forced to yield the processor, I have thoroughly investigated the code-base and the only relevant part of the code to process preemption is below (in trap.c):
// Force process to give up CPU on clock tick.
// If interrupts were on while locks held, would need to check nlock.
if(myproc() && myproc() -> state == RUNNING && tf -> trapno == T_IRQ0 + IRQ_TIMER)
yield();
我想计时是在T_IRQ0 + IRQ_TIMER
中指定的,但是我不知道如何修改这两个,在 trap.h 中指定了这两个:
I guess that timing is specified in T_IRQ0 + IRQ_TIMER
, but I can't figure out how these two can be modified, these two are specified in trap.h:
#define T_IRQ0 32 // IRQ 0 corresponds to int T_IRQ
#define IRQ_TIMER 0
我想知道如何更改默认的RR调度时间片(现在是1个时钟滴答,第一个示例将其设为10个时钟滴答)?
I wonder how I can change the default RR scheduling time-slice (which is right now 1 clock tick, fir example make it 10 clock-tick)?
推荐答案
如果您想要一个进程比其他进程执行更多的时间 ,则可以允许它使用更多的时间片,而无需更改时间片持续时间.
If you want a process to be executed more time than the others, you can allow it more timeslices, *without` changing the timeslice duration.
为此,您可以在struct proc
中添加一些extra_slice
和current_slice
并以这种方式修改TIMER陷阱处理程序:
To do so, you can add some extra_slice
and current_slice
in struct proc
and modify the TIMER trap handler this way:
if(myproc() && myproc()->state == RUNNING &&
tf->trapno == T_IRQ0+IRQ_TIMER)
{
int current = myproc()->current_slice;
if ( current )
myproc()->current_slice = current - 1;
else
yield();
}
然后,您只需要创建一个系统调用来设置extra_slice
并修改scheduler
函数以在进程唤醒时将current_slice
重置为extra_slice
:
Then you just have to create a syscall to set extra_slice
and modify the scheduler
function to reset current_slice
to extra_slice
at process wakeup:
// Switch to chosen process. It is the process's job
// to release ptable.lock and then reacquire it
// before jumping back to us.
c->proc = p;
switchuvm(p);
p->state = RUNNING;
p->current_slice = p->extra_slice
这篇关于如何在XV6中修改进程抢占策略(例如RR时间片)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!