📜  编程 I/O 和中断启动 I/O 之间的区别

📅  最后修改于: 2021-09-28 11:09:41             🧑  作者: Mango

先决条件 – I/O 接口(中断和 DMA 模式)
CPU 和 I/O 设备之间的数据传输可以采用多种模式进行。这是三种可能的模式:

  1. 编程输入/输出
  2. 中断发起的 I/O
  3. 直接内存访问 (DMA)

在本文中,我们将只讨论前两种模式。

1. 可编程输入/输出:
在这种模式下,数据传输由编写在计算机程序中的指令启动。需要输入指令将数据从设备存储到 CPU,并且需要存储指令将数据从 CPU 传输到设备。通过这种模式进行的数据传输需要 CPU 对外围设备进行持续监控,并且一旦传输开始,还要监控新传输的可能性。因此,CPU 一直处于循环状态,直到 I/O 设备指示它已准备好进行数据传输。因此,编程的 I/O 是一个耗时的过程,它使处理器不必要地忙碌并导致 CPU 周期的浪费。
这可以通过使用中断工具来克服。这构成了中断启动 I/O 的基础。

2. 中断发起的 I/O :
该模式使用中断设施和特殊命令来通知接口在数据可用且接口准备好进行数据传输时发出中断命令。与此同时,CPU 继续执行其他任务,无需检查标志。当标志被设置时,接口被通知并发起中断。该中断导致 CPU 偏离其响应 I/O 传输的操作。 CPU 通过将程序计数器 (PC) 的返回地址存储到内存堆栈中来响应该信号,然后分支到处理 I/O 请求的服务。传输完成后,CPU 返回到它正在执行的前一个任务。可以通过向量中断和非向量中断两种方式选择服务的分支地址。在向量中断中,中断源向 CPU 提供分支信息,而在非向量中断的情况下,分支地址被分配到内存中的固定位置。

编程和中断启动 I/O 之间的区别:

Programmed I/O Interrupt Initiated I/O
Data transfer is initiated by the means of instructions stored in the computer program. Whenever there is a request for I/O transfer the instructions are executed from the program. The I/O transfer is initiated by the interrupt command issued to the CPU.
The CPU stays in the loop to know if the device is ready for transfer and has to continuously monitor the peripheral device. There is no need for the CPU to stay in the loop as the interrupt command interrupts the CPU when the device is ready for data transfer.
This leads to the wastage of CPU cycles as CPU remains busy needlessly and thus the efficiency of system gets reduced. The CPU cycles are not wasted as CPU continues with other work during this time and hence this method is more efficient.
CPU cannot do any work until the transfer is complete as it has to stay in the loop to continuously monitor the peripheral device. CPU can do any other work until it is interrupted by the command indicating the readiness of device for data transfer
Its module is treated as a slow module. Its module is faster than programmed I/O module.
It is quite easy to program and understand. It can be tricky and complicated to understand if one uses low level language.
The performance of the system is severely degraded. The performance of the system is enhanced to some extent.