我今晚有一个操作系统项目,需要澄清一个主题。我们正在使用XINU操作系统。我正在尝试更改默认的操作系统调度程序,以解决某些流程被饿死的问题。我被指向clkint.S文件,我认为它是时钟中断处理程序。我的问题是,我如何知道它中断的频率?如何设置每5秒钟进行一次函数调用的时间?我查看过intel x86手册,但是他们有大量的信息需要筛选,我的时间很短如果有人能指出我正确的方向,我将不胜感激。
以下是我认为必要的几个文件:
clkint.S:
/* clkint.s - _clkint */
#include <icu.s>
.text
count1000: .word 1000
.globl sltop
.globl clkint
clkint:
pushal
cli
movb $EOI,%al
outb %al,$OCW1_2
incl ctr1000
subw $1,count1000
ja cl1
incl clktime
movw $1000,count1000
cl1:
cmpl $0,slnonempty # if no sleeping processes,
je clpreem # skip to preemption check
movl sltop,%eax # decrement key of first
decl (%eax) # sleeping process
jg clpreem # must use jg for signed int
call wakeup # if zero, call wakeup
clpreem: decl preempt # decrement preemption counter
jg clret # must use jg for signed int
call resched # if preemption, call resched
clret: # return from interrupt
sti
popal
iret
clkinit.c:
/* clkinit.c - clkinit */
#include <xinu.h>
#include <interrupt.h>
#include <clock.h>
uint32 clktime; /* seconds since boot */
uint32 ctr1000 = 0; /* milliseconds since boot */
qid16 sleepq; /* queue of sleeping processes */
int32 slnempty; /* zero if the sleep queue is empty; */
/* non-zero otherwise */
int32 *sltop; /* ptr to key in first entry of sleepq */
/* if sleepq is not empty */
uint32 preempt; /* preemption counter */
/*------------------------------------------------------------------------
* clkinit - initialize the clock and sleep queue at startup
*------------------------------------------------------------------------
*/
void clkinit(void)
{
uint16 intv; /* clock rate in KHz */
/* Set interrupt vector for clock to invoke clkint */
set_evec(IRQBASE, (uint32)clkint);
/* clock rate is 1.190 Mhz; this is 10ms interrupt rate */
intv = 1190;
sleepq = newqueue(); /* allocate a queue to hold the delta */
/* list of sleeping processes */
preempt = QUANTUM; /* initial time quantum */
/* Specify that seepq is initially empty */
slnonempty = FALSE;
clktime = 0; /* start counting seconds */
/* set to: timer 0, 16-bit counter, rate generator mode,
counter is binary */
outb(CLKCNTL, 0x34);
/* must write LSB first, then MSB */
outb(CLOCK0, (char)intv);
outb(CLOCK0, intv>>8);
return;
}
clkhandler.c:
/* clkhandler.c - clkhandler */
#include <xinu.h>
/*------------------------------------------------------------------------
* clkhandler - handle clock interrupt and process preemption events
* as well as awakening sleeping processes
*------------------------------------------------------------------------
*/
interrupt clkhandler(void)
{
clkupdate(CLKCYCS_PER_TICK);
/* record clock ticks */
clkticks++;
/* update global counter for seconds */
if (clkticks == CLKTICKS_PER_SEC) {
clktime++;
clkticks = 0;
}
/* If sleep queue is nonempty, decrement first key; when the */
/* key reaches zero, awaken a sleeping process */
if (nonempty(sleepq) && (--firstkey(sleepq) <= 0)) {
wakeup();
}
/* Check to see if this proc should be preempted */
if (--preempt <= 0) {
preempt = QUANTUM;
resched();
}
return;
}
我可以自己添加所有的饥饿功能,我只需要弄清楚如何使clkint.s处理程序调用我的函数让我们说每隔5秒A ...我不明白时钟是如何工作的或完全组装。我不是要求别人给我一个解决方案,我只需要一些指导。
答案 0 :(得分:2)
intv
是用于调度的中断计时器的切片粒度(以Khz为单位)(至少在此代码中)。每5秒听起来很慢,可能会使你的系统几乎没有响应,尝试毫秒级。
要计算新的间隔,您需要更改此值并对频率进行一些计算。您可以从intv
上的计算中得出这一步,得到10毫秒。
在x86中,可以通过使用0x40
汇编指令将定时器中断值(KHz)写入端口outb
来建立定时器值。如代码所示,您必须写入最低有效字节,然后是最高有效字节(outb
一次写入一个字节)。要启用计时器,请将0x36
写入同一端口,并且必须将IRQ处理程序绑定到IRQ0才能接收中断。我尝试为你缩小信息,但这是特定于x86的。