操作系统如何知道I/O操作何时完成执行?
考虑情况,您可以从光盘(I/O操作)中发出阅读。那么,操作系统用来了解操作是否已执行的确切机制是什么?
Consider the situation, where you issue a read from the disc (I/O operation). Then what is the exact mechanism that the OS uses to get to know whether the operation has been executed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确切的机制取决于特定的硬件(以及OS和方案);但是通常,当设备完成某些操作时,设备会触发一个IRQ,该IRQ会导致CPU中断其所做的任何事情并切换到设备驱动程序的中断处理程序。
有时/经常设备驱动程序最终会保持待处理命令的队列或缓冲区;因此,当执行其中断处理程序(告诉它已经完成了一个命令)时,请采用下一个待处理命令并告诉设备启动它。有时/通常这还包括某种IO优先级方案,驾驶员可以要求设备更快地做更重要的工作(而不太重要的工作被推迟/仍在待处理中)。
设备驱动程序通常还以某种方式与调度程序绑定 - 用户空间中的正常线程可能(例如直接或间接 - 通过。文件系统)请求数据传输数据,并且将告知调度程序不给该线程CPU时间因为它被阻止/等待某物;然后,当传输完成后,设备驱动程序的中断处理程序告诉调度程序,请求线程可以继续,从而使其被调度程序未经阻止/可以通过调度程序给予CPU时间。
The exact mechanism depends on the specific hardware (and OS and scenario); but typically when a device finishes doing something the device triggers an IRQ that causes the CPU to interrupt whatever it was doing and switch to a device driver's interrupt handler.
Sometimes/often device driver ends up maintaining a queue or buffer of pending commands; so that when its interrupt handler is executed (telling it that a previous command has completed) it takes the next pending command and tells the device to start it. Sometimes/often this also includes some kind of IO priority scheme, where driver can ask device to do more important work sooner (while less important work is postponed/remains pending).
A device driver is typically also tied to scheduler in some way - a normal thread in user-space might (directly or indirectly - e.g. via. file system) request that data be transferred and the scheduler will be told to not give that thread CPU time because it's blocked/waiting for something; and then later when the transfer is completed the device driver's interrupt handler tells the scheduler that the requesting thread can continue, causing it to be unblocked/able to be given CPU time by scheduler again.