Windows 中的中断处理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/712678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:15:18  来源:igfitidea点击:

Interrupt processing in Windows

windowsinterrupt

提问by Canopus

I want to know which threads processes device interrupts. What happens when there is a interrupt when a user mode thread is running? Also do other user threads get a chance to run when the system is processing an interrupt?

我想知道哪些线程处理设备中断。当用户模式线程正在运行时出现中断会发生什么?当系统处理中断时,其他用户线程也有机会运行吗?

Kindly suggest me some reference material describing how interrupts are handled by windows.

请给我推荐一些描述 Windows 如何处理中断的参考资料。

采纳答案by RBerteig

Device interrupts themselves are (usually) processed by whatever thread had the CPU that took the interrupt, but in a ring 0 and at a different protection level. This limits some of the actions an interrupt handler can take, because most of the time the current thread will not be related to the thread that is waiting for the event to happen that the interrupt is indicating.

设备中断本身(通常)由拥有中断中断的 CPU 的任何线程处理,但在环 0 中并处于不同的保护级别。这限制了中断处理程序可以采取的一些操作,因为在大多数情况下,当前线程与正在等待中断指示的事件发生的线程无关。

The kernel itself is closed source, and only documented through its internal API. That API is exposed to device driver authors, and described in the driver development kits.

内核本身是封闭源代码,仅通过其内部 API 进行记录。该 API 向设备驱动程序作者公开,并在驱动程序开发工具包中进行了描述。

Some resources to get you started:

一些帮助您入门的资源:

  • Any edition of Microsoft Windows Internalsby Solomon and Russinovich. The current seems to be the 4th edition, but even an old edition will help.

  • The Windows DDK, now renamed the WDK. Its documentation is available onlinetoo. Be sure to read the Kernel Mode Design Guide...

  • Sysinternalshas tools and articles to probe at and explain the kernel's behavior. This used to be an independent site until Microsoft got tired of Mark Russinovich seeming to know more about how the kernel worked than they did. ;-)

  • Solomon 和 Russinovich 编写的任何版本的Microsoft Windows Internals。当前似乎是第 4 版,但即使是旧版也会有所帮助。

  • Windows DDK,现在更名为WDK. 它的文档也可以在线获取。请务必阅读内核模式设计指南...

  • Sysinternals提供工具和文章来探究和解释内核的行为。这曾经是一个独立的站点,直到微软厌倦了 Mark Russinovich 似乎比他们更了解内核的工作原理。;-)

Note that source code to many of the common device drivers are included in the DDK in the samples. Although the production versions are almost certainly different, reading the sample drivers can answer some questions even if you don't want to implement a driver yourself.

请注意,示例中的 DDK 中包含许多常见设备驱动程序的源代码。尽管生产版本几乎肯定会有所不同,但即使您不想自己实现驱动程序,阅读示例驱动程序也可以回答一些问题。

回答by John Saunders

Like any other operating system, Windows processes interrupts in Kernel mode, with an elevated Interrupt Priority Level (I think they call them IRPL's, but I don't know what the "R" stands for). Any user thread or lower-level Kernel thread running on the same machine will be interrupted while the interrupt request is processed, and will be resumed when the ineterrupt processing is complete.

与任何其他操作系统一样,Windows 以内核模式处理中断,并具有更高的中断优先级(我认为他们称它们为 IRPL,但我不知道“R”代表什么)。任何运行在同一台机器上的用户线程或低级内核线程在处理中断请求时都会被中断,并在中断处理完成时恢复。

回答by kgiannakakis

In order to learn more about device interrupts on Windows you need to study device driver development. This is a niche topic, I don't think you can find many useful resources in the Web and you may have to look for a book or a training course.

为了了解有关 Windows 上设备中断的更多信息,您需要学习设备驱动程序开发。这是一个小众话题,我认为您无法在 Web 上找到很多有用的资源,您可能需要寻找一本书或培训课程。

Anyway, Windows handle interrupts with Interrupt Request Levels (IRQLs) and Deferred procedure calls. An interrupt is handled in Kernel mode, which runs in higher priority than user mode. A proper interrupt handler needs to react very quickly. It only performs the absolutely necessary operations and registers a Deferred Procedure Call to run in the future. This will happen, when the system is in a Interrupt Request Level.

无论如何,Windows 使用中断请求级别 (IRQL) 和延迟过程调用来处理中断。中断在内核模式下处理,内核模式运行的优先级高于用户模式。一个合适的中断处理程序需要非常快速地做出反应。它只执行绝对必要的操作并注册一个延迟过程调用以在将来运行。当系统处于中断请求级别时,就会发生这种情况。