我今晚有一个操作系统项目,需要澄清一个主题。我们正在使用操作系统 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 秒说一次...我不明白时钟是如何工作的或组装完全。我不是要求有人给我一个解决方案,我只是需要一些指导。