为什么不需要 CPU 来处理 I/O 请求? [英] Why is the CPU not needed to service I/O requests?

查看:41
本文介绍了为什么不需要 CPU 来处理 I/O 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习操作系统,但有一个我无法理解的小概念.假设进程 1 在 CPU 上运行,然后它发出 I/O 请求从磁盘读取.为提高效率,CPU 在处理此请求时开始执行进程 2.这一切都说得通,但 I/O 不需要使用 CPU 吗?

I am learning about operating systems but there is a small concept I cannot grasp. Say a process 1 is running on the CPU and then it issues an I/O request to read from a disk. For efficiency, the CPU begins executing process 2 as this request is handled. That all makes sense but doesn't the I/O need to use the CPU?

我的问题:为什么不需要 CPU 来服务进程 1 的请求?

My Question: Why isn't the CPU needed to service process 1's request?

推荐答案

这将有助于理解 I/O 的 3 个重要方面在计算机架构中的作用:中断、DMA 和硬件控制器.

It would help to understand the role of 3 important aspects of I/O in computer architecture: Interrupts, DMA, and Hardware Controllers.

当 CPU 向硬盘发出 I/O 请求时,硬盘有自己的专用芯片,称为设备(或硬件)控制器,专门用于处理来自 CPU 的命令,例如从磁盘读取.最初这些是为 CPU 执行特定操作的简单芯片,但现代硬件控制器基本上是它们自己的微处理器,带有固件和一切,因此它们能够在没有主 CPU 帮助的情况下进行非常复杂的操作.当硬盘驱动器的控制器忙于执行请求时,主 CPU 可以自由地做任何它想做的事情,例如在您的示例中执行进程 2.控制器能够使用所谓的直接内存访问 (DMA) 控制器直接从系统 RAM 读取和写入,这是一个特殊的单元,可将数据从硬件控制器传输到主 RAM,而 CPU 无需执行任何操作.

When the CPU issues an I/O request to the hard disk, the hard disk has its own specialized chip called a device (or hardware) controller designed solely for processing commands from the CPU, such as reading from the disk. Originally these were simple chips that performed specific operations for the CPU, but modern hardware controllers are basically their own microprocessors with firmware and everything, so they are capable of very complex operations without the main CPU's help. While the hard drive's controller is busy performing the request, the main CPU is free to do whatever it wishes, such as execute process 2 in your example. The controller is able to read and write directly to and from system RAM using what is called a Direct Memory Access (DMA) controller, a special unit that transfers data from the hardware controller to main RAM without the CPU needing to do anything.

当硬盘驱动器完成请求并且相关数据已通过 DMA 加载到 RAM 中时,它会发出一个中断请求,通知 CPU 数据已加载到 RAM 中.此时,CPU 可以将控制权转移回进程 1.因此,CPU 不需要对所有涉及 I/O 的任务进行微观管理.曾经是这种情况,但发明了这些技巧(中断、DMA、特殊控制器)是为了提高 CPU 性能并提高效率.

When the hard drive is done with the request and the relevant data has been loaded into RAM through DMA, it issues an interrupt request which informs the CPU that the data has been loaded into RAM. At this point the CPU can transfer control back to process 1. Thus, the CPU does not need to micromanage all tasks involved with I/O. At one time this used to be the case, but these tricks (interrupts, DMA, special controllers) were invented in order to improve CPU performance and make things more efficient.

这篇关于为什么不需要 CPU 来处理 I/O 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆