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

查看:1165
本文介绍了为什么不需要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在计算机体系结构中的三个重要方面的作用:中断,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 chip that transfers data from the hardware controller to main RAM without the CPU needing to do anything.

当硬盘完成请求并且相关数据已通过DMA加载到RAM中时,它会发出中断请求,通知CPU数据已加载到内存。此时,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 a lot more efficient.

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

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