windows2000中断处理

   在开始说windows2000 中断处理之前,先介绍几个名词:

  • trap:CPU中断正常的程序流程,转入到特定的地方.WINDOWS2000是把中断转给trap handler 

    Click to view at full size.

    Figure 1 Trap dispatching

  • interrupt:trap的一种(中断).他是一个异步时间(随时可能发生).与CPU的执行无关,主要由I/O,CPU时钟产生
  • exception:trap的一种(异常).与CPU执行有关.不用时间读相同程序肯定能产生相同的exception
  • trap handler:trap处理器
  • interrupt service routine(ISR):中断处理程序
  • interrupt request(IRQ):中断请求
  • interrupt dispatch table(IDT):一个把中断请求转成中断编号的表
  • programmable interrupt controller(PIC):可编程的中断控制器
  • advanced programmable interrupt control(APIC):加强型可编程的中断控制器
  • software interrupt levels(IRQLs):软件中断优先级
  • process control region(PCR):处理器控制区(包含了处理器目前的IRQL,IDT指针,正在执行的线程,下一个要执行的线程.etc.简单说就是一个描述处理器状态的结构)
  • interrupt object:中断对象(用来描述一个中断的对象,包括ISR地址,IRQL,内核中IDT的项.etc)
  • dispatch or deferred procedure call(DPC) interrupt:一种dispatch/延期例程调用中断(是一种IRQL)
  • asynchronous procedure call(APC) interrpt:一种异步例程调用中断(是一种IRQL)

介绍完了这些新名词之后,现在说下WINDOWS2000处理中断的过程.

硬件中断:

正如上面的图所画的.中断的处理是通过一种trap handler-interrupt trap handler来实现的.一个设备产生中断,内核中断处理器,然后把控制权交给ISR(是中断设备的驱动所提供的)或者内核提供的interrupt handling routines.

下面来详细的说下中断处理的过程:

  1. 外部的I/O中断进入interrupt controller的某一条线(interrupt controller有很多并行的中断线,让中断通过这些线来中断CPU).然后interrupt controller中断CPU.
  2. 一旦CPU被中断,就查询interrupt controller来得到IRQ.
  3. 然后interrupt controller通过查询IDT来得到相应的中断号.
  4. 最后把控制权交给合适的ISR(在系统启动的时候,WINDOWS2000会用各个中断的内核例程的指针来添满IDT)

下面来介绍一下interrupt controller.现在大部分x86体系结构都用了i8259A PIC或者 i8259A APIC.两者的区别在于后者支持多处理器

Figure 2 x86 APIC architecture

  • I/O APIC:接受来自设备的中断
  • Local APIC:接受来自I/O APIC的中断并中断他们所关联的CPU
  • i8259A-equivalent PIC:是一个APIC-PIC的处理器,他将APIC输入信号转成PIC输入信号

软件中断

在说软件中断之前,不得不说下IRQLs.内核把IRQLS分成了0-31个等级.

Click to view at full size.

Figure 3 Interrupt request levels (IRQLs)

处理器的IRQL只能在内核模式下被更改.

那么WINDOWS2000是怎么把中断映射到不同的IRQL的呢?IRQLs和IRQs不同,在硬件层中没有IRQLs.WINDOWS2000是通过HAL来实现这个映射的.在WINDOWS2000中有一种驱动叫做总线驱动.,他确定什么设备出现在了总线上,什么IRQ能被发派到这个设备上.在HAL把IRQ分配到每个设备上后,WINDOWS2000调用HAL的HalpGetSystemInterruptVector来映射中断到IRQLs.

下面就来说下软件中断,软件中断有以下几种:

  • Initiating thread dispatching

     

     

  • Non-time-critical interrupt processing

     

     

  • Handling timer expiration

     

     

  • Asynchronously executing a procedure in the context of a particular thread

     

     

  • Supporting asynchronous I/O operations
  • 下面重点说下DPC和APC:

    DPC:When a thread can no longer continue executing, perhaps because it has terminated or because it voluntarily enters a wait state, the kernel calls the dispatcher directly to effect an immediate context switch. Sometimes, however, the kernel detects that rescheduling should occur when it is deep within many layers of code. In this situation, the ideal solution is to request dispatching but defer its occurrence until the kernel completes its current activity. Using a DPC software interrupt is a convenient way to achieve this delay.

    DPCs provide the operating system with the capability to generate an interrupt and execute a system function in kernel mode. The kernel uses DPCs to process timer expiration (and release threads waiting on the timers) and to reschedule the processor after a thread's quantum expires. Device drivers use DPCs to complete I/O requests. To provide timely service for hardware interrupts, Windows 2000—with the cooperation of device drivers—attempts to keep the IRQL below device IRQL levels. One way that this goal is achieved is for device driver ISRs to perform the minimal work necessary to acknowledge their device, save volatile interrupt state, and defer data transfer or other less time-critical interrupt processing activity for execution in a DPC at DPC/dispatch IRQL

    Asynchronous procedure call (APC) interrupts Asynchronous procedure calls (APCs) provide a way for user programs and system code to execute in the context of a particular user thread (and hence a particular process address space). Because APCs are queued to execute in the context of a particular thread and run at an IRQL less than 2, they don't operate under the same restrictions as a DPC. An APC routine can acquire resources (objects), wait on object handles, incur page faults, and call system services.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值